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
......
This diff is collapsed.
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