Reviewers: Jakob,

Description:
Remove reinvented wheel for partial snapshot cache.

[email protected]

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

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

Affected files (+17, -55 lines):
  M src/isolate.h
  M src/isolate.cc
  M src/serialize.h
  M src/serialize.cc


Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 2c8367d7a1b26a480dd9be27dc0ff14fc2ac0fda..203ad1f6a06a576f7ccc561699c84dcf992b8d79 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -1757,11 +1757,6 @@ void Isolate::TearDown() {
     thread_data_table_->RemoveAllThreads(this);
   }

-  if (serialize_partial_snapshot_cache_ != NULL) {
-    delete[] serialize_partial_snapshot_cache_;
-    serialize_partial_snapshot_cache_ = NULL;
-  }
-
   delete this;

   // Restore the previous current isolate.
@@ -1825,26 +1820,6 @@ void Isolate::Deinit() {
 }


-void Isolate::PushToPartialSnapshotCache(Object* obj) {
-  int length = serialize_partial_snapshot_cache_length();
-  int capacity = serialize_partial_snapshot_cache_capacity();
-
-  if (length >= capacity) {
-    int new_capacity = static_cast<int>((capacity + 10) * 1.2);
-    Object** new_array = new Object*[new_capacity];
-    for (int i = 0; i < length; i++) {
-      new_array[i] = serialize_partial_snapshot_cache()[i];
-    }
-    if (capacity != 0) delete[] serialize_partial_snapshot_cache();
-    set_serialize_partial_snapshot_cache(new_array);
-    set_serialize_partial_snapshot_cache_capacity(new_capacity);
-  }
-
-  serialize_partial_snapshot_cache()[length] = obj;
-  set_serialize_partial_snapshot_cache_length(length + 1);
-}
-
-
 void Isolate::SetIsolateThreadLocals(Isolate* isolate,
                                      PerIsolateThreadData* data) {
   base::Thread::SetThreadLocal(isolate_key_, isolate);
@@ -2088,7 +2063,7 @@ bool Isolate::Init(Deserializer* des) {

   if (create_heap_objects) {
     // Terminate the cache array with the sentinel so we can iterate.
-    PushToPartialSnapshotCache(heap_.undefined_value());
+    partial_snapshot_cache_.Add(heap_.undefined_value());
   }

   InitializeThreadLocal();
Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index fdd183288897f4721d8aa96b5435db48b2a73b95..01a064d21d3fa5b8a5634f064082ba6f8aba391c 100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -361,10 +361,6 @@ class ThreadLocalTop BASE_EMBEDDED {
 typedef List<HeapObject*> DebugObjectCache;

#define ISOLATE_INIT_LIST(V) \ - /* SerializerDeserializer state. */ \ - V(int, serialize_partial_snapshot_cache_length, 0) \ - V(int, serialize_partial_snapshot_cache_capacity, 0) \ - V(Object**, serialize_partial_snapshot_cache, NULL) \ /* Assembler state. */ \ V(FatalErrorCallback, exception_behavior, NULL) \ V(LogEventCallback, event_logger, NULL) \
@@ -649,9 +645,6 @@ class Isolate {
     return exception != heap()->termination_exception();
   }

-  // Serializer.
-  void PushToPartialSnapshotCache(Object* obj);
-
   // JS execution stack (see frames.h).
   static Address c_entry_fp(ThreadLocalTop* thread) {
     return thread->c_entry_fp_;
@@ -1139,6 +1132,8 @@ class Isolate {
   void AddDetachedContext(Handle<Context> context);
   void CheckDetachedContextsAfterGC();

+ List<Object*>* partial_snapshot_cache() { return &partial_snapshot_cache_; }
+
  private:
   explicit Isolate(bool enable_serializer);

@@ -1360,6 +1355,7 @@ class Isolate {
   v8::Isolate::UseCounterCallback use_counter_callback_;
   BasicBlockProfiler* basic_block_profiler_;

+  List<Object*> partial_snapshot_cache_;

   friend class ExecutionAccess;
   friend class HandleScopeImplementer;
Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index 1d18fac04c086342035649eb3349f55c4e724ca6..f30c8e046a699179ae0c3d8806ae7b1e1becc5b9 100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -998,7 +998,7 @@ void Deserializer::ReadData(Object** current, Object** limit, int source_space, emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ } else if (where == kPartialSnapshotCache) { \ int cache_index = source_.GetInt(); \ - new_object = isolate->serialize_partial_snapshot_cache()[cache_index]; \ + new_object = isolate->partial_snapshot_cache()->at(cache_index); \ emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ } else if (where == kExternalReference) { \ int skip = source_.GetInt(); \
@@ -1508,43 +1508,34 @@ void Serializer::EncodeReservations(
 void SerializerDeserializer::Iterate(Isolate* isolate,
                                      ObjectVisitor* visitor) {
   if (isolate->serializer_enabled()) return;
-  for (int i = 0; ; i++) {
-    if (isolate->serialize_partial_snapshot_cache_length() <= i) {
-      // Extend the array ready to get a value from the visitor when
-      // deserializing.
-      isolate->PushToPartialSnapshotCache(Smi::FromInt(0));
-    }
-    Object** cache = isolate->serialize_partial_snapshot_cache();
-    visitor->VisitPointers(&cache[i], &cache[i + 1]);
+  List<Object*>* cache = isolate->partial_snapshot_cache();
+  for (int i = 0;; ++i) {
+    // Extend the array ready to get a value when deserializing.
+    if (cache->length() <= i) cache->Add(Smi::FromInt(0));
+    visitor->VisitPointer(&cache->at(i));
// Sentinel is the undefined object, which is a root so it will not normally
     // be found in the cache.
-    if (cache[i] == isolate->heap()->undefined_value()) {
-      break;
-    }
+    if (cache->at(i)->IsUndefined()) break;
   }
 }


 int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
   Isolate* isolate = this->isolate();
-
-  for (int i = 0;
-       i < isolate->serialize_partial_snapshot_cache_length();
-       i++) {
-    Object* entry = isolate->serialize_partial_snapshot_cache()[i];
+  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.
-  int length = isolate->serialize_partial_snapshot_cache_length();
-  isolate->PushToPartialSnapshotCache(heap_object);
+  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.
-  DCHECK(length == isolate->serialize_partial_snapshot_cache_length() - 1);
-  return length;
+  return cache->length() - 1;
 }


Index: src/serialize.h
diff --git a/src/serialize.h b/src/serialize.h
index b76abbcbac7e3895b2a8a8b3fcee9aa32ab2f64a..cfe9e1158dbad73e2c0779a955ae72c3e04b23c0 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -814,7 +814,7 @@ class StartupSerializer : public Serializer {
     // strong roots have been serialized we can create a partial snapshot
     // which will repopulate the cache with objects needed by that partial
     // snapshot.
-    isolate->set_serialize_partial_snapshot_cache_length(0);
+    isolate->partial_snapshot_cache()->Clear();
     InitializeCodeAddressMap();
   }



--
--
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