Commit c18de602 authored by yangguo's avatar yangguo Committed by Commit bot

Use a hashmap to lookup items in the partial snapshot cache when serializing.

R=vogelheim@chromium.org

Review URL: https://codereview.chromium.org/952933002

Cr-Commit-Position: refs/heads/master@{#26839}
parent bc483dda
...@@ -1523,19 +1523,20 @@ void SerializerDeserializer::Iterate(Isolate* isolate, ...@@ -1523,19 +1523,20 @@ void SerializerDeserializer::Iterate(Isolate* isolate,
int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) { int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
Isolate* isolate = this->isolate(); Isolate* isolate = this->isolate();
List<Object*>* cache = isolate->partial_snapshot_cache(); List<Object*>* cache = isolate->partial_snapshot_cache();
for (int i = 0; i < cache->length(); ++i) { int new_index = cache->length();
Object* entry = cache->at(i);
if (entry == heap_object) return i; int index = partial_cache_index_map_.LookupOrInsert(heap_object, new_index);
} if (index == PartialCacheIndexMap::kInvalidIndex) {
// We didn't find the object in the cache. So we add it to the cache and
// We didn't find the object in the cache. So we add it to the cache and // then visit the pointer so that it becomes part of the startup snapshot
// then visit the pointer so that it becomes part of the startup snapshot // and we can refer to it from the partial snapshot.
// and we can refer to it from the partial snapshot. cache->Add(heap_object);
cache->Add(heap_object); startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object));
startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object)); // We don't recurse from the startup snapshot generator into the partial
// We don't recurse from the startup snapshot generator into the partial // snapshot generator.
// snapshot generator. return new_index;
return cache->length() - 1; }
return index;
} }
......
...@@ -186,6 +186,28 @@ class RootIndexMap : public AddressMapBase { ...@@ -186,6 +186,28 @@ class RootIndexMap : public AddressMapBase {
}; };
class PartialCacheIndexMap : public AddressMapBase {
public:
PartialCacheIndexMap() : map_(HashMap::PointersMatch) {}
static const int kInvalidIndex = -1;
// Lookup object in the map. Return its index if found, or create
// a new entry with new_index as value, and return kInvalidIndex.
int LookupOrInsert(HeapObject* obj, int new_index) {
HashMap::Entry* entry = LookupEntry(&map_, obj, true);
if (entry->value != NULL) return GetValue(entry);
SetValue(entry, static_cast<uint32_t>(new_index));
return kInvalidIndex;
}
private:
HashMap map_;
DISALLOW_COPY_AND_ASSIGN(PartialCacheIndexMap);
};
class BackReference { class BackReference {
public: public:
explicit BackReference(uint32_t bitfield) : bitfield_(bitfield) {} explicit BackReference(uint32_t bitfield) : bitfield_(bitfield) {}
...@@ -802,6 +824,7 @@ class PartialSerializer : public Serializer { ...@@ -802,6 +824,7 @@ class PartialSerializer : public Serializer {
Serializer* startup_serializer_; Serializer* startup_serializer_;
List<BackReference> outdated_contexts_; List<BackReference> outdated_contexts_;
Object* global_object_; Object* global_object_;
PartialCacheIndexMap partial_cache_index_map_;
DISALLOW_COPY_AND_ASSIGN(PartialSerializer); DISALLOW_COPY_AND_ASSIGN(PartialSerializer);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment