Revert "Defer allocation of native function literals."

This reverts r17017 for breaking LayoutTests.

R=mstarzinger@chromium.org
TBR=mstarzinger@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17024 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
jkummerow@chromium.org 2013-09-30 17:42:58 +00:00
parent 3f461303bd
commit 85ae341b09
8 changed files with 59 additions and 52 deletions

View File

@ -1143,7 +1143,7 @@ DONT_OPTIMIZE_NODE(WithStatement)
DONT_OPTIMIZE_NODE(TryCatchStatement)
DONT_OPTIMIZE_NODE(TryFinallyStatement)
DONT_OPTIMIZE_NODE(DebuggerStatement)
DONT_OPTIMIZE_NODE(NativeFunctionLiteral)
DONT_OPTIMIZE_NODE(SharedFunctionInfoLiteral)
DONT_SELFOPTIMIZE_NODE(DoWhileStatement)
DONT_SELFOPTIMIZE_NODE(WhileStatement)

View File

@ -97,7 +97,7 @@ namespace internal {
#define EXPRESSION_NODE_LIST(V) \
V(FunctionLiteral) \
V(NativeFunctionLiteral) \
V(SharedFunctionInfoLiteral) \
V(Conditional) \
V(VariableProxy) \
V(Literal) \
@ -2380,18 +2380,23 @@ class FunctionLiteral V8_FINAL : public Expression {
};
class NativeFunctionLiteral V8_FINAL : public Expression {
class SharedFunctionInfoLiteral V8_FINAL : public Expression {
public:
DECLARE_NODE_TYPE(NativeFunctionLiteral)
DECLARE_NODE_TYPE(SharedFunctionInfoLiteral)
Handle<String> name() const { return name_; }
Handle<SharedFunctionInfo> shared_function_info() const {
return shared_function_info_;
}
protected:
NativeFunctionLiteral(Isolate* isolate, Handle<String> name)
: Expression(isolate), name_(name) { }
SharedFunctionInfoLiteral(
Isolate* isolate,
Handle<SharedFunctionInfo> shared_function_info)
: Expression(isolate),
shared_function_info_(shared_function_info) { }
private:
Handle<String> name_;
Handle<SharedFunctionInfo> shared_function_info_;
};
@ -3232,10 +3237,11 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
return lit;
}
NativeFunctionLiteral* NewNativeFunctionLiteral(Handle<String> name) {
NativeFunctionLiteral* lit =
new(zone_) NativeFunctionLiteral(isolate_, name);
VISIT_AND_RETURN(NativeFunctionLiteral, lit)
SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral(
Handle<SharedFunctionInfo> shared_function_info) {
SharedFunctionInfoLiteral* lit =
new(zone_) SharedFunctionInfoLiteral(isolate_, shared_function_info);
VISIT_AND_RETURN(SharedFunctionInfoLiteral, lit)
}
ThisFunction* NewThisFunction() {

View File

@ -197,8 +197,8 @@ void BreakableStatementChecker::VisitFunctionLiteral(FunctionLiteral* expr) {
}
void BreakableStatementChecker::VisitNativeFunctionLiteral(
NativeFunctionLiteral* expr) {
void BreakableStatementChecker::VisitSharedFunctionInfoLiteral(
SharedFunctionInfoLiteral* expr) {
}
@ -1567,33 +1567,10 @@ void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
}
void FullCodeGenerator::VisitNativeFunctionLiteral(
NativeFunctionLiteral* expr) {
Comment cmnt(masm_, "[ NativeFunctionLiteral");
// Compute the function template for the native function.
Handle<String> name = expr->name();
v8::Handle<v8::FunctionTemplate> fun_template =
info_->extension()->GetNativeFunction(v8::Utils::ToLocal(name));
ASSERT(!fun_template.IsEmpty());
// Instantiate the function and create a shared function info from it.
Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction());
const int literals = fun->NumberOfLiterals();
Handle<Code> code = Handle<Code>(fun->shared()->code());
Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
bool is_generator = false;
Handle<SharedFunctionInfo> shared =
isolate()->factory()->NewSharedFunctionInfo(name, literals, is_generator,
code, Handle<ScopeInfo>(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);
void FullCodeGenerator::VisitSharedFunctionInfoLiteral(
SharedFunctionInfoLiteral* expr) {
Comment cmnt(masm_, "[ SharedFunctionInfoLiteral");
EmitNewClosure(expr->shared_function_info(), false);
}

View File

@ -3983,12 +3983,12 @@ void HOptimizedGraphBuilder::VisitFunctionLiteral(FunctionLiteral* expr) {
}
void HOptimizedGraphBuilder::VisitNativeFunctionLiteral(
NativeFunctionLiteral* expr) {
void HOptimizedGraphBuilder::VisitSharedFunctionInfoLiteral(
SharedFunctionInfoLiteral* expr) {
ASSERT(!HasStackOverflow());
ASSERT(current_block() != NULL);
ASSERT(current_block()->HasPredecessor());
return Bailout(kNativeFunctionLiteral);
return Bailout(kSharedFunctionInfoLiteral);
}

View File

@ -1206,7 +1206,6 @@ 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") \
@ -1250,6 +1249,7 @@ 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") \

View File

@ -1667,6 +1667,27 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
// because of lazy compilation.
DeclarationScope(VAR)->ForceEagerCompilation();
// Compute the function template for the native function.
v8::Handle<v8::FunctionTemplate> fun_template =
extension_->GetNativeFunction(v8::Utils::ToLocal(name));
ASSERT(!fun_template.IsEmpty());
// Instantiate the function and create a shared function info from it.
Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction());
const int literals = fun->NumberOfLiterals();
Handle<Code> code = Handle<Code>(fun->shared()->code());
Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
bool is_generator = false;
Handle<SharedFunctionInfo> shared =
isolate()->factory()->NewSharedFunctionInfo(name, literals, is_generator,
code, Handle<ScopeInfo>(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.
@ -1674,7 +1695,8 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
Declaration* declaration =
factory()->NewVariableDeclaration(proxy, VAR, top_scope_);
Declare(declaration, true, CHECK_OK);
NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral(name);
SharedFunctionInfoLiteral* lit =
factory()->NewSharedFunctionInfoLiteral(shared);
return factory()->NewExpressionStatement(
factory()->NewAssignment(
Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition));

View File

@ -297,9 +297,10 @@ void PrettyPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
}
void PrettyPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {
void PrettyPrinter::VisitSharedFunctionInfoLiteral(
SharedFunctionInfoLiteral* node) {
Print("(");
PrintLiteral(node->name(), false);
PrintLiteral(node->shared_function_info(), true);
Print(")");
}
@ -981,9 +982,10 @@ void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
}
void AstPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {
IndentedScope indent(this, "NATIVE FUNC LITERAL");
PrintLiteralIndented("NAME", node->name(), false);
void AstPrinter::VisitSharedFunctionInfoLiteral(
SharedFunctionInfoLiteral* node) {
IndentedScope indent(this, "FUNC LITERAL");
PrintLiteralIndented("SHARED INFO", node->shared_function_info(), true);
}

View File

@ -305,7 +305,7 @@ void AstTyper::VisitFunctionLiteral(FunctionLiteral* expr) {
}
void AstTyper::VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) {
void AstTyper::VisitSharedFunctionInfoLiteral(SharedFunctionInfoLiteral* expr) {
}