From ace94df55831d8c075f7fae3624b0fd41c850d4c Mon Sep 17 00:00:00 2001 From: yangguo Date: Fri, 16 Jan 2015 14:22:13 -0800 Subject: [PATCH] Use back reference map to find references to global proxy. R=mvstanton@chromium.org Review URL: https://codereview.chromium.org/825933004 Cr-Commit-Position: refs/heads/master@{#26114} --- src/serialize.cc | 20 +++++++++----------- src/serialize.h | 14 +++++++++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/serialize.cc b/src/serialize.cc index 085f4e5..140902f 100644 --- a/src/serialize.cc +++ b/src/serialize.cc @@ -1405,7 +1405,7 @@ void PartialSerializer::Serialize(Object** o) { if ((*o)->IsContext()) { Context* context = Context::cast(*o); global_object_ = context->global_object(); - global_proxy_ = context->global_proxy(); + back_reference_map()->AddGlobalProxy(context->global_proxy()); } VisitPointer(o); SerializeOutdatedContextsAsFixedArray(); @@ -1562,8 +1562,14 @@ bool Serializer::SerializeKnownObject(HeapObject* obj, HowToCode how_to_code, FlushSkip(skip); if (FLAG_trace_serializer) PrintF(" Encoding source object\n"); DCHECK(how_to_code == kPlain && where_to_point == kStartOfObject); - sink_->Put(kAttachedReference + how_to_code + where_to_point, "Source"); - sink_->PutInt(kSourceObjectReference, "kSourceObjectIndex"); + sink_->Put(kAttachedReference + kPlain + kStartOfObject, "Source"); + sink_->PutInt(kSourceObjectReference, "kSourceObjectReference"); + } else if (back_reference.is_global_proxy()) { + FlushSkip(skip); + if (FLAG_trace_serializer) PrintF(" Encoding global proxy\n"); + DCHECK(how_to_code == kPlain && where_to_point == kStartOfObject); + sink_->Put(kAttachedReference + kPlain + kStartOfObject, "Global Proxy"); + sink_->PutInt(kGlobalProxyReference, "kGlobalProxyReference"); } else { if (FLAG_trace_serializer) { PrintF(" Encoding back reference to: "); @@ -1696,14 +1702,6 @@ void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, FlushSkip(skip); - if (obj == global_proxy_) { - FlushSkip(skip); - DCHECK(how_to_code == kPlain && where_to_point == kStartOfObject); - sink_->Put(kAttachedReference + how_to_code + where_to_point, "Reference"); - sink_->PutInt(kGlobalProxyReference, "kGlobalProxyReferenceIndex"); - return; - } - // Object has not yet been serialized. Serialize it here. ObjectSerializer serializer(this, obj, sink_, how_to_code, where_to_point); serializer.Serialize(); diff --git a/src/serialize.h b/src/serialize.h index 53dc6eb..cc267aa 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -193,6 +193,10 @@ class BackReference { static BackReference SourceReference() { return BackReference(kSourceValue); } + static BackReference GlobalProxyReference() { + return BackReference(kGlobalProxyValue); + } + static BackReference LargeObjectReference(uint32_t index) { return BackReference(SpaceBits::encode(LO_SPACE) | ChunkOffsetBits::encode(index)); @@ -209,6 +213,7 @@ class BackReference { bool is_valid() const { return bitfield_ != kInvalidValue; } bool is_source() const { return bitfield_ == kSourceValue; } + bool is_global_proxy() const { return bitfield_ == kGlobalProxyValue; } AllocationSpace space() const { DCHECK(is_valid()); @@ -235,6 +240,7 @@ class BackReference { private: static const uint32_t kInvalidValue = 0xFFFFFFFF; static const uint32_t kSourceValue = 0xFFFFFFFE; + static const uint32_t kGlobalProxyValue = 0xFFFFFFFD; static const int kChunkOffsetSize = kPageSizeBits - kObjectAlignmentBits; static const int kChunkIndexSize = 32 - kChunkOffsetSize - kSpaceTagSize; @@ -278,6 +284,10 @@ class BackReferenceMap : public AddressMapBase { Add(string, BackReference::SourceReference()); } + void AddGlobalProxy(HeapObject* global_proxy) { + Add(global_proxy, BackReference::GlobalProxyReference()); + } + private: DisallowHeapAllocation no_allocation_; HashMap* map_; @@ -751,8 +761,7 @@ class PartialSerializer : public Serializer { : Serializer(isolate, sink), startup_serializer_(startup_snapshot_serializer), outdated_contexts_(0), - global_object_(NULL), - global_proxy_(NULL) { + global_object_(NULL) { InitializeCodeAddressMap(); } @@ -781,7 +790,6 @@ class PartialSerializer : public Serializer { Serializer* startup_serializer_; List outdated_contexts_; Object* global_object_; - Object* global_proxy_; DISALLOW_COPY_AND_ASSIGN(PartialSerializer); }; -- 2.7.4