[compiler] Sidestep optimizing of generator resumers.

This ensures our optimizing compilers as well as the interpreter are
never tasked with compiling the generator-resuming builtin methods. The
corresponding intrinsics for those methods are not supported and it is
not possible to provide a C++ reference implementation for them. We do
this by assigning builtin function ids to them that we can recognize
during the compiler dispatch.

Note that this also affects the interpreter, because methods having a
builtin function id assigned are not interpreted ({function_data} field
is overlapping). If this ever changes we can still do an early check in
the compiler dispatch (similar to the optimizing compilers) easily.

This applies to the following methods:
- Generator.prototype.next (calls Runtime_GeneratorNext).
- Generator.prototype.return (calls Runtime_GeneratorReturn).
- Generator.prototype.throw (calls Runtime_GeneratorThrow).

R=neis@chromium.org
BUG=v8:4681
LOG=n

Review URL: https://codereview.chromium.org/1779123003

Cr-Commit-Position: refs/heads/master@{#34675}
This commit is contained in:
mstarzinger 2016-03-10 06:06:05 -08:00 committed by Commit bot
parent daea0e7518
commit 855176533c
8 changed files with 47 additions and 184 deletions

View File

@ -89,6 +89,7 @@ namespace internal {
"The function_data field should be a BytecodeArray on interpreter entry") \
V(kGeneratedCodeIsTooLarge, "Generated code is too large") \
V(kGeneratorFailedToResume, "Generator failed to resume") \
V(kGeneratorResumeMethod, "Generator resume method is being called") \
V(kGenerator, "Generator") \
V(kGlobalFunctionsMustHaveInitialMap, \
"Global functions must have initial map") \

View File

@ -2745,6 +2745,37 @@ bool Genesis::InstallNatives(GlobalContextType context_type) {
InstallBuiltinFunctionIds();
// Also install builtin function ids to some generator object methods. These
// three methods use the three resume operations (Runtime_GeneratorNext,
// Runtime_GeneratorReturn, Runtime_GeneratorThrow) respectively. Those
// operations are not supported by Crankshaft, TurboFan, nor Ignition.
{
Handle<JSObject> generator_object_prototype(JSObject::cast(
native_context()->generator_object_prototype_map()->prototype()));
{ // GeneratorObject.prototype.next
Handle<String> key = factory()->next_string();
Handle<JSFunction> function = Handle<JSFunction>::cast(
JSReceiver::GetProperty(generator_object_prototype, key)
.ToHandleChecked());
function->shared()->set_builtin_function_id(kGeneratorObjectNext);
}
{ // GeneratorObject.prototype.return
Handle<String> key = factory()->NewStringFromAsciiChecked("return");
Handle<JSFunction> function = Handle<JSFunction>::cast(
JSReceiver::GetProperty(generator_object_prototype, key)
.ToHandleChecked());
function->shared()->set_builtin_function_id(kGeneratorObjectReturn);
}
{ // GeneratorObject.prototype.throw
Handle<String> key = factory()->throw_string();
Handle<JSFunction> function = Handle<JSFunction>::cast(
JSReceiver::GetProperty(generator_object_prototype, key)
.ToHandleChecked());
function->shared()->set_builtin_function_id(kGeneratorObjectThrow);
}
}
// Create a map for accessor property descriptors (a variant of JSObject
// that predefines four properties get, set, configurable and enumerable).
{

View File

@ -383,6 +383,14 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
return AbortOptimization(kFunctionBeingDebugged);
}
// Resuming a suspended frame is not supported by Crankshaft/TurboFan.
if (info()->shared_info()->HasBuiltinFunctionId() &&
(info()->shared_info()->builtin_function_id() == kGeneratorObjectNext ||
info()->shared_info()->builtin_function_id() == kGeneratorObjectReturn ||
info()->shared_info()->builtin_function_id() == kGeneratorObjectThrow)) {
return AbortOptimization(kGeneratorResumeMethod);
}
// Limit the number of times we try to optimize functions.
const int kMaxOptCount =
FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000;

View File

@ -2568,22 +2568,12 @@ void AstGraphBuilder::VisitCallRuntime(CallRuntime* expr) {
return VisitCallJSRuntime(expr);
}
const Runtime::Function* function = expr->function();
// TODO(mstarzinger): This bailout is a gigantic hack, the owner is ashamed.
if (function->function_id == Runtime::kInlineGeneratorNext ||
function->function_id == Runtime::kInlineGeneratorReturn ||
function->function_id == Runtime::kInlineGeneratorThrow) {
ast_context()->ProduceValue(jsgraph()->TheHoleConstant());
return SetStackOverflow();
}
// Evaluate all arguments to the runtime call.
ZoneList<Expression*>* args = expr->arguments();
VisitForValues(args);
// Create node to perform the runtime call.
Runtime::FunctionId functionId = function->function_id;
Runtime::FunctionId functionId = expr->function()->function_id;
const Operator* call = javascript()->CallRuntime(functionId, args->length());
FrameStateBeforeAndAfter states(this, expr->CallId());
Node* value = ProcessArguments(call, args->length());

View File

@ -6622,6 +6622,9 @@ class Script: public Struct {
enum BuiltinFunctionId {
kArrayCode,
kGeneratorObjectNext,
kGeneratorObjectReturn,
kGeneratorObjectThrow,
#define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \
k##name,
FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID)

View File

@ -203,26 +203,23 @@ RUNTIME_FUNCTION(Runtime_GeneratorGetSourcePosition) {
return isolate->heap()->undefined_value();
}
// Optimization for the following three functions is disabled in
// js/generator.js and compiler/ast-graph-builder.cc.
// Optimization for builtins calling any of the following three functions is
// disabled in js/generator.js and compiler.cc, hence they are unreachable.
RUNTIME_FUNCTION(Runtime_GeneratorNext) {
UNREACHABLE();
return nullptr;
}
RUNTIME_FUNCTION(Runtime_GeneratorReturn) {
UNREACHABLE();
return nullptr;
}
RUNTIME_FUNCTION(Runtime_GeneratorThrow) {
UNREACHABLE();
return nullptr;
}
} // namespace internal
} // namespace v8

View File

@ -767,7 +767,6 @@
'debug-allscopes-on-debugger': [FAIL],
'debug-return-value': [FAIL],
'es6/debug-stepnext-for': [FAIL],
'es6/debug-stepin-generators': [FAIL],
'es6/debug-stepin-string-template': [FAIL],
'es6/debug-promises/stepin-constructor': [FAIL],
'harmony/debug-stepin-proxies': [FAIL],
@ -799,38 +798,18 @@
'regress/regress-crbug-424142': [SKIP],
# TODO(rmcilroy,4681): Requires support for generators.
'messages': [FAIL],
'es6/array-from': [FAIL],
'regress-3225': [FAIL],
'es6/classes-subclass-builtins': [FAIL],
'es6/computed-property-names-classes': [FAIL],
'es6/computed-property-names-object-literals-methods': [FAIL],
'es6/generators-poisoned-properties': [FAIL],
'es6/generators-runtime': [FAIL],
'es6/generators-parsing': [FAIL],
'es6/generators-iteration': [FAIL],
'es6/generators-states': [FAIL],
'es6/iteration-semantics': [FAIL],
'es6/generators-mirror': [FAIL],
'es6/object-literals-method': [FAIL],
'es6/object-literals-super': [FAIL],
'es6/generators-relocation': [FAIL],
'es6/spread-array': [FAIL],
'es6/generators-debug-liveedit': [FAIL],
'es6/spread-call': [FAIL],
'es6/typedarray-from': [FAIL],
'es6/typedarray': [FAIL],
'es6/regress/regress-2681': [FAIL],
'es6/regress/regress-2691': [FAIL],
'es6/regress/regress-3280': [FAIL],
'harmony/destructuring-assignment': [FAIL],
'harmony/function-sent': [FAIL],
'harmony/destructuring': [FAIL],
'harmony/regress/regress-4482': [FAIL],
'harmony/generators': [FAIL],
'harmony/iterator-close': [FAIL],
'harmony/reflect-construct': [FAIL],
'es6/promises': [FAIL],
# TODO(mythria, 4780): Related to type feedback for calls in interpreter.
'array-literal-feedback': [FAIL],

View File

@ -424,56 +424,13 @@
'built-ins/GeneratorFunction/invoked-as-function-multiple-arguments': [FAIL],
'built-ins/GeneratorFunction/invoked-as-function-no-arguments': [FAIL],
'built-ins/GeneratorFunction/invoked-as-function-single-argument': [FAIL],
'built-ins/GeneratorPrototype/next/consecutive-yields': [FAIL],
'built-ins/GeneratorPrototype/next/context-method-invocation': [FAIL],
'built-ins/GeneratorPrototype/next/from-state-executing': [FAIL],
'built-ins/GeneratorPrototype/next/lone-return': [FAIL],
'built-ins/GeneratorPrototype/next/lone-yield': [FAIL],
'built-ins/GeneratorPrototype/next/no-control-flow': [FAIL],
'built-ins/GeneratorPrototype/next/result-prototype': [FAIL],
'built-ins/GeneratorPrototype/next/return-yield-expr': [FAIL],
'built-ins/GeneratorPrototype/return/from-state-completed': [FAIL],
'built-ins/GeneratorPrototype/return/from-state-executing': [FAIL],
'built-ins/GeneratorPrototype/return/from-state-suspended-start': [FAIL],
'built-ins/GeneratorPrototype/return/try-catch-before-try': [FAIL],
'built-ins/GeneratorPrototype/return/try-catch-following-catch': [FAIL],
'built-ins/GeneratorPrototype/return/try-catch-within-catch': [FAIL],
'built-ins/GeneratorPrototype/return/try-catch-within-try': [FAIL],
'built-ins/GeneratorPrototype/return/try-finally-before-try': [FAIL],
'built-ins/GeneratorPrototype/return/try-finally-following-finally': [FAIL],
'built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-catch': [FAIL],
'built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-finally': [FAIL],
'built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-inner-try': [FAIL],
'built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-after-nested': [FAIL],
'built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-before-nested': [FAIL],
'built-ins/GeneratorPrototype/return/try-finally-within-finally': [FAIL],
'built-ins/GeneratorPrototype/return/try-finally-within-try': [FAIL],
'built-ins/GeneratorPrototype/Symbol.toStringTag': [FAIL],
'built-ins/GeneratorPrototype/throw/from-state-completed': [FAIL],
'built-ins/GeneratorPrototype/throw/from-state-executing': [FAIL],
'built-ins/GeneratorPrototype/throw/from-state-suspended-start': [FAIL],
'built-ins/GeneratorPrototype/throw/try-catch-before-try': [FAIL],
'built-ins/GeneratorPrototype/throw/try-catch-following-catch': [FAIL],
'built-ins/GeneratorPrototype/throw/try-catch-within-catch': [FAIL],
'built-ins/GeneratorPrototype/throw/try-catch-within-try': [FAIL],
'built-ins/GeneratorPrototype/throw/try-finally-before-try': [FAIL],
'built-ins/GeneratorPrototype/throw/try-finally-following-finally': [FAIL],
'built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-catch': [FAIL],
'built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-finally': [FAIL],
'built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-inner-try': [FAIL],
'built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-after-nested': [FAIL],
'built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-before-nested': [FAIL],
'built-ins/GeneratorPrototype/throw/try-finally-within-finally': [FAIL],
'built-ins/GeneratorPrototype/throw/try-finally-within-try': [FAIL],
'built-ins/TypedArrays/object-arg-as-generator-iterable-returns': [FAIL],
'built-ins/TypedArrays/object-arg-iterating-throws': [FAIL],
'language/default-parameters/generators': [FAIL],
'language/expressions/assignment/destructuring/array-elem-init-yield-expr': [FAIL],
'language/expressions/assignment/destructuring/array-elem-nested-array-yield-expr': [FAIL],
'language/expressions/assignment/destructuring/array-elem-nested-obj-yield-expr': [FAIL],
'language/expressions/assignment/destructuring/array-elem-target-yield-expr': [FAIL],
'language/expressions/assignment/destructuring/array-iteration': [FAIL],
'language/expressions/assignment/destructuring/array-rest-iteration': [FAIL],
'language/expressions/assignment/destructuring/array-rest-nested-array-yield-expr': [FAIL],
'language/expressions/assignment/destructuring/array-rest-nested-obj-yield-expr': [FAIL],
'language/expressions/assignment/destructuring/array-rest-yield-expr': [FAIL],
@ -482,104 +439,15 @@
'language/expressions/assignment/destructuring/obj-prop-elem-target-yield-expr': [FAIL],
'language/expressions/assignment/destructuring/obj-prop-nested-array-yield-expr': [FAIL],
'language/expressions/assignment/destructuring/obj-prop-nested-obj-yield-expr': [FAIL],
'language/expressions/generators/implicit-name': [FAIL],
'language/expressions/generators/no-name': [FAIL],
'language/expressions/generators/no-yield': [FAIL],
'language/expressions/generators/return': [FAIL],
'language/expressions/generators/yield-as-expression-without-rhs': [FAIL],
'language/expressions/generators/yield-as-expression-with-rhs': [FAIL],
'language/expressions/generators/yield-as-function-expression-binding-identifier': [FAIL],
'language/expressions/generators/yield-as-identifier-in-nested-function': [FAIL],
'language/expressions/generators/yield-as-literal-property-name': [FAIL],
'language/expressions/generators/yield-as-property-name': [FAIL],
'language/expressions/generators/yield-as-statement': [FAIL],
'language/expressions/generators/yield-as-yield-operand': [FAIL],
'language/expressions/generators/yield-newline': [FAIL],
'language/expressions/generators/yield-star-before-newline': [FAIL],
'language/expressions/object/concise-generator': [FAIL],
'language/expressions/object/method-definition/generator-invoke-fn-no-strict': [FAIL],
'language/expressions/object/method-definition/generator-invoke-fn-strict': [FAIL],
'language/expressions/object/method-definition/generator-no-yield': [FAIL],
'language/expressions/object/method-definition/generator-params': [FAIL],
'language/expressions/object/method-definition/generator-prop-name-yield-expr': [FAIL],
'language/expressions/object/method-definition/generator-return': [FAIL],
'language/expressions/object/method-definition/generator-super-prop-body': [FAIL],
'language/expressions/object/method-definition/generator-super-prop-param': [FAIL],
'language/expressions/object/method-definition/name-prop-name-yield-expr': [FAIL],
'language/expressions/object/method-definition/yield-as-expression-without-rhs': [FAIL],
'language/expressions/object/method-definition/yield-as-expression-with-rhs': [FAIL],
'language/expressions/object/method-definition/yield-as-function-expression-binding-identifier': [FAIL],
'language/expressions/object/method-definition/yield-as-generator-method-binding-identifier': [FAIL],
'language/expressions/object/method-definition/yield-as-identifier-in-nested-function': [FAIL],
'language/expressions/object/method-definition/yield-as-literal-property-name': [FAIL],
'language/expressions/object/method-definition/yield-as-property-name': [FAIL],
'language/expressions/object/method-definition/yield-as-statement': [FAIL],
'language/expressions/object/method-definition/yield-as-yield-operand': [FAIL],
'language/expressions/object/method-definition/yield-newline': [FAIL],
'language/expressions/object/method-definition/yield-return': [FAIL],
'language/expressions/object/method-definition/yield-star-before-newline': [FAIL],
'language/expressions/yield/arguments-object-attributes': [FAIL],
'language/expressions/yield/captured-free-vars': [FAIL],
'language/expressions/yield/expr-value-specified': [FAIL],
'language/expressions/yield/expr-value-unspecified': [FAIL],
'language/expressions/yield/formal-parameters-after-reassignment-non-strict': [FAIL],
'language/expressions/yield/formal-parameters-after-reassignment-strict': [FAIL],
'language/expressions/yield/formal-parameters': [FAIL],
'language/expressions/yield/from-catch': [FAIL],
'language/expressions/yield/from-try': [FAIL],
'language/expressions/yield/from-with': [FAIL],
'language/expressions/yield/star-array': [FAIL],
'language/expressions/yield/star-iterable': [FAIL],
'language/expressions/yield/star-string': [FAIL],
'language/expressions/yield/then-return': [FAIL],
'language/expressions/yield/within-for': [FAIL],
'language/expressions/yield/yield-expr': [FAIL],
'language/object-literal/concise-generator': [FAIL],
'language/statements/class/definition/methods-gen-no-yield': [FAIL],
'language/statements/class/definition/methods-gen-return': [FAIL],
'language/statements/class/definition/methods-gen-yield-as-expression-without-rhs': [FAIL],
'language/statements/class/definition/methods-gen-yield-as-expression-with-rhs': [FAIL],
'language/statements/class/definition/methods-gen-yield-as-generator-method-binding-identifier': [FAIL],
'language/statements/class/definition/methods-gen-yield-as-literal-property-name': [FAIL],
'language/statements/class/definition/methods-gen-yield-as-property-name': [FAIL],
'language/statements/class/definition/methods-gen-yield-as-statement': [FAIL],
'language/statements/class/definition/methods-gen-yield-as-yield-operand': [FAIL],
'language/statements/class/definition/methods-gen-yield-newline': [FAIL],
'language/statements/class/definition/methods-gen-yield-star-before-newline': [FAIL],
'language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-length': [FAIL],
'language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-name': [FAIL],
'language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-prototype': [FAIL],
'language/statements/class/subclass/builtin-objects/GeneratorFunction/super-must-be-called': [FAIL],
'language/statements/class/subclass/builtin-objects/GeneratorFunction/regular-subclassing': [FAIL],
'language/statements/for-of/break': [FAIL],
'language/statements/for-of/break-from-catch': [FAIL],
'language/statements/for-of/break-from-finally': [FAIL],
'language/statements/for-of/break-from-try': [FAIL],
'language/statements/for-of/break-label': [FAIL],
'language/statements/for-of/break-label-from-catch': [FAIL],
'language/statements/for-of/break-label-from-finally': [FAIL],
'language/statements/for-of/break-label-from-try': [FAIL],
'language/statements/for-of/continue': [FAIL],
'language/statements/for-of/continue-from-catch': [FAIL],
'language/statements/for-of/continue-from-finally': [FAIL],
'language/statements/for-of/continue-from-try': [FAIL],
'language/statements/for-of/continue-label': [FAIL],
'language/statements/for-of/continue-label-from-catch': [FAIL],
'language/statements/for-of/continue-label-from-finally': [FAIL],
'language/statements/for-of/continue-label-from-try': [FAIL],
'language/statements/for-of/generator-close-via-break': [FAIL],
'language/statements/for-of/generator-close-via-return': [FAIL],
'language/statements/for-of/generator-close-via-throw': [FAIL],
'language/statements/for-of/generator': [FAIL],
'language/statements/for-of/generator-next-error': [FAIL],
'language/statements/for-of/nested': [FAIL],
'language/statements/for-of/return': [FAIL],
'language/statements/for-of/return-from-catch': [FAIL],
'language/statements/for-of/return-from-finally': [FAIL],
'language/statements/for-of/return-from-try': [FAIL],
'language/statements/for-of/throw': [FAIL],
'language/statements/for-of/throw-from-catch': [FAIL],
'language/statements/for-of/throw-from-finally': [FAIL],
'language/statements/for-of/yield': [FAIL],
'language/statements/for-of/yield-from-catch': [FAIL],
'language/statements/for-of/yield-from-finally': [FAIL],
@ -588,20 +456,6 @@
'language/statements/for-of/yield-star-from-catch': [FAIL],
'language/statements/for-of/yield-star-from-finally': [FAIL],
'language/statements/for-of/yield-star-from-try': [FAIL],
'language/statements/generators/declaration': [FAIL],
'language/statements/generators/no-yield': [FAIL],
'language/statements/generators/return': [FAIL],
'language/statements/generators/yield-as-expression-without-rhs': [FAIL],
'language/statements/generators/yield-as-expression-with-rhs': [FAIL],
'language/statements/generators/yield-as-function-expression-binding-identifier': [FAIL],
'language/statements/generators/yield-as-generator-declaration-binding-identifier': [FAIL],
'language/statements/generators/yield-as-identifier-in-nested-function': [FAIL],
'language/statements/generators/yield-as-literal-property-name': [FAIL],
'language/statements/generators/yield-as-property-name': [FAIL],
'language/statements/generators/yield-as-statement': [FAIL],
'language/statements/generators/yield-as-yield-operand': [FAIL],
'language/statements/generators/yield-newline': [FAIL],
'language/statements/generators/yield-star-before-newline': [FAIL],
}], # ignition == True
]