From b9b528e030138719cfae4d8dc909765bebd69ead Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Tue, 1 Oct 2013 09:47:37 +0000 Subject: [PATCH] Defer allocation of native function literals. R=dcarney@chromium.org Review URL: https://codereview.chromium.org/25473002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17038 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/ast.cc | 2 +- src/ast.h | 32 +++++++++++++++----------------- src/full-codegen.cc | 35 +++++++++++++++++++++++++++++------ src/hydrogen.cc | 6 +++--- src/objects.h | 2 +- src/parser.cc | 25 ++----------------------- src/prettyprinter.cc | 12 +++++------- src/typing.cc | 2 +- 8 files changed, 57 insertions(+), 59 deletions(-) diff --git a/src/ast.cc b/src/ast.cc index 5f085d3..b98d2a6 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -1143,7 +1143,7 @@ DONT_OPTIMIZE_NODE(WithStatement) DONT_OPTIMIZE_NODE(TryCatchStatement) DONT_OPTIMIZE_NODE(TryFinallyStatement) DONT_OPTIMIZE_NODE(DebuggerStatement) -DONT_OPTIMIZE_NODE(SharedFunctionInfoLiteral) +DONT_OPTIMIZE_NODE(NativeFunctionLiteral) DONT_SELFOPTIMIZE_NODE(DoWhileStatement) DONT_SELFOPTIMIZE_NODE(WhileStatement) diff --git a/src/ast.h b/src/ast.h index 71a51ab..9c6f213 100644 --- a/src/ast.h +++ b/src/ast.h @@ -97,7 +97,7 @@ namespace internal { #define EXPRESSION_NODE_LIST(V) \ V(FunctionLiteral) \ - V(SharedFunctionInfoLiteral) \ + V(NativeFunctionLiteral) \ V(Conditional) \ V(VariableProxy) \ V(Literal) \ @@ -2380,23 +2380,21 @@ class FunctionLiteral V8_FINAL : public Expression { }; -class SharedFunctionInfoLiteral V8_FINAL : public Expression { +class NativeFunctionLiteral V8_FINAL : public Expression { public: - DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) + DECLARE_NODE_TYPE(NativeFunctionLiteral) - Handle shared_function_info() const { - return shared_function_info_; - } + Handle name() const { return name_; } + v8::Extension* extension() const { return extension_; } protected: - SharedFunctionInfoLiteral( - Isolate* isolate, - Handle shared_function_info) - : Expression(isolate), - shared_function_info_(shared_function_info) { } + NativeFunctionLiteral( + Isolate* isolate, Handle name, v8::Extension* extension) + : Expression(isolate), name_(name), extension_(extension) { } private: - Handle shared_function_info_; + Handle name_; + v8::Extension* extension_; }; @@ -3237,11 +3235,11 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { return lit; } - SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral( - Handle shared_function_info) { - SharedFunctionInfoLiteral* lit = - new(zone_) SharedFunctionInfoLiteral(isolate_, shared_function_info); - VISIT_AND_RETURN(SharedFunctionInfoLiteral, lit) + NativeFunctionLiteral* NewNativeFunctionLiteral(Handle name, + v8::Extension* extension) { + NativeFunctionLiteral* lit = + new(zone_) NativeFunctionLiteral(isolate_, name, extension); + VISIT_AND_RETURN(NativeFunctionLiteral, lit) } ThisFunction* NewThisFunction() { diff --git a/src/full-codegen.cc b/src/full-codegen.cc index c4ae1d7..f3e1bd7 100644 --- a/src/full-codegen.cc +++ b/src/full-codegen.cc @@ -197,8 +197,8 @@ void BreakableStatementChecker::VisitFunctionLiteral(FunctionLiteral* expr) { } -void BreakableStatementChecker::VisitSharedFunctionInfoLiteral( - SharedFunctionInfoLiteral* expr) { +void BreakableStatementChecker::VisitNativeFunctionLiteral( + NativeFunctionLiteral* expr) { } @@ -1567,10 +1567,33 @@ void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { } -void FullCodeGenerator::VisitSharedFunctionInfoLiteral( - SharedFunctionInfoLiteral* expr) { - Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); - EmitNewClosure(expr->shared_function_info(), false); +void FullCodeGenerator::VisitNativeFunctionLiteral( + NativeFunctionLiteral* expr) { + Comment cmnt(masm_, "[ NativeFunctionLiteral"); + + // Compute the function template for the native function. + Handle name = expr->name(); + v8::Handle fun_template = + expr->extension()->GetNativeFunction(v8::Utils::ToLocal(name)); + ASSERT(!fun_template.IsEmpty()); + + // Instantiate the function and create a shared function info from it. + Handle fun = Utils::OpenHandle(*fun_template->GetFunction()); + const int literals = fun->NumberOfLiterals(); + Handle code = Handle(fun->shared()->code()); + Handle construct_stub = Handle(fun->shared()->construct_stub()); + bool is_generator = false; + Handle shared = + isolate()->factory()->NewSharedFunctionInfo(name, literals, is_generator, + code, Handle(fun->shared()->scope_info())); + 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()->formal_parameter_count(); + shared->set_formal_parameter_count(parameters); + + EmitNewClosure(shared, false); } diff --git a/src/hydrogen.cc b/src/hydrogen.cc index c22d6c3..ef07d96 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -3983,12 +3983,12 @@ void HOptimizedGraphBuilder::VisitFunctionLiteral(FunctionLiteral* expr) { } -void HOptimizedGraphBuilder::VisitSharedFunctionInfoLiteral( - SharedFunctionInfoLiteral* expr) { +void HOptimizedGraphBuilder::VisitNativeFunctionLiteral( + NativeFunctionLiteral* expr) { ASSERT(!HasStackOverflow()); ASSERT(current_block() != NULL); ASSERT(current_block()->HasPredecessor()); - return Bailout(kSharedFunctionInfoLiteral); + return Bailout(kNativeFunctionLiteral); } diff --git a/src/objects.h b/src/objects.h index 209f1bb..374fa14 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1196,6 +1196,7 @@ class MaybeObject BASE_EMBEDDED { V(kModuleStatement, "Module statement") \ V(kModuleVariable, "Module variable") \ V(kModuleUrl, "Module url") \ + V(kNativeFunctionLiteral, "Native function literal") \ V(kNoCasesLeft, "no cases left") \ V(kNoEmptyArraysHereInEmitFastAsciiArrayJoin, \ "No empty arrays here in EmitFastAsciiArrayJoin") \ @@ -1239,7 +1240,6 @@ class MaybeObject BASE_EMBEDDED { V(kRegisterDidNotMatchExpectedRoot, "Register did not match expected root") \ V(kRegisterWasClobbered, "register was clobbered") \ V(kScopedBlock, "ScopedBlock") \ - V(kSharedFunctionInfoLiteral, "Shared function info literal") \ V(kSmiAdditionOverflow, "Smi addition overflow") \ V(kSmiSubtractionOverflow, "Smi subtraction overflow") \ V(kStackFrameTypesMustMatch, "stack frame types must match") \ diff --git a/src/parser.cc b/src/parser.cc index c77c171..6466ea2 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -1667,27 +1667,6 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { // because of lazy compilation. DeclarationScope(VAR)->ForceEagerCompilation(); - // Compute the function template for the native function. - v8::Handle fun_template = - extension_->GetNativeFunction(v8::Utils::ToLocal(name)); - ASSERT(!fun_template.IsEmpty()); - - // Instantiate the function and create a shared function info from it. - Handle fun = Utils::OpenHandle(*fun_template->GetFunction()); - const int literals = fun->NumberOfLiterals(); - Handle code = Handle(fun->shared()->code()); - Handle construct_stub = Handle(fun->shared()->construct_stub()); - bool is_generator = false; - Handle shared = - isolate()->factory()->NewSharedFunctionInfo(name, literals, is_generator, - code, Handle(fun->shared()->scope_info())); - 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()->formal_parameter_count(); - shared->set_formal_parameter_count(parameters); - // TODO(1240846): It's weird that native function declarations are // introduced dynamically when we meet their declarations, whereas // other functions are set up when entering the surrounding scope. @@ -1695,8 +1674,8 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { Declaration* declaration = factory()->NewVariableDeclaration(proxy, VAR, top_scope_); Declare(declaration, true, CHECK_OK); - SharedFunctionInfoLiteral* lit = - factory()->NewSharedFunctionInfoLiteral(shared); + NativeFunctionLiteral* lit = + factory()->NewNativeFunctionLiteral(name, extension_); return factory()->NewExpressionStatement( factory()->NewAssignment( Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition)); diff --git a/src/prettyprinter.cc b/src/prettyprinter.cc index b1bac4c..14ad707 100644 --- a/src/prettyprinter.cc +++ b/src/prettyprinter.cc @@ -297,10 +297,9 @@ void PrettyPrinter::VisitFunctionLiteral(FunctionLiteral* node) { } -void PrettyPrinter::VisitSharedFunctionInfoLiteral( - SharedFunctionInfoLiteral* node) { +void PrettyPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) { Print("("); - PrintLiteral(node->shared_function_info(), true); + PrintLiteral(node->name(), false); Print(")"); } @@ -982,10 +981,9 @@ void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) { } -void AstPrinter::VisitSharedFunctionInfoLiteral( - SharedFunctionInfoLiteral* node) { - IndentedScope indent(this, "FUNC LITERAL"); - PrintLiteralIndented("SHARED INFO", node->shared_function_info(), true); +void AstPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) { + IndentedScope indent(this, "NATIVE FUNC LITERAL"); + PrintLiteralIndented("NAME", node->name(), false); } diff --git a/src/typing.cc b/src/typing.cc index 34bb64b..3fd1ce5 100644 --- a/src/typing.cc +++ b/src/typing.cc @@ -305,7 +305,7 @@ void AstTyper::VisitFunctionLiteral(FunctionLiteral* expr) { } -void AstTyper::VisitSharedFunctionInfoLiteral(SharedFunctionInfoLiteral* expr) { +void AstTyper::VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { } -- 2.7.4