From 8a02fd3be35495eb1a36009bb6b378acfe3aa6e2 Mon Sep 17 00:00:00 2001 From: "mvstanton@chromium.org" Date: Tue, 4 Jun 2013 12:48:51 +0000 Subject: [PATCH] Turn off allocation site info for crankshafted array constructor calls. Once we crankshaft a method, we should turn off allocation site info for constructed arrays. Additionally, the semantics for doing this were awkward because the constructed array code stubs get an AllocationSiteMode as a minor key, but it's used as a permission to determine the final mode locally based on ElementsKind. I refactored this to a simpler boolean for override or local control. BUG= R=hpayer@chromium.org Review URL: https://codereview.chromium.org/16206007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14934 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/code-stubs-arm.cc | 4 ++++ src/arm/lithium-codegen-arm.cc | 9 ++++++--- src/code-stubs-hydrogen.cc | 6 +++--- src/code-stubs.h | 29 ++++++++++++++++------------- src/hydrogen.cc | 10 ++++------ src/hydrogen.h | 2 +- src/ia32/code-stubs-ia32.cc | 6 +++++- src/ia32/lithium-codegen-ia32.cc | 9 ++++++--- src/x64/code-stubs-x64.cc | 4 ++++ src/x64/lithium-codegen-x64.cc | 9 ++++++--- 10 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index 0360994..0227b25 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -7244,6 +7244,10 @@ static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); T stub(kind); stub.GetCode(isolate)->set_is_pregenerated(true); + if (AllocationSiteInfo::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { + T stub1(kind, true); + stub1.GetCode(isolate)->set_is_pregenerated(true); + } } } diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index d2b2c26..d1be92f 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -4229,14 +4229,17 @@ void LCodeGen::DoCallNewArray(LCallNewArray* instr) { __ mov(r0, Operand(instr->arity())); __ mov(r2, Operand(instr->hydrogen()->property_cell())); ElementsKind kind = instr->hydrogen()->elements_kind(); + bool disable_allocation_sites = + (AllocationSiteInfo::GetMode(kind) == TRACK_ALLOCATION_SITE); + if (instr->arity() == 0) { - ArrayNoArgumentConstructorStub stub(kind); + ArrayNoArgumentConstructorStub stub(kind, disable_allocation_sites); CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); } else if (instr->arity() == 1) { - ArraySingleArgumentConstructorStub stub(kind); + ArraySingleArgumentConstructorStub stub(kind, disable_allocation_sites); CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); } else { - ArrayNArgumentsConstructorStub stub(kind); + ArrayNArgumentsConstructorStub stub(kind, disable_allocation_sites); CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); } } diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc index 4ec8654..77657c0 100644 --- a/src/code-stubs-hydrogen.cc +++ b/src/code-stubs-hydrogen.cc @@ -537,7 +537,7 @@ HValue* CodeStubGraphBuilder::BuildCodeStub() { this, casted_stub()->elements_kind(), GetParameter(ArrayConstructorStubBase::kPropertyCell), - casted_stub()->mode()); + casted_stub()->disable_allocation_sites()); return array_builder.AllocateEmptyArray(); } @@ -589,7 +589,7 @@ HValue* CodeStubGraphBuilder:: this, casted_stub()->elements_kind(), GetParameter(ArrayConstructorStubBase::kPropertyCell), - casted_stub()->mode()); + casted_stub()->disable_allocation_sites()); return array_builder.AllocateArray(capacity, length, true); } @@ -612,7 +612,7 @@ HValue* CodeStubGraphBuilder::BuildCodeStub() { this, kind, GetParameter(ArrayConstructorStubBase::kPropertyCell), - casted_stub()->mode()); + casted_stub()->disable_allocation_sites()); // We need to fill with the hole if it's a smi array in the multi-argument // case because we might have to bail out while copying arguments into diff --git a/src/code-stubs.h b/src/code-stubs.h index 75c1295..5a5abcb 100644 --- a/src/code-stubs.h +++ b/src/code-stubs.h @@ -1726,19 +1726,22 @@ class TransitionElementsKindStub : public HydrogenCodeStub { class ArrayConstructorStubBase : public HydrogenCodeStub { public: - ArrayConstructorStubBase(ElementsKind kind, AllocationSiteMode mode) { + ArrayConstructorStubBase(ElementsKind kind, bool disable_allocation_sites) { + // It only makes sense to override local allocation site behavior + // if there is a difference between the global allocation site policy + // for an ElementsKind and the desired usage of the stub. + ASSERT(!disable_allocation_sites || + AllocationSiteInfo::GetMode(kind) == TRACK_ALLOCATION_SITE); bit_field_ = ElementsKindBits::encode(kind) | - AllocationSiteModeBits::encode(mode == TRACK_ALLOCATION_SITE); + DisableAllocationSitesBits::encode(disable_allocation_sites); } ElementsKind elements_kind() const { return ElementsKindBits::decode(bit_field_); } - AllocationSiteMode mode() const { - return AllocationSiteModeBits::decode(bit_field_) - ? TRACK_ALLOCATION_SITE - : DONT_TRACK_ALLOCATION_SITE; + bool disable_allocation_sites() const { + return DisableAllocationSitesBits::decode(bit_field_); } virtual bool IsPregenerated() { return true; } @@ -1753,7 +1756,7 @@ class ArrayConstructorStubBase : public HydrogenCodeStub { int NotMissMinorKey() { return bit_field_; } class ElementsKindBits: public BitField {}; - class AllocationSiteModeBits: public BitField {}; + class DisableAllocationSitesBits: public BitField {}; uint32_t bit_field_; DISALLOW_COPY_AND_ASSIGN(ArrayConstructorStubBase); @@ -1764,8 +1767,8 @@ class ArrayNoArgumentConstructorStub : public ArrayConstructorStubBase { public: ArrayNoArgumentConstructorStub( ElementsKind kind, - AllocationSiteMode mode = TRACK_ALLOCATION_SITE) - : ArrayConstructorStubBase(kind, mode) { + bool disable_allocation_sites = false) + : ArrayConstructorStubBase(kind, disable_allocation_sites) { } virtual Handle GenerateCode(); @@ -1785,8 +1788,8 @@ class ArraySingleArgumentConstructorStub : public ArrayConstructorStubBase { public: ArraySingleArgumentConstructorStub( ElementsKind kind, - AllocationSiteMode mode = TRACK_ALLOCATION_SITE) - : ArrayConstructorStubBase(kind, mode) { + bool disable_allocation_sites = false) + : ArrayConstructorStubBase(kind, disable_allocation_sites) { } virtual Handle GenerateCode(); @@ -1806,8 +1809,8 @@ class ArrayNArgumentsConstructorStub : public ArrayConstructorStubBase { public: ArrayNArgumentsConstructorStub( ElementsKind kind, - AllocationSiteMode mode = TRACK_ALLOCATION_SITE) : - ArrayConstructorStubBase(kind, mode) { + bool disable_allocation_sites = false) + : ArrayConstructorStubBase(kind, disable_allocation_sites) { } virtual Handle GenerateCode(); diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 1cf6d83..f424a47 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -1766,15 +1766,13 @@ HInstruction* HGraphBuilder::BuildGetArrayFunction(HValue* context) { HGraphBuilder::JSArrayBuilder::JSArrayBuilder(HGraphBuilder* builder, ElementsKind kind, HValue* allocation_site_payload, - AllocationSiteMode mode) : + bool disable_allocation_sites) : builder_(builder), kind_(kind), allocation_site_payload_(allocation_site_payload) { - if (mode == DONT_TRACK_ALLOCATION_SITE) { - mode_ = mode; - } else { - mode_ = AllocationSiteInfo::GetMode(kind); - } + mode_ = disable_allocation_sites + ? DONT_TRACK_ALLOCATION_SITE + : AllocationSiteInfo::GetMode(kind); } diff --git a/src/hydrogen.h b/src/hydrogen.h index 6163e1e..df9b963 100644 --- a/src/hydrogen.h +++ b/src/hydrogen.h @@ -1232,7 +1232,7 @@ class HGraphBuilder { JSArrayBuilder(HGraphBuilder* builder, ElementsKind kind, HValue* allocation_site_payload, - AllocationSiteMode mode); + bool disable_allocation_sites); HValue* AllocateEmptyArray(); HValue* AllocateArray(HValue* capacity, HValue* length_field, diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc index f8d10a1..40af087 100644 --- a/src/ia32/code-stubs-ia32.cc +++ b/src/ia32/code-stubs-ia32.cc @@ -7823,8 +7823,12 @@ static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { TERMINAL_FAST_ELEMENTS_KIND); for (int i = 0; i <= to_index; ++i) { ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); - T stub(kind); + T stub(kind, false); stub.GetCode(isolate)->set_is_pregenerated(true); + if (AllocationSiteInfo::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { + T stub1(kind, true); + stub1.GetCode(isolate)->set_is_pregenerated(true); + } } } diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 9472722..98f1e8b 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -4238,14 +4238,17 @@ void LCodeGen::DoCallNewArray(LCallNewArray* instr) { __ Set(eax, Immediate(instr->arity())); __ mov(ebx, instr->hydrogen()->property_cell()); ElementsKind kind = instr->hydrogen()->elements_kind(); + bool disable_allocation_sites = + (AllocationSiteInfo::GetMode(kind) == TRACK_ALLOCATION_SITE); + if (instr->arity() == 0) { - ArrayNoArgumentConstructorStub stub(kind); + ArrayNoArgumentConstructorStub stub(kind, disable_allocation_sites); CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); } else if (instr->arity() == 1) { - ArraySingleArgumentConstructorStub stub(kind); + ArraySingleArgumentConstructorStub stub(kind, disable_allocation_sites); CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); } else { - ArrayNArgumentsConstructorStub stub(kind); + ArrayNArgumentsConstructorStub stub(kind, disable_allocation_sites); CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); } } diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc index 48a0507..0efd8c8 100644 --- a/src/x64/code-stubs-x64.cc +++ b/src/x64/code-stubs-x64.cc @@ -6830,6 +6830,10 @@ static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); T stub(kind); stub.GetCode(isolate)->set_is_pregenerated(true); + if (AllocationSiteInfo::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { + T stub1(kind, true); + stub1.GetCode(isolate)->set_is_pregenerated(true); + } } } diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 8d86675..4a469f7 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -3935,14 +3935,17 @@ void LCodeGen::DoCallNewArray(LCallNewArray* instr) { __ Set(rax, instr->arity()); __ Move(rbx, instr->hydrogen()->property_cell()); ElementsKind kind = instr->hydrogen()->elements_kind(); + bool disable_allocation_sites = + (AllocationSiteInfo::GetMode(kind) == TRACK_ALLOCATION_SITE); + if (instr->arity() == 0) { - ArrayNoArgumentConstructorStub stub(kind); + ArrayNoArgumentConstructorStub stub(kind, disable_allocation_sites); CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); } else if (instr->arity() == 1) { - ArraySingleArgumentConstructorStub stub(kind); + ArraySingleArgumentConstructorStub stub(kind, disable_allocation_sites); CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); } else { - ArrayNArgumentsConstructorStub stub(kind); + ArrayNArgumentsConstructorStub stub(kind, disable_allocation_sites); CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); } } -- 2.7.4