OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gin/v8_initializer.h" | 5 #include "gin/v8_initializer.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "crypto/sha2.h" | 17 #include "crypto/sha2.h" |
18 | 18 |
19 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 19 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
20 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
21 #include "base/mac/foundation_util.h" | 21 #include "base/mac/foundation_util.h" |
22 #endif // OS_MACOSX | 22 #endif // OS_MACOSX |
23 #include "base/path_service.h" | 23 #include "base/path_service.h" |
24 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 24 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
25 | 25 |
26 namespace gin { | 26 namespace gin { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // None of these globals are ever freed nor closed. | |
30 base::MemoryMappedFile* g_mapped_natives = nullptr; | 31 base::MemoryMappedFile* g_mapped_natives = nullptr; |
31 base::MemoryMappedFile* g_mapped_snapshot = nullptr; | 32 base::MemoryMappedFile* g_mapped_snapshot = nullptr; |
32 | 33 |
33 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 34 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
35 | |
36 const base::PlatformFile kInvalidPlatformFile = | |
37 #if defined(OS_WIN) | |
38 INVALID_HANDLE_VALUE; | |
39 #else | |
40 -1; | |
41 #endif | |
42 | |
43 // File handles intentionally never closed. Not using File here because its | |
44 // Windows implementation guards against two instances owning the same | |
45 // PlatformFile (which we allow since we know it is never freed). | |
46 base::PlatformFile g_natives_pf = kInvalidPlatformFile; | |
47 base::PlatformFile g_snapshot_pf = kInvalidPlatformFile; | |
48 // Jump through hoops here to avoid introducing static initializers. | |
49 char g_natives_region_data[sizeof(base::MemoryMappedFile::Region)] = {0}; | |
50 char g_snapshot_region_data[sizeof(base::MemoryMappedFile::Region)] = {0}; | |
51 base::MemoryMappedFile::Region& g_natives_region = | |
52 *reinterpret_cast<base::MemoryMappedFile::Region*>(g_natives_region_data); | |
53 base::MemoryMappedFile::Region& g_snapshot_region = | |
54 *reinterpret_cast<base::MemoryMappedFile::Region*>(g_snapshot_region_data); | |
rmcilroy
2015/06/17 08:00:50
This seems a bit hacky personally. I would prefer
| |
55 | |
34 #if !defined(OS_MACOSX) | 56 #if !defined(OS_MACOSX) |
35 const int kV8SnapshotBasePathKey = | 57 const int kV8SnapshotBasePathKey = |
36 #if defined(OS_ANDROID) | 58 #if defined(OS_ANDROID) |
37 base::DIR_ANDROID_APP_DATA; | 59 base::DIR_ANDROID_APP_DATA; |
38 #elif defined(OS_POSIX) | 60 #elif defined(OS_POSIX) |
39 base::DIR_EXE; | 61 base::DIR_EXE; |
40 #elif defined(OS_WIN) | 62 #elif defined(OS_WIN) |
41 base::DIR_MODULE; | 63 base::DIR_MODULE; |
42 #endif // OS_ANDROID | 64 #endif // OS_ANDROID |
43 #endif // !OS_MACOSX | 65 #endif // !OS_MACOSX |
(...skipping 14 matching lines...) Expand all Loading... | |
58 | 80 |
59 *path_out = data_path.AppendASCII(file_name); | 81 *path_out = data_path.AppendASCII(file_name); |
60 #else // !defined(OS_MACOSX) | 82 #else // !defined(OS_MACOSX) |
61 base::ScopedCFTypeRef<CFStringRef> natives_file_name( | 83 base::ScopedCFTypeRef<CFStringRef> natives_file_name( |
62 base::SysUTF8ToCFStringRef(file_name)); | 84 base::SysUTF8ToCFStringRef(file_name)); |
63 *path_out = base::mac::PathForFrameworkBundleResource(natives_file_name); | 85 *path_out = base::mac::PathForFrameworkBundleResource(natives_file_name); |
64 #endif // !defined(OS_MACOSX) | 86 #endif // !defined(OS_MACOSX) |
65 DCHECK(!path_out->empty()); | 87 DCHECK(!path_out->empty()); |
66 } | 88 } |
67 | 89 |
68 static bool MapV8File(base::File file, | 90 static bool MapV8File(base::PlatformFile platform_file, |
69 base::MemoryMappedFile::Region region, | 91 base::MemoryMappedFile::Region region, |
70 base::MemoryMappedFile** mmapped_file_out) { | 92 base::MemoryMappedFile** mmapped_file_out) { |
71 DCHECK(*mmapped_file_out == NULL); | 93 DCHECK(*mmapped_file_out == NULL); |
72 base::MemoryMappedFile* mmapped_file = *mmapped_file_out = | 94 base::MemoryMappedFile* mmapped_file = *mmapped_file_out = |
73 new base::MemoryMappedFile; | 95 new base::MemoryMappedFile; |
74 if (!mmapped_file->Initialize(file.Pass(), region)) { | 96 if (!mmapped_file->Initialize(base::File(platform_file), region)) { |
75 delete mmapped_file; | 97 delete mmapped_file; |
76 *mmapped_file_out = NULL; | 98 *mmapped_file_out = NULL; |
77 return false; | 99 return false; |
78 } | 100 } |
79 | 101 |
80 return true; | 102 return true; |
81 } | 103 } |
82 | 104 |
83 static bool OpenV8File(const base::FilePath& path, | 105 base::PlatformFile OpenV8File(const char* file_name, |
84 int flags, | 106 base::MemoryMappedFile::Region* region_out) { |
85 base::File& file) { | |
86 // Re-try logic here is motivated by http://crbug.com/479537 | 107 // Re-try logic here is motivated by http://crbug.com/479537 |
87 // for A/V on Windows (https://support.microsoft.com/en-us/kb/316609). | 108 // for A/V on Windows (https://support.microsoft.com/en-us/kb/316609). |
88 | 109 |
89 // These match tools/metrics/histograms.xml | 110 // These match tools/metrics/histograms.xml |
90 enum OpenV8FileResult { | 111 enum OpenV8FileResult { |
91 OPENED = 0, | 112 OPENED = 0, |
92 OPENED_RETRY, | 113 OPENED_RETRY, |
93 FAILED_IN_USE, | 114 FAILED_IN_USE, |
94 FAILED_OTHER, | 115 FAILED_OTHER, |
95 MAX_VALUE | 116 MAX_VALUE |
96 }; | 117 }; |
97 | 118 |
119 base::FilePath path; | |
120 GetV8FilePath(file_name, &path); | |
121 | |
98 OpenV8FileResult result = OpenV8FileResult::FAILED_IN_USE; | 122 OpenV8FileResult result = OpenV8FileResult::FAILED_IN_USE; |
123 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | |
124 base::File file; | |
99 for (int attempt = 0; attempt < kMaxOpenAttempts; attempt++) { | 125 for (int attempt = 0; attempt < kMaxOpenAttempts; attempt++) { |
100 file.Initialize(path, flags); | 126 file.Initialize(path, flags); |
101 if (file.IsValid()) { | 127 if (file.IsValid()) { |
128 *region_out = base::MemoryMappedFile::Region::kWholeFile; | |
102 if (attempt == 0) { | 129 if (attempt == 0) { |
103 result = OpenV8FileResult::OPENED; | 130 result = OpenV8FileResult::OPENED; |
104 break; | 131 break; |
105 } else { | 132 } else { |
106 result = OpenV8FileResult::OPENED_RETRY; | 133 result = OpenV8FileResult::OPENED_RETRY; |
107 break; | 134 break; |
108 } | 135 } |
109 } else if (file.error_details() != base::File::FILE_ERROR_IN_USE) { | 136 } else if (file.error_details() != base::File::FILE_ERROR_IN_USE) { |
110 result = OpenV8FileResult::FAILED_OTHER; | 137 result = OpenV8FileResult::FAILED_OTHER; |
111 break; | 138 break; |
112 } else if (kMaxOpenAttempts - 1 != attempt) { | 139 } else if (kMaxOpenAttempts - 1 != attempt) { |
113 base::PlatformThread::Sleep( | 140 base::PlatformThread::Sleep( |
114 base::TimeDelta::FromMilliseconds(kOpenRetryDelayMillis)); | 141 base::TimeDelta::FromMilliseconds(kOpenRetryDelayMillis)); |
115 } | 142 } |
116 } | 143 } |
117 | 144 |
118 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result", | 145 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result", |
119 result, | 146 result, |
120 OpenV8FileResult::MAX_VALUE); | 147 OpenV8FileResult::MAX_VALUE); |
148 return file.TakePlatformFile(); | |
149 } | |
121 | 150 |
122 return result == OpenV8FileResult::OPENED | 151 void OpenNativesFileIfNecessary() { |
123 || result == OpenV8FileResult::OPENED_RETRY; | 152 if (g_natives_pf == kInvalidPlatformFile) { |
153 g_natives_pf = OpenV8File(kNativesFileName, &g_natives_region); | |
154 } | |
155 } | |
156 | |
157 void OpenSnapshotFileIfNecessary() { | |
158 if (g_snapshot_pf == kInvalidPlatformFile) { | |
159 g_snapshot_pf = OpenV8File(kSnapshotFileName, &g_snapshot_region); | |
160 } | |
124 } | 161 } |
125 | 162 |
126 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 163 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
127 bool VerifyV8StartupFile(base::MemoryMappedFile** file, | 164 bool VerifyV8StartupFile(base::MemoryMappedFile** file, |
128 const unsigned char* fingerprint) { | 165 const unsigned char* fingerprint) { |
129 unsigned char output[crypto::kSHA256Length]; | 166 unsigned char output[crypto::kSHA256Length]; |
130 crypto::SHA256HashString( | 167 crypto::SHA256HashString( |
131 base::StringPiece(reinterpret_cast<const char*>((*file)->data()), | 168 base::StringPiece(reinterpret_cast<const char*>((*file)->data()), |
132 (*file)->length()), | 169 (*file)->length()), |
133 output, sizeof(output)); | 170 output, sizeof(output)); |
(...skipping 22 matching lines...) Expand all Loading... | |
156 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA | 193 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
157 | 194 |
158 enum LoadV8FileResult { | 195 enum LoadV8FileResult { |
159 V8_LOAD_SUCCESS = 0, | 196 V8_LOAD_SUCCESS = 0, |
160 V8_LOAD_FAILED_OPEN, | 197 V8_LOAD_FAILED_OPEN, |
161 V8_LOAD_FAILED_MAP, | 198 V8_LOAD_FAILED_MAP, |
162 V8_LOAD_FAILED_VERIFY, | 199 V8_LOAD_FAILED_VERIFY, |
163 V8_LOAD_MAX_VALUE | 200 V8_LOAD_MAX_VALUE |
164 }; | 201 }; |
165 | 202 |
166 static LoadV8FileResult OpenMapVerify( | 203 static LoadV8FileResult MapVerify(base::PlatformFile platform_file, |
167 const char* file_name, | 204 const base::MemoryMappedFile::Region& region, |
168 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 205 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
169 const unsigned char* fingerprint, | 206 const unsigned char* fingerprint, |
170 #endif | 207 #endif |
171 base::MemoryMappedFile** mmapped_file_out) { | 208 base::MemoryMappedFile** mmapped_file_out) { |
172 base::FilePath path; | 209 if (platform_file == kInvalidPlatformFile) |
173 GetV8FilePath(file_name, &path); | |
174 | |
175 base::File file; | |
176 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | |
177 | |
178 if (!OpenV8File(path, flags, file)) | |
179 return V8_LOAD_FAILED_OPEN; | 210 return V8_LOAD_FAILED_OPEN; |
180 if (!MapV8File(file.Pass(), base::MemoryMappedFile::Region::kWholeFile, | 211 if (!MapV8File(platform_file, region, mmapped_file_out)) |
181 mmapped_file_out)) | |
182 return V8_LOAD_FAILED_MAP; | 212 return V8_LOAD_FAILED_MAP; |
183 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 213 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
184 if (!VerifyV8StartupFile(mmapped_file_out, fingerprint)) | 214 if (!VerifyV8StartupFile(mmapped_file_out, fingerprint)) |
185 return V8_LOAD_FAILED_VERIFY; | 215 return V8_LOAD_FAILED_VERIFY; |
186 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA | 216 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
187 return V8_LOAD_SUCCESS; | 217 return V8_LOAD_SUCCESS; |
188 } | 218 } |
189 | 219 |
190 // static | 220 // static |
191 void V8Initializer::LoadV8Snapshot() { | 221 void V8Initializer::LoadV8Snapshot() { |
192 if (g_mapped_snapshot) | 222 if (g_mapped_snapshot) |
193 return; | 223 return; |
194 | 224 |
195 LoadV8FileResult result = OpenMapVerify(kSnapshotFileName, | 225 OpenSnapshotFileIfNecessary(); |
226 LoadV8FileResult result = MapVerify(g_snapshot_pf, g_snapshot_region, | |
196 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 227 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
197 g_snapshot_fingerprint, | 228 g_snapshot_fingerprint, |
198 #endif | 229 #endif |
199 &g_mapped_snapshot); | 230 &g_mapped_snapshot); |
231 // V8 can't start up without the source of the natives, but it can | |
232 // start up (slower) without the snapshot. | |
200 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, | 233 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, |
201 V8_LOAD_MAX_VALUE); | 234 V8_LOAD_MAX_VALUE); |
202 } | 235 } |
203 | 236 |
204 void V8Initializer::LoadV8Natives() { | 237 void V8Initializer::LoadV8Natives() { |
205 if (g_mapped_natives) | 238 if (g_mapped_natives) |
206 return; | 239 return; |
207 | 240 |
208 LoadV8FileResult result = OpenMapVerify(kNativesFileName, | 241 OpenNativesFileIfNecessary(); |
242 LoadV8FileResult result = MapVerify(g_natives_pf, g_natives_region, | |
209 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 243 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
210 g_natives_fingerprint, | 244 g_natives_fingerprint, |
211 #endif | 245 #endif |
212 &g_mapped_natives); | 246 &g_mapped_natives); |
213 if (result != V8_LOAD_SUCCESS) { | 247 if (result != V8_LOAD_SUCCESS) { |
214 LOG(FATAL) << "Couldn't mmap v8 natives data file, status code is " | 248 LOG(FATAL) << "Couldn't mmap v8 natives data file, status code is " |
215 << static_cast<int>(result); | 249 << static_cast<int>(result); |
216 } | 250 } |
217 } | 251 } |
218 | 252 |
219 // static | 253 // static |
220 void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf, | 254 void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf, |
221 int64 snapshot_offset, | 255 int64 snapshot_offset, |
222 int64 snapshot_size) { | 256 int64 snapshot_size) { |
223 if (g_mapped_snapshot) | 257 if (g_mapped_snapshot) |
224 return; | 258 return; |
225 | 259 |
226 if (snapshot_pf == reinterpret_cast<base::PlatformFile>(-1)) | 260 if (snapshot_pf == kInvalidPlatformFile) |
227 return; | 261 return; |
228 | 262 |
229 base::MemoryMappedFile::Region snapshot_region = | 263 base::MemoryMappedFile::Region snapshot_region = |
230 base::MemoryMappedFile::Region::kWholeFile; | 264 base::MemoryMappedFile::Region::kWholeFile; |
231 if (snapshot_size != 0 || snapshot_offset != 0) { | 265 if (snapshot_size != 0 || snapshot_offset != 0) { |
232 snapshot_region = | 266 snapshot_region = |
233 base::MemoryMappedFile::Region(snapshot_offset, snapshot_size); | 267 base::MemoryMappedFile::Region(snapshot_offset, snapshot_size); |
234 } | 268 } |
235 | 269 |
236 LoadV8FileResult result = V8_LOAD_SUCCESS; | 270 LoadV8FileResult result = V8_LOAD_SUCCESS; |
237 if (!MapV8File(base::File(snapshot_pf), snapshot_region, &g_mapped_snapshot)) | 271 if (!MapV8File(snapshot_pf, snapshot_region, &g_mapped_snapshot)) |
238 result = V8_LOAD_FAILED_MAP; | 272 result = V8_LOAD_FAILED_MAP; |
239 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 273 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
240 if (!VerifyV8StartupFile(&g_mapped_snapshot, g_snapshot_fingerprint)) | 274 if (!VerifyV8StartupFile(&g_mapped_snapshot, g_snapshot_fingerprint)) |
241 result = V8_LOAD_FAILED_VERIFY; | 275 result = V8_LOAD_FAILED_VERIFY; |
242 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA | 276 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
243 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, | 277 UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result, |
244 V8_LOAD_MAX_VALUE); | 278 V8_LOAD_MAX_VALUE); |
245 } | 279 } |
246 | 280 |
247 // static | 281 // static |
248 void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf, | 282 void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf, |
249 int64 natives_offset, | 283 int64 natives_offset, |
250 int64 natives_size) { | 284 int64 natives_size) { |
251 if (g_mapped_natives) | 285 if (g_mapped_natives) |
252 return; | 286 return; |
253 | 287 |
254 CHECK_NE(natives_pf, reinterpret_cast<base::PlatformFile>(-1)); | 288 CHECK_NE(natives_pf, kInvalidPlatformFile); |
255 | 289 |
256 base::MemoryMappedFile::Region natives_region = | 290 base::MemoryMappedFile::Region natives_region = |
257 base::MemoryMappedFile::Region::kWholeFile; | 291 base::MemoryMappedFile::Region::kWholeFile; |
258 if (natives_size != 0 || natives_offset != 0) { | 292 if (natives_size != 0 || natives_offset != 0) { |
259 natives_region = | 293 natives_region = |
260 base::MemoryMappedFile::Region(natives_offset, natives_size); | 294 base::MemoryMappedFile::Region(natives_offset, natives_size); |
261 } | 295 } |
262 | 296 |
263 if (!MapV8File(base::File(natives_pf), natives_region, &g_mapped_natives)) { | 297 if (!MapV8File(natives_pf, natives_region, &g_mapped_natives)) { |
264 LOG(FATAL) << "Couldn't mmap v8 natives data file"; | 298 LOG(FATAL) << "Couldn't mmap v8 natives data file"; |
265 } | 299 } |
266 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) | 300 #if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA) |
267 if (!VerifyV8StartupFile(&g_mapped_natives, g_natives_fingerprint)) { | 301 if (!VerifyV8StartupFile(&g_mapped_natives, g_natives_fingerprint)) { |
268 LOG(FATAL) << "Couldn't verify contents of v8 natives data file"; | 302 LOG(FATAL) << "Couldn't verify contents of v8 natives data file"; |
269 } | 303 } |
270 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA | 304 #endif // V8_VERIFY_EXTERNAL_STARTUP_DATA |
271 } | 305 } |
272 | 306 |
273 // static | 307 // static |
274 bool V8Initializer::OpenV8FilesForChildProcesses( | 308 base::PlatformFile V8Initializer::GetOpenNativesFileForChildProcesses( |
275 base::PlatformFile* natives_fd_out, | 309 base::MemoryMappedFile::Region* region_out) { |
276 base::PlatformFile* snapshot_fd_out) { | 310 OpenNativesFileIfNecessary(); |
277 base::FilePath natives_data_path; | 311 *region_out = g_natives_region; |
278 base::FilePath snapshot_data_path; | 312 return g_natives_pf; |
279 GetV8FilePath(kNativesFileName, &natives_data_path); | |
280 GetV8FilePath(kSnapshotFileName, &snapshot_data_path); | |
281 | |
282 base::File natives_data_file; | |
283 base::File snapshot_data_file; | |
284 int file_flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | |
285 | |
286 bool natives_success = | |
287 OpenV8File(natives_data_path, file_flags, natives_data_file); | |
288 if (natives_success) { | |
289 *natives_fd_out = natives_data_file.TakePlatformFile(); | |
290 } | |
291 bool snapshot_success = | |
292 OpenV8File(snapshot_data_path, file_flags, snapshot_data_file); | |
293 if (snapshot_success) { | |
294 *snapshot_fd_out = snapshot_data_file.TakePlatformFile(); | |
295 } | |
296 // We can start up without the snapshot file, but not without the natives. | |
297 return natives_success; | |
298 } | 313 } |
299 | 314 |
300 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 315 // static |
316 base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses( | |
317 base::MemoryMappedFile::Region* region_out) { | |
318 OpenSnapshotFileIfNecessary(); | |
319 *region_out = g_snapshot_region; | |
320 return g_snapshot_pf; | |
321 } | |
322 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
301 | 323 |
302 // static | 324 // static |
303 void V8Initializer::Initialize(gin::IsolateHolder::ScriptMode mode) { | 325 void V8Initializer::Initialize(gin::IsolateHolder::ScriptMode mode) { |
304 static bool v8_is_initialized = false; | 326 static bool v8_is_initialized = false; |
305 if (v8_is_initialized) | 327 if (v8_is_initialized) |
306 return; | 328 return; |
307 | 329 |
308 v8::V8::InitializePlatform(V8Platform::Get()); | 330 v8::V8::InitializePlatform(V8Platform::Get()); |
309 | 331 |
310 if (gin::IsolateHolder::kStrictMode == mode) { | 332 if (gin::IsolateHolder::kStrictMode == mode) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 *snapshot_data_out = | 370 *snapshot_data_out = |
349 reinterpret_cast<const char*>(g_mapped_snapshot->data()); | 371 reinterpret_cast<const char*>(g_mapped_snapshot->data()); |
350 *snapshot_size_out = static_cast<int>(g_mapped_snapshot->length()); | 372 *snapshot_size_out = static_cast<int>(g_mapped_snapshot->length()); |
351 } else { | 373 } else { |
352 *snapshot_data_out = NULL; | 374 *snapshot_data_out = NULL; |
353 *snapshot_size_out = 0; | 375 *snapshot_size_out = 0; |
354 } | 376 } |
355 } | 377 } |
356 | 378 |
357 } // namespace gin | 379 } // namespace gin |
OLD | NEW |