summaryrefslogtreecommitdiffstats
path: root/gin/v8_initializer.cc
diff options
context:
space:
mode:
authormek <mek@chromium.org>2015-06-16 15:30:38 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-16 22:32:31 +0000
commit39ae215990f4ff081ca2a505eb2f2adfe22cb4ab (patch)
tree89abfc58ba0b0b2da848ab758396c67bdb5f13cb /gin/v8_initializer.cc
parent7c6b20f381b88bb590772a002ff07a7e4c63baf2 (diff)
downloadchromium_src-39ae215990f4ff081ca2a505eb2f2adfe22cb4ab.zip
chromium_src-39ae215990f4ff081ca2a505eb2f2adfe22cb4ab.tar.gz
chromium_src-39ae215990f4ff081ca2a505eb2f2adfe22cb4ab.tar.bz2
Revert of Moved logic for mapping child process FDs for ICU and V8 into child_process_launcher.cc (patchset #20 id:380001 of https://codereview.chromium.org/1182443003/)
Reason for revert: Adds new static initializers in http://build.chromium.org/p/chromium/buildstatus?builder=Linux%20x64&number=4979 # icu_util.cc cc::VertexShaderQuadAA::VertexShaderQuadAA() # icu_util.cc base::MemoryMappedFile::MemoryMappedFile() # icu_util.cc base::i18n::(anonymous namespace)::g_icudtl_region # icu_util.cc base::i18n::(anonymous namespace)::g_icudtl_mapped_file # icu_util.cc operator new(unsigned long) Original issue's description: > Moved logic for mapping child process FDs for ICU and V8 into child_process_launcher.cc > > Used to be defined in each app's ContentBrowserClient, but since > content/ is the one that receives the FDs, it makes sense that it should > be the one to send them. > > This also removes ChildProcessLauncher::AppendMappedFileCommandLineSwitches > as it is no longer needed. > > BUG=394502 > > Committed: https://crrev.com/228414fc8870f88f11ada7512e88ea6999890f56 > Cr-Commit-Position: refs/heads/master@{#334702} TBR=jochen@chromium.org,jam@chromium.org,jungshik@google.com,michaelbai@chromium.org,rmcilroy@chromium.org,thestig@chromium.org,agrieve@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=394502 Review URL: https://codereview.chromium.org/1187213002 Cr-Commit-Position: refs/heads/master@{#334719}
Diffstat (limited to 'gin/v8_initializer.cc')
-rw-r--r--gin/v8_initializer.cc127
1 files changed, 55 insertions, 72 deletions
diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc
index 2ba5106..0568fe7 100644
--- a/gin/v8_initializer.cc
+++ b/gin/v8_initializer.cc
@@ -27,27 +27,10 @@ namespace gin {
namespace {
-// None of these globals are ever freed nor closed.
base::MemoryMappedFile* g_mapped_natives = nullptr;
base::MemoryMappedFile* g_mapped_snapshot = nullptr;
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
-
-const base::PlatformFile kInvalidPlatformFile =
-#if defined(OS_WIN)
- INVALID_HANDLE_VALUE;
-#else
- -1;
-#endif
-
-// 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).
-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_MACOSX)
const int kV8SnapshotBasePathKey =
#if defined(OS_ANDROID)
@@ -82,13 +65,13 @@ void GetV8FilePath(const char* file_name, base::FilePath* path_out) {
DCHECK(!path_out->empty());
}
-static bool MapV8File(base::PlatformFile platform_file,
+static bool MapV8File(base::File file,
base::MemoryMappedFile::Region region,
base::MemoryMappedFile** mmapped_file_out) {
DCHECK(*mmapped_file_out == NULL);
base::MemoryMappedFile* mmapped_file = *mmapped_file_out =
new base::MemoryMappedFile;
- if (!mmapped_file->Initialize(base::File(platform_file), region)) {
+ if (!mmapped_file->Initialize(file.Pass(), region)) {
delete mmapped_file;
*mmapped_file_out = NULL;
return false;
@@ -97,8 +80,9 @@ static bool MapV8File(base::PlatformFile platform_file,
return true;
}
-base::PlatformFile OpenV8File(const char* file_name,
- base::MemoryMappedFile::Region* region_out) {
+static bool OpenV8File(const base::FilePath& path,
+ int flags,
+ base::File& file) {
// Re-try logic here is motivated by http://crbug.com/479537
// for A/V on Windows (https://support.microsoft.com/en-us/kb/316609).
@@ -111,16 +95,10 @@ base::PlatformFile OpenV8File(const char* file_name,
MAX_VALUE
};
- base::FilePath path;
- GetV8FilePath(file_name, &path);
-
OpenV8FileResult result = OpenV8FileResult::FAILED_IN_USE;
- int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
- base::File file;
for (int attempt = 0; attempt < kMaxOpenAttempts; attempt++) {
file.Initialize(path, flags);
if (file.IsValid()) {
- *region_out = base::MemoryMappedFile::Region::kWholeFile;
if (attempt == 0) {
result = OpenV8FileResult::OPENED;
break;
@@ -140,19 +118,9 @@ base::PlatformFile OpenV8File(const char* file_name,
UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result",
result,
OpenV8FileResult::MAX_VALUE);
- return file.TakePlatformFile();
-}
-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 result == OpenV8FileResult::OPENED
+ || result == OpenV8FileResult::OPENED_RETRY;
}
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
@@ -195,15 +163,22 @@ enum LoadV8FileResult {
V8_LOAD_MAX_VALUE
};
-static LoadV8FileResult MapVerify(base::PlatformFile platform_file,
- const base::MemoryMappedFile::Region& region,
+static LoadV8FileResult OpenMapVerify(
+ const char* file_name,
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
- const unsigned char* fingerprint,
+ const unsigned char* fingerprint,
#endif
- base::MemoryMappedFile** mmapped_file_out) {
- if (platform_file == kInvalidPlatformFile)
+ base::MemoryMappedFile** mmapped_file_out) {
+ base::FilePath path;
+ GetV8FilePath(file_name, &path);
+
+ base::File file;
+ int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
+
+ if (!OpenV8File(path, flags, file))
return V8_LOAD_FAILED_OPEN;
- if (!MapV8File(platform_file, region, mmapped_file_out))
+ if (!MapV8File(file.Pass(), base::MemoryMappedFile::Region::kWholeFile,
+ mmapped_file_out))
return V8_LOAD_FAILED_MAP;
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
if (!VerifyV8StartupFile(mmapped_file_out, fingerprint))
@@ -217,14 +192,11 @@ void V8Initializer::LoadV8Snapshot() {
if (g_mapped_snapshot)
return;
- OpenSnapshotFileIfNecessary();
- LoadV8FileResult result = MapVerify(g_snapshot_pf, g_snapshot_region,
+ LoadV8FileResult result = OpenMapVerify(kSnapshotFileName,
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
- g_snapshot_fingerprint,
+ g_snapshot_fingerprint,
#endif
- &g_mapped_snapshot);
- // V8 can't start up without the source of the natives, but it can
- // start up (slower) without the snapshot.
+ &g_mapped_snapshot);
UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result,
V8_LOAD_MAX_VALUE);
}
@@ -233,12 +205,11 @@ void V8Initializer::LoadV8Natives() {
if (g_mapped_natives)
return;
- OpenNativesFileIfNecessary();
- LoadV8FileResult result = MapVerify(g_natives_pf, g_natives_region,
+ LoadV8FileResult result = OpenMapVerify(kNativesFileName,
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
- g_natives_fingerprint,
+ g_natives_fingerprint,
#endif
- &g_mapped_natives);
+ &g_mapped_natives);
if (result != V8_LOAD_SUCCESS) {
LOG(FATAL) << "Couldn't mmap v8 natives data file, status code is "
<< static_cast<int>(result);
@@ -252,7 +223,7 @@ void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf,
if (g_mapped_snapshot)
return;
- if (snapshot_pf == kInvalidPlatformFile)
+ if (snapshot_pf == reinterpret_cast<base::PlatformFile>(-1))
return;
base::MemoryMappedFile::Region snapshot_region =
@@ -263,7 +234,7 @@ void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf,
}
LoadV8FileResult result = V8_LOAD_SUCCESS;
- if (!MapV8File(snapshot_pf, snapshot_region, &g_mapped_snapshot))
+ if (!MapV8File(base::File(snapshot_pf), snapshot_region, &g_mapped_snapshot))
result = V8_LOAD_FAILED_MAP;
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
if (!VerifyV8StartupFile(&g_mapped_snapshot, g_snapshot_fingerprint))
@@ -280,7 +251,7 @@ void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf,
if (g_mapped_natives)
return;
- CHECK_NE(natives_pf, kInvalidPlatformFile);
+ CHECK_NE(natives_pf, reinterpret_cast<base::PlatformFile>(-1));
base::MemoryMappedFile::Region natives_region =
base::MemoryMappedFile::Region::kWholeFile;
@@ -289,7 +260,7 @@ void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf,
base::MemoryMappedFile::Region(natives_offset, natives_size);
}
- if (!MapV8File(natives_pf, natives_region, &g_mapped_natives)) {
+ if (!MapV8File(base::File(natives_pf), natives_region, &g_mapped_natives)) {
LOG(FATAL) << "Couldn't mmap v8 natives data file";
}
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
@@ -300,21 +271,33 @@ void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf,
}
// static
-base::PlatformFile V8Initializer::GetOpenNativesFileForChildProcesses(
- base::MemoryMappedFile::Region* region_out) {
- OpenNativesFileIfNecessary();
- *region_out = g_natives_region;
- return g_natives_pf;
+bool V8Initializer::OpenV8FilesForChildProcesses(
+ base::PlatformFile* natives_fd_out,
+ base::PlatformFile* snapshot_fd_out) {
+ base::FilePath natives_data_path;
+ base::FilePath snapshot_data_path;
+ GetV8FilePath(kNativesFileName, &natives_data_path);
+ GetV8FilePath(kSnapshotFileName, &snapshot_data_path);
+
+ base::File natives_data_file;
+ base::File snapshot_data_file;
+ int file_flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
+
+ bool natives_success =
+ OpenV8File(natives_data_path, file_flags, natives_data_file);
+ if (natives_success) {
+ *natives_fd_out = natives_data_file.TakePlatformFile();
+ }
+ bool snapshot_success =
+ OpenV8File(snapshot_data_path, file_flags, snapshot_data_file);
+ if (snapshot_success) {
+ *snapshot_fd_out = snapshot_data_file.TakePlatformFile();
+ }
+ // We can start up without the snapshot file, but not without the natives.
+ return natives_success;
}
-// static
-base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses(
- base::MemoryMappedFile::Region* region_out) {
- OpenSnapshotFileIfNecessary();
- *region_out = g_snapshot_region;
- return g_snapshot_pf;
-}
-#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA)
+#endif // V8_USE_EXTERNAL_STARTUP_DATA
// static
void V8Initializer::Initialize(gin::IsolateHolder::ScriptMode mode) {