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" |
| 21 | #include "src/objects.h" |
| 22 | #include "src/runtime-profiler.h" |
| 23 | #include "src/sampler.h" |
| 24 | #include "src/serialize.h" |
| 25 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 26 | |
| 27 | namespace v8 { |
| 28 | namespace internal { |
| 29 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 30 | V8_DECLARE_ONCE(init_once); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 31 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 32 | v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL; |
| 33 | v8::Platform* V8::platform_ = NULL; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 34 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 35 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 36 | bool V8::Initialize() { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 37 | InitializeOncePerProcess(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 38 | return true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | |
| 42 | void V8::TearDown() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 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. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 55 | void V8::SetReturnAddressLocationResolver( |
| 56 | ReturnAddressLocationResolver resolver) { |
| 57 | StackFrame::SetReturnAddressLocationResolver(resolver); |
| 58 | } |
| 59 | |
| 60 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 61 | void V8::InitializeOncePerProcessImpl() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 62 | FlagList::EnforceFlagImplications(); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 63 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 64 | if (FLAG_predictable && FLAG_random_seed == 0) { |
| 65 | // Avoid random seeds in predictable mode. |
| 66 | FLAG_random_seed = 12347; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 69 | if (FLAG_stress_compaction) { |
| 70 | FLAG_force_marking_deque_overflows = true; |
| 71 | FLAG_gc_global = true; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 72 | FLAG_max_semi_space_size = 1; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 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(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 89 | LOperand::SetUpCaches(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 90 | compiler::Pipeline::SetUp(); |
| 91 | SetUpJSCallerSavedCodeData(); |
| 92 | ExternalReference::SetUp(); |
| 93 | Bootstrapper::InitializeOncePerProcess(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 96 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 97 | void V8::InitializeOncePerProcess() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 98 | base::CallOnce(&init_once, &InitializeOncePerProcessImpl); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | void V8::InitializePlatform(v8::Platform* platform) { |
| 103 | CHECK(!platform_); |
| 104 | CHECK(platform); |
| 105 | platform_ = platform; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void V8::ShutdownPlatform() { |
| 110 | CHECK(platform_); |
| 111 | platform_ = NULL; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | v8::Platform* V8::GetCurrentPlatform() { |
| 116 | DCHECK(platform_); |
| 117 | return platform_; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 120 | } } // namespace v8::internal |