Chromium Code Reviews| Index: src/mksnapshot.cc |
| diff --git a/src/mksnapshot.cc b/src/mksnapshot.cc |
| index 4f8d4149cc8dd40e37ec04b461b288315f30153a..35a0460bb2774892a40548f8ea269b57322588a8 100644 |
| --- a/src/mksnapshot.cc |
| +++ b/src/mksnapshot.cc |
| @@ -48,33 +48,80 @@ class SnapshotWriter { |
| : fp_(GetFileDescriptorOrDie(snapshot_file)) |
| , raw_file_(NULL) |
| , raw_context_file_(NULL) |
| - , compressor_(NULL) |
| - , omit_(false) { |
| + , startup_blob_file_(NULL) |
| + , compressor_(NULL) { |
| } |
| ~SnapshotWriter() { |
| fclose(fp_); |
| if (raw_file_) fclose(raw_file_); |
| if (raw_context_file_) fclose(raw_context_file_); |
| + if (startup_blob_file_) fclose(startup_blob_file_); |
| } |
| void SetCompressor(Compressor* compressor) { |
| compressor_ = compressor; |
| } |
| - void SetOmit(bool omit) { |
| - omit_ = omit; |
| - } |
| - |
| void SetRawFiles(const char* raw_file, const char* raw_context_file) { |
| raw_file_ = GetFileDescriptorOrDie(raw_file); |
| raw_context_file_ = GetFileDescriptorOrDie(raw_context_file); |
| } |
| + void SetStartupBlobFile(const char* startup_blob_file) { |
| + startup_blob_file_ = GetFileDescriptorOrDie(startup_blob_file); |
| + } |
| + |
| void WriteSnapshot(const i::List<char>& snapshot_data, |
| const i::Serializer& serializer, |
| const i::List<char>& context_snapshot_data, |
| const i::Serializer& context_serializer) const { |
| + WriteSnapshotFile(snapshot_data, serializer, |
| + context_snapshot_data, context_serializer); |
| + MaybeWriteStartupBlob(snapshot_data, serializer, |
| + context_snapshot_data, context_serializer); |
| + } |
| + |
| + private: |
| + void MaybeWriteStartupBlob(const i::List<char>& snapshot_data, |
| + const i::Serializer& serializer, |
| + const i::List<char>& context_snapshot_data, |
| + const i::Serializer& context_serializer) const { |
| + if (!startup_blob_file_) |
| + return; |
| + |
| + i::List<char> startup_blob; |
| + ListSnapshotSink sink(&startup_blob); |
| + |
| + int spaces[] = { |
| + i::NEW_SPACE, i::OLD_POINTER_SPACE, i::OLD_DATA_SPACE, i::CODE_SPACE, |
| + i::MAP_SPACE, i::CELL_SPACE, i::PROPERTY_CELL_SPACE |
| + }; |
| + |
| + i::byte* snapshot_bytes = reinterpret_cast<i::byte*>(snapshot_data.begin()); |
| + sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot"); |
| + for (size_t i = 0; i < ARRAY_SIZE(spaces); ++i) |
| + sink.PutInt(serializer.CurrentAllocationAddress(spaces[i]), "spaces"); |
| + |
| + i::byte* context_bytes = |
| + reinterpret_cast<i::byte*>(context_snapshot_data.begin()); |
| + sink.PutBlob(context_bytes, context_snapshot_data.length(), "context"); |
| + for (size_t i = 0; i < ARRAY_SIZE(spaces); ++i) |
| + sink.PutInt(context_serializer.CurrentAllocationAddress(spaces[i]), |
| + "spaces"); |
| + |
| + size_t written = fwrite(startup_blob.begin(), 1, startup_blob.length(), |
| + startup_blob_file_); |
| + if (written != (size_t)startup_blob.length()) { |
| + i::PrintF("Writing snapshot file failed.. Aborting.\n"); |
| + exit(1); |
| + } |
| + } |
| + |
| + void WriteSnapshotFile(const i::List<char>& snapshot_data, |
| + const i::Serializer& serializer, |
| + const i::List<char>& context_snapshot_data, |
| + const i::Serializer& context_serializer) const { |
| WriteFilePrefix(); |
| WriteData("", snapshot_data, raw_file_); |
| WriteData("context_", context_snapshot_data, raw_context_file_); |
| @@ -83,7 +130,6 @@ class SnapshotWriter { |
| WriteFileSuffix(); |
| } |
| - private: |
| void WriteFilePrefix() const { |
| fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n"); |
| fprintf(fp_, "#include \"v8.h\"\n"); |
| @@ -137,13 +183,12 @@ class SnapshotWriter { |
| const i::List<char>& source_data, |
| const i::List<char>* data_to_be_written) const { |
| fprintf(fp_, "const byte Snapshot::%sdata_[] = {\n", prefix); |
| - if (!omit_) |
| - WriteSnapshotData(data_to_be_written); |
| + WriteSnapshotData(data_to_be_written); |
| fprintf(fp_, "};\n"); |
| fprintf(fp_, "const int Snapshot::%ssize_ = %d;\n", prefix, |
| data_to_be_written->length()); |
| - if (data_to_be_written == &source_data && !omit_) { |
| + if (data_to_be_written == &source_data) { |
| fprintf(fp_, "const byte* Snapshot::%sraw_data_ = Snapshot::%sdata_;\n", |
| prefix, prefix); |
| fprintf(fp_, "const int Snapshot::%sraw_size_ = Snapshot::%ssize_;\n", |
| @@ -196,8 +241,8 @@ class SnapshotWriter { |
| FILE* fp_; |
| FILE* raw_file_; |
| FILE* raw_context_file_; |
| + FILE* startup_blob_file_; |
| Compressor* compressor_; |
| - bool omit_; |
| }; |
| @@ -257,6 +302,23 @@ class BZip2Decompressor : public StartupDataDecompressor { |
| #endif |
| +#ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| +// Stupid hack: When V8 is compiled with V8_USE_EXTERNAL_STARTUP_DATA, then |
| +// V8 will not contain the startup sources + snapshot and the |
| +// embedder is responsible for supplying them. Unfortunately, |
| +// 'mksnapshot' needs those sources but doesn't really have |
| +// an embedder to provide the data. Thus: |
| +// 1, we always link mksnapshot against the compiled-in sources, |
| +// 2, fake the Set*DataBlob functions an embedder would call. |
| +namespace v8 { |
| +namespace internal { |
| + void SetNativesFromFile(StartupData* data) { ASSERT(false); } |
| + void SetSnapshotFromFile(StartupData* data) { ASSERT(false); } |
|
jochen (gone - plz use gerrit)
2014/05/23 11:44:44
i guess this should go into snapshot-empty.cc?
vogelheim
2014/05/26 12:36:03
Done.
Actually, to snapshot-common.cc, since that
|
| +} // namespace internal |
| +} // namespace v8 |
| +#endif // V8_USE_EXTERNAL_STARTUP_DATA |
| + |
| + |
| void DumpException(Handle<Message> message) { |
| String::Utf8Value message_string(message->Get()); |
| String::Utf8Value message_line(message->GetSourceLine()); |
| @@ -380,13 +442,13 @@ int main(int argc, char** argv) { |
| { |
| SnapshotWriter writer(argv[1]); |
| - writer.SetOmit(i::FLAG_omit); |
| if (i::FLAG_raw_file && i::FLAG_raw_context_file) |
| writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file); |
| #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| BZip2Compressor bzip2; |
| writer.SetCompressor(&bzip2); |
| #endif |
| + writer.SetStartupBlobFile(i::FLAG_startup_blob); |
| writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser); |
| } |