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

Unified Diff: gin/isolate_holder.cc

Issue 594603003: Infrastructure for reading V8's initial snapshot from external files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Turn static variables into pointers and remove v8 init in net Created 6 years, 3 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
Index: gin/isolate_holder.cc
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
index db4473ec0f9ee3d3976f8521523fd6a5459dbb18..f19028b63dad1c79f2704fa2fcc5bd3b375a939a 100644
--- a/gin/isolate_holder.cc
+++ b/gin/isolate_holder.cc
@@ -8,6 +8,14 @@
#include <string.h>
#include "base/logging.h"
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+
+#ifdef OS_MACOSX
+#include "base/mac/bundle_locations.h"
+#endif
+
rmcilroy 2014/09/23 14:05:40 nit - Generally Ifdef'ed defines are placed in a s
baixo 2014/09/23 19:30:30 Done.
+#include "base/path_service.h"
+#endif // V8_USE_EXTERNAL_STARTUP_DATA
#include "base/rand_util.h"
#include "base/sys_info.h"
#include "gin/array_buffer.h"
@@ -29,6 +37,86 @@ bool GenerateEntropy(unsigned char* buffer, size_t amount) {
} // namespace
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+// static
+base::MemoryMappedFile* IsolateHolder::mapped_natives = NULL;
+base::MemoryMappedFile* IsolateHolder::mapped_snapshot = NULL;
rmcilroy 2014/09/23 14:05:40 As mentioned, these should be globals, not static
baixo 2014/09/23 19:30:30 Done.
+#endif // V8_USE_EXTERNAL_STARTUP_DATA
+
+#if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID)
+//static
+bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) {
+ if (mapped_natives && mapped_snapshot)
+ return true;
+
+ mapped_natives = new base::MemoryMappedFile;
+ CHECK(mapped_natives);
+ if (!mapped_natives->IsValid()) {
+ if (!mapped_natives->Initialize(base::File(natives_fd))) {
rmcilroy 2014/09/23 14:05:39 create the new mapped_snapshot here rather than ab
baixo 2014/09/23 19:30:30 We need the created object to initialize the file
+ LOG(ERROR) << "Couldn't mmap v8 natives data file";
+ return false;
+ }
+ }
+
+ mapped_snapshot = new base::MemoryMappedFile;
rmcilroy 2014/09/23 14:05:39 ditto
baixo 2014/09/23 19:30:30 Same as above.
+ CHECK(mapped_snapshot);
+ if (!mapped_snapshot->IsValid()) {
+ if (!mapped_snapshot->Initialize(base::File(snapshot_fd))) {
+ LOG(ERROR) << "Couldn't mmap v8 snapshot data file";
+ return false;
+ }
+ }
+
+ return true;
+}
+#endif // V8_USE_EXTERNAL_STARTUP_DATA && OS_ANDROID
+
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+// static
+bool IsolateHolder::LoadV8Snapshot() {
+ if (mapped_natives && mapped_snapshot)
+ return true;
+
+#if !defined(OS_MACOSX)
+ base::FilePath data_path;
+ PathService::Get(
+#if defined(OS_ANDROID)
+ base::DIR_ANDROID_APP_DATA,
+#elif defined(OS_POSIX) || defined(OS_WIN)
+ base::DIR_EXE,
+#endif
+ &data_path);
+#else
+ base::FilePath data_path = base::mac::FrameworkBundlePath();
+#endif
+ DCHECK(!data_path.empty());
+
+ mapped_natives = new base::MemoryMappedFile;
+ CHECK(mapped_natives);
+ if (!mapped_natives->IsValid()) {
+ base::FilePath natives_data_path =
+ data_path.AppendASCII("natives_blob.bin");
+ if (!mapped_natives->Initialize(natives_data_path)) {
+ LOG(ERROR) << "Couldn't mmap v8 natives data file";
+ return false;
+ }
+ }
rmcilroy 2014/09/23 14:05:39 There seems like a lot of duplication here between
baixo 2014/09/23 19:30:30 Done.
+
+ mapped_snapshot = new base::MemoryMappedFile;
+ CHECK(mapped_snapshot);
+ if (!mapped_snapshot->IsValid()) {
+ base::FilePath snapshot_data_path =
+ data_path.AppendASCII("snapshot_blob.bin");
+ if (!mapped_snapshot->Initialize(snapshot_data_path)) {
+ LOG(ERROR) << "Couldn't mmap v8 snapshot data file";
+ return false;
+ }
+ }
+
+ return true;
+}
+#endif // V8_USE_EXTERNAL_STARTUP_DATA
+
IsolateHolder::IsolateHolder() {
CHECK(g_array_buffer_allocator)
<< "You need to invoke gin::IsolateHolder::Initialize first";
@@ -62,6 +150,19 @@ void IsolateHolder::Initialize(ScriptMode mode,
v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1);
}
v8::V8::SetEntropySource(&GenerateEntropy);
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+ v8::StartupData natives;
+ natives.data = reinterpret_cast<const char*>(mapped_natives->data());
+ natives.raw_size = mapped_natives->length();
+ natives.compressed_size = mapped_natives->length();
+ v8::V8::SetNativesDataBlob(&natives);
+
+ v8::StartupData snapshot;
+ snapshot.data = reinterpret_cast<const char*>(mapped_snapshot->data());
+ snapshot.raw_size = mapped_snapshot->length();
+ snapshot.compressed_size = mapped_snapshot->length();
+ v8::V8::SetSnapshotDataBlob(&snapshot);
+#endif // V8_USE_EXTERNAL_STARTUP_DATA
v8::V8::Initialize();
v8_is_initialized = true;
}

Powered by Google App Engine
This is Rietveld 408576698