| Index: src/mksnapshot.cc
|
| diff --git a/src/mksnapshot.cc b/src/mksnapshot.cc
|
| index d4262c4cea1351af3c3f003487d1daa0f079810d..91baeba2a34e55af9a23980f76f27fa4a172fccc 100644
|
| --- a/src/mksnapshot.cc
|
| +++ b/src/mksnapshot.cc
|
| @@ -48,33 +48,81 @@ 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) {
|
| + if (startup_blob_file != NULL)
|
| + 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 +131,6 @@ class SnapshotWriter {
|
| WriteFileSuffix();
|
| }
|
|
|
| - private:
|
| void WriteFilePrefix() const {
|
| fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n");
|
| fprintf(fp_, "#include \"src/v8.h\"\n");
|
| @@ -137,13 +184,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 +242,8 @@ class SnapshotWriter {
|
| FILE* fp_;
|
| FILE* raw_file_;
|
| FILE* raw_context_file_;
|
| + FILE* startup_blob_file_;
|
| Compressor* compressor_;
|
| - bool omit_;
|
| };
|
|
|
|
|
| @@ -381,9 +427,10 @@ 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);
|
| + if (i::FLAG_startup_blob)
|
| + writer.SetStartupBlobFile(i::FLAG_startup_blob);
|
| #ifdef COMPRESS_STARTUP_DATA_BZ2
|
| BZip2Compressor bzip2;
|
| writer.SetCompressor(&bzip2);
|
|
|