Reviewers: vogelheim,

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

[email protected]

Please review this at https://codereview.chromium.org/952933002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+37, -13 lines):
  M src/serialize.h
  M src/serialize.cc


Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index f30c8e046a699179ae0c3d8806ae7b1e1becc5b9..05a54188b86cfbeef9bc010a083fcad001d9adb5 100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -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;
-  }
-
-  // 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 new_index = cache->length();
+
+ 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;
 }


Index: src/serialize.h
diff --git a/src/serialize.h b/src/serialize.h
index cfe9e1158dbad73e2c0779a955ae72c3e04b23c0..64164c803a931c61b4808b64a025ab2c4d4e6e55 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -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);
 };



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to