blob: 62c3da4cf79399e4b5f2895f2bcba0975a678e37 [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"
21#include "src/objects.h"
22#include "src/runtime-profiler.h"
23#include "src/sampler.h"
24#include "src/serialize.h"
25
Steve Blocka7e24c12009-10-30 11:49:00 +000026
27namespace v8 {
28namespace internal {
29
Ben Murdoch3ef787d2012-04-12 10:51:47 +010030V8_DECLARE_ONCE(init_once);
Ben Murdoch8b112d22011-06-08 16:22:53 +010031
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
33v8::Platform* V8::platform_ = NULL;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000034
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -080035
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036bool V8::Initialize() {
Ben Murdoch8b112d22011-06-08 16:22:53 +010037 InitializeOncePerProcess();
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038 return true;
Steve Blocka7e24c12009-10-30 11:49:00 +000039}
40
41
42void V8::TearDown() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000043 Bootstrapper::TearDownExtensions();
44 ElementsAccessor::TearDown();
45 LOperand::TearDownCaches();
46 compiler::Pipeline::TearDown();
47 ExternalReference::TearDownMathExpData();
48 RegisteredExtension::UnregisterAll();
49 Isolate::GlobalTearDown();
50 Sampler::TearDown();
51 FlagList::ResetAllFlags(); // Frees memory held by string arguments.
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -080052}
53
54
Ben Murdoch3ef787d2012-04-12 10:51:47 +010055void V8::SetReturnAddressLocationResolver(
56 ReturnAddressLocationResolver resolver) {
57 StackFrame::SetReturnAddressLocationResolver(resolver);
58}
59
60
Ben Murdoch3ef787d2012-04-12 10:51:47 +010061void V8::InitializeOncePerProcessImpl() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000062 FlagList::EnforceFlagImplications();
Ben Murdoch8b112d22011-06-08 16:22:53 +010063
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064 if (FLAG_predictable && FLAG_random_seed == 0) {
65 // Avoid random seeds in predictable mode.
66 FLAG_random_seed = 12347;
Ben Murdoch8b112d22011-06-08 16:22:53 +010067 }
68
Ben Murdoch3ef787d2012-04-12 10:51:47 +010069 if (FLAG_stress_compaction) {
70 FLAG_force_marking_deque_overflows = true;
71 FLAG_gc_global = true;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072 FLAG_max_semi_space_size = 1;
Ben Murdoch3ef787d2012-04-12 10:51:47 +010073 }
74
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075 base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
76
77 Isolate::InitializeOncePerProcess();
78
79 Sampler::SetUp();
80 CpuFeatures::Probe(false);
81 init_memcopy_functions();
82 // The custom exp implementation needs 16KB of lookup data; initialize it
83 // on demand.
84 init_fast_sqrt_function();
85#ifdef _WIN64
86 init_modulo_function();
87#endif
88 ElementsAccessor::InitializeOncePerProcess();
Ben Murdoch3ef787d2012-04-12 10:51:47 +010089 LOperand::SetUpCaches();
Ben Murdochb8a8cc12014-11-26 15:28:44 +000090 compiler::Pipeline::SetUp();
91 SetUpJSCallerSavedCodeData();
92 ExternalReference::SetUp();
93 Bootstrapper::InitializeOncePerProcess();
Ben Murdoch3ef787d2012-04-12 10:51:47 +010094}
95
Ben Murdochb8a8cc12014-11-26 15:28:44 +000096
Ben Murdoch3ef787d2012-04-12 10:51:47 +010097void V8::InitializeOncePerProcess() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000098 base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
99}
100
101
102void V8::InitializePlatform(v8::Platform* platform) {
103 CHECK(!platform_);
104 CHECK(platform);
105 platform_ = platform;
106}
107
108
109void V8::ShutdownPlatform() {
110 CHECK(platform_);
111 platform_ = NULL;
112}
113
114
115v8::Platform* V8::GetCurrentPlatform() {
116 DCHECK(platform_);
117 return platform_;
Ben Murdoch8b112d22011-06-08 16:22:53 +0100118}
119
Steve Blocka7e24c12009-10-30 11:49:00 +0000120} } // namespace v8::internal