v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
bootstrapper.h
Go to the documentation of this file.
1// Copyright 2014 the V8 project 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 V8_INIT_BOOTSTRAPPER_H_
6#define V8_INIT_BOOTSTRAPPER_H_
7
10#include "include/v8-snapshot.h"
11#include "src/heap/factory.h"
16
17namespace v8 {
18namespace internal {
19
20// A SourceCodeCache uses a FixedArray to store pairs of (OneByteString,
21// SharedFunctionInfo), mapping names of native extensions code files to
22// precompiled functions.
23class SourceCodeCache final {
24 public:
25 explicit SourceCodeCache(Script::Type type) : type_(type) {}
28
29 void Initialize(Isolate* isolate, bool create_heap_objects);
30
31 void Iterate(RootVisitor* v);
32
33 bool Lookup(Isolate* isolate, base::Vector<const char> name,
35
36 void Add(Isolate* isolate, base::Vector<const char> name,
38
39 private:
42};
43
44// The Boostrapper is the public interface for creating a JavaScript global
45// context.
46class Bootstrapper final {
47 public:
48 Bootstrapper(const Bootstrapper&) = delete;
50
51 static void InitializeOncePerProcess();
52
53 // Requires: Heap::SetUp has been called.
54 void Initialize(bool create_heap_objects);
55 void TearDown();
56
57 // Creates a JavaScript Global Context with initial object graph.
58 // The returned value is a global handle casted to V8Environment*.
60 MaybeDirectHandle<JSGlobalProxy> maybe_global_proxy,
61 v8::Local<v8::ObjectTemplate> global_object_template,
62 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
63 DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
65
66 // Used for testing context deserialization. No code runs in the generated
67 // context. It only needs to pass heap verification.
70 v8::Local<v8::ObjectTemplate> no_global_object_template;
71 ExtensionConfiguration no_extensions;
72 static constexpr int kDefaultContextIndex = 0;
74 v8::MicrotaskQueue* no_microtask_queue = nullptr;
75 return CreateEnvironment(no_global_proxy, no_global_object_template,
76 &no_extensions, kDefaultContextIndex, no_callback,
77 no_microtask_queue);
78 }
79
81 MaybeDirectHandle<JSGlobalProxy> maybe_global_proxy,
82 v8::Local<v8::ObjectTemplate> global_object_template);
83
84 // Traverses the pointers for memory management.
85 void Iterate(RootVisitor* v);
86
87 // Tells whether bootstrapping is active.
88 bool IsActive() const { return nesting_ != 0; }
89
90 // Support for thread preemption.
91 static int ArchiveSpacePerThread();
92 char* ArchiveState(char* to);
93 char* RestoreState(char* from);
95
96 // Used for new context creation.
98 v8::ExtensionConfiguration* extensions);
99
101
102 private:
103 // Log newly created Map objects if no snapshot was used.
104 void LogAllMaps();
105
110
111 friend class BootstrapperActive;
112 friend class Isolate;
114
115 explicit Bootstrapper(Isolate* isolate);
116};
117
119 public:
120 explicit BootstrapperActive(Bootstrapper* bootstrapper)
121 : bootstrapper_(bootstrapper) {
123 }
126
128
129 private:
131};
132
133// Exposed for Wasm bootstrapping.
135 Isolate* isolate, DirectHandle<JSObject> base, const char* name,
136 Builtin call, int len, AdaptArguments adapt,
138
139// Exposed for Wasm bootstrapping.
142 int context_index, Builtin error_constructor = Builtin::kErrorConstructor,
143 int error_function_length = 1);
144
145} // namespace internal
146} // namespace v8
147
148#endif // V8_INIT_BOOTSTRAPPER_H_
BootstrapperActive(Bootstrapper *bootstrapper)
BootstrapperActive & operator=(const BootstrapperActive &)=delete
BootstrapperActive(const BootstrapperActive &)=delete
char * RestoreState(char *from)
DirectHandle< NativeContext > CreateEnvironmentForTesting()
DirectHandle< NativeContext > CreateEnvironment(MaybeDirectHandle< JSGlobalProxy > maybe_global_proxy, v8::Local< v8::ObjectTemplate > global_object_template, v8::ExtensionConfiguration *extensions, size_t context_snapshot_index, DeserializeEmbedderFieldsCallback embedder_fields_deserializer, v8::MicrotaskQueue *microtask_queue)
Bootstrapper & operator=(const Bootstrapper &)=delete
friend class NativesExternalStringResource
SourceCodeCache * extensions_cache()
void Iterate(RootVisitor *v)
void Initialize(bool create_heap_objects)
Bootstrapper(const Bootstrapper &)=delete
SourceCodeCache extensions_cache_
NestingCounterType nesting_
DirectHandle< JSGlobalProxy > NewRemoteContext(MaybeDirectHandle< JSGlobalProxy > maybe_global_proxy, v8::Local< v8::ObjectTemplate > global_object_template)
bool InstallExtensions(DirectHandle< NativeContext > native_context, v8::ExtensionConfiguration *extensions)
char * ArchiveState(char *to)
static void InitializeOncePerProcess()
SourceCodeCache(const SourceCodeCache &)=delete
Tagged< FixedArray > cache_
SourceCodeCache & operator=(const SourceCodeCache &)=delete
SourceCodeCache(Script::Type type)
void Initialize(Isolate *isolate, bool create_heap_objects)
void Iterate(RootVisitor *v)
bool Lookup(Isolate *isolate, base::Vector< const char > name, DirectHandle< SharedFunctionInfo > *handle)
void Add(Isolate *isolate, base::Vector< const char > name, DirectHandle< SharedFunctionInfo > shared)
MicrotaskQueue * microtask_queue
Definition execution.cc:77
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
Handle< JSFunction > SimpleInstallFunction(Isolate *isolate, DirectHandle< JSObject > base, const char *name, Builtin call, int len, AdaptArguments adapt, PropertyAttributes attrs)
void InstallError(Isolate *isolate, DirectHandle< JSObject > global, DirectHandle< String > name, int context_index, Builtin error_constructor, int error_function_length)
!IsContextMap !IsContextMap native_context
Definition map-inl.h:877
#define V8_NOINLINE
Definition v8config.h:586