Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Unified Diff: src/mksnapshot.cc

Issue 787033002: Use same blob format for internal and external snapshots. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/mksnapshot.cc
diff --git a/src/mksnapshot.cc b/src/mksnapshot.cc
index 77015a2b98f6522451ad3121f9cd41211649199f..8febadd0882eeeae292b154abb135c1cb5f70976 100644
--- a/src/mksnapshot.cc
+++ b/src/mksnapshot.cc
@@ -25,19 +25,16 @@ class SnapshotWriter {
explicit SnapshotWriter(const char* snapshot_file)
: fp_(GetFileDescriptorOrDie(snapshot_file)),
raw_file_(NULL),
- raw_context_file_(NULL),
startup_blob_file_(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 SetRawFiles(const char* raw_file, const char* raw_context_file) {
+ void SetRawFiles(const char* raw_file) {
raw_file_ = GetFileDescriptorOrDie(raw_file);
- raw_context_file_ = GetFileDescriptorOrDie(raw_context_file);
}
void SetStartupBlobFile(const char* startup_blob_file) {
@@ -47,34 +44,40 @@ class SnapshotWriter {
void WriteSnapshot(const i::SnapshotData& sd,
const i::SnapshotData& csd) const {
- WriteSnapshotFile(sd, csd);
- MaybeWriteStartupBlob(sd, csd);
+ i::SnapshotByteSink sink;
+ sink.PutBlob(sd.RawData(), "startup");
+ sink.PutBlob(csd.RawData(), "context");
+ const i::Vector<const i::byte>& blob = sink.data().ToConstVector();
+
+ WriteSnapshotFile(blob);
+ MaybeWriteRawFile(blob);
+ MaybeWriteStartupBlob(blob);
vogelheim1 2014/12/09 13:26:50 If we have one format for both, why would we need
Yang 2014/12/09 14:40:37 Good point. I removed the --raw-file option altoge
}
private:
- void MaybeWriteStartupBlob(const i::SnapshotData& sd,
- const i::SnapshotData& csd) const {
+ void MaybeWriteStartupBlob(const i::Vector<const i::byte>& blob) const {
if (!startup_blob_file_) return;
- i::SnapshotByteSink sink;
+ size_t written = fwrite(blob.begin(), 1, blob.length(), startup_blob_file_);
+ if (written != static_cast<size_t>(blob.length())) {
+ i::PrintF("Writing snapshot file failed.. Aborting.\n");
+ exit(1);
+ }
+ }
- sink.PutBlob(sd.RawData(), "snapshot");
- sink.PutBlob(csd.RawData(), "context");
+ void MaybeWriteRawFile(const i::Vector<const i::byte>& blob) const {
vogelheim1 2014/12/09 13:26:50 The two MaybeWrite* methods are identical except f
Yang 2014/12/09 14:40:37 Done.
+ if (!raw_file_) return;
- const i::List<i::byte>& startup_blob = sink.data();
- size_t written = fwrite(startup_blob.begin(), 1, startup_blob.length(),
- startup_blob_file_);
- if (written != static_cast<size_t>(startup_blob.length())) {
- i::PrintF("Writing snapshot file failed.. Aborting.\n");
+ size_t written = fwrite(blob.begin(), 1, blob.length(), raw_file_);
+ if (written != static_cast<size_t>(blob.length())) {
+ i::PrintF("Writing raw file failed.. Aborting.\n");
exit(1);
}
}
- void WriteSnapshotFile(const i::SnapshotData& snapshot_data,
- const i::SnapshotData& context_snapshot_data) const {
+ void WriteSnapshotFile(const i::Vector<const i::byte>& blob) const {
WriteFilePrefix();
- WriteData("", snapshot_data.RawData(), raw_file_);
- WriteData("context_", context_snapshot_data.RawData(), raw_context_file_);
+ WriteData(blob);
WriteFileSuffix();
}
@@ -88,47 +91,29 @@ class SnapshotWriter {
}
void WriteFileSuffix() const {
+ fprintf(fp_, "const v8::StartupData Snapshot::SnapshotBlob() {\n");
+ fprintf(fp_, " v8::StartupData blob;\n");
+ fprintf(fp_, " blob.data = reinterpret_cast<const char*>(blob_data);\n");
+ fprintf(fp_, " blob.raw_size = blob_size;\n");
+ fprintf(fp_, " return blob;\n");
+ fprintf(fp_, "}\n\n");
fprintf(fp_, "} // namespace internal\n");
fprintf(fp_, "} // namespace v8\n");
}
- void WriteData(const char* prefix,
- const i::Vector<const i::byte>& source_data,
- FILE* raw_file) const {
- MaybeWriteRawFile(&source_data, raw_file);
- WriteData(prefix, source_data);
- }
-
- void MaybeWriteRawFile(const i::Vector<const i::byte>* data,
- FILE* raw_file) const {
- if (!data || !raw_file) return;
-
- // Sanity check, whether i::List iterators truly return pointers to an
- // internal array.
- DCHECK(data->end() - data->begin() == data->length());
-
- size_t written = fwrite(data->begin(), 1, data->length(), raw_file);
- if (written != static_cast<size_t>(data->length())) {
- i::PrintF("Writing raw file failed.. Aborting.\n");
- exit(1);
- }
- }
-
- void WriteData(const char* prefix,
- const i::Vector<const i::byte>& source_data) const {
- fprintf(fp_, "const byte Snapshot::%sdata_[] = {\n", prefix);
- WriteSnapshotData(source_data);
+ void WriteData(const i::Vector<const i::byte>& blob) const {
+ fprintf(fp_, "static const byte blob_data[] = {\n");
+ WriteSnapshotData(blob);
fprintf(fp_, "};\n");
- fprintf(fp_, "const int Snapshot::%ssize_ = %d;\n", prefix,
- source_data.length());
+ fprintf(fp_, "static const int blob_size = %d;\n", blob.length());
fprintf(fp_, "\n");
}
- void WriteSnapshotData(const i::Vector<const i::byte>& data) const {
- for (int i = 0; i < data.length(); i++) {
+ void WriteSnapshotData(const i::Vector<const i::byte>& blob) const {
+ for (int i = 0; i < blob.length(); i++) {
if ((i & 0x1f) == 0x1f) fprintf(fp_, "\n");
if (i > 0) fprintf(fp_, ",");
- fprintf(fp_, "%u", static_cast<unsigned char>(data.at(i)));
+ fprintf(fp_, "%u", static_cast<unsigned char>(blob.at(i)));
}
fprintf(fp_, "\n");
}
@@ -144,7 +129,6 @@ class SnapshotWriter {
FILE* fp_;
FILE* raw_file_;
- FILE* raw_context_file_;
FILE* startup_blob_file_;
};
@@ -270,8 +254,7 @@ int main(int argc, char** argv) {
{
SnapshotWriter writer(argv[1]);
- if (i::FLAG_raw_file && i::FLAG_raw_context_file)
- writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file);
+ if (i::FLAG_raw_file) writer.SetRawFiles(i::FLAG_raw_file);
if (i::FLAG_startup_blob)
writer.SetStartupBlobFile(i::FLAG_startup_blob);
i::SnapshotData sd(snapshot_sink, ser);

Powered by Google App Engine
This is Rietveld 408576698