| OLD | NEW | 
|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include <errno.h> | 5 #include <errno.h> | 
| 6 #include <stdio.h> | 6 #include <stdio.h> | 
| 7 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 7 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 
| 8 #include <bzlib.h> | 8 #include <bzlib.h> | 
| 9 #endif | 9 #endif | 
| 10 #include <signal.h> | 10 #include <signal.h> | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 84     i::List<i::byte> startup_blob; | 84     i::List<i::byte> startup_blob; | 
| 85     i::ListSnapshotSink sink(&startup_blob); | 85     i::ListSnapshotSink sink(&startup_blob); | 
| 86 | 86 | 
| 87     int spaces[] = {i::NEW_SPACE,           i::OLD_POINTER_SPACE, | 87     int spaces[] = {i::NEW_SPACE,           i::OLD_POINTER_SPACE, | 
| 88                     i::OLD_DATA_SPACE,      i::CODE_SPACE, | 88                     i::OLD_DATA_SPACE,      i::CODE_SPACE, | 
| 89                     i::MAP_SPACE,           i::CELL_SPACE, | 89                     i::MAP_SPACE,           i::CELL_SPACE, | 
| 90                     i::PROPERTY_CELL_SPACE, i::LO_SPACE}; | 90                     i::PROPERTY_CELL_SPACE, i::LO_SPACE}; | 
| 91 | 91 | 
| 92     i::byte* snapshot_bytes = snapshot_data.begin(); | 92     i::byte* snapshot_bytes = snapshot_data.begin(); | 
| 93     sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot"); | 93     sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot"); | 
| 94     for (size_t i = 0; i < arraysize(spaces); ++i) | 94     for (size_t i = 0; i < arraysize(spaces); ++i) { | 
| 95       sink.PutInt(serializer.CurrentAllocationAddress(spaces[i]), "spaces"); | 95       i::Vector<const uint32_t> chunks = | 
|  | 96           serializer.FinalAllocationChunks(spaces[i]); | 
|  | 97       // For the start-up snapshot, none of the reservations has more than | 
|  | 98       // one chunk (reservation for each space fits onto a single page). | 
|  | 99       CHECK_EQ(1, chunks.length()); | 
|  | 100       sink.PutInt(chunks[0], "spaces"); | 
|  | 101     } | 
| 96 | 102 | 
| 97     i::byte* context_bytes = context_snapshot_data.begin(); | 103     i::byte* context_bytes = context_snapshot_data.begin(); | 
| 98     sink.PutBlob(context_bytes, context_snapshot_data.length(), "context"); | 104     sink.PutBlob(context_bytes, context_snapshot_data.length(), "context"); | 
| 99     for (size_t i = 0; i < arraysize(spaces); ++i) | 105     for (size_t i = 0; i < arraysize(spaces); ++i) { | 
| 100       sink.PutInt(context_serializer.CurrentAllocationAddress(spaces[i]), | 106       i::Vector<const uint32_t> chunks = | 
| 101                   "spaces"); | 107           context_serializer.FinalAllocationChunks(spaces[i]); | 
|  | 108       // For the context snapshot, none of the reservations has more than | 
|  | 109       // one chunk (reservation for each space fits onto a single page). | 
|  | 110       CHECK_EQ(1, chunks.length()); | 
|  | 111       sink.PutInt(chunks[0], "spaces"); | 
|  | 112     } | 
| 102 | 113 | 
| 103     size_t written = fwrite(startup_blob.begin(), 1, startup_blob.length(), | 114     size_t written = fwrite(startup_blob.begin(), 1, startup_blob.length(), | 
| 104                             startup_blob_file_); | 115                             startup_blob_file_); | 
| 105     if (written != (size_t)startup_blob.length()) { | 116     if (written != (size_t)startup_blob.length()) { | 
| 106       i::PrintF("Writing snapshot file failed.. Aborting.\n"); | 117       i::PrintF("Writing snapshot file failed.. Aborting.\n"); | 
| 107       exit(1); | 118       exit(1); | 
| 108     } | 119     } | 
| 109   } | 120   } | 
| 110 | 121 | 
| 111   void WriteSnapshotFile(const i::List<i::byte>& snapshot_data, | 122   void WriteSnapshotFile(const i::List<i::byte>& snapshot_data, | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 196     WriteSizeVar(ser, prefix, "code", i::CODE_SPACE); | 207     WriteSizeVar(ser, prefix, "code", i::CODE_SPACE); | 
| 197     WriteSizeVar(ser, prefix, "map", i::MAP_SPACE); | 208     WriteSizeVar(ser, prefix, "map", i::MAP_SPACE); | 
| 198     WriteSizeVar(ser, prefix, "cell", i::CELL_SPACE); | 209     WriteSizeVar(ser, prefix, "cell", i::CELL_SPACE); | 
| 199     WriteSizeVar(ser, prefix, "property_cell", i::PROPERTY_CELL_SPACE); | 210     WriteSizeVar(ser, prefix, "property_cell", i::PROPERTY_CELL_SPACE); | 
| 200     WriteSizeVar(ser, prefix, "lo", i::LO_SPACE); | 211     WriteSizeVar(ser, prefix, "lo", i::LO_SPACE); | 
| 201     fprintf(fp_, "\n"); | 212     fprintf(fp_, "\n"); | 
| 202   } | 213   } | 
| 203 | 214 | 
| 204   void WriteSizeVar(const i::Serializer& ser, const char* prefix, | 215   void WriteSizeVar(const i::Serializer& ser, const char* prefix, | 
| 205                     const char* name, int space) const { | 216                     const char* name, int space) const { | 
| 206     fprintf(fp_, "const int Snapshot::%s%s_space_used_ = %d;\n", | 217     i::Vector<const uint32_t> chunks = ser.FinalAllocationChunks(space); | 
| 207             prefix, name, ser.CurrentAllocationAddress(space)); | 218     // For the start-up snapshot, none of the reservations has more than | 
|  | 219     // one chunk (total reservation fits into a single page). | 
|  | 220     CHECK_EQ(1, chunks.length()); | 
|  | 221     fprintf(fp_, "const int Snapshot::%s%s_space_used_ = %d;\n", prefix, name, | 
|  | 222             chunks[0]); | 
| 208   } | 223   } | 
| 209 | 224 | 
| 210   void WriteSnapshotData(const i::List<i::byte>* data) const { | 225   void WriteSnapshotData(const i::List<i::byte>* data) const { | 
| 211     for (int i = 0; i < data->length(); i++) { | 226     for (int i = 0; i < data->length(); i++) { | 
| 212       if ((i & 0x1f) == 0x1f) | 227       if ((i & 0x1f) == 0x1f) | 
| 213         fprintf(fp_, "\n"); | 228         fprintf(fp_, "\n"); | 
| 214       if (i > 0) | 229       if (i > 0) | 
| 215         fprintf(fp_, ","); | 230         fprintf(fp_, ","); | 
| 216       fprintf(fp_, "%u", static_cast<unsigned char>(data->at(i))); | 231       fprintf(fp_, "%u", static_cast<unsigned char>(data->at(i))); | 
| 217     } | 232     } | 
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 409     i::ListSnapshotSink snapshot_sink(&snapshot_data); | 424     i::ListSnapshotSink snapshot_sink(&snapshot_data); | 
| 410     i::StartupSerializer ser(internal_isolate, &snapshot_sink); | 425     i::StartupSerializer ser(internal_isolate, &snapshot_sink); | 
| 411     ser.SerializeStrongReferences(); | 426     ser.SerializeStrongReferences(); | 
| 412 | 427 | 
| 413     i::List<i::byte> context_data; | 428     i::List<i::byte> context_data; | 
| 414     i::ListSnapshotSink contex_sink(&context_data); | 429     i::ListSnapshotSink contex_sink(&context_data); | 
| 415     i::PartialSerializer context_ser(internal_isolate, &ser, &contex_sink); | 430     i::PartialSerializer context_ser(internal_isolate, &ser, &contex_sink); | 
| 416     context_ser.Serialize(&raw_context); | 431     context_ser.Serialize(&raw_context); | 
| 417     ser.SerializeWeakReferences(); | 432     ser.SerializeWeakReferences(); | 
| 418 | 433 | 
|  | 434     context_ser.FinalizeAllocation(); | 
|  | 435     ser.FinalizeAllocation(); | 
|  | 436 | 
| 419     { | 437     { | 
| 420       SnapshotWriter writer(argv[1]); | 438       SnapshotWriter writer(argv[1]); | 
| 421       if (i::FLAG_raw_file && i::FLAG_raw_context_file) | 439       if (i::FLAG_raw_file && i::FLAG_raw_context_file) | 
| 422         writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file); | 440         writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file); | 
| 423       if (i::FLAG_startup_blob) | 441       if (i::FLAG_startup_blob) | 
| 424         writer.SetStartupBlobFile(i::FLAG_startup_blob); | 442         writer.SetStartupBlobFile(i::FLAG_startup_blob); | 
| 425   #ifdef COMPRESS_STARTUP_DATA_BZ2 | 443   #ifdef COMPRESS_STARTUP_DATA_BZ2 | 
| 426       BZip2Compressor bzip2; | 444       BZip2Compressor bzip2; | 
| 427       writer.SetCompressor(&bzip2); | 445       writer.SetCompressor(&bzip2); | 
| 428   #endif | 446   #endif | 
| 429       writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser); | 447       writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser); | 
| 430     } | 448     } | 
| 431   } | 449   } | 
| 432 | 450 | 
| 433   isolate->Dispose(); | 451   isolate->Dispose(); | 
| 434   V8::Dispose(); | 452   V8::Dispose(); | 
| 435   V8::ShutdownPlatform(); | 453   V8::ShutdownPlatform(); | 
| 436   delete platform; | 454   delete platform; | 
| 437   return 0; | 455   return 0; | 
| 438 } | 456 } | 
| OLD | NEW | 
|---|