blob: 8601b15238e12635365e632d538004d9dc3841a7 [file] [log] [blame]
oth05c26fde2015-04-05 14:30:571// 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
avi90e658dd2015-12-21 07:16:198#include <stdint.h>
9
oth05c26fde2015-04-05 14:30:5710#include "base/files/file.h"
agrievefd2d44ab2015-06-19 04:33:0311#include "base/files/memory_mapped_file.h"
oth05c26fde2015-04-05 14:30:5712#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
18namespace gin {
19
20class GIN_EXPORT V8Initializer {
21 public:
oth05c26fde2015-04-05 14:30:5722 // This should be called by IsolateHolder::Initialize().
yhirano93150242015-12-07 12:28:3323 static void Initialize(IsolateHolder::ScriptMode mode,
24 IsolateHolder::V8ExtrasMode v8_extras_mode);
oth05c26fde2015-04-05 14:30:5725
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.
29 static void GetV8ExternalSnapshotData(const char** natives_data_out,
30 int* natives_size_out,
31 const char** snapshot_data_out,
32 int* snapshot_size_out);
33
34#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
35
36 // Load V8 snapshot from user provided platform file descriptors.
37 // The offset and size arguments, if non-zero, specify the portions
erikcorryc94eff12015-06-08 11:29:1638 // of the files to be loaded. Since the VM can boot with or without
39 // the snapshot, this function does not return a status.
40 static void LoadV8SnapshotFromFD(base::PlatformFile snapshot_fd,
avi90e658dd2015-12-21 07:16:1941 int64_t snapshot_offset,
42 int64_t snapshot_size);
erikcorryc94eff12015-06-08 11:29:1643 // Similar to LoadV8SnapshotFromFD, but for the source of the natives.
44 // Without the natives we cannot continue, so this function contains
45 // release mode asserts and won't return if it fails.
46 static void LoadV8NativesFromFD(base::PlatformFile natives_fd,
avi90e658dd2015-12-21 07:16:1947 int64_t natives_offset,
48 int64_t natives_size);
oth05c26fde2015-04-05 14:30:5749
erikcorryc94eff12015-06-08 11:29:1650 // Load V8 snapshot from default resources, if they are available.
51 static void LoadV8Snapshot();
52
53 // Load V8 natives source from default resources. Contains asserts
54 // so that it will not return if natives cannot be loaded.
55 static void LoadV8Natives();
oth05c26fde2015-04-05 14:30:5756
agrievefd2d44ab2015-06-19 04:33:0357 // Opens (unless already cached) and returns the V8 natives file.
58 // Use with LoadV8NativesFromFD().
59 // Asserts if the file does not exist.
60 static base::PlatformFile GetOpenNativesFileForChildProcesses(
61 base::MemoryMappedFile::Region* region_out);
62
63 // Opens (unless already cached) and returns the V8 snapshot file.
64 // Use with LoadV8SnapshotFromFD().
65 // Will return -1 if the file does not exist.
66 static base::PlatformFile GetOpenSnapshotFileForChildProcesses(
67 base::MemoryMappedFile::Region* region_out);
tobiasjsb20016272016-02-10 11:54:1268
69#if defined(OS_ANDROID)
tobiasjsb20016272016-02-10 11:54:1270 static base::PlatformFile GetOpenSnapshotFileForChildProcesses(
71 base::MemoryMappedFile::Region* region_out,
72 bool abi_32_bit);
73
michaelbai020375882016-06-21 16:08:1574 static base::FilePath GetNativesFilePath();
tobiasjsb20016272016-02-10 11:54:1275 static base::FilePath GetSnapshotFilePath(bool abi_32_bit);
76#endif
77
oth05c26fde2015-04-05 14:30:5778#endif // V8_USE_EXTERNAL_STARTUP_DATA
Hitoshi Yoshidaf2f50de2017-08-22 13:23:5579
80 // Load V8 context snapshot from user provided platform file descriptors.
81 // Other details are same with LoadV8SnapshotFromFD.
82 static void LoadV8ContextSnapshotFromFD(base::PlatformFile snapshot_fd,
83 int64_t snapshot_offset,
84 int64_t snapshot_size);
85
86 // Load V8 context snapshot from default resources, if they are available.
87 static void LoadV8ContextSnapshot();
88
89 // Get address and size information for currently loaded V8 context snapshot.
90 // If no snapshot is loaded, the return values are nullptr and 0.
91 static void GetV8ContextSnapshotData(const char** snapshot_data_out,
92 int* snapshot_size_out);
oth05c26fde2015-04-05 14:30:5793};
94
95} // namespace gin
96
97#endif // GIN_V8_INITIALIZER_H_