diff options
author | mkosiba <mkosiba@chromium.org> | 2015-01-09 05:10:22 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-09 13:11:05 +0000 |
commit | 3c766cc321a77febd8cf726436e22ab385f8ac1b (patch) | |
tree | 69f80a3088b48f0cd108a179f30adcc315b862b2 /gin | |
parent | c5feb0407d876d63c4db686e0b7c8b8f2b73bf6e (diff) | |
download | chromium_src-3c766cc321a77febd8cf726436e22ab385f8ac1b.zip chromium_src-3c766cc321a77febd8cf726436e22ab385f8ac1b.tar.gz chromium_src-3c766cc321a77febd8cf726436e22ab385f8ac1b.tar.bz2 |
mmap V8 snapshot and ICU data file in the android_webview
This makes it possible to mmap the V8 snapshot and ICU data file
directly from the WebView APK.
Doing so makes it possible to remove the android_webview_telemetry_build
flag which in turns means we can build the WebView with the same
set of flags that Chrome on Android uses.
BUG=442338
Review URL: https://codereview.chromium.org/812393002
Cr-Commit-Position: refs/heads/master@{#310765}
Diffstat (limited to 'gin')
-rw-r--r-- | gin/isolate_holder.cc | 62 | ||||
-rw-r--r-- | gin/public/isolate_holder.h | 12 |
2 files changed, 60 insertions, 14 deletions
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc index 38215b2..ab18ce4 100644 --- a/gin/isolate_holder.cc +++ b/gin/isolate_holder.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/message_loop/message_loop.h" #include "base/rand_util.h" +#include "base/strings/sys_string_conversions.h" #include "base/sys_info.h" #include "crypto/sha2.h" #include "gin/array_buffer.h" @@ -42,15 +43,23 @@ base::MemoryMappedFile* g_mapped_natives = NULL; base::MemoryMappedFile* g_mapped_snapshot = NULL; #if defined(V8_USE_EXTERNAL_STARTUP_DATA) -bool MapV8Files(base::FilePath* natives_path, base::FilePath* snapshot_path, - int natives_fd = -1, int snapshot_fd = -1) { +bool MapV8Files(base::FilePath* natives_path, + base::FilePath* snapshot_path, + int natives_fd = -1, + int snapshot_fd = -1, + base::MemoryMappedFile::Region natives_region = + base::MemoryMappedFile::Region::kWholeFile, + base::MemoryMappedFile::Region snapshot_region = + base::MemoryMappedFile::Region::kWholeFile) { int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; g_mapped_natives = new base::MemoryMappedFile; if (!g_mapped_natives->IsValid()) { if (natives_fd == -1 - ? !g_mapped_natives->Initialize(base::File(*natives_path, flags)) - : !g_mapped_natives->Initialize(base::File(natives_fd))) { + ? !g_mapped_natives->Initialize(base::File(*natives_path, flags), + natives_region) + : !g_mapped_natives->Initialize(base::File(natives_fd), + natives_region)) { delete g_mapped_natives; g_mapped_natives = NULL; LOG(FATAL) << "Couldn't mmap v8 natives data file"; @@ -61,8 +70,10 @@ bool MapV8Files(base::FilePath* natives_path, base::FilePath* snapshot_path, g_mapped_snapshot = new base::MemoryMappedFile; if (!g_mapped_snapshot->IsValid()) { if (snapshot_fd == -1 - ? !g_mapped_snapshot->Initialize(base::File(*snapshot_path, flags)) - : !g_mapped_snapshot->Initialize(base::File(snapshot_fd))) { + ? !g_mapped_snapshot->Initialize(base::File(*snapshot_path, flags), + snapshot_region) + : !g_mapped_snapshot->Initialize(base::File(snapshot_fd), + snapshot_region)) { delete g_mapped_snapshot; g_mapped_snapshot = NULL; LOG(ERROR) << "Couldn't mmap v8 snapshot data file"; @@ -106,6 +117,9 @@ extern const unsigned char g_natives_fingerprint[]; extern const unsigned char g_snapshot_fingerprint[]; #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA +const char IsolateHolder::kNativesFileName[] = "natives_blob.bin"; +const char IsolateHolder::kSnapshotFileName[] = "snapshot_blob.bin"; + // static bool IsolateHolder::LoadV8Snapshot() { if (g_mapped_natives && g_mapped_snapshot) @@ -116,13 +130,17 @@ bool IsolateHolder::LoadV8Snapshot() { PathService::Get(v8_snapshot_dir, &data_path); DCHECK(!data_path.empty()); - base::FilePath natives_path = data_path.AppendASCII("natives_blob.bin"); - base::FilePath snapshot_path = data_path.AppendASCII("snapshot_blob.bin"); + base::FilePath natives_path = data_path.AppendASCII(kNativesFileName); + base::FilePath snapshot_path = data_path.AppendASCII(kSnapshotFileName); #else // !defined(OS_MACOSX) + base::ScopedCFTypeRef<CFStringRef> natives_file_name( + base::SysUTF8ToCFStringRef(kNativesFileName)); base::FilePath natives_path = base::mac::PathForFrameworkBundleResource( - CFSTR("natives_blob.bin")); + natives_file_name); + base::ScopedCFTypeRef<CFStringRef> snapshot_file_name( + base::SysUTF8ToCFStringRef(kSnapshotFileName)); base::FilePath snapshot_path = base::mac::PathForFrameworkBundleResource( - CFSTR("snapshot_blob.bin")); + snapshot_file_name); DCHECK(!natives_path.empty()); DCHECK(!snapshot_path.empty()); #endif // !defined(OS_MACOSX) @@ -139,11 +157,31 @@ bool IsolateHolder::LoadV8Snapshot() { } //static -bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) { +bool IsolateHolder::LoadV8SnapshotFd(int natives_fd, + int64 natives_offset, + int64 natives_size, + int snapshot_fd, + int64 snapshot_offset, + int64 snapshot_size) { if (g_mapped_natives && g_mapped_snapshot) return true; - return MapV8Files(NULL, NULL, natives_fd, snapshot_fd); + base::MemoryMappedFile::Region natives_region = + base::MemoryMappedFile::Region::kWholeFile; + if (natives_size != 0 || natives_offset != 0) { + natives_region = + base::MemoryMappedFile::Region(natives_offset, natives_size); + } + + base::MemoryMappedFile::Region snapshot_region = + base::MemoryMappedFile::Region::kWholeFile; + if (natives_size != 0 || natives_offset != 0) { + snapshot_region = + base::MemoryMappedFile::Region(snapshot_offset, snapshot_size); + } + + return MapV8Files( + NULL, NULL, natives_fd, snapshot_fd, natives_region, snapshot_region); } #endif // V8_USE_EXTERNAL_STARTUP_DATA diff --git a/gin/public/isolate_holder.h b/gin/public/isolate_holder.h index 64fc952..44d1d89 100644 --- a/gin/public/isolate_holder.h +++ b/gin/public/isolate_holder.h @@ -33,7 +33,7 @@ class GIN_EXPORT IsolateHolder { // Should be invoked once before creating IsolateHolder instances to // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is defined, // V8's initial snapshot should be loaded (by calling LoadV8Snapshot or - // LoadV8SnapshotFD) before calling Initialize. + // LoadV8SnapshotFd) before calling Initialize. static void Initialize(ScriptMode mode, v8::ArrayBuffer::Allocator* allocator); @@ -52,7 +52,15 @@ class GIN_EXPORT IsolateHolder { void RemoveRunMicrotasksObserver(); #if defined(V8_USE_EXTERNAL_STARTUP_DATA) - static bool LoadV8SnapshotFD(int natives_fd, int snapshot_fd); + static const char kNativesFileName[]; + static const char kSnapshotFileName[]; + + static bool LoadV8SnapshotFd(int natives_fd, + int64 natives_offset, + int64 natives_size, + int snapshot_fd, + int64 snapshot_offset, + int64 snapshot_size); static bool LoadV8Snapshot(); #endif // V8_USE_EXTERNAL_STARTUP_DATA static void GetV8ExternalSnapshotData(const char** natives_data_out, |