Index: test/cctest/test-serialize.cc |
diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc |
index de22a5da6862e0da90959a6f46f57b830afe0c50..6abb3845f969d2c3c89bac908e8718a9a30ece4e 100644 |
--- a/test/cctest/test-serialize.cc |
+++ b/test/cctest/test-serialize.cc |
@@ -114,7 +114,7 @@ |
} |
-void WritePayload(const Vector<const byte>& payload, const char* file_name) { |
+void WritePayload(const List<byte>& payload, const char* file_name) { |
FILE* file = v8::base::OS::FOpen(file_name, "wb"); |
if (file == NULL) { |
PrintF("Unable to write to snapshot file \"%s\"\n", file_name); |
@@ -129,12 +129,50 @@ |
} |
+void WriteSpaceUsed(Serializer* ser, const char* file_name) { |
+ int file_name_length = StrLength(file_name) + 10; |
+ Vector<char> name = Vector<char>::New(file_name_length + 1); |
+ SNPrintF(name, "%s.size", file_name); |
+ FILE* fp = v8::base::OS::FOpen(name.start(), "w"); |
+ name.Dispose(); |
+ |
+ Vector<const uint32_t> chunks = ser->FinalAllocationChunks(NEW_SPACE); |
+ CHECK_EQ(1, chunks.length()); |
+ fprintf(fp, "new %d\n", chunks[0]); |
+ chunks = ser->FinalAllocationChunks(OLD_POINTER_SPACE); |
+ CHECK_EQ(1, chunks.length()); |
+ fprintf(fp, "pointer %d\n", chunks[0]); |
+ chunks = ser->FinalAllocationChunks(OLD_DATA_SPACE); |
+ CHECK_EQ(1, chunks.length()); |
+ fprintf(fp, "data %d\n", chunks[0]); |
+ chunks = ser->FinalAllocationChunks(CODE_SPACE); |
+ CHECK_EQ(1, chunks.length()); |
+ fprintf(fp, "code %d\n", chunks[0]); |
+ chunks = ser->FinalAllocationChunks(MAP_SPACE); |
+ CHECK_EQ(1, chunks.length()); |
+ fprintf(fp, "map %d\n", chunks[0]); |
+ chunks = ser->FinalAllocationChunks(CELL_SPACE); |
+ CHECK_EQ(1, chunks.length()); |
+ fprintf(fp, "cell %d\n", chunks[0]); |
+ chunks = ser->FinalAllocationChunks(PROPERTY_CELL_SPACE); |
+ CHECK_EQ(1, chunks.length()); |
+ fprintf(fp, "property cell %d\n", chunks[0]); |
+ chunks = ser->FinalAllocationChunks(LO_SPACE); |
+ CHECK_EQ(1, chunks.length()); |
+ fprintf(fp, "lo %d\n", chunks[0]); |
+ fclose(fp); |
+} |
+ |
+ |
static bool WriteToFile(Isolate* isolate, const char* snapshot_file) { |
SnapshotByteSink sink; |
StartupSerializer ser(isolate, &sink); |
ser.Serialize(); |
- SnapshotData snapshot_data(sink, ser); |
- WritePayload(snapshot_data.RawData(), snapshot_file); |
+ ser.FinalizeAllocation(); |
+ |
+ WritePayload(sink.data(), snapshot_file); |
+ WriteSpaceUsed(&ser, snapshot_file); |
+ |
return true; |
} |
@@ -182,14 +220,53 @@ |
//---------------------------------------------------------------------------- |
// Tests that the heap can be deserialized. |
+ |
+static void ReserveSpaceForSnapshot(Deserializer* deserializer, |
+ const char* file_name) { |
+ int file_name_length = StrLength(file_name) + 10; |
+ Vector<char> name = Vector<char>::New(file_name_length + 1); |
+ SNPrintF(name, "%s.size", file_name); |
+ FILE* fp = v8::base::OS::FOpen(name.start(), "r"); |
+ name.Dispose(); |
+ int new_size, pointer_size, data_size, code_size, map_size, cell_size, |
+ property_cell_size, lo_size; |
+#if V8_CC_MSVC |
+ // Avoid warning about unsafe fscanf from MSVC. |
+ // Please note that this is only fine if %c and %s are not being used. |
+#define fscanf fscanf_s |
+#endif |
+ CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); |
+ CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); |
+ CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); |
+ CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); |
+ CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); |
+ CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); |
+ CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size)); |
+ CHECK_EQ(1, fscanf(fp, "lo %d\n", &lo_size)); |
+#if V8_CC_MSVC |
+#undef fscanf |
+#endif |
+ fclose(fp); |
+ deserializer->AddReservation(NEW_SPACE, new_size); |
+ deserializer->AddReservation(OLD_POINTER_SPACE, pointer_size); |
+ deserializer->AddReservation(OLD_DATA_SPACE, data_size); |
+ deserializer->AddReservation(CODE_SPACE, code_size); |
+ deserializer->AddReservation(MAP_SPACE, map_size); |
+ deserializer->AddReservation(CELL_SPACE, cell_size); |
+ deserializer->AddReservation(PROPERTY_CELL_SPACE, property_cell_size); |
+ deserializer->AddReservation(LO_SPACE, lo_size); |
+} |
+ |
+ |
v8::Isolate* InitializeFromFile(const char* snapshot_file) { |
int len; |
byte* str = ReadBytes(snapshot_file, &len); |
if (!str) return NULL; |
v8::Isolate* v8_isolate = NULL; |
{ |
- SnapshotData snapshot_data(str, len); |
- Deserializer deserializer(&snapshot_data); |
+ SnapshotByteSource source(str, len); |
+ Deserializer deserializer(&source); |
+ ReserveSpaceForSnapshot(&deserializer, snapshot_file); |
Isolate* isolate = Isolate::NewForTesting(); |
v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
v8::Isolate::Scope isolate_scope(v8_isolate); |
@@ -359,11 +436,14 @@ |
startup_serializer.SerializeWeakReferences(); |
- SnapshotData startup_snapshot(startup_sink, startup_serializer); |
- SnapshotData partial_snapshot(partial_sink, partial_serializer); |
- |
- WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); |
- WritePayload(startup_snapshot.RawData(), startup_name.start()); |
+ partial_serializer.FinalizeAllocation(); |
+ startup_serializer.FinalizeAllocation(); |
+ |
+ WritePayload(partial_sink.data(), FLAG_testing_serialization_file); |
+ WritePayload(startup_sink.data(), startup_name.start()); |
+ |
+ WriteSpaceUsed(&partial_serializer, FLAG_testing_serialization_file); |
+ WriteSpaceUsed(&startup_serializer, startup_name.start()); |
startup_name.Dispose(); |
} |
@@ -393,8 +473,9 @@ |
Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
Object* root; |
{ |
- SnapshotData snapshot_data(snapshot, snapshot_size); |
- Deserializer deserializer(&snapshot_data); |
+ SnapshotByteSource source(snapshot, snapshot_size); |
+ Deserializer deserializer(&source); |
+ ReserveSpaceForSnapshot(&deserializer, file_name); |
deserializer.DeserializePartial(isolate, &root); |
CHECK(root->IsString()); |
} |
@@ -404,8 +485,9 @@ |
Object* root2; |
{ |
- SnapshotData snapshot_data(snapshot, snapshot_size); |
- Deserializer deserializer(&snapshot_data); |
+ SnapshotByteSource source(snapshot, snapshot_size); |
+ Deserializer deserializer(&source); |
+ ReserveSpaceForSnapshot(&deserializer, file_name); |
deserializer.DeserializePartial(isolate, &root2); |
CHECK(root2->IsString()); |
CHECK(*root_handle == root2); |
@@ -470,11 +552,14 @@ |
partial_serializer.Serialize(&raw_context); |
startup_serializer.SerializeWeakReferences(); |
- SnapshotData startup_snapshot(startup_sink, startup_serializer); |
- SnapshotData partial_snapshot(partial_sink, partial_serializer); |
- |
- WritePayload(startup_snapshot.RawData(), FLAG_testing_serialization_file); |
- WritePayload(startup_snapshot.RawData(), startup_name.start()); |
+ partial_serializer.FinalizeAllocation(); |
+ startup_serializer.FinalizeAllocation(); |
+ |
+ WritePayload(partial_sink.data(), FLAG_testing_serialization_file); |
+ WritePayload(startup_sink.data(), startup_name.start()); |
+ |
+ WriteSpaceUsed(&partial_serializer, FLAG_testing_serialization_file); |
+ WriteSpaceUsed(&startup_serializer, startup_name.start()); |
startup_name.Dispose(); |
} |
@@ -503,8 +588,9 @@ |
Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
Object* root; |
{ |
- SnapshotData snapshot_data(snapshot, snapshot_size); |
- Deserializer deserializer(&snapshot_data); |
+ SnapshotByteSource source(snapshot, snapshot_size); |
+ Deserializer deserializer(&source); |
+ ReserveSpaceForSnapshot(&deserializer, file_name); |
deserializer.DeserializePartial(isolate, &root); |
CHECK(root->IsContext()); |
} |
@@ -514,8 +600,9 @@ |
Object* root2; |
{ |
- SnapshotData snapshot_data(snapshot, snapshot_size); |
- Deserializer deserializer(&snapshot_data); |
+ SnapshotByteSource source(snapshot, snapshot_size); |
+ Deserializer deserializer(&source); |
+ ReserveSpaceForSnapshot(&deserializer, file_name); |
deserializer.DeserializePartial(isolate, &root2); |
CHECK(root2->IsContext()); |
CHECK(*root_handle != root2); |