diff options
author | thakis <thakis@chromium.org> | 2016-02-09 07:36:39 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-09 15:37:57 +0000 |
commit | 09ea387c322ef962ab795f82b75b8c24d4a1da1f (patch) | |
tree | d9565ef6b2a985905a08efdd5f535ca10bf5dbf9 | |
parent | 765bab08e4a1d32a505539b10a1a1665c51d62ea (diff) | |
download | chromium_src-09ea387c322ef962ab795f82b75b8c24d4a1da1f.zip chromium_src-09ea387c322ef962ab795f82b75b8c24d4a1da1f.tar.gz chromium_src-09ea387c322ef962ab795f82b75b8c24d4a1da1f.tar.bz2 |
Revert of Pass both 32 and 64 bit snapshot and natives fds to child processes. (patchset #3 id:40001 of https://codereview.chromium.org/1665513002/ )
Reason for revert:
Added a static initializer: https://build.chromium.org/p/chromium/builders/Linux/builds/71576
# v8_initializer.cc _GLOBAL__sub_I_v8_initializer.cc+0xf
# v8_initializer.cc __cxa_atexit@plt [registers a dtor to run at exit]
Original issue's description:
> Pass both 32 and 64 bit snapshot and natives fds to child processes.
>
> Child processes are in the best position to determine which files
> to use, therefore it is simplest just to provide both 32 and 64
> bit versions from the parent.
>
> BUG=581380,455699
>
> Committed: https://crrev.com/c560d75783aca05249092dd11503b53f7b631be1
> Cr-Commit-Position: refs/heads/master@{#374371}
TBR=jochen@chromium.org,torne@chromium.org,tobiasjs@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=581380,455699
Review URL: https://codereview.chromium.org/1681003003
Cr-Commit-Position: refs/heads/master@{#374380}
-rw-r--r-- | android_webview/lib/DEPS | 1 | ||||
-rw-r--r-- | android_webview/lib/main/aw_main_delegate.cc | 32 | ||||
-rw-r--r-- | content/app/content_main_runner.cc | 10 | ||||
-rw-r--r-- | content/browser/child_process_launcher.cc | 29 | ||||
-rw-r--r-- | content/public/common/content_descriptors.h | 7 | ||||
-rw-r--r-- | gin/v8_initializer.cc | 124 | ||||
-rw-r--r-- | gin/v8_initializer.h | 13 |
7 files changed, 56 insertions, 160 deletions
diff --git a/android_webview/lib/DEPS b/android_webview/lib/DEPS index 572fe0c..e46fa53 100644 --- a/android_webview/lib/DEPS +++ b/android_webview/lib/DEPS @@ -3,7 +3,6 @@ include_rules = [ "+components", # For jni registers. "+content/public", "+gin/public", - "+gin/v8_initializer.h", "+media/base/media_switches.h", # For media command line switches. "+ui/events/gesture_detection", "+ui/gl", diff --git a/android_webview/lib/main/aw_main_delegate.cc b/android_webview/lib/main/aw_main_delegate.cc index e858652..e0025fe 100644 --- a/android_webview/lib/main/aw_main_delegate.cc +++ b/android_webview/lib/main/aw_main_delegate.cc @@ -34,7 +34,6 @@ #include "content/public/common/content_descriptors.h" #include "content/public/common/content_switches.h" #include "gin/public/isolate_holder.h" -#include "gin/v8_initializer.h" #include "gpu/command_buffer/client/gl_in_process_context.h" #include "gpu/command_buffer/service/gpu_switches.h" #include "media/base/media_switches.h" @@ -118,19 +117,24 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) { if (cl->GetSwitchValueASCII(switches::kProcessType).empty()) { // Browser process (no type specified). - base::android::RegisterApkAssetWithGlobalDescriptors( - kV8NativesDataDescriptor32, - gin::V8Initializer::GetNativesFilePath(true).AsUTF8Unsafe()); - base::android::RegisterApkAssetWithGlobalDescriptors( - kV8SnapshotDataDescriptor32, - gin::V8Initializer::GetSnapshotFilePath(true).AsUTF8Unsafe()); - - base::android::RegisterApkAssetWithGlobalDescriptors( - kV8NativesDataDescriptor64, - gin::V8Initializer::GetNativesFilePath(false).AsUTF8Unsafe()); - base::android::RegisterApkAssetWithGlobalDescriptors( - kV8SnapshotDataDescriptor64, - gin::V8Initializer::GetSnapshotFilePath(false).AsUTF8Unsafe()); + // This code is needed to be able to mmap the V8 snapshot directly from + // the WebView .apk using architecture-specific names. + // This needs to be here so that it gets to run before the code in + // content_main_runner that reads these values tries to do so. +#ifdef __LP64__ + const char kNativesFileName[] = "assets/natives_blob_64.bin"; + const char kSnapshotFileName[] = "assets/snapshot_blob_64.bin"; +#else + const char kNativesFileName[] = "assets/natives_blob_32.bin"; + const char kSnapshotFileName[] = "assets/snapshot_blob_32.bin"; +#endif // __LP64__ + // TODO(gsennton) we should use + // gin::IsolateHolder::kNativesFileName/kSnapshotFileName + // here when those files have arch specific names http://crbug.com/455699 + CHECK(base::android::RegisterApkAssetWithGlobalDescriptors( + kV8NativesDataDescriptor, kNativesFileName)); + CHECK(base::android::RegisterApkAssetWithGlobalDescriptors( + kV8SnapshotDataDescriptor, kSnapshotFileName)); } if (cl->HasSwitch(switches::kWebViewSandboxedRenderer)) { diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc index 59efad3..e8d31b0 100644 --- a/content/app/content_main_runner.cc +++ b/content/app/content_main_runner.cc @@ -142,16 +142,6 @@ base::LazyInstance<ContentUtilityClient> g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; #endif // !OS_IOS && !CHROME_MULTIPLE_DLL_BROWSER -#if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) -#if defined __LP64__ -#define kV8NativesDataDescriptor kV8NativesDataDescriptor64 -#define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64 -#else -#define kV8NativesDataDescriptor kV8NativesDataDescriptor32 -#define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32 -#endif -#endif - #if defined(OS_POSIX) && !defined(OS_IOS) // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. diff --git a/content/browser/child_process_launcher.cc b/content/browser/child_process_launcher.cc index e92554c..4398e2b 100644 --- a/content/browser/child_process_launcher.cc +++ b/content/browser/child_process_launcher.cc @@ -156,31 +156,6 @@ void LaunchOnLauncherThread(const NotifyCallback& callback, #endif ); #if defined(V8_USE_EXTERNAL_STARTUP_DATA) - bool snapshot_loaded = false; -#if defined(OS_ANDROID) - base::MemoryMappedFile::Region region; - auto maybe_register = [®ion, ®ions, &files_to_register](int key, - int fd) { - if (fd != -1) { - files_to_register->Share(key, fd); - regions.insert(std::make_pair(key, region)); - } - }; - maybe_register( - kV8NativesDataDescriptor32, - gin::V8Initializer::GetOpenNativesFileForChildProcesses(®ion, true)); - maybe_register( - kV8NativesDataDescriptor64, - gin::V8Initializer::GetOpenNativesFileForChildProcesses(®ion, false)); - maybe_register( - kV8SnapshotDataDescriptor32, - gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, true)); - maybe_register( - kV8SnapshotDataDescriptor64, - gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, false)); - - snapshot_loaded = true; -#else base::PlatformFile natives_pf = gin::V8Initializer::GetOpenNativesFileForChildProcesses( ®ions[kV8NativesDataDescriptor]); @@ -194,15 +169,13 @@ void LaunchOnLauncherThread(const NotifyCallback& callback, // Failure to load the V8 snapshot is not necessarily an error. V8 can start // up (slower) without the snapshot. if (snapshot_pf != -1) { - snapshot_loaded = true; files_to_register->Share(kV8SnapshotDataDescriptor, snapshot_pf); regions.insert(std::make_pair(kV8SnapshotDataDescriptor, snapshot_region)); } -#endif if (process_type != switches::kZygoteProcess) { cmd_line->AppendSwitch(::switches::kV8NativesPassedByFD); - if (snapshot_loaded) { + if (snapshot_pf != -1) { cmd_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); } } diff --git a/content/public/common/content_descriptors.h b/content/public/common/content_descriptors.h index 692b8bd..a3077cd 100644 --- a/content/public/common/content_descriptors.h +++ b/content/public/common/content_descriptors.h @@ -15,16 +15,9 @@ enum { kSandboxIPCChannel, // https://chromium.googlesource.com/chromium/src/+/master/docs/linux_sandbox_ipc.md #if defined(V8_USE_EXTERNAL_STARTUP_DATA) -#if defined(OS_ANDROID) - kV8NativesDataDescriptor32, - kV8SnapshotDataDescriptor32, - kV8NativesDataDescriptor64, - kV8SnapshotDataDescriptor64, -#else kV8NativesDataDescriptor, kV8SnapshotDataDescriptor, #endif -#endif #if defined(OS_ANDROID) kAndroidPropertyDescriptor, diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc index 2233e3f..cfb3630 100644 --- a/gin/v8_initializer.cc +++ b/gin/v8_initializer.cc @@ -50,32 +50,19 @@ const base::PlatformFile kInvalidPlatformFile = // File handles intentionally never closed. Not using File here because its // Windows implementation guards against two instances owning the same // PlatformFile (which we allow since we know it is never freed). -typedef std::map<const char*, - std::pair<base::PlatformFile, base::MemoryMappedFile::Region>> - OpenedFileMap; -OpenedFileMap g_opened_files; - -OpenedFileMap::mapped_type& GetOpenedFile(const char* file) { - if (g_opened_files.find(file) == g_opened_files.end()) { - g_opened_files[file] = - std::make_pair(kInvalidPlatformFile, base::MemoryMappedFile::Region()); - } - return g_opened_files[file]; -} +base::PlatformFile g_natives_pf = kInvalidPlatformFile; +base::PlatformFile g_snapshot_pf = kInvalidPlatformFile; +base::MemoryMappedFile::Region g_natives_region; +base::MemoryMappedFile::Region g_snapshot_region; #if defined(OS_ANDROID) -const char kNativesFileName64[] = "natives_blob_64.bin"; -const char kSnapshotFileName64[] = "snapshot_blob_64.bin"; -const char kNativesFileName32[] = "natives_blob_32.bin"; -const char kSnapshotFileName32[] = "snapshot_blob_32.bin"; - -#if defined(__LP64__) -#define kNativesFileName kNativesFileName64 -#define kSnapshotFileName kSnapshotFileName64 +#ifdef __LP64__ +const char kNativesFileName[] = "natives_blob_64.bin"; +const char kSnapshotFileName[] = "snapshot_blob_64.bin"; #else -#define kNativesFileName kNativesFileName32 -#define kSnapshotFileName kSnapshotFileName32 -#endif +const char kNativesFileName[] = "natives_blob_32.bin"; +const char kSnapshotFileName[] = "snapshot_blob_32.bin"; +#endif // __LP64__ #else // defined(OS_ANDROID) const char kNativesFileName[] = "natives_blob.bin"; @@ -183,13 +170,16 @@ base::PlatformFile OpenV8File(const char* file_name, return file.TakePlatformFile(); } -static const OpenedFileMap::mapped_type OpenFileIfNecessary( - const char* file_name) { - OpenedFileMap::mapped_type& opened = GetOpenedFile(file_name); - if (opened.first == kInvalidPlatformFile) { - opened.first = OpenV8File(file_name, &opened.second); +void OpenNativesFileIfNecessary() { + if (g_natives_pf == kInvalidPlatformFile) { + g_natives_pf = OpenV8File(kNativesFileName, &g_natives_region); + } +} + +void OpenSnapshotFileIfNecessary() { + if (g_snapshot_pf == kInvalidPlatformFile) { + g_snapshot_pf = OpenV8File(kSnapshotFileName, &g_snapshot_region); } - return opened; } #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) @@ -246,14 +236,15 @@ enum LoadV8FileResult { V8_LOAD_MAX_VALUE }; -static LoadV8FileResult MapVerify(const OpenedFileMap::mapped_type& file_region, +static LoadV8FileResult MapVerify(base::PlatformFile platform_file, + const base::MemoryMappedFile::Region& region, #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) const unsigned char* fingerprint, #endif base::MemoryMappedFile** mmapped_file_out) { - if (file_region.first == kInvalidPlatformFile) + if (platform_file == kInvalidPlatformFile) return V8_LOAD_FAILED_OPEN; - if (!MapV8File(file_region.first, file_region.second, mmapped_file_out)) + if (!MapV8File(platform_file, region, mmapped_file_out)) return V8_LOAD_FAILED_MAP; #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) if (!VerifyV8StartupFile(mmapped_file_out, fingerprint)) @@ -267,8 +258,8 @@ void V8Initializer::LoadV8Snapshot() { if (g_mapped_snapshot) return; - OpenFileIfNecessary(kSnapshotFileName); - LoadV8FileResult result = MapVerify(GetOpenedFile(kSnapshotFileName), + OpenSnapshotFileIfNecessary(); + LoadV8FileResult result = MapVerify(g_snapshot_pf, g_snapshot_region, #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) g_snapshot_fingerprint, #endif @@ -283,8 +274,8 @@ void V8Initializer::LoadV8Natives() { if (g_mapped_natives) return; - OpenFileIfNecessary(kNativesFileName); - LoadV8FileResult result = MapVerify(GetOpenedFile(kNativesFileName), + OpenNativesFileIfNecessary(); + LoadV8FileResult result = MapVerify(g_natives_pf, g_natives_region, #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) g_natives_fingerprint, #endif @@ -320,8 +311,8 @@ void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf, result = V8_LOAD_FAILED_VERIFY; #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA if (result == V8_LOAD_SUCCESS) { - g_opened_files[kSnapshotFileName] = - std::make_pair(snapshot_pf, snapshot_region); + g_snapshot_pf = snapshot_pf; + g_snapshot_region = snapshot_region; } UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, V8_LOAD_MAX_VALUE); @@ -351,50 +342,25 @@ void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf, LOG(FATAL) << "Couldn't verify contents of v8 natives data file"; } #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA - g_opened_files[kNativesFileName] = std::make_pair(natives_pf, natives_region); + g_natives_pf = natives_pf; + g_natives_region = natives_region; } // static base::PlatformFile V8Initializer::GetOpenNativesFileForChildProcesses( base::MemoryMappedFile::Region* region_out) { - const OpenedFileMap::mapped_type& opened = - OpenFileIfNecessary(kNativesFileName); - *region_out = opened.second; - return opened.first; + OpenNativesFileIfNecessary(); + *region_out = g_natives_region; + return g_natives_pf; } // static base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses( base::MemoryMappedFile::Region* region_out) { - const OpenedFileMap::mapped_type& opened = - OpenFileIfNecessary(kSnapshotFileName); - *region_out = opened.second; - return opened.first; -} - -#if defined(OS_ANDROID) -// static -base::PlatformFile V8Initializer::GetOpenNativesFileForChildProcesses( - base::MemoryMappedFile::Region* region_out, - bool abi_32_bit) { - const char* natives_file = - abi_32_bit ? kNativesFileName32 : kNativesFileName64; - const OpenedFileMap::mapped_type& opened = OpenFileIfNecessary(natives_file); - *region_out = opened.second; - return opened.first; -} - -// static -base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses( - base::MemoryMappedFile::Region* region_out, - bool abi_32_bit) { - const char* snapshot_file = - abi_32_bit ? kSnapshotFileName32 : kSnapshotFileName64; - const OpenedFileMap::mapped_type& opened = OpenFileIfNecessary(snapshot_file); - *region_out = opened.second; - return opened.first; + OpenSnapshotFileIfNecessary(); + *region_out = g_snapshot_region; + return g_snapshot_pf; } -#endif // defined(OS_ANDROID) #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) // static @@ -457,20 +423,4 @@ void V8Initializer::GetV8ExternalSnapshotData(const char** natives_data_out, } } -#if defined(OS_ANDROID) -// static -base::FilePath V8Initializer::GetNativesFilePath(bool abi_32_bit) { - base::FilePath path; - GetV8FilePath(abi_32_bit ? kNativesFileName32 : kNativesFileName64, &path); - return path; -} - -// static -base::FilePath V8Initializer::GetSnapshotFilePath(bool abi_32_bit) { - base::FilePath path; - GetV8FilePath(abi_32_bit ? kSnapshotFileName32 : kSnapshotFileName64, &path); - return path; -} -#endif // defined(OS_ANDROID) - } // namespace gin diff --git a/gin/v8_initializer.h b/gin/v8_initializer.h index 4c03480..dcb5329 100644 --- a/gin/v8_initializer.h +++ b/gin/v8_initializer.h @@ -65,19 +65,6 @@ class GIN_EXPORT V8Initializer { // Will return -1 if the file does not exist. static base::PlatformFile GetOpenSnapshotFileForChildProcesses( base::MemoryMappedFile::Region* region_out); - -#if defined(OS_ANDROID) - static base::PlatformFile GetOpenNativesFileForChildProcesses( - base::MemoryMappedFile::Region* region_out, - bool abi_32_bit); - static base::PlatformFile GetOpenSnapshotFileForChildProcesses( - base::MemoryMappedFile::Region* region_out, - bool abi_32_bit); - - static base::FilePath GetNativesFilePath(bool abi_32_bit); - static base::FilePath GetSnapshotFilePath(bool abi_32_bit); -#endif - #endif // V8_USE_EXTERNAL_STARTUP_DATA }; |