Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / 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/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
26
27 namespace v8 {
28 namespace internal {
29
30 V8_DECLARE_ONCE(init_once);
31
32 v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
33 v8::Platform* V8::platform_ = NULL;
34
35
36 bool V8::Initialize(Deserializer* des) {
37   InitializeOncePerProcess();
38   Isolate* isolate = Isolate::UncheckedCurrent();
39   if (isolate == NULL) return true;
40   if (isolate->IsDead()) return false;
41   if (isolate->IsInitialized()) return true;
42
43   return isolate->Init(des);
44 }
45
46
47 void V8::TearDown() {
48   Bootstrapper::TearDownExtensions();
49   ElementsAccessor::TearDown();
50   LOperand::TearDownCaches();
51   compiler::Pipeline::TearDown();
52   ExternalReference::TearDownMathExpData();
53   RegisteredExtension::UnregisterAll();
54   Isolate::GlobalTearDown();
55
56   Sampler::TearDown();
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   Sampler::SetUp();
83   CpuFeatures::Probe(false);
84   init_memcopy_functions();
85   // The custom exp implementation needs 16KB of lookup data; initialize it
86   // on demand.
87   init_fast_sqrt_function();
88 #ifdef _WIN64
89   init_modulo_function();
90 #endif
91   ElementsAccessor::InitializeOncePerProcess();
92   LOperand::SetUpCaches();
93   compiler::Pipeline::SetUp();
94   SetUpJSCallerSavedCodeData();
95   ExternalReference::SetUp();
96   Bootstrapper::InitializeOncePerProcess();
97 }
98
99
100 void V8::InitializeOncePerProcess() {
101   base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
102 }
103
104
105 void V8::InitializePlatform(v8::Platform* platform) {
106   CHECK(!platform_);
107   CHECK(platform);
108   platform_ = platform;
109 }
110
111
112 void V8::ShutdownPlatform() {
113   CHECK(platform_);
114   platform_ = NULL;
115 }
116
117
118 v8::Platform* V8::GetCurrentPlatform() {
119   DCHECK(platform_);
120   return platform_;
121 }
122
123 } }  // namespace v8::internal