blob: 065fecb7efd703f0463c01eca3f8d1efb8905530 [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.
Hitoshi Yoshidad88a223e2017-09-10 05:55:2529 static void GetV8ExternalSnapshotData(v8::StartupData* natives,
30 v8::StartupData* snapshot);
oth05c26fde2015-04-05 14:30:5731 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
erikcorryc94eff12015-06-08 11:29:1640 // 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,
avi90e658dd2015-12-21 07:16:1943 int64_t snapshot_offset,
44 int64_t snapshot_size);
erikcorryc94eff12015-06-08 11:29:1645 // 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,
avi90e658dd2015-12-21 07:16:1949 int64_t natives_offset,
50 int64_t natives_size);
oth05c26fde2015-04-05 14:30:5751
erikcorryc94eff12015-06-08 11:29:1652 // 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();
oth05c26fde2015-04-05 14:30:5758
tobiasjsb20016272016-02-10 11:54:1259#if defined(OS_ANDROID)
michaelbai020375882016-06-21 16:08:1560 static base::FilePath GetNativesFilePath();
tobiasjsb20016272016-02-10 11:54:1261 static base::FilePath GetSnapshotFilePath(bool abi_32_bit);
62#endif
63
oth05c26fde2015-04-05 14:30:5764#endif // V8_USE_EXTERNAL_STARTUP_DATA
Hitoshi Yoshidaf2f50de2017-08-22 13:23:5565
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 Yoshidad88a223e2017-09-10 05:55:2577 static void GetV8ContextSnapshotData(v8::StartupData* snapshot);
oth05c26fde2015-04-05 14:30:5778};
79
80} // namespace gin
81
82#endif // GIN_V8_INITIALIZER_H_