10 #include "src/base/atomicops.h" 11 #include "src/base/once.h" 12 #include "src/base/platform/platform.h" 13 #include "src/bootstrapper.h" 14 #include "src/debug/debug.h" 15 #include "src/deoptimizer.h" 16 #include "src/elements.h" 17 #include "src/frames.h" 18 #include "src/interface-descriptors.h" 19 #include "src/isolate.h" 20 #include "src/libsampler/sampler.h" 21 #include "src/objects-inl.h" 22 #include "src/profiler/heap-profiler.h" 23 #include "src/reloc-info.h" 24 #include "src/runtime-profiler.h" 25 #include "src/simulator.h" 26 #include "src/snapshot/natives.h" 27 #include "src/snapshot/snapshot.h" 28 #include "src/tracing/tracing-category-observer.h" 29 #include "src/wasm/wasm-engine.h" 34 V8_DECLARE_ONCE(init_once);
36 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 37 V8_DECLARE_ONCE(init_natives_once);
38 V8_DECLARE_ONCE(init_snapshot_once);
43 bool V8::Initialize() {
44 InitializeOncePerProcess();
50 #if defined(USE_SIMULATOR) 51 Simulator::GlobalTearDown();
53 wasm::WasmEngine::GlobalTearDown();
54 CallDescriptors::TearDown();
55 Bootstrapper::TearDownExtensions();
56 ElementsAccessor::TearDown();
57 RegisteredExtension::UnregisterAll();
58 sampler::Sampler::TearDown();
59 FlagList::ResetAllFlags();
63 void V8::InitializeOncePerProcessImpl() {
64 FlagList::EnforceFlagImplications();
66 if (FLAG_predictable && FLAG_random_seed == 0) {
68 FLAG_random_seed = 12347;
71 if (FLAG_stress_compaction) {
72 FLAG_force_marking_deque_overflows =
true;
73 FLAG_gc_global =
true;
74 FLAG_max_semi_space_size = 1;
77 if (FLAG_trace_turbo) {
79 std::ofstream(Isolate::GetTurboCfgFileName(
nullptr).c_str(),
80 std::ios_base::trunc);
83 base::OS::Initialize(FLAG_hard_abort, FLAG_gc_fake_mmap);
85 if (FLAG_random_seed) SetRandomMmapSeed(FLAG_random_seed);
87 Isolate::InitializeOncePerProcess();
89 #if defined(USE_SIMULATOR) 90 Simulator::InitializeOncePerProcess();
92 sampler::Sampler::SetUp();
93 CpuFeatures::Probe(
false);
94 ElementsAccessor::InitializeOncePerProcess();
95 Bootstrapper::InitializeOncePerProcess();
96 CallDescriptors::InitializeOncePerProcess();
97 wasm::WasmEngine::InitializeOncePerProcess();
101 void V8::InitializeOncePerProcess() {
102 base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
109 platform_ = platform;
111 v8::tracing::TracingCategoryObserver::SetUp();
115 void V8::ShutdownPlatform() {
117 v8::tracing::TracingCategoryObserver::TearDown();
118 v8::base::SetPrintStackTrace(
nullptr);
125 base::Relaxed_Load(reinterpret_cast<base::AtomicWord*>(&platform_)));
130 void V8::SetPlatformForTesting(
v8::Platform* platform) {
131 base::Relaxed_Store(reinterpret_cast<base::AtomicWord*>(&platform_),
132 reinterpret_cast<base::AtomicWord>(platform));
135 void V8::SetNativesBlob(StartupData* natives_blob) {
136 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 137 base::CallOnce(&init_natives_once, &SetNativesFromFile, natives_blob);
144 void V8::SetSnapshotBlob(StartupData* snapshot_blob) {
145 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 146 base::CallOnce(&init_snapshot_once, &SetSnapshotFromFile, snapshot_blob);
155 return base::OS::TimeCurrentMillis();