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

Unified Diff: src/d8.cc

Issue 334913004: Support external startup data in V8. (retry) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase + style fix Created 6 years, 6 months 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/d8.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 82fe6f76f335aeaac764cfe02b44ad81c6aa97de..1718fbd228707c861d5b7cedd61634cc80395343 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1327,6 +1327,14 @@ bool Shell::SetOptions(int argc, char* argv[]) {
printf("Javascript debugger not included\n");
return false;
#endif // V8_SHARED
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+ } else if (strncmp(argv[i], "--natives_blob=", 15) == 0) {
+ options.natives_blob = argv[i] + 15;
+ argv[i] = NULL;
+ } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) {
+ options.snapshot_blob = argv[i] + 16;
+ argv[i] = NULL;
+#endif // V8_USE_EXTERNAL_STARTUP_DATA
}
}
@@ -1485,9 +1493,65 @@ class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
};
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+class StartupDataHandler {
+ public:
+ StartupDataHandler(const char* natives_blob,
+ const char* snapshot_blob) {
+ Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob);
+ Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob);
+ }
+
+ ~StartupDataHandler() {
+ delete[] natives_.data;
+ delete[] snapshot_.data;
+ }
+
+ private:
+ void Load(const char* blob_file,
+ v8::StartupData* startup_data,
+ void (*setter_fn)(v8::StartupData*)) {
+ startup_data->data = NULL;
+ startup_data->compressed_size = 0;
+ startup_data->raw_size = 0;
+
+ if (!blob_file)
+ return;
+
+ FILE* file = fopen(blob_file, "rb");
+ if (!file)
+ return;
+
+ fseek(file, 0, SEEK_END);
+ startup_data->raw_size = ftell(file);
+ rewind(file);
+
+ startup_data->data = new char[startup_data->raw_size];
+ startup_data->compressed_size = fread(
+ const_cast<char*>(startup_data->data), 1, startup_data->raw_size,
+ file);
+ fclose(file);
+
+ if (startup_data->raw_size == startup_data->compressed_size)
+ (*setter_fn)(startup_data);
+ }
+
+ v8::StartupData natives_;
+ v8::StartupData snapshot_;
+
+ // Disallow copy & assign.
+ StartupDataHandler(const StartupDataHandler& other);
+ void operator=(const StartupDataHandler& other);
+};
+#endif // V8_USE_EXTERNAL_STARTUP_DATA
+
+
int Shell::Main(int argc, char* argv[]) {
if (!SetOptions(argc, argv)) return 1;
v8::V8::InitializeICU(options.icu_data_file);
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+ StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob);
+#endif
SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg");
SetFlagsFromString("--redirect-code-traces-to=code.asm");
ShellArrayBufferAllocator array_buffer_allocator;
« no previous file with comments | « src/d8.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698