blob: b04ccc07c700e35f572bc42f4eec949315174766 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#include "src/v8.h"
Steve Blocka7e24c12009-10-30 11:49:00 +00006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#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/compiler/pipeline.h"
12#include "src/debug.h"
13#include "src/deoptimizer.h"
14#include "src/elements.h"
15#include "src/frames.h"
16#include "src/heap/store-buffer.h"
17#include "src/heap-profiler.h"
18#include "src/hydrogen.h"
19#include "src/isolate.h"
20#include "src/lithium-allocator.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040021#include "src/natives.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022#include "src/objects.h"
23#include "src/runtime-profiler.h"
24#include "src/sampler.h"
25#include "src/serialize.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040026#include "src/snapshot.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027
Steve Blocka7e24c12009-10-30 11:49:00 +000028
29namespace v8 {
30namespace internal {
31
Ben Murdoch3ef787d2012-04-12 10:51:47 +010032V8_DECLARE_ONCE(init_once);
Ben Murdoch8b112d22011-06-08 16:22:53 +010033
Emily Bernierd0a1eb72015-03-24 16:35:39 -040034#ifdef V8_USE_EXTERNAL_STARTUP_DATA
35V8_DECLARE_ONCE(init_natives_once);
36V8_DECLARE_ONCE(init_snapshot_once);
37#endif
38
Ben Murdochb8a8cc12014-11-26 15:28:44 +000039v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
40v8::Platform* V8::platform_ = NULL;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000041
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -080042
Ben Murdochb8a8cc12014-11-26 15:28:44 +000043bool V8::Initialize() {
Ben Murdoch8b112d22011-06-08 16:22:53 +010044 InitializeOncePerProcess();
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045 return true;
Steve Blocka7e24c12009-10-30 11:49:00 +000046}
47
48
49void V8::TearDown() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050 Bootstrapper::TearDownExtensions();
51 ElementsAccessor::TearDown();
52 LOperand::TearDownCaches();
53 compiler::Pipeline::TearDown();
54 ExternalReference::TearDownMathExpData();
55 RegisteredExtension::UnregisterAll();
56 Isolate::GlobalTearDown();
57 Sampler::TearDown();
58 FlagList::ResetAllFlags(); // Frees memory held by string arguments.
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -080059}
60
61
Ben Murdoch3ef787d2012-04-12 10:51:47 +010062void V8::SetReturnAddressLocationResolver(
63 ReturnAddressLocationResolver resolver) {
64 StackFrame::SetReturnAddressLocationResolver(resolver);
65}
66
67
Ben Murdoch3ef787d2012-04-12 10:51:47 +010068void V8::InitializeOncePerProcessImpl() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000069 FlagList::EnforceFlagImplications();
Ben Murdoch8b112d22011-06-08 16:22:53 +010070
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071 if (FLAG_predictable && FLAG_random_seed == 0) {
72 // Avoid random seeds in predictable mode.
73 FLAG_random_seed = 12347;
Ben Murdoch8b112d22011-06-08 16:22:53 +010074 }
75
Ben Murdoch3ef787d2012-04-12 10:51:47 +010076 if (FLAG_stress_compaction) {
77 FLAG_force_marking_deque_overflows = true;
78 FLAG_gc_global = true;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 FLAG_max_semi_space_size = 1;
Ben Murdoch3ef787d2012-04-12 10:51:47 +010080 }
81
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082 base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
83
84 Isolate::InitializeOncePerProcess();
85
86 Sampler::SetUp();
87 CpuFeatures::Probe(false);
88 init_memcopy_functions();
89 // The custom exp implementation needs 16KB of lookup data; initialize it
90 // on demand.
91 init_fast_sqrt_function();
92#ifdef _WIN64
93 init_modulo_function();
94#endif
95 ElementsAccessor::InitializeOncePerProcess();
Ben Murdoch3ef787d2012-04-12 10:51:47 +010096 LOperand::SetUpCaches();
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097 compiler::Pipeline::SetUp();
98 SetUpJSCallerSavedCodeData();
99 ExternalReference::SetUp();
100 Bootstrapper::InitializeOncePerProcess();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100101}
102
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000103
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100104void V8::InitializeOncePerProcess() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105 base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
106}
107
108
109void V8::InitializePlatform(v8::Platform* platform) {
110 CHECK(!platform_);
111 CHECK(platform);
112 platform_ = platform;
113}
114
115
116void V8::ShutdownPlatform() {
117 CHECK(platform_);
118 platform_ = NULL;
119}
120
121
122v8::Platform* V8::GetCurrentPlatform() {
123 DCHECK(platform_);
124 return platform_;
Ben Murdoch8b112d22011-06-08 16:22:53 +0100125}
126
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400127
128void V8::SetNativesBlob(StartupData* natives_blob) {
129#ifdef V8_USE_EXTERNAL_STARTUP_DATA
130 base::CallOnce(&init_natives_once, &SetNativesFromFile, natives_blob);
131#else
132 CHECK(false);
133#endif
134}
135
136
137void V8::SetSnapshotBlob(StartupData* snapshot_blob) {
138#ifdef V8_USE_EXTERNAL_STARTUP_DATA
139 base::CallOnce(&init_snapshot_once, &SetSnapshotFromFile, snapshot_blob);
140#else
141 CHECK(false);
142#endif
143}
Steve Blocka7e24c12009-10-30 11:49:00 +0000144} } // namespace v8::internal