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}
This commit is contained in:
parent
bc483ddac4
commit
c18de60248
@ -1523,19 +1523,20 @@ void SerializerDeserializer::Iterate(Isolate* isolate,
|
||||
int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
|
||||
Isolate* isolate = this->isolate();
|
||||
List<Object*>* cache = isolate->partial_snapshot_cache();
|
||||
for (int i = 0; i < cache->length(); ++i) {
|
||||
Object* entry = cache->at(i);
|
||||
if (entry == heap_object) return i;
|
||||
}
|
||||
int new_index = cache->length();
|
||||
|
||||
// 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
|
||||
// and we can refer to it from the partial snapshot.
|
||||
cache->Add(heap_object);
|
||||
startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object));
|
||||
// We don't recurse from the startup snapshot generator into the partial
|
||||
// snapshot generator.
|
||||
return cache->length() - 1;
|
||||
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
|
||||
// then visit the pointer so that it becomes part of the startup snapshot
|
||||
// and we can refer to it from the partial snapshot.
|
||||
cache->Add(heap_object);
|
||||
startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object));
|
||||
// We don't recurse from the startup snapshot generator into the partial
|
||||
// snapshot generator.
|
||||
return new_index;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 {
|
||||
public:
|
||||
explicit BackReference(uint32_t bitfield) : bitfield_(bitfield) {}
|
||||
@ -802,6 +824,7 @@ class PartialSerializer : public Serializer {
|
||||
Serializer* startup_serializer_;
|
||||
List<BackReference> outdated_contexts_;
|
||||
Object* global_object_;
|
||||
PartialCacheIndexMap partial_cache_index_map_;
|
||||
DISALLOW_COPY_AND_ASSIGN(PartialSerializer);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user