Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/v8.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 21 | #include "src/natives.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | #include "src/objects.h" |
| 23 | #include "src/runtime-profiler.h" |
| 24 | #include "src/sampler.h" |
| 25 | #include "src/serialize.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 26 | #include "src/snapshot.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 28 | |
| 29 | namespace v8 { |
| 30 | namespace internal { |
| 31 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 32 | V8_DECLARE_ONCE(init_once); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 33 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 34 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 35 | V8_DECLARE_ONCE(init_natives_once); |
| 36 | V8_DECLARE_ONCE(init_snapshot_once); |
| 37 | #endif |
| 38 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 39 | v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL; |
| 40 | v8::Platform* V8::platform_ = NULL; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 41 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 42 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 43 | bool V8::Initialize() { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 44 | InitializeOncePerProcess(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | return true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | |
| 49 | void V8::TearDown() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 50 | Bootstrapper::TearDownExtensions(); |
| 51 | ElementsAccessor::TearDown(); |
| 52 | LOperand::TearDownCaches(); |
| 53 | compiler::Pipeline::TearDown(); |
| 54 | ExternalReference::TearDownMathExpData(); |
| 55 | RegisteredExtension::UnregisterAll(); |
| 56 | Isolate::GlobalTearDown(); |
| 57 | Sampler::TearDown(); |
| 58 | FlagList::ResetAllFlags(); // Frees memory held by string arguments. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 62 | void V8::SetReturnAddressLocationResolver( |
| 63 | ReturnAddressLocationResolver resolver) { |
| 64 | StackFrame::SetReturnAddressLocationResolver(resolver); |
| 65 | } |
| 66 | |
| 67 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 68 | void V8::InitializeOncePerProcessImpl() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 69 | FlagList::EnforceFlagImplications(); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 70 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 71 | if (FLAG_predictable && FLAG_random_seed == 0) { |
| 72 | // Avoid random seeds in predictable mode. |
| 73 | FLAG_random_seed = 12347; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 76 | if (FLAG_stress_compaction) { |
| 77 | FLAG_force_marking_deque_overflows = true; |
| 78 | FLAG_gc_global = true; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 79 | FLAG_max_semi_space_size = 1; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 82 | base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap); |
| 83 | |
| 84 | Isolate::InitializeOncePerProcess(); |
| 85 | |
| 86 | Sampler::SetUp(); |
| 87 | CpuFeatures::Probe(false); |
| 88 | init_memcopy_functions(); |
| 89 | // The custom exp implementation needs 16KB of lookup data; initialize it |
| 90 | // on demand. |
| 91 | init_fast_sqrt_function(); |
| 92 | #ifdef _WIN64 |
| 93 | init_modulo_function(); |
| 94 | #endif |
| 95 | ElementsAccessor::InitializeOncePerProcess(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 96 | LOperand::SetUpCaches(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 97 | compiler::Pipeline::SetUp(); |
| 98 | SetUpJSCallerSavedCodeData(); |
| 99 | ExternalReference::SetUp(); |
| 100 | Bootstrapper::InitializeOncePerProcess(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 103 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 104 | void V8::InitializeOncePerProcess() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | base::CallOnce(&init_once, &InitializeOncePerProcessImpl); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void V8::InitializePlatform(v8::Platform* platform) { |
| 110 | CHECK(!platform_); |
| 111 | CHECK(platform); |
| 112 | platform_ = platform; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | void V8::ShutdownPlatform() { |
| 117 | CHECK(platform_); |
| 118 | platform_ = NULL; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | v8::Platform* V8::GetCurrentPlatform() { |
| 123 | DCHECK(platform_); |
| 124 | return platform_; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 125 | } |
| 126 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 127 | |
| 128 | void V8::SetNativesBlob(StartupData* natives_blob) { |
| 129 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 130 | base::CallOnce(&init_natives_once, &SetNativesFromFile, natives_blob); |
| 131 | #else |
| 132 | CHECK(false); |
| 133 | #endif |
| 134 | } |
| 135 | |
| 136 | |
| 137 | void V8::SetSnapshotBlob(StartupData* snapshot_blob) { |
| 138 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 139 | base::CallOnce(&init_snapshot_once, &SetSnapshotFromFile, snapshot_blob); |
| 140 | #else |
| 141 | CHECK(false); |
| 142 | #endif |
| 143 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 144 | } } // namespace v8::internal |