1 // Copyright 2012 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.
7 #include "src/assembler.h"
8 #include "src/base/once.h"
9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h"
11 #include "src/debug.h"
12 #include "src/deoptimizer.h"
13 #include "src/elements.h"
14 #include "src/frames.h"
15 #include "src/heap/store-buffer.h"
16 #include "src/heap-profiler.h"
17 #include "src/hydrogen.h"
18 #include "src/isolate.h"
19 #include "src/lithium-allocator.h"
20 #include "src/natives.h"
21 #include "src/objects.h"
22 #include "src/runtime-profiler.h"
23 #include "src/sampler.h"
24 #include "src/serialize.h"
25 #include "src/snapshot.h"
31 V8_DECLARE_ONCE(init_once);
33 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
34 V8_DECLARE_ONCE(init_natives_once);
35 V8_DECLARE_ONCE(init_snapshot_once);
38 v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
39 v8::Platform* V8::platform_ = NULL;
42 bool V8::Initialize() {
43 InitializeOncePerProcess();
49 Bootstrapper::TearDownExtensions();
50 ElementsAccessor::TearDown();
51 LOperand::TearDownCaches();
52 ExternalReference::TearDownMathExpData();
53 RegisteredExtension::UnregisterAll();
54 Isolate::GlobalTearDown();
56 FlagList::ResetAllFlags(); // Frees memory held by string arguments.
60 void V8::SetReturnAddressLocationResolver(
61 ReturnAddressLocationResolver resolver) {
62 StackFrame::SetReturnAddressLocationResolver(resolver);
66 void V8::InitializeOncePerProcessImpl() {
67 FlagList::EnforceFlagImplications();
69 if (FLAG_predictable && FLAG_random_seed == 0) {
70 // Avoid random seeds in predictable mode.
71 FLAG_random_seed = 12347;
74 if (FLAG_stress_compaction) {
75 FLAG_force_marking_deque_overflows = true;
76 FLAG_gc_global = true;
77 FLAG_max_semi_space_size = 1;
80 base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
82 Isolate::InitializeOncePerProcess();
85 CpuFeatures::Probe(false);
86 init_memcopy_functions();
87 // The custom exp implementation needs 16KB of lookup data; initialize it
89 init_fast_sqrt_function();
91 init_modulo_function();
93 ElementsAccessor::InitializeOncePerProcess();
94 LOperand::SetUpCaches();
95 SetUpJSCallerSavedCodeData();
96 ExternalReference::SetUp();
97 Bootstrapper::InitializeOncePerProcess();
101 void V8::InitializeOncePerProcess() {
102 base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
106 void V8::InitializePlatform(v8::Platform* platform) {
109 platform_ = platform;
113 void V8::ShutdownPlatform() {
119 v8::Platform* V8::GetCurrentPlatform() {
125 void V8::SetNativesBlob(StartupData* natives_blob) {
126 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
127 base::CallOnce(&init_natives_once, &SetNativesFromFile, natives_blob);
134 void V8::SetSnapshotBlob(StartupData* snapshot_blob) {
135 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
136 base::CallOnce(&init_snapshot_once, &SetSnapshotFromFile, snapshot_blob);
141 } } // namespace v8::internal