Commit befe61fa authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Interpreter] Add native function literal support.

Adds support for calling native function literals. Moves the logic for building
the native function's SharedFunctionInfo out of full-codegen into compiler.cc
to allow it to be shared between fullcodegen and Ignition.

BUG=v8:4686
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#33510}
parent 6131ab1e
......@@ -1651,6 +1651,37 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
return existing;
}
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative(
v8::Extension* extension, Handle<String> name) {
Isolate* isolate = name->GetIsolate();
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
// Compute the function template for the native function.
v8::Local<v8::FunctionTemplate> fun_template =
extension->GetNativeFunctionTemplate(v8_isolate,
v8::Utils::ToLocal(name));
DCHECK(!fun_template.IsEmpty());
// Instantiate the function and create a shared function info from it.
Handle<JSFunction> fun = Handle<JSFunction>::cast(Utils::OpenHandle(
*fun_template->GetFunction(v8_isolate->GetCurrentContext())
.ToLocalChecked()));
const int literals = fun->NumberOfLiterals();
Handle<Code> code = Handle<Code>(fun->shared()->code());
Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
name, literals, FunctionKind::kNormalFunction, code,
Handle<ScopeInfo>(fun->shared()->scope_info()),
Handle<TypeFeedbackVector>(fun->shared()->feedback_vector()));
shared->set_construct_stub(*construct_stub);
// Copy the function data to the shared function info.
shared->set_function_data(fun->shared()->function_data());
int parameters = fun->shared()->internal_formal_parameter_count();
shared->set_internal_formal_parameter_count(parameters);
return shared;
}
MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function,
ConcurrencyMode mode,
......
......@@ -621,6 +621,10 @@ class Compiler : public AllStatic {
static Handle<SharedFunctionInfo> GetSharedFunctionInfo(
FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer);
// Create a shared function info object for a native function literal.
static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative(
v8::Extension* extension, Handle<String> name);
enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT };
// Generate and return optimized code or start a concurrent optimization job.
......
......@@ -1348,35 +1348,8 @@ void FullCodeGenerator::VisitClassLiteral(ClassLiteral* lit) {
void FullCodeGenerator::VisitNativeFunctionLiteral(
NativeFunctionLiteral* expr) {
Comment cmnt(masm_, "[ NativeFunctionLiteral");
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate());
// Compute the function template for the native function.
Handle<String> name = expr->name();
v8::Local<v8::FunctionTemplate> fun_template =
expr->extension()->GetNativeFunctionTemplate(v8_isolate,
v8::Utils::ToLocal(name));
DCHECK(!fun_template.IsEmpty());
// Instantiate the function and create a shared function info from it.
Handle<JSFunction> fun = Handle<JSFunction>::cast(Utils::OpenHandle(
*fun_template->GetFunction(v8_isolate->GetCurrentContext())
.ToLocalChecked()));
const int literals = fun->NumberOfLiterals();
Handle<Code> code = Handle<Code>(fun->shared()->code());
Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
Handle<SharedFunctionInfo> shared =
isolate()->factory()->NewSharedFunctionInfo(
name, literals, FunctionKind::kNormalFunction, code,
Handle<ScopeInfo>(fun->shared()->scope_info()),
Handle<TypeFeedbackVector>(fun->shared()->feedback_vector()));
shared->set_construct_stub(*construct_stub);
// Copy the function data to the shared function info.
shared->set_function_data(fun->shared()->function_data());
int parameters = fun->shared()->internal_formal_parameter_count();
shared->set_internal_formal_parameter_count(parameters);
Compiler::GetSharedFunctionInfoForNative(expr->extension(), expr->name());
EmitNewClosure(shared, false);
}
......
......@@ -1213,7 +1213,11 @@ void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) {
void BytecodeGenerator::VisitNativeFunctionLiteral(
NativeFunctionLiteral* expr) {
UNIMPLEMENTED();
// Find or build a shared function info for the native function template.
Handle<SharedFunctionInfo> shared_info =
Compiler::GetSharedFunctionInfoForNative(expr->extension(), expr->name());
builder()->CreateClosure(shared_info, NOT_TENURED);
execution_result()->SetResultInAccumulator();
}
......
......@@ -527,32 +527,24 @@
'test-api-interceptors/InterceptorLoadICInvalidatedFieldViaGlobal': [SKIP],
'test-bytecode-generator/TryCatch': [SKIP],
'test-bytecode-generator/TryFinally': [SKIP],
'test-compiler/C2JSFrames': [SKIP],
'test-compiler/FeedbackVectorPreservedAcrossRecompiles': [SKIP],
'test-compiler/FeedbackVectorUnaffectedByScopeChanges': [SKIP],
'test-compiler/OptimizedCodeSharing2': [SKIP],
'test-compiler/OptimizedCodeSharing3': [SKIP],
'test-compiler/Print': [SKIP],
'test-decls/CrossScriptDynamicLookup': [SKIP],
'test-decls/Regress425510': [SKIP],
'test-feedback-vector/VectorCallICStates': [SKIP],
'test-heap/AddInstructionChangesNewSpacePromotion': [SKIP],
'test-heap/ArrayShiftSweeping': [SKIP],
'test-heap/CanonicalSharedFunctionInfo': [SKIP],
'test-heap/CellsInOptimizedCodeAreWeak': [SKIP],
'test-heap/CompilationCacheCachingBehavior': [SKIP],
'test-heap/CountForcedGC': [SKIP],
'test-heap/IncrementalMarkingClearsMonomorphicConstructor': [SKIP],
'test-heap/IncrementalMarkingPreservesMonomorphicCallIC': [SKIP],
'test-heap/IncrementalMarkingPreservesMonomorphicConstructor': [SKIP],
'test-heap/NoWeakHashTableLeakWithIncrementalMarking': [SKIP],
'test-heap-profiler/HeapSnapshotSimd': [SKIP],
'test-heap/OptimizedAllocationAlwaysInNewSpace': [SKIP],
'test-heap/PromotionQueue': [SKIP],
'test-heap/Regress169209': [SKIP],
'test-heap/Regress357137': [SKIP],
'test-heap/Regress3631': [SKIP],
'test-heap/Regress388880': [SKIP],
'test-heap/TestCodeFlushingIncrementalAbort': [SKIP],
'test-heap/TestCodeFlushingIncrementalScavenge': [SKIP],
'test-heap/TestCodeFlushingIncremental': [SKIP],
......@@ -560,8 +552,6 @@
'test-heap/TestCodeFlushing': [SKIP],
'test-heap/WeakFunctionInConstructor': [SKIP],
'test-log-stack-tracer/CFromJSStackTrace': [SKIP],
'test-log-stack-tracer/JsEntrySp': [SKIP],
'test-log-stack-tracer/PureCStackTrace': [SKIP],
'test-log-stack-tracer/PureJSStackTrace': [SKIP],
'test-parsing/DestructuringNegativeTests': [SKIP],
'test-parsing/StrongModeFreeVariablesDeclaredByLanguage': [SKIP],
......@@ -603,6 +593,7 @@
'test-decls/CrossScriptReferencesHarmony': [SKIP],
'test-js-arm64-variables/lookup_slots': [SKIP],
'test-spaces/SizeOfFirstPageIsLargeEnough': [SKIP],
'test-heap/AddInstructionChangesNewSpacePromotion': [SKIP],
'test-heap/Regress538257': [SKIP],
}], # ignition == True and arch == arm64
......
......@@ -752,9 +752,6 @@
'regress/debug*': [SKIP],
'regress/regress-debug*': [SKIP],
# TODO(bradnelson): Figure out why these tests fail with ignition.
'wasm/*': [SKIP],
# TODO(4684): Support for "with" statements is missing.
'regress/regress-1528': [FAIL],
'regress/regress-2594': [FAIL],
......@@ -766,11 +763,8 @@
'throw-and-catch-function': [FAIL],
'with-leave': [FAIL],
'allocation-folding': [SKIP],
'apply-arguments-gc-safepoint': [SKIP],
'arguments-load-across-eval': [SKIP],
'arguments-read-and-assignment': [SKIP],
'array-bounds-check-removal': [SKIP],
'array-constructor': [SKIP],
'array-functions-prototype-misc': [SKIP],
'array-join': [SKIP],
......@@ -781,51 +775,40 @@
'compiler/compare-map-elim2': [SKIP],
'compiler/deopt-inlined-smi': [SKIP],
'compiler/deopt-tonumber-compare': [SKIP],
'compiler/escape-analysis-arguments': [SKIP],
'compiler/escape-analysis': [SKIP],
'compiler/expression-trees': [SKIP],
'compiler/inline-arguments': [SKIP],
'compiler/inline-arity-mismatch': [SKIP],
'compiler/inline-construct': [SKIP],
'compiler/lazy-deopt-in-literal': [SKIP],
'compiler/manual-concurrent-recompile': [SKIP],
'compiler/optimized-for-in': [SKIP],
'compiler/optimized-function-calls': [SKIP],
'compiler/opt-next-call-turbo': [SKIP],
'compiler/property-refs': [SKIP],
'compiler/regress-3786': [SKIP],
'compiler/regress-446647': [SKIP],
'compiler/regress-447567': [SKIP],
'compiler/regress-469089': [SKIP],
'compiler/regress-96989': [SKIP],
'compiler/regress-const': [SKIP],
'compiler/regress-funarguments': [SKIP],
'compiler/regress-stacktrace-methods': [SKIP],
'compiler/regress-variable-liveness': [SKIP],
'compiler/rotate': [SKIP],
'compiler/safepoint': [SKIP],
'compiler/strict-recompile': [SKIP],
'compiler/try-binop': [SKIP],
'compiler/try-deopt': [SKIP],
'compiler/uint32': [SKIP],
'compiler/variables': [SKIP],
'context-calls-maintained': [SKIP],
'contextual-calls': [SKIP],
'cyclic-array-to-string': [SKIP],
'd8-worker-sharedarraybuffer': [SKIP],
'declare-locally': [SKIP],
'delete-in-with': [SKIP],
'deopt-minus-zero': [SKIP],
'deserialize-optimize-inner': [SKIP],
'double-equals': [SKIP],
'eval-enclosing-function-name': [SKIP],
'eval': [SKIP],
'eval-stack-trace': [SKIP],
'eval-typeof-non-existing': [SKIP],
'fast-prototype': [SKIP],
'field-type-tracking': [SKIP],
'for-in-opt': [SKIP],
'for-in-special-cases': [SKIP],
'getter-in-prototype': [SKIP],
'global-const-var-conflicts': [SKIP],
'global-hash': [SKIP],
......@@ -833,15 +816,12 @@
'global-load-from-nested-eval': [SKIP],
'global-vars-with': [SKIP],
'messages': [SKIP],
'object-literal-gc': [SKIP],
'osr-elements-kind': [SKIP],
'override-read-only-property': [SKIP],
'property-load-across-eval': [SKIP],
'proto-accessor': [SKIP],
'readonly': [SKIP],
'receiver-in-with-calls': [SKIP],
'regress-3225': [SKIP],
'regress/clear-keyed-call': [SKIP],
'regress/poly_count_operation': [SKIP],
'regress/regress-102153': [SKIP],
'regress/regress-1030466': [SKIP],
......@@ -849,10 +829,8 @@
'regress/regress-109195': [SKIP],
'regress/regress-1114040': [SKIP],
'regress/regress-1125': [SKIP],
'regress/regress-1129': [SKIP],
'regress/regress-1170187': [SKIP],
'regress/regress-1170': [SKIP],
'regress/regress-117409': [SKIP],
'regress/regress-1177809': [SKIP],
'regress/regress-1178598': [SKIP],
'regress/regress-119609': [SKIP],
......@@ -861,34 +839,21 @@
'regress/regress-123919': [SKIP],
'regress/regress-124594': [SKIP],
'regress/regress-124': [SKIP],
'regress/regress-125515': [SKIP],
'regress/regress-128018': [SKIP],
'regress/regress-131994': [SKIP],
'regress/regress-133211b': [SKIP],
'regress/regress-1365': [SKIP],
'regress/regress-1369': [SKIP],
'regress/regress-1412': [SKIP],
'regress/regress-1436': [SKIP],
'regress/regress-147497': [SKIP],
'regress/regress-1493017': [SKIP],
'regress/regress-1523': [SKIP],
'regress/regress-1560': [SKIP],
'regress/regress-1586': [SKIP],
'regress/regress-1639-2': [SKIP],
'regress/regress-1639': [SKIP],
'regress/regress-166553': [SKIP],
'regress/regress-1708': [SKIP],
'regress/regress-1757': [SKIP],
'regress/regress-1790': [SKIP],
'regress/regress-1853': [SKIP],
'regress/regress-186': [SKIP],
'regress/regress-1980': [SKIP],
'regress/regress-2071': [SKIP],
'regress/regress-2163': [SKIP],
'regress/regress-220': [SKIP],
'regress/regress-2318': [SKIP],
'regress/regress-2339': [SKIP],
'regress/regress-2593': [SKIP],
'regress/regress-2618': [SKIP],
'regress/regress-263': [SKIP],
'regress/regress-265': [SKIP],
......@@ -897,31 +862,14 @@
'regress/regress-2825': [SKIP],
'regress/regress-3138': [SKIP],
'regress/regress-318420': [SKIP],
'regress/regress-320532': [SKIP],
'regress/regress-331444': [SKIP],
'regress/regress-343609': [SKIP],
'regress/regress-347530': [SKIP],
'regress/regress-347914': [SKIP],
'regress/regress-351261': [SKIP],
'regress/regress-352982': [SKIP],
'regress/regress-353551': [SKIP],
'regress/regress-354357': [SKIP],
'regress/regress-356053': [SKIP],
'regress/regress-357105': [SKIP],
'regress/regress-359441': [SKIP],
'regress/regress-361025': [SKIP],
'regress/regress-365172-3': [SKIP],
'regress/regress-370827': [SKIP],
'regress/regress-377290': [SKIP],
'regress/regress-3884': [SKIP],
'regress/regress-3926': [SKIP],
'regress/regress-3960': [SKIP],
'regress/regress-3969': [SKIP],
'regress/regress-3985': [SKIP],
'regress/regress-4023': [SKIP],
'regress/regress-4027': [SKIP],
'regress/regress-403292': [SKIP],
'regress/regress-410912': [SKIP],
'regress/regress-4121': [SKIP],
'regress/regress-4169': [SKIP],
'regress/regress-419663': [SKIP],
......@@ -934,7 +882,6 @@
'regress/regress-4309-2': [SKIP],
'regress/regress-4309-3': [SKIP],
'regress/regress-4320': [SKIP],
'regress/regress-4325': [SKIP],
'regress/regress-4374': [SKIP],
'regress/regress-4388': [SKIP],
'regress/regress-446389': [SKIP],
......@@ -944,54 +891,31 @@
'regress/regress-4521': [SKIP],
'regress/regress-4525': [SKIP],
'regress/regress-453481': [SKIP],
'regress/regress-4534': [SKIP],
'regress/regress-454725': [SKIP],
'regress/regress-455207': [SKIP],
'regress/regress-457935': [SKIP],
'regress/regress-470804': [SKIP],
'regress/regress-476488': [SKIP],
'regress/regress-503565': [SKIP],
'regress/regress-514362': [SKIP],
'regress/regress-520029': [SKIP],
'regress/regress-542100': [SKIP],
'regress/regress-544991': [SKIP],
'regress/regress-568765': [SKIP],
'regress/regress-572589': [SKIP],
'regress/regress-580': [SKIP],
'regress/regress-69': [SKIP],
'regress/regress-70066': [SKIP],
'regress/regress-747': [SKIP],
'regress/regress-799761': [SKIP],
'regress/regress-806473': [SKIP],
'regress/regress-842017': [SKIP],
'regress/regress-84234': [SKIP],
'regress/regress-88591': [SKIP],
'regress/regress-88858': [SKIP],
'regress/regress-94425': [SKIP],
'regress/regress-94873': [SKIP],
'regress/regress-95485': [SKIP],
'regress/regress-97116b': [SKIP],
'regress/regress-97116': [SKIP],
'regress/regress-974': [SKIP],
'regress/regress-99167': [SKIP],
'regress/regress-998565': [SKIP],
'regress/regress-arg-materialize-store': [SKIP],
'regress/regress-arguments-gc': [SKIP],
'regress/regress-assignment-in-test-context': [SKIP],
'regress/regress-bce-underflow': [SKIP],
'regress/regress-cnlt-elements': [SKIP],
'regress/regress-cnlt-enum-indices': [SKIP],
'regress/regress-cntl-descriptors-enum': [SKIP],
'regress/regress-conditional-position': [SKIP],
'regress/regress-convert-enum': [SKIP],
'regress/regress-crbug-109362': [SKIP],
'regress/regress-crbug-119800': [SKIP],
'regress/regress-crbug-135008': [SKIP],
'regress/regress-crbug-163530': [SKIP],
'regress/regress-crbug-229923': [SKIP],
'regress/regress-crbug-242502': [SKIP],
'regress/regress-crbug-242924': [SKIP],
'regress/regress-crbug-245480': [SKIP],
'regress/regress-crbug-259300': [SKIP],
'regress/regress-crbug-352058': [SKIP],
'regress/regress-crbug-357137': [SKIP],
......@@ -1000,7 +924,6 @@
'regress/regress-crbug-405517': [SKIP],
'regress/regress-crbug-405922': [SKIP],
'regress/regress-crbug-409614': [SKIP],
'regress/regress-crbug-410033': [SKIP],
'regress/regress-crbug-424142': [SKIP],
'regress/regress-crbug-429159': [SKIP],
'regress/regress-crbug-431602': [SKIP],
......@@ -1011,11 +934,8 @@
'regress/regress-crbug-465298': [SKIP],
'regress/regress-crbug-467180': [SKIP],
'regress/regress-crbug-467531': [SKIP],
'regress/regress-crbug-474297': [SKIP],
'regress/regress-crbug-480819': [SKIP],
'regress/regress-crbug-481896': [SKIP],
'regress/regress-crbug-485548-1': [SKIP],
'regress/regress-crbug-485548-2': [SKIP],
'regress/regress-crbug-487289': [SKIP],
'regress/regress-crbug-489293': [SKIP],
'regress/regress-crbug-498022': [SKIP],
......@@ -1031,43 +951,24 @@
'regress/regress-crbug-568477-2': [SKIP],
'regress/regress-crbug-568477-3': [SKIP],
'regress/regress-crbug-568477-4': [SKIP],
'regress/regress-crbug-572590': [SKIP],
'regress/regress-crbug-573857': [SKIP],
'regress/regress-crbug-575080': [SKIP],
'regress/regress-crbug-580506': [SKIP],
'regress/regress-deopt-gcb': [SKIP],
'regress/regress-deopt-gc': [SKIP],
'regress/regress-deopt-in-array-literal-spread': [SKIP],
'regress/regress-embedded-cons-string': [SKIP],
'regress/regress-existing-shared-function-info': [SKIP],
'regress/regress-fast-literal-transition': [SKIP],
'regress/regress-function-constructor-receiver': [SKIP],
'regress/regress-handle-illegal-redeclaration': [SKIP],
'regress/regress-inline-class-constructor': [SKIP],
'regress/regress-inlining-function-literal-context': [SKIP],
'regress/regress-lazy-deopt-reloc': [SKIP],
'regress/regress-opt-after-debug-deopt': [SKIP],
'regress/regress-osr-in-case-label': [SKIP],
'regress/regress-osr-in-literal': [SKIP],
'regress/regress-prepare-break-while-recompile': [SKIP],
'regress/regress-put-prototype-transition': [SKIP],
'regress/regress-sliced-external-cons-regexp': [SKIP],
'regress/regress-store-heapobject': [SKIP],
'regress/regress-transcendental': [SKIP],
'regress/regress-typedarray-length': [SKIP],
'regress/splice-missing-wb': [SKIP],
'scope-calls-eval': [SKIP],
'shift-for-integer-div': [SKIP],
'stack-traces': [SKIP],
'strict-mode': [SKIP],
'string-case': [SKIP],
'string-external-cached': [SKIP],
'string-externalize': [SKIP],
'string-natives': [SKIP],
'string-replace-with-empty': [SKIP],
'string-slices': [SKIP],
'tools/profviz': [SKIP],
'try': [SKIP],
'try-binop': [SKIP],
'undetectable-compare': [SKIP],
'unused-context-in-with': [SKIP],
......@@ -1097,9 +998,11 @@
'regress/regress-165637': [SKIP],
'regress/regress-2249': [SKIP],
'regress/regress-319722-ArrayBuffer': [SKIP],
'regress/regress-347914': [SKIP],
'regress/regress-411210': [SKIP],
'regress/regress-91008': [SKIP],
'regress/regress-crbug-347903': [SKIP],
'regress/regress-crbug-474297': [SKIP],
'regress/regress-crbug-500497': [SKIP],
'regress/regress-crbug-505007-1': [SKIP],
'regress/regress-crbug-505007-2': [SKIP],
......@@ -1115,6 +1018,7 @@
'regress/regress-crbug-513507': [SKIP],
'regress/regress-deep-proto': [SKIP],
'regress/regress-deopt-store-effect': [SKIP],
'regress/regress-put-prototype-transition': [SKIP],
'regress/regress-undefined-store-keyed-fast-element': [SKIP],
'stack-traces-overflow': [SKIP],
'unicodelctest': [SKIP],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment