svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 30 | #include "assembler.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 31 | #include "isolate.h" |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 32 | #include "elements.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | #include "bootstrapper.h" |
| 34 | #include "debug.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 35 | #include "deoptimizer.h" |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 36 | #include "frames.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 37 | #include "heap-profiler.h" |
| 38 | #include "hydrogen.h" |
| 39 | #include "lithium-allocator.h" |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 40 | #include "objects.h" |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 41 | #include "once.h" |
| 42 | #include "platform.h" |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 43 | #include "sampler.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 44 | #include "runtime-profiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | #include "serialize.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 46 | #include "store-buffer.h" |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 47 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 48 | namespace v8 { |
| 49 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 51 | V8_DECLARE_ONCE(init_once); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 52 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 53 | bool V8::is_running_ = false; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 54 | bool V8::has_been_set_up_ = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | bool V8::has_been_disposed_ = false; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 56 | bool V8::has_fatal_error_ = false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 57 | bool V8::use_crankshaft_ = true; |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 58 | List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL; |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 59 | v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 61 | static LazyMutex entropy_mutex = LAZY_MUTEX_INITIALIZER; |
| 62 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 63 | static EntropySource entropy_source; |
| 64 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 65 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 66 | bool V8::Initialize(Deserializer* des) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 67 | InitializeOncePerProcess(); |
| 68 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 69 | // The current thread may not yet had entered an isolate to run. |
| 70 | // Note the Isolate::Current() may be non-null because for various |
| 71 | // initialization purposes an initializing thread may be assigned an isolate |
| 72 | // but not actually enter it. |
| 73 | if (i::Isolate::CurrentPerIsolateThreadData() == NULL) { |
| 74 | i::Isolate::EnterDefaultIsolate(); |
| 75 | } |
| 76 | |
| 77 | ASSERT(i::Isolate::CurrentPerIsolateThreadData() != NULL); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 78 | ASSERT(i::Isolate::CurrentPerIsolateThreadData()->thread_id().Equals( |
| 79 | i::ThreadId::Current())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 80 | ASSERT(i::Isolate::CurrentPerIsolateThreadData()->isolate() == |
| 81 | i::Isolate::Current()); |
| 82 | |
| 83 | if (IsDead()) return false; |
| 84 | |
| 85 | Isolate* isolate = Isolate::Current(); |
| 86 | if (isolate->IsInitialized()) return true; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 87 | |
| 88 | is_running_ = true; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 89 | has_been_set_up_ = true; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 90 | has_fatal_error_ = false; |
| 91 | has_been_disposed_ = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 93 | return isolate->Init(des); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 97 | void V8::SetFatalError() { |
| 98 | is_running_ = false; |
| 99 | has_fatal_error_ = true; |
| 100 | } |
| 101 | |
| 102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | void V8::TearDown() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 104 | Isolate* isolate = Isolate::Current(); |
| 105 | ASSERT(isolate->IsDefaultIsolate()); |
| 106 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 107 | if (!has_been_set_up_ || has_been_disposed_) return; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 108 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 109 | // The isolate has to be torn down before clearing the LOperand |
| 110 | // caches so that the optimizing compiler thread (if running) |
| 111 | // doesn't see an inconsistent view of the lithium instructions. |
| 112 | isolate->TearDown(); |
| 113 | delete isolate; |
| 114 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 115 | ElementsAccessor::TearDown(); |
| 116 | LOperand::TearDownCaches(); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 117 | ExternalReference::TearDownMathExpData(); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 118 | RegisteredExtension::UnregisterAll(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 119 | Isolate::GlobalTearDown(); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 120 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 121 | is_running_ = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | has_been_disposed_ = true; |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 123 | |
| 124 | delete call_completed_callbacks_; |
| 125 | call_completed_callbacks_ = NULL; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 126 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 127 | Sampler::TearDown(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 128 | OS::TearDown(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 129 | } |
| 130 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 131 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 132 | static void seed_random(uint32_t* state) { |
| 133 | for (int i = 0; i < 2; ++i) { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 134 | if (FLAG_random_seed != 0) { |
| 135 | state[i] = FLAG_random_seed; |
| 136 | } else if (entropy_source != NULL) { |
| 137 | uint32_t val; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 138 | ScopedLock lock(entropy_mutex.Pointer()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 139 | entropy_source(reinterpret_cast<unsigned char*>(&val), sizeof(uint32_t)); |
| 140 | state[i] = val; |
| 141 | } else { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 142 | state[i] = random(); |
| 143 | } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 144 | } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 148 | // Random number generator using George Marsaglia's MWC algorithm. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 149 | static uint32_t random_base(uint32_t* state) { |
| 150 | // Initialize seed using the system random(). |
| 151 | // No non-zero seed will ever become zero again. |
| 152 | if (state[0] == 0) seed_random(state); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 153 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 154 | // Mix the bits. Never replaces state[i] with 0 if it is nonzero. |
| 155 | state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16); |
| 156 | state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16); |
| 157 | |
| 158 | return (state[0] << 14) + (state[1] & 0x3FFFF); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 162 | void V8::SetEntropySource(EntropySource source) { |
| 163 | entropy_source = source; |
| 164 | } |
| 165 | |
| 166 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 167 | void V8::SetReturnAddressLocationResolver( |
| 168 | ReturnAddressLocationResolver resolver) { |
| 169 | StackFrame::SetReturnAddressLocationResolver(resolver); |
| 170 | } |
| 171 | |
| 172 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 173 | // Used by JavaScript APIs |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 174 | uint32_t V8::Random(Context* context) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 175 | ASSERT(context->IsNativeContext()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 176 | ByteArray* seed = context->random_seed(); |
| 177 | return random_base(reinterpret_cast<uint32_t*>(seed->GetDataStartAddress())); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | |
| 181 | // Used internally by the JIT and memory allocator for security |
| 182 | // purposes. So, we keep a different state to prevent informations |
| 183 | // leaks that could be used in an exploit. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 184 | uint32_t V8::RandomPrivate(Isolate* isolate) { |
| 185 | ASSERT(isolate == Isolate::Current()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 186 | return random_base(isolate->private_random_seed()); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 187 | } |
| 188 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 189 | |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 190 | bool V8::IdleNotification(int hint) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 191 | // Returning true tells the caller that there is no need to call |
| 192 | // IdleNotification again. |
| 193 | if (!FLAG_use_idle_notification) return true; |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 194 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 195 | // Tell the heap that it may want to adjust. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 196 | return HEAP->IdleNotification(hint); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 197 | } |
| 198 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 199 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 200 | void V8::AddCallCompletedCallback(CallCompletedCallback callback) { |
| 201 | if (call_completed_callbacks_ == NULL) { // Lazy init. |
| 202 | call_completed_callbacks_ = new List<CallCompletedCallback>(); |
| 203 | } |
| 204 | for (int i = 0; i < call_completed_callbacks_->length(); i++) { |
| 205 | if (callback == call_completed_callbacks_->at(i)) return; |
| 206 | } |
| 207 | call_completed_callbacks_->Add(callback); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) { |
| 212 | if (call_completed_callbacks_ == NULL) return; |
| 213 | for (int i = 0; i < call_completed_callbacks_->length(); i++) { |
| 214 | if (callback == call_completed_callbacks_->at(i)) { |
| 215 | call_completed_callbacks_->Remove(i); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | |
| 221 | void V8::FireCallCompletedCallback(Isolate* isolate) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 222 | bool has_call_completed_callbacks = call_completed_callbacks_ != NULL; |
| 223 | bool observer_delivery_pending = |
| 224 | FLAG_harmony_observation && isolate->observer_delivery_pending(); |
| 225 | if (!has_call_completed_callbacks && !observer_delivery_pending) return; |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 226 | HandleScopeImplementer* handle_scope_implementer = |
| 227 | isolate->handle_scope_implementer(); |
| 228 | if (!handle_scope_implementer->CallDepthIsZero()) return; |
| 229 | // Fire callbacks. Increase call depth to prevent recursive callbacks. |
| 230 | handle_scope_implementer->IncrementCallDepth(); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 231 | if (observer_delivery_pending) { |
| 232 | JSObject::DeliverChangeRecords(isolate); |
| 233 | } |
| 234 | if (has_call_completed_callbacks) { |
| 235 | for (int i = 0; i < call_completed_callbacks_->length(); i++) { |
| 236 | call_completed_callbacks_->at(i)(); |
| 237 | } |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 238 | } |
| 239 | handle_scope_implementer->DecrementCallDepth(); |
| 240 | } |
| 241 | |
| 242 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 243 | // Use a union type to avoid type-aliasing optimizations in GCC. |
| 244 | typedef union { |
| 245 | double double_value; |
| 246 | uint64_t uint64_t_value; |
| 247 | } double_int_union; |
| 248 | |
| 249 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 250 | Object* V8::FillHeapNumberWithRandom(Object* heap_number, |
| 251 | Context* context) { |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 252 | double_int_union r; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 253 | uint64_t random_bits = Random(context); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 254 | // Convert 32 random bits to 0.(32 random bits) in a double |
| 255 | // by computing: |
| 256 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 257 | static const double binary_million = 1048576.0; |
| 258 | r.double_value = binary_million; |
| 259 | r.uint64_t_value |= random_bits; |
| 260 | r.double_value -= binary_million; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 261 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 262 | HeapNumber::cast(heap_number)->set_value(r.double_value); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 263 | return heap_number; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 264 | } |
| 265 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 266 | void V8::InitializeOncePerProcessImpl() { |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 267 | FlagList::EnforceFlagImplications(); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 268 | if (FLAG_stress_compaction) { |
| 269 | FLAG_force_marking_deque_overflows = true; |
| 270 | FLAG_gc_global = true; |
| 271 | FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2; |
| 272 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 273 | if (FLAG_trace_hydrogen) FLAG_parallel_recompilation = false; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 274 | |
| 275 | if (FLAG_sweeper_threads <= 0) { |
| 276 | if (FLAG_concurrent_sweeping) { |
| 277 | FLAG_sweeper_threads = SystemThreadManager:: |
| 278 | NumberOfParallelSystemThreads( |
| 279 | SystemThreadManager::CONCURRENT_SWEEPING); |
| 280 | } else if (FLAG_parallel_sweeping) { |
| 281 | FLAG_sweeper_threads = SystemThreadManager:: |
| 282 | NumberOfParallelSystemThreads( |
| 283 | SystemThreadManager::PARALLEL_SWEEPING); |
| 284 | } |
| 285 | if (FLAG_sweeper_threads == 0) { |
| 286 | FLAG_concurrent_sweeping = false; |
| 287 | FLAG_parallel_sweeping = false; |
| 288 | } |
| 289 | } else if (!FLAG_concurrent_sweeping && !FLAG_parallel_sweeping) { |
| 290 | FLAG_sweeper_threads = 0; |
| 291 | } |
| 292 | |
| 293 | if (FLAG_parallel_marking) { |
| 294 | if (FLAG_marking_threads <= 0) { |
| 295 | FLAG_marking_threads = SystemThreadManager:: |
| 296 | NumberOfParallelSystemThreads( |
| 297 | SystemThreadManager::PARALLEL_MARKING); |
| 298 | } |
| 299 | if (FLAG_marking_threads == 0) { |
| 300 | FLAG_parallel_marking = false; |
| 301 | } |
| 302 | } else { |
| 303 | FLAG_marking_threads = 0; |
| 304 | } |
| 305 | |
| 306 | if (FLAG_parallel_recompilation && |
| 307 | SystemThreadManager::NumberOfParallelSystemThreads( |
| 308 | SystemThreadManager::PARALLEL_RECOMPILATION) == 0) { |
| 309 | FLAG_parallel_recompilation = false; |
| 310 | } |
| 311 | |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 312 | OS::SetUp(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 313 | Sampler::SetUp(); |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 314 | CPU::SetUp(); |
| 315 | use_crankshaft_ = FLAG_crankshaft |
| 316 | && !Serializer::enabled() |
| 317 | && CPU::SupportsCrankshaft(); |
| 318 | OS::PostSetUp(); |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 319 | ElementsAccessor::InitializeOncePerProcess(); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 320 | LOperand::SetUpCaches(); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 321 | SetUpJSCallerSavedCodeData(); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 322 | ExternalReference::SetUp(); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 323 | Bootstrapper::InitializeOncePerProcess(); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void V8::InitializeOncePerProcess() { |
| 327 | CallOnce(&init_once, &InitializeOncePerProcessImpl); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 328 | } |
| 329 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | } } // namespace v8::internal |