Revision: 3785
Author: [email protected]
Date: Wed Feb  3 04:58:31 2010
Log: Create a test that serializes and deserializes a context.  Fix
minor related bugs.
Review URL: http://codereview.chromium.org/560031
http://code.google.com/p/v8/source/detail?r=3785

Modified:
 /branches/experimental/partial_snapshots/src/serialize.cc
 /branches/experimental/partial_snapshots/src/serialize.h
 /branches/experimental/partial_snapshots/test/cctest/test-serialize.cc

=======================================
--- /branches/experimental/partial_snapshots/src/serialize.cc Wed Feb 3 02:52:22 2010 +++ /branches/experimental/partial_snapshots/src/serialize.cc Wed Feb 3 04:58:31 2010
@@ -990,6 +990,7 @@
     Object* entry = partial_snapshot_cache_[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.
=======================================
--- /branches/experimental/partial_snapshots/src/serialize.h Wed Feb 3 02:52:22 2010 +++ /branches/experimental/partial_snapshots/src/serialize.h Wed Feb 3 04:58:31 2010
@@ -231,7 +231,7 @@
   }

   static int partial_snapshot_cache_length_;
-  static const int kPartialSnapshotCacheCapacity = 1024;
+  static const int kPartialSnapshotCacheCapacity = 1300;
   static Object* partial_snapshot_cache_[];
   static bool tracing_;
 };
@@ -522,7 +522,7 @@
   virtual int RootIndex(HeapObject* o);
   virtual int PartialSnapshotCacheIndex(HeapObject* o);
   virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
-    return o->IsString() || o->IsSharedFunctionInfo();
+    return o->IsString() || o->IsSharedFunctionInfo() || o->IsHeapNumber();
   }

  private:
=======================================
--- /branches/experimental/partial_snapshots/test/cctest/test-serialize.cc Wed Feb 3 02:52:22 2010 +++ /branches/experimental/partial_snapshots/test/cctest/test-serialize.cc Wed Feb 3 04:58:31 2010
@@ -394,14 +394,8 @@
 }


-DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
-  int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
-  Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
- OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
-
-  CHECK(Snapshot::Initialize(startup_name.start()));
-
-  const char* file_name = FLAG_testing_serialization_file;
+static void ReserveSpaceForPartialSnapshot(const char* file_name) {
+  int file_name_length = StrLength(file_name) + 10;
   Vector<char> name = Vector<char>::New(file_name_length + 1);
   OS::SNPrintF(name, "%s.size", file_name);
   FILE* fp = OS::FOpen(name.start(), "r");
@@ -430,6 +424,19 @@
                      map_size,
                      cell_size,
                      large_size);
+}
+
+
+DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
+  int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
+  Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
+ OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
+
+  CHECK(Snapshot::Initialize(startup_name.start()));
+
+  const char* file_name = FLAG_testing_serialization_file;
+  ReserveSpaceForPartialSnapshot(file_name);
+
   int snapshot_size = 0;
   byte* snapshot = ReadBytes(file_name, &snapshot_size);

@@ -452,6 +459,85 @@
     CHECK(*root_handle == root2);
   }
 }
+
+
+TEST(ContextSerialization) {
+  Serializer::Enable();
+  v8::V8::Initialize();
+
+  v8::Persistent<v8::Context> env = v8::Context::New();
+  ASSERT(!env.IsEmpty());
+  env->Enter();
+  // Make sure all builtin scripts are cached.
+  { HandleScope scope;
+    for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
+      Bootstrapper::NativesSourceLookup(i);
+    }
+  }
+  // If we don't do this then we end up with a stray root pointing at the
+  // context even after we have disposed of env.
+  Heap::CollectAllGarbage(true);
+
+  int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
+  Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
+ OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
+
+  env->Exit();
+
+  Object* raw_context = *(v8::Utils::OpenHandle(*env));
+
+  env.Dispose();
+
+  FileByteSink startup_sink(startup_name.start());
+  StartupSerializer startup_serializer(&startup_sink);
+  startup_serializer.SerializeStrongReferences();
+
+  FileByteSink partial_sink(FLAG_testing_serialization_file);
+  PartialSerializer p_ser(&startup_serializer, &partial_sink);
+  p_ser.Serialize(&raw_context);
+  startup_serializer.SerializeWeakReferences();
+  partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE),
+ p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), + p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
+                              p_ser.CurrentAllocationAddress(CODE_SPACE),
+                              p_ser.CurrentAllocationAddress(MAP_SPACE),
+                              p_ser.CurrentAllocationAddress(CELL_SPACE),
+                              p_ser.CurrentAllocationAddress(LO_SPACE));
+}
+
+
+DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
+  int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
+  Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
+ OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
+
+  CHECK(Snapshot::Initialize(startup_name.start()));
+
+  const char* file_name = FLAG_testing_serialization_file;
+  ReserveSpaceForPartialSnapshot(file_name);
+
+  int snapshot_size = 0;
+  byte* snapshot = ReadBytes(file_name, &snapshot_size);
+
+  Object* root;
+  {
+    SnapshotByteSource source(snapshot, snapshot_size);
+    Deserializer deserializer(&source);
+    deserializer.DeserializePartial(&root);
+    CHECK(root->IsContext());
+  }
+  v8::HandleScope handle_scope;
+  Handle<Object>root_handle(root);
+
+  Object* root2;
+  {
+    SnapshotByteSource source(snapshot, snapshot_size);
+    Deserializer deserializer(&source);
+    deserializer.DeserializePartial(&root2);
+    CHECK(root2->IsContext());
+    CHECK(*root_handle != root2);
+  }
+}


 TEST(LinearAllocation) {

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to