Line data Source code
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/api.h"
8 : #include "src/assembler.h"
9 : #include "src/base/atomicops.h"
10 : #include "src/base/once.h"
11 : #include "src/base/platform/platform.h"
12 : #include "src/bootstrapper.h"
13 : #include "src/debug/debug.h"
14 : #include "src/deoptimizer.h"
15 : #include "src/elements.h"
16 : #include "src/frames.h"
17 : #include "src/isolate.h"
18 : #include "src/libsampler/sampler.h"
19 : #include "src/objects-inl.h"
20 : #include "src/profiler/heap-profiler.h"
21 : #include "src/runtime-profiler.h"
22 : #include "src/snapshot/natives.h"
23 : #include "src/snapshot/snapshot.h"
24 : #include "src/tracing/tracing-category-observer.h"
25 :
26 : namespace v8 {
27 : namespace internal {
28 :
29 : V8_DECLARE_ONCE(init_once);
30 :
31 : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
32 : V8_DECLARE_ONCE(init_natives_once);
33 : V8_DECLARE_ONCE(init_snapshot_once);
34 : #endif
35 :
36 : v8::Platform* V8::platform_ = nullptr;
37 :
38 54331 : bool V8::Initialize() {
39 : InitializeOncePerProcess();
40 54331 : return true;
41 : }
42 :
43 :
44 29500 : void V8::TearDown() {
45 29500 : Bootstrapper::TearDownExtensions();
46 29500 : ElementsAccessor::TearDown();
47 29500 : RegisteredExtension::UnregisterAll();
48 29500 : Isolate::GlobalTearDown();
49 29500 : sampler::Sampler::TearDown();
50 29500 : FlagList::ResetAllFlags(); // Frees memory held by string arguments.
51 29500 : }
52 :
53 :
54 53977 : void V8::InitializeOncePerProcessImpl() {
55 53977 : FlagList::EnforceFlagImplications();
56 :
57 53977 : if (FLAG_predictable && FLAG_random_seed == 0) {
58 : // Avoid random seeds in predictable mode.
59 0 : FLAG_random_seed = 12347;
60 : }
61 :
62 53977 : if (FLAG_stress_compaction) {
63 102 : FLAG_force_marking_deque_overflows = true;
64 102 : FLAG_gc_global = true;
65 102 : FLAG_max_semi_space_size = 1;
66 : }
67 :
68 53977 : base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
69 :
70 53977 : Isolate::InitializeOncePerProcess();
71 :
72 53977 : sampler::Sampler::SetUp();
73 : CpuFeatures::Probe(false);
74 53977 : ElementsAccessor::InitializeOncePerProcess();
75 53977 : SetUpJSCallerSavedCodeData();
76 53977 : ExternalReference::SetUp();
77 53977 : Bootstrapper::InitializeOncePerProcess();
78 53977 : }
79 :
80 :
81 0 : void V8::InitializeOncePerProcess() {
82 54331 : base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
83 0 : }
84 :
85 :
86 53977 : void V8::InitializePlatform(v8::Platform* platform) {
87 53977 : CHECK(!platform_);
88 53977 : CHECK(platform);
89 53977 : platform_ = platform;
90 53977 : v8::base::SetPrintStackTrace(platform_->GetStackTracePrinter());
91 53977 : v8::tracing::TracingCategoryObserver::SetUp();
92 53977 : }
93 :
94 :
95 53151 : void V8::ShutdownPlatform() {
96 53151 : CHECK(platform_);
97 53151 : v8::tracing::TracingCategoryObserver::TearDown();
98 53151 : v8::base::SetPrintStackTrace(nullptr);
99 53151 : platform_ = nullptr;
100 53151 : }
101 :
102 :
103 10587791 : v8::Platform* V8::GetCurrentPlatform() {
104 : v8::Platform* platform = reinterpret_cast<v8::Platform*>(
105 10587791 : base::Relaxed_Load(reinterpret_cast<base::AtomicWord*>(&platform_)));
106 : DCHECK(platform);
107 10587791 : return platform;
108 : }
109 :
110 670 : void V8::SetPlatformForTesting(v8::Platform* platform) {
111 : base::Relaxed_Store(reinterpret_cast<base::AtomicWord*>(&platform_),
112 : reinterpret_cast<base::AtomicWord>(platform));
113 670 : }
114 :
115 53983 : void V8::SetNativesBlob(StartupData* natives_blob) {
116 : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
117 53983 : base::CallOnce(&init_natives_once, &SetNativesFromFile, natives_blob);
118 : #else
119 : CHECK(false);
120 : #endif
121 53983 : }
122 :
123 :
124 53983 : void V8::SetSnapshotBlob(StartupData* snapshot_blob) {
125 : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
126 53983 : base::CallOnce(&init_snapshot_once, &SetSnapshotFromFile, snapshot_blob);
127 : #else
128 : CHECK(false);
129 : #endif
130 53983 : }
131 : } // namespace internal
132 :
133 : // static
134 0 : double Platform::SystemClockTimeMillis() {
135 0 : return base::OS::TimeCurrentMillis();
136 : }
137 : } // namespace v8
|