From c1669450834436508e0007885eb7ac266cbcf083 Mon Sep 17 00:00:00 2001 From: yangguo Date: Fri, 19 Jun 2015 07:40:22 -0700 Subject: [PATCH] Keep a canonical list of shared function infos. Each Script object now keeps a WeakFixedArray of SharedFunctionInfo objects created from this script. This way, when compiling a function, we do not create duplicate shared function info objects when recompiling with either compiler. This fixes a class of issues in the debugger, where we set break points on one shared function info, but functions from duplicate shared function infos are not affected. LOG=N BUG=v8:4132 Review URL: https://codereview.chromium.org/1183733006 Cr-Commit-Position: refs/heads/master@{#29151} --- src/arm/full-codegen-arm.cc | 2 +- src/arm64/full-codegen-arm64.cc | 2 +- src/ast.cc | 19 --------- src/ast.h | 6 --- src/bootstrapper.cc | 2 +- src/codegen.h | 1 - src/compiler.cc | 58 +++++++++++++++++++--------- src/compiler.h | 5 +-- src/compiler/ast-graph-builder.cc | 16 +++----- src/debug.cc | 2 +- src/factory.cc | 1 + src/full-codegen.cc | 2 +- src/hydrogen.cc | 9 ++--- src/ia32/full-codegen-ia32.cc | 2 +- src/liveedit.cc | 2 +- src/mips/full-codegen-mips.cc | 2 +- src/mips64/full-codegen-mips64.cc | 2 +- src/objects-inl.h | 1 + src/objects-printer.cc | 1 + src/objects.cc | 46 ++++++++++++++++++++++ src/objects.h | 35 ++++++++++------- src/ppc/full-codegen-ppc.cc | 2 +- src/runtime/runtime-function.cc | 3 +- src/snapshot/serialize.cc | 6 ++- src/typing.cc | 4 +- src/x64/full-codegen-x64.cc | 2 +- src/x87/full-codegen-x87.cc | 2 +- test/cctest/test-heap.cc | 47 ++++++++++++++++++++++ test/mjsunit/regress/regress-4121.js | 3 ++ 29 files changed, 192 insertions(+), 93 deletions(-) diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index 246415742..36dc89f78 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -931,7 +931,7 @@ void FullCodeGenerator::VisitFunctionDeclaration( case Variable::UNALLOCATED: { globals_->Add(variable->name(), zone()); Handle function = - Compiler::BuildFunctionInfo(declaration->fun(), script(), info_); + Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_); // Check for stack-overflow exception. if (function.is_null()) return SetStackOverflow(); globals_->Add(function, zone()); diff --git a/src/arm64/full-codegen-arm64.cc b/src/arm64/full-codegen-arm64.cc index ff47e34cf..acd8baad1 100644 --- a/src/arm64/full-codegen-arm64.cc +++ b/src/arm64/full-codegen-arm64.cc @@ -923,7 +923,7 @@ void FullCodeGenerator::VisitFunctionDeclaration( case Variable::UNALLOCATED: { globals_->Add(variable->name(), zone()); Handle function = - Compiler::BuildFunctionInfo(declaration->fun(), script(), info_); + Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_); // Check for stack overflow exception. if (function.is_null()) return SetStackOverflow(); globals_->Add(function, zone()); diff --git a/src/ast.cc b/src/ast.cc index c9e4c0f21..089bd27c6 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -241,25 +241,6 @@ bool FunctionLiteral::NeedsHomeObject(Expression* expr) { } -// Helper to find an existing shared function info in the baseline code for the -// given function literal. Used to canonicalize SharedFunctionInfo objects. -void FunctionLiteral::InitializeSharedInfo( - Handle unoptimized_code) { - for (RelocIterator it(*unoptimized_code); !it.done(); it.next()) { - RelocInfo* rinfo = it.rinfo(); - if (rinfo->rmode() != RelocInfo::EMBEDDED_OBJECT) continue; - Object* obj = rinfo->target_object(); - if (obj->IsSharedFunctionInfo()) { - SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); - if (shared->start_position() == start_position()) { - shared_info_ = Handle(shared); - break; - } - } - } -} - - ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, bool is_static, bool is_computed_name) diff --git a/src/ast.h b/src/ast.h index 8eae84935..c6f7dbd10 100644 --- a/src/ast.h +++ b/src/ast.h @@ -2518,8 +2518,6 @@ class FunctionLiteral final : public Expression { bool AllowsLazyCompilation(); bool AllowsLazyCompilationWithoutContext(); - void InitializeSharedInfo(Handle code); - Handle debug_name() const { if (raw_name_ != NULL && !raw_name_->IsEmpty()) { return raw_name_->string(); @@ -2554,9 +2552,6 @@ class FunctionLiteral final : public Expression { inferred_name_ = Handle(); } - // shared_info may be null if it's not cached in full code. - Handle shared_info() { return shared_info_; } - bool pretenure() { return Pretenure::decode(bitfield_); } void set_pretenure() { bitfield_ |= Pretenure::encode(true); } @@ -2638,7 +2633,6 @@ class FunctionLiteral final : public Expression { private: const AstRawString* raw_name_; Handle name_; - Handle shared_info_; Scope* scope_; ZoneList* body_; const AstString* raw_inferred_name_; diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 63ba0dc66..c38e9da4f 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -563,10 +563,10 @@ Handle Genesis::CreateEmptyFunction(Isolate* isolate) { Handle source = factory->NewStringFromStaticChars("() {}"); Handle