From 388e791df91c299507d62f91bc4f618a4dc80276 Mon Sep 17 00:00:00 2001 From: bmeurer Date: Thu, 28 May 2015 00:11:53 -0700 Subject: [PATCH] [crankshaft] Record inlined shared function infos instead of closures. The list of inlined functions is used in exactly two places - for live edit and to prevent code flushing for inlined functions - and those are fine with SharedFunctionInfo and don't require a closure. This is one additional step towards inlining based on SharedFunctionInfo instead of JSFunction. R=jarin@chromium.org Review URL: https://codereview.chromium.org/1145893003 Cr-Commit-Position: refs/heads/master@{#28672} --- src/arm/lithium-arm.cc | 2 +- src/arm/lithium-codegen-arm.cc | 13 +++---------- src/arm64/lithium-arm64.cc | 2 +- src/arm64/lithium-codegen-arm64.cc | 11 +++-------- src/heap/objects-visiting-inl.h | 16 +++++++--------- src/hydrogen-instructions.h | 3 +++ src/ia32/lithium-codegen-ia32.cc | 13 +++---------- src/ia32/lithium-ia32.cc | 2 +- src/lithium.cc | 2 +- src/lithium.h | 10 +++++----- src/liveedit.cc | 31 +++++++++++++++---------------- src/mips/lithium-codegen-mips.cc | 13 +++---------- src/mips/lithium-mips.cc | 2 +- src/mips64/lithium-codegen-mips64.cc | 13 +++---------- src/mips64/lithium-mips64.cc | 2 +- src/ppc/lithium-codegen-ppc.cc | 11 ++++------- src/x64/lithium-codegen-x64.cc | 13 +++---------- src/x64/lithium-x64.cc | 2 +- 18 files changed, 59 insertions(+), 102 deletions(-) diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc index f50d7bc..59a24b3 100644 --- a/src/arm/lithium-arm.cc +++ b/src/arm/lithium-arm.cc @@ -2603,7 +2603,7 @@ LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { inner->BindContext(instr->closure_context()); inner->set_entry(instr); current_block_->UpdateEnvironment(inner); - chunk_->AddInlinedClosure(instr->closure()); + chunk_->AddInlinedFunction(instr->shared()); return NULL; } diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index d3cec62..53d0e60 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -972,17 +972,10 @@ int LCodeGen::DefineDeoptimizationLiteral(Handle literal) { void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { - DCHECK(deoptimization_literals_.length() == 0); - - const ZoneList >* inlined_closures = - chunk()->inlined_closures(); - - for (int i = 0, length = inlined_closures->length(); - i < length; - i++) { - DefineDeoptimizationLiteral(inlined_closures->at(i)); + DCHECK_EQ(0, deoptimization_literals_.length()); + for (auto function : chunk()->inlined_functions()) { + DefineDeoptimizationLiteral(function); } - inlined_function_count_ = deoptimization_literals_.length(); } diff --git a/src/arm64/lithium-arm64.cc b/src/arm64/lithium-arm64.cc index 91b4430..822e736 100644 --- a/src/arm64/lithium-arm64.cc +++ b/src/arm64/lithium-arm64.cc @@ -1504,7 +1504,7 @@ LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { inner->BindContext(instr->closure_context()); inner->set_entry(instr); current_block_->UpdateEnvironment(inner); - chunk_->AddInlinedClosure(instr->closure()); + chunk_->AddInlinedFunction(instr->shared()); return NULL; } diff --git a/src/arm64/lithium-codegen-arm64.cc b/src/arm64/lithium-codegen-arm64.cc index 5552481..94f09e0 100644 --- a/src/arm64/lithium-codegen-arm64.cc +++ b/src/arm64/lithium-codegen-arm64.cc @@ -997,15 +997,10 @@ void LCodeGen::PopulateDeoptimizationData(Handle code) { void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { - DCHECK(deoptimization_literals_.length() == 0); - - const ZoneList >* inlined_closures = - chunk()->inlined_closures(); - - for (int i = 0, length = inlined_closures->length(); i < length; i++) { - DefineDeoptimizationLiteral(inlined_closures->at(i)); + DCHECK_EQ(0, deoptimization_literals_.length()); + for (auto function : chunk()->inlined_functions()) { + DefineDeoptimizationLiteral(function); } - inlined_function_count_ = deoptimization_literals_.length(); } diff --git a/src/heap/objects-visiting-inl.h b/src/heap/objects-visiting-inl.h index 6afee26..ff26c76 100644 --- a/src/heap/objects-visiting-inl.h +++ b/src/heap/objects-visiting-inl.h @@ -5,6 +5,7 @@ #ifndef V8_OBJECTS_VISITING_INL_H_ #define V8_OBJECTS_VISITING_INL_H_ +#include "src/heap/objects-visiting.h" namespace v8 { namespace internal { @@ -618,19 +619,16 @@ void StaticMarkingVisitor::MarkTransitionArray( template void StaticMarkingVisitor::MarkInlinedFunctionsCode(Heap* heap, Code* code) { - // Skip in absence of inlining. - // TODO(turbofan): Revisit once we support inlining. - if (code->is_turbofanned()) return; // For optimized functions we should retain both non-optimized version // of its code and non-optimized version of all inlined functions. // This is required to support bailing out from inlined code. - DeoptimizationInputData* data = + DeoptimizationInputData* const data = DeoptimizationInputData::cast(code->deoptimization_data()); - FixedArray* literals = data->LiteralArray(); - for (int i = 0, count = data->InlinedFunctionCount()->value(); i < count; - i++) { - JSFunction* inlined = JSFunction::cast(literals->get(i)); - StaticVisitor::MarkObject(heap, inlined->shared()->code()); + FixedArray* const literals = data->LiteralArray(); + int const inlined_count = data->InlinedFunctionCount()->value(); + for (int i = 0; i < inlined_count; ++i) { + StaticVisitor::MarkObject( + heap, SharedFunctionInfo::cast(literals->get(i))->code()); } } diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index e56e367..8beee14 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -1958,6 +1958,7 @@ class HEnterInlined final : public HTemplateInstruction<0> { std::ostream& PrintDataTo(std::ostream& os) const override; // NOLINT + Handle shared() const { return shared_; } Handle closure() const { return closure_; } HConstant* closure_context() const { return closure_context_; } int arguments_count() const { return arguments_count_; } @@ -1985,6 +1986,7 @@ class HEnterInlined final : public HTemplateInstruction<0> { Variable* arguments_var, HArgumentsObject* arguments_object, Zone* zone) : return_id_(return_id), + shared_(handle(closure->shared())), closure_(closure), closure_context_(closure_context), arguments_count_(arguments_count), @@ -1997,6 +1999,7 @@ class HEnterInlined final : public HTemplateInstruction<0> { return_targets_(2, zone) {} BailoutId return_id_; + Handle shared_; Handle closure_; HConstant* closure_context_; int arguments_count_; diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index ad8c9e0..a7a7c42 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -977,17 +977,10 @@ int LCodeGen::DefineDeoptimizationLiteral(Handle literal) { void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { - DCHECK(deoptimization_literals_.length() == 0); - - const ZoneList >* inlined_closures = - chunk()->inlined_closures(); - - for (int i = 0, length = inlined_closures->length(); - i < length; - i++) { - DefineDeoptimizationLiteral(inlined_closures->at(i)); + DCHECK_EQ(0, deoptimization_literals_.length()); + for (auto function : chunk()->inlined_functions()) { + DefineDeoptimizationLiteral(function); } - inlined_function_count_ = deoptimization_literals_.length(); } diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc index bea66d3..0186c04 100644 --- a/src/ia32/lithium-ia32.cc +++ b/src/ia32/lithium-ia32.cc @@ -2665,7 +2665,7 @@ LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { inner->BindContext(instr->closure_context()); inner->set_entry(instr); current_block_->UpdateEnvironment(inner); - chunk_->AddInlinedClosure(instr->closure()); + chunk_->AddInlinedFunction(instr->shared()); return NULL; } diff --git a/src/lithium.cc b/src/lithium.cc index 53ed919..ba3517d 100644 --- a/src/lithium.cc +++ b/src/lithium.cc @@ -272,7 +272,7 @@ LChunk::LChunk(CompilationInfo* info, HGraph* graph) graph_(graph), instructions_(32, info->zone()), pointer_maps_(8, info->zone()), - inlined_closures_(1, info->zone()), + inlined_functions_(1, info->zone()), deprecation_dependencies_(MapLess(), MapAllocator(info->zone())), stability_dependencies_(MapLess(), MapAllocator(info->zone())) {} diff --git a/src/lithium.h b/src/lithium.h index f586882..c972cbd 100644 --- a/src/lithium.h +++ b/src/lithium.h @@ -653,12 +653,12 @@ class LChunk : public ZoneObject { int LookupDestination(int block_id) const; Label* GetAssemblyLabel(int block_id) const; - const ZoneList >* inlined_closures() const { - return &inlined_closures_; + const ZoneList>& inlined_functions() const { + return inlined_functions_; } - void AddInlinedClosure(Handle closure) { - inlined_closures_.Add(closure, zone()); + void AddInlinedFunction(Handle closure) { + inlined_functions_.Add(closure, zone()); } void AddDeprecationDependency(Handle map) { @@ -702,7 +702,7 @@ class LChunk : public ZoneObject { BitVector* allocated_double_registers_; ZoneList instructions_; ZoneList pointer_maps_; - ZoneList > inlined_closures_; + ZoneList> inlined_functions_; MapSet deprecation_dependencies_; MapSet stability_dependencies_; }; diff --git a/src/liveedit.cc b/src/liveedit.cc index c03d8d3..41aa83d 100644 --- a/src/liveedit.cc +++ b/src/liveedit.cc @@ -1089,37 +1089,36 @@ class LiteralFixer { }; +namespace { + // Check whether the code is natural function code (not a lazy-compile stub // code). -static bool IsJSFunctionCode(Code* code) { - return code->kind() == Code::FUNCTION; -} +bool IsJSFunctionCode(Code* code) { return code->kind() == Code::FUNCTION; } // Returns true if an instance of candidate were inlined into function's code. -static bool IsInlined(JSFunction* function, SharedFunctionInfo* candidate) { +bool IsInlined(JSFunction* function, SharedFunctionInfo* candidate) { DisallowHeapAllocation no_gc; if (function->code()->kind() != Code::OPTIMIZED_FUNCTION) return false; - DeoptimizationInputData* data = + DeoptimizationInputData* const data = DeoptimizationInputData::cast(function->code()->deoptimization_data()); - - if (data == function->GetIsolate()->heap()->empty_fixed_array()) { - return false; - } - - FixedArray* literals = data->LiteralArray(); - - int inlined_count = data->InlinedFunctionCount()->value(); - for (int i = 0; i < inlined_count; ++i) { - JSFunction* inlined = JSFunction::cast(literals->get(i)); - if (inlined->shared() == candidate) return true; + if (data != function->GetIsolate()->heap()->empty_fixed_array()) { + FixedArray* const literals = data->LiteralArray(); + int const inlined_count = data->InlinedFunctionCount()->value(); + for (int i = 0; i < inlined_count; ++i) { + if (SharedFunctionInfo::cast(literals->get(i)) == candidate) { + return true; + } + } } return false; } +} // namespace + // Marks code that shares the same shared function info or has inlined // code that shares the same function info. diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index b08506d..cd76b18 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -939,17 +939,10 @@ int LCodeGen::DefineDeoptimizationLiteral(Handle literal) { void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { - DCHECK(deoptimization_literals_.length() == 0); - - const ZoneList >* inlined_closures = - chunk()->inlined_closures(); - - for (int i = 0, length = inlined_closures->length(); - i < length; - i++) { - DefineDeoptimizationLiteral(inlined_closures->at(i)); + DCHECK_EQ(0, deoptimization_literals_.length()); + for (auto function : chunk()->inlined_functions()) { + DefineDeoptimizationLiteral(function); } - inlined_function_count_ = deoptimization_literals_.length(); } diff --git a/src/mips/lithium-mips.cc b/src/mips/lithium-mips.cc index a345944..8397013 100644 --- a/src/mips/lithium-mips.cc +++ b/src/mips/lithium-mips.cc @@ -2550,7 +2550,7 @@ LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { inner->BindContext(instr->closure_context()); inner->set_entry(instr); current_block_->UpdateEnvironment(inner); - chunk_->AddInlinedClosure(instr->closure()); + chunk_->AddInlinedFunction(instr->shared()); return NULL; } diff --git a/src/mips64/lithium-codegen-mips64.cc b/src/mips64/lithium-codegen-mips64.cc index eccf09d..466c7c4 100644 --- a/src/mips64/lithium-codegen-mips64.cc +++ b/src/mips64/lithium-codegen-mips64.cc @@ -928,17 +928,10 @@ int LCodeGen::DefineDeoptimizationLiteral(Handle literal) { void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { - DCHECK(deoptimization_literals_.length() == 0); - - const ZoneList >* inlined_closures = - chunk()->inlined_closures(); - - for (int i = 0, length = inlined_closures->length(); - i < length; - i++) { - DefineDeoptimizationLiteral(inlined_closures->at(i)); + DCHECK_EQ(0, deoptimization_literals_.length()); + for (auto function : chunk()->inlined_functions()) { + DefineDeoptimizationLiteral(function); } - inlined_function_count_ = deoptimization_literals_.length(); } diff --git a/src/mips64/lithium-mips64.cc b/src/mips64/lithium-mips64.cc index 9ccb240..97826e2 100644 --- a/src/mips64/lithium-mips64.cc +++ b/src/mips64/lithium-mips64.cc @@ -2550,7 +2550,7 @@ LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { inner->BindContext(instr->closure_context()); inner->set_entry(instr); current_block_->UpdateEnvironment(inner); - chunk_->AddInlinedClosure(instr->closure()); + chunk_->AddInlinedFunction(instr->shared()); return NULL; } diff --git a/src/ppc/lithium-codegen-ppc.cc b/src/ppc/lithium-codegen-ppc.cc index 57def67..95d7cd9 100644 --- a/src/ppc/lithium-codegen-ppc.cc +++ b/src/ppc/lithium-codegen-ppc.cc @@ -895,15 +895,12 @@ int LCodeGen::DefineDeoptimizationLiteral(Handle literal) { void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { - DCHECK(deoptimization_literals_.length() == 0); - - const ZoneList >* inlined_closures = + DCHECK_EQ(0, deoptimization_literals_.length()); + const ZoneList>* const inlined_closures = chunk()->inlined_closures(); - - for (int i = 0, length = inlined_closures->length(); i < length; i++) { - DefineDeoptimizationLiteral(inlined_closures->at(i)); + for (int i = 0; i < inlined_closures->length(); ++i) { + DefineDeoptimizationLiteral(handle(inlined_closures->at(i)->shared())); } - inlined_function_count_ = deoptimization_literals_.length(); } diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 740ea8a..b9b6aba 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -900,17 +900,10 @@ int LCodeGen::DefineDeoptimizationLiteral(Handle literal) { void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { - DCHECK(deoptimization_literals_.length() == 0); - - const ZoneList >* inlined_closures = - chunk()->inlined_closures(); - - for (int i = 0, length = inlined_closures->length(); - i < length; - i++) { - DefineDeoptimizationLiteral(inlined_closures->at(i)); + DCHECK_EQ(0, deoptimization_literals_.length()); + for (auto function : chunk()->inlined_functions()) { + DefineDeoptimizationLiteral(function); } - inlined_function_count_ = deoptimization_literals_.length(); } diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc index 7b08383..18d282a 100644 --- a/src/x64/lithium-x64.cc +++ b/src/x64/lithium-x64.cc @@ -2636,7 +2636,7 @@ LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { inner->BindContext(instr->closure_context()); inner->set_entry(instr); current_block_->UpdateEnvironment(inner); - chunk_->AddInlinedClosure(instr->closure()); + chunk_->AddInlinedFunction(instr->shared()); return NULL; } -- 2.7.4