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) |
| 37 | |
| 38 | // Load V8 snapshot from user provided platform file descriptors. |
| 39 | // The offset and size arguments, if non-zero, specify the portions |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 40 | // of the files to be loaded. Since the VM can boot with or without |
| 41 | // the snapshot, this function does not return a status. |
| 42 | static void LoadV8SnapshotFromFD(base::PlatformFile snapshot_fd, |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 43 | int64_t snapshot_offset, |
| 44 | int64_t snapshot_size); |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 45 | // Similar to LoadV8SnapshotFromFD, but for the source of the natives. |
| 46 | // Without the natives we cannot continue, so this function contains |
| 47 | // release mode asserts and won't return if it fails. |
| 48 | static void LoadV8NativesFromFD(base::PlatformFile natives_fd, |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 49 | int64_t natives_offset, |
| 50 | int64_t natives_size); |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 51 | |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 52 | // Load V8 snapshot from default resources, if they are available. |
| 53 | static void LoadV8Snapshot(); |
| 54 | |
| 55 | // Load V8 natives source from default resources. Contains asserts |
| 56 | // so that it will not return if natives cannot be loaded. |
| 57 | static void LoadV8Natives(); |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 58 | |
tobiasjs | b2001627 | 2016-02-10 11:54:12 | [diff] [blame] | 59 | #if defined(OS_ANDROID) |
michaelbai | 02037588 | 2016-06-21 16:08:15 | [diff] [blame] | 60 | static base::FilePath GetNativesFilePath(); |
tobiasjs | b2001627 | 2016-02-10 11:54:12 | [diff] [blame] | 61 | static base::FilePath GetSnapshotFilePath(bool abi_32_bit); |
| 62 | #endif |
| 63 | |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 64 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Hitoshi Yoshida | f2f50de | 2017-08-22 13:23:55 | [diff] [blame] | 65 | |
| 66 | // Load V8 context snapshot from user provided platform file descriptors. |
| 67 | // Other details are same with LoadV8SnapshotFromFD. |
| 68 | static void LoadV8ContextSnapshotFromFD(base::PlatformFile snapshot_fd, |
| 69 | int64_t snapshot_offset, |
| 70 | int64_t snapshot_size); |
| 71 | |
| 72 | // Load V8 context snapshot from default resources, if they are available. |
| 73 | static void LoadV8ContextSnapshot(); |
| 74 | |
| 75 | // Get address and size information for currently loaded V8 context snapshot. |
| 76 | // If no snapshot is loaded, the return values are nullptr and 0. |
Hitoshi Yoshida | d88a223e | 2017-09-10 05:55:25 | [diff] [blame] | 77 | static void GetV8ContextSnapshotData(v8::StartupData* snapshot); |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace gin |
| 81 | |
| 82 | #endif // GIN_V8_INITIALIZER_H_ |