deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / v8.cc
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.
4
5 #include "src/v8.h"
6
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/objects.h"
21 #include "src/runtime-profiler.h"
22 #include "src/sampler.h"
23 #include "src/snapshot/natives.h"
24 #include "src/snapshot/serialize.h"
25 #include "src/snapshot/snapshot.h"
26
27
28 namespace v8 {
29 namespace internal {
30
31 V8_DECLARE_ONCE(init_once);
32
33 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
34 V8_DECLARE_ONCE(init_natives_once);
35 V8_DECLARE_ONCE(init_snapshot_once);
36 #endif
37
38 v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
39 v8::Platform* V8::platform_ = NULL;
40
41
42 bool V8::Initialize() {
43   InitializeOncePerProcess();
44   return true;
45 }
46
47
48 void V8::TearDown() {
49   Bootstrapper::TearDownExtensions();
50   ElementsAccessor::TearDown();
51   LOperand::TearDownCaches();
52   ExternalReference::TearDownMathExpData();
53   RegisteredExtension::UnregisterAll();
54   Isolate::GlobalTearDown();
55   Sampler::TearDown();
56   FlagList::ResetAllFlags();  // Frees memory held by string arguments.
57 }
58
59
60 void V8::SetReturnAddressLocationResolver(
61       ReturnAddressLocationResolver resolver) {
62   StackFrame::SetReturnAddressLocationResolver(resolver);
63 }
64
65
66 void V8::InitializeOncePerProcessImpl() {
67   FlagList::EnforceFlagImplications();
68
69   if (FLAG_predictable && FLAG_random_seed == 0) {
70     // Avoid random seeds in predictable mode.
71     FLAG_random_seed = 12347;
72   }
73
74   if (FLAG_stress_compaction) {
75     FLAG_force_marking_deque_overflows = true;
76     FLAG_gc_global = true;
77     FLAG_max_semi_space_size = 1;
78   }
79
80   base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
81
82   Isolate::InitializeOncePerProcess();
83
84   Sampler::SetUp();
85   CpuFeatures::Probe(false);
86   init_memcopy_functions();
87   // The custom exp implementation needs 16KB of lookup data; initialize it
88   // on demand.
89   init_fast_sqrt_function();
90 #ifdef _WIN64
91   init_modulo_function();
92 #endif
93   ElementsAccessor::InitializeOncePerProcess();
94   LOperand::SetUpCaches();
95   SetUpJSCallerSavedCodeData();
96   ExternalReference::SetUp();
97   Bootstrapper::InitializeOncePerProcess();
98 }
99
100
101 void V8::InitializeOncePerProcess() {
102   base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
103 }
104
105
106 void V8::InitializePlatform(v8::Platform* platform) {
107   CHECK(!platform_);
108   CHECK(platform);
109   platform_ = platform;
110 }
111
112
113 void V8::ShutdownPlatform() {
114   CHECK(platform_);
115   platform_ = NULL;
116 }
117
118
119 v8::Platform* V8::GetCurrentPlatform() {
120   DCHECK(platform_);
121   return platform_;
122 }
123
124
125 void V8::SetNativesBlob(StartupData* natives_blob) {
126 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
127   base::CallOnce(&init_natives_once, &SetNativesFromFile, natives_blob);
128 #else
129   CHECK(false);
130 #endif
131 }
132
133
134 void V8::SetSnapshotBlob(StartupData* snapshot_blob) {
135 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
136   base::CallOnce(&init_snapshot_once, &SetSnapshotFromFile, snapshot_blob);
137 #else
138   CHECK(false);
139 #endif
140 }
141 } }  // namespace v8::internal