oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef GIN_V8_INITIALIZER_H_ |
| 6 | #define GIN_V8_INITIALIZER_H_ |
| 7 | |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 10 | #include "base/files/file.h" |
agrieve | fd2d44ab | 2015-06-19 04:33:03 | [diff] [blame] | 11 | #include "base/files/memory_mapped_file.h" |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 12 | #include "gin/array_buffer.h" |
| 13 | #include "gin/gin_export.h" |
| 14 | #include "gin/public/isolate_holder.h" |
| 15 | #include "gin/public/v8_platform.h" |
| 16 | #include "v8/include/v8.h" |
| 17 | |
| 18 | namespace gin { |
| 19 | |
| 20 | class GIN_EXPORT V8Initializer { |
| 21 | public: |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 22 | // This should be called by IsolateHolder::Initialize(). |
yhirano | 9315024 | 2015-12-07 12:28:33 | [diff] [blame] | 23 | static void Initialize(IsolateHolder::ScriptMode mode, |
| 24 | IsolateHolder::V8ExtrasMode v8_extras_mode); |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 25 | |
| 26 | // Get address and size information for currently loaded snapshot. |
| 27 | // If no snapshot is loaded, the return values are null for addresses |
| 28 | // and 0 for sizes. |
Hitoshi Yoshida | d88a223e | 2017-09-10 05:55:25 | [diff] [blame] | 29 | static void GetV8ExternalSnapshotData(v8::StartupData* natives, |
| 30 | v8::StartupData* snapshot); |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 31 | static void GetV8ExternalSnapshotData(const char** natives_data_out, |
| 32 | int* natives_size_out, |
| 33 | const char** snapshot_data_out, |
| 34 | int* snapshot_size_out); |
| 35 | |
| 36 | #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
Hitoshi Yoshida | 9aff02e | 2018-01-19 16:55:03 | [diff] [blame] | 37 | // Indicates which file to load as a snapshot blob image. |
| 38 | enum class V8SnapshotFileType { |
| 39 | kDefault, |
| 40 | |
| 41 | // Snapshot augmented with customized contexts, which can be deserialized |
| 42 | // using v8::Context::FromSnapshot. |
| 43 | kWithAdditionalContext, |
| 44 | }; |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 45 | |
Hitoshi Yoshida | ba9c2f0f | 2017-11-27 03:11:46 | [diff] [blame] | 46 | // Load V8 snapshot from default resources, if they are available. |
Hitoshi Yoshida | 9aff02e | 2018-01-19 16:55:03 | [diff] [blame] | 47 | static void LoadV8Snapshot( |
| 48 | V8SnapshotFileType snapshot_file_type = V8SnapshotFileType::kDefault); |
Hitoshi Yoshida | ba9c2f0f | 2017-11-27 03:11:46 | [diff] [blame] | 49 | // Load V8 natives source from default resources. Contains asserts |
| 50 | // so that it will not return if natives cannot be loaded. |
| 51 | static void LoadV8Natives(); |
Hitoshi Yoshida | ba9c2f0f | 2017-11-27 03:11:46 | [diff] [blame] | 52 | |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 53 | // Load V8 snapshot from user provided platform file descriptors. |
| 54 | // The offset and size arguments, if non-zero, specify the portions |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 55 | // of the files to be loaded. Since the VM can boot with or without |
| 56 | // the snapshot, this function does not return a status. |
| 57 | static void LoadV8SnapshotFromFD(base::PlatformFile snapshot_fd, |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 58 | int64_t snapshot_offset, |
Hitoshi Yoshida | 9aff02e | 2018-01-19 16:55:03 | [diff] [blame] | 59 | int64_t snapshot_size, |
| 60 | V8SnapshotFileType snapshot_file_type); |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 61 | // Similar to LoadV8SnapshotFromFD, but for the source of the natives. |
| 62 | // Without the natives we cannot continue, so this function contains |
| 63 | // release mode asserts and won't return if it fails. |
| 64 | static void LoadV8NativesFromFD(base::PlatformFile natives_fd, |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 65 | int64_t natives_offset, |
| 66 | int64_t natives_size); |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 67 | |
tobiasjs | b2001627 | 2016-02-10 11:54:12 | [diff] [blame] | 68 | #if defined(OS_ANDROID) |
michaelbai | 02037588 | 2016-06-21 16:08:15 | [diff] [blame] | 69 | static base::FilePath GetNativesFilePath(); |
Hitoshi Yoshida | 0669723 | 2018-03-05 04:09:15 | [diff] [blame] | 70 | static base::FilePath GetSnapshotFilePath( |
| 71 | bool abi_32_bit, |
| 72 | V8SnapshotFileType snapshot_file_type); |
tobiasjs | b2001627 | 2016-02-10 11:54:12 | [diff] [blame] | 73 | #endif |
| 74 | |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 75 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Hitoshi Yoshida | f2f50de | 2017-08-22 13:23:55 | [diff] [blame] | 76 | |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace gin |
| 80 | |
| 81 | #endif // GIN_V8_INITIALIZER_H_ |