• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
Initialize()36 bool V8::Initialize() {
37   InitializeOncePerProcess();
38   return true;
39 }
40 
41 
TearDown()42 void V8::TearDown() {
43   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.
52 }
53 
54 
SetReturnAddressLocationResolver(ReturnAddressLocationResolver resolver)55 void V8::SetReturnAddressLocationResolver(
56       ReturnAddressLocationResolver resolver) {
57   StackFrame::SetReturnAddressLocationResolver(resolver);
58 }
59 
60 
InitializeOncePerProcessImpl()61 void V8::InitializeOncePerProcessImpl() {
62   FlagList::EnforceFlagImplications();
63 
64   if (FLAG_predictable && FLAG_random_seed == 0) {
65     // Avoid random seeds in predictable mode.
66     FLAG_random_seed = 12347;
67   }
68 
69   if (FLAG_stress_compaction) {
70     FLAG_force_marking_deque_overflows = true;
71     FLAG_gc_global = true;
72     FLAG_max_semi_space_size = 1;
73   }
74 
75   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();
89   LOperand::SetUpCaches();
90   compiler::Pipeline::SetUp();
91   SetUpJSCallerSavedCodeData();
92   ExternalReference::SetUp();
93   Bootstrapper::InitializeOncePerProcess();
94 }
95 
96 
InitializeOncePerProcess()97 void V8::InitializeOncePerProcess() {
98   base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
99 }
100 
101 
InitializePlatform(v8::Platform * platform)102 void V8::InitializePlatform(v8::Platform* platform) {
103   CHECK(!platform_);
104   CHECK(platform);
105   platform_ = platform;
106 }
107 
108 
ShutdownPlatform()109 void V8::ShutdownPlatform() {
110   CHECK(platform_);
111   platform_ = NULL;
112 }
113 
114 
GetCurrentPlatform()115 v8::Platform* V8::GetCurrentPlatform() {
116   DCHECK(platform_);
117   return platform_;
118 }
119 
120 } }  // namespace v8::internal
121