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

Unified Diff: src/mksnapshot.cc

Issue 792563002: Revert of 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
« no previous file with comments | « src/flag-definitions.h ('k') | src/natives-external.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/mksnapshot.cc
diff --git a/src/mksnapshot.cc b/src/mksnapshot.cc
index 7194a61f6afcda2a37696ab9d878114925945f6a..77015a2b98f6522451ad3121f9cd41211649199f 100644
--- a/src/mksnapshot.cc
+++ b/src/mksnapshot.cc
@@ -24,11 +24,20 @@
public:
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) {
+ raw_file_ = GetFileDescriptorOrDie(raw_file);
+ raw_context_file_ = GetFileDescriptorOrDie(raw_context_file);
}
void SetStartupBlobFile(const char* startup_blob_file) {
@@ -38,29 +47,34 @@
void WriteSnapshot(const i::SnapshotData& sd,
const i::SnapshotData& csd) const {
+ WriteSnapshotFile(sd, csd);
+ MaybeWriteStartupBlob(sd, csd);
+ }
+
+ private:
+ void MaybeWriteStartupBlob(const i::SnapshotData& sd,
+ const i::SnapshotData& csd) const {
+ if (!startup_blob_file_) return;
+
i::SnapshotByteSink sink;
- sink.PutBlob(sd.RawData(), "startup");
+
+ sink.PutBlob(sd.RawData(), "snapshot");
sink.PutBlob(csd.RawData(), "context");
- const i::Vector<const i::byte>& blob = sink.data().ToConstVector();
-
- WriteSnapshotFile(blob);
- MaybeWriteStartupBlob(blob);
- }
-
- private:
- void MaybeWriteStartupBlob(const i::Vector<const i::byte>& blob) const {
- if (!startup_blob_file_) return;
-
- size_t written = fwrite(blob.begin(), 1, blob.length(), startup_blob_file_);
- if (written != static_cast<size_t>(blob.length())) {
+
+ 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");
exit(1);
}
}
- void WriteSnapshotFile(const i::Vector<const i::byte>& blob) const {
+ void WriteSnapshotFile(const i::SnapshotData& snapshot_data,
+ const i::SnapshotData& context_snapshot_data) const {
WriteFilePrefix();
- WriteData(blob);
+ WriteData("", snapshot_data.RawData(), raw_file_);
+ WriteData("context_", context_snapshot_data.RawData(), raw_context_file_);
WriteFileSuffix();
}
@@ -74,29 +88,47 @@
}
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 i::Vector<const i::byte>& blob) const {
- fprintf(fp_, "static const byte blob_data[] = {\n");
- WriteSnapshotData(blob);
+ 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);
fprintf(fp_, "};\n");
- fprintf(fp_, "static const int blob_size = %d;\n", blob.length());
+ fprintf(fp_, "const int Snapshot::%ssize_ = %d;\n", prefix,
+ source_data.length());
fprintf(fp_, "\n");
}
- void WriteSnapshotData(const i::Vector<const i::byte>& blob) const {
- for (int i = 0; i < blob.length(); i++) {
+ void WriteSnapshotData(const i::Vector<const i::byte>& data) const {
+ for (int i = 0; i < data.length(); i++) {
if ((i & 0x1f) == 0x1f) fprintf(fp_, "\n");
if (i > 0) fprintf(fp_, ",");
- fprintf(fp_, "%u", static_cast<unsigned char>(blob.at(i)));
+ fprintf(fp_, "%u", static_cast<unsigned char>(data.at(i)));
}
fprintf(fp_, "\n");
}
@@ -111,6 +143,8 @@
}
FILE* fp_;
+ FILE* raw_file_;
+ FILE* raw_context_file_;
FILE* startup_blob_file_;
};
@@ -236,6 +270,8 @@
{
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_startup_blob)
writer.SetStartupBlobFile(i::FLAG_startup_blob);
i::SnapshotData sd(snapshot_sink, ser);
« no previous file with comments | « src/flag-definitions.h ('k') | src/natives-external.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698