From edb70555fff745825106061d083d964fd9cbc6ee Mon Sep 17 00:00:00 2001 From: ulan Date: Tue, 3 Feb 2015 03:26:52 -0800 Subject: [PATCH] Use weak cell to embed property cell in StoreGlobal. BUG=v8:3629 LOG=N Review URL: https://codereview.chromium.org/898723002 Cr-Commit-Position: refs/heads/master@{#26396} --- src/code-stubs-hydrogen.cc | 11 ++++++----- src/code-stubs.h | 8 +++++--- src/hydrogen-instructions.h | 10 ++++++++++ src/objects.h | 2 ++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc index 826c1dd..dd2f788 100644 --- a/src/code-stubs-hydrogen.cc +++ b/src/code-stubs-hydrogen.cc @@ -1310,9 +1310,6 @@ Handle ToBooleanStub::GenerateCode() { template <> HValue* CodeStubGraphBuilder::BuildCodeInitializedStub() { StoreGlobalStub* stub = casted_stub(); - Handle placeholer_value(Smi::FromInt(0), isolate()); - Handle placeholder_cell = - isolate()->factory()->NewPropertyCell(placeholer_value); HParameter* value = GetParameter(StoreDescriptor::kValueIndex); if (stub->check_global()) { // Check that the map of the global has not changed: use a placeholder map @@ -1334,7 +1331,10 @@ HValue* CodeStubGraphBuilder::BuildCodeInitializedStub() { map_check.End(); } - HValue* cell = Add(placeholder_cell); + HValue* weak_cell = Add(isolate()->factory()->NewWeakCell( + StoreGlobalStub::property_cell_placeholder(isolate()))); + HValue* cell = Add(weak_cell, nullptr, + HObjectAccess::ForWeakCellValue()); HObjectAccess access(HObjectAccess::ForCellPayload(isolate())); HValue* cell_contents = Add(cell, nullptr, access); @@ -1354,7 +1354,8 @@ HValue* CodeStubGraphBuilder::BuildCodeInitializedStub() { builder.Then(); builder.Deopt("Unexpected cell contents in global store"); builder.Else(); - Add(cell, access, value); + HStoreNamedField* store = Add(cell, access, value); + store->MarkReceiverAsCell(); builder.End(); } diff --git a/src/code-stubs.h b/src/code-stubs.h index f8009a2..2c9f1fb 100644 --- a/src/code-stubs.h +++ b/src/code-stubs.h @@ -1084,7 +1084,7 @@ class StoreGlobalStub : public HandlerStub { CheckGlobalBits::encode(check_global)); } - static Handle global_placeholder(Isolate* isolate) { + static Handle property_cell_placeholder(Isolate* isolate) { return isolate->factory()->uninitialized_value(); } @@ -1094,11 +1094,13 @@ class StoreGlobalStub : public HandlerStub { Code::FindAndReplacePattern pattern; pattern.Add(isolate()->factory()->meta_map(), Map::WeakCellForMap(Handle(global->map()))); - pattern.Add(isolate()->factory()->global_property_cell_map(), cell); + pattern.Add(Handle(property_cell_placeholder(isolate())->map()), + isolate()->factory()->NewWeakCell(cell)); return CodeStub::GetCodeCopy(pattern); } else { Code::FindAndReplacePattern pattern; - pattern.Add(isolate()->factory()->global_property_cell_map(), cell); + pattern.Add(Handle(property_cell_placeholder(isolate())->map()), + isolate()->factory()->NewWeakCell(cell)); return CodeStub::GetCodeCopy(pattern); } } diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index ed4b065..b69ce79 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -6969,6 +6969,14 @@ class HStoreNamedField FINAL : public HTemplateInstruction<3> { SetChangesFlag(kMaps); } + void MarkReceiverAsCell() { + bit_field_ = ReceiverIsCellField::update(bit_field_, true); + } + + bool receiver_is_cell() const { + return ReceiverIsCellField::decode(bit_field_); + } + bool NeedsWriteBarrier() const { DCHECK(!field_representation().IsDouble() || (FLAG_unbox_double_fields && access_.IsInobject()) || @@ -6977,6 +6985,7 @@ class HStoreNamedField FINAL : public HTemplateInstruction<3> { if (field_representation().IsSmi()) return false; if (field_representation().IsInteger32()) return false; if (field_representation().IsExternal()) return false; + if (receiver_is_cell()) return false; return StoringValueNeedsWriteBarrier(value()) && ReceiverObjectNeedsWriteBarrier(object(), value(), dominator()); } @@ -7036,6 +7045,7 @@ class HStoreNamedField FINAL : public HTemplateInstruction<3> { class HasTransitionField : public BitField {}; class StoreModeField : public BitField {}; + class ReceiverIsCellField : public BitField {}; HObjectAccess access_; HValue* dominator_; diff --git a/src/objects.h b/src/objects.h index 919a558..d1e5acf 100644 --- a/src/objects.h +++ b/src/objects.h @@ -5256,6 +5256,8 @@ class Code: public HeapObject { // function replaces the corresponding placeholder in the code with the // object-to-replace. The function assumes that pairs in the pattern come in // the same order as the placeholders in the code. + // If the placeholder is a weak cell, then the value of weak cell is matched + // against the map-to-find. void FindAndReplace(const FindAndReplacePattern& pattern); // The entire code object including its header is copied verbatim to the -- 2.7.4