| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "sampler.h" | 43 #include "sampler.h" |
| 44 #include "runtime-profiler.h" | 44 #include "runtime-profiler.h" |
| 45 #include "serialize.h" | 45 #include "serialize.h" |
| 46 #include "store-buffer.h" | 46 #include "store-buffer.h" |
| 47 | 47 |
| 48 namespace v8 { | 48 namespace v8 { |
| 49 namespace internal { | 49 namespace internal { |
| 50 | 50 |
| 51 V8_DECLARE_ONCE(init_once); | 51 V8_DECLARE_ONCE(init_once); |
| 52 | 52 |
| 53 bool V8::has_been_set_up_ = false; | |
| 54 bool V8::has_been_disposed_ = false; | |
| 55 bool V8::has_fatal_error_ = false; | |
| 56 bool V8::use_crankshaft_ = true; | |
| 57 List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL; | 53 List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL; |
| 58 v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL; | 54 v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL; |
| 59 | 55 |
| 60 static LazyMutex entropy_mutex = LAZY_MUTEX_INITIALIZER; | 56 static LazyMutex entropy_mutex = LAZY_MUTEX_INITIALIZER; |
| 61 | 57 |
| 62 static EntropySource entropy_source; | 58 static EntropySource entropy_source; |
| 63 | 59 |
| 64 | 60 |
| 65 bool V8::Initialize(Deserializer* des) { | 61 bool V8::Initialize(Deserializer* des) { |
| 66 InitializeOncePerProcess(); | 62 InitializeOncePerProcess(); |
| 67 | 63 |
| 68 // The current thread may not yet had entered an isolate to run. | 64 // The current thread may not yet had entered an isolate to run. |
| 69 // Note the Isolate::Current() may be non-null because for various | 65 // Note the Isolate::Current() may be non-null because for various |
| 70 // initialization purposes an initializing thread may be assigned an isolate | 66 // initialization purposes an initializing thread may be assigned an isolate |
| 71 // but not actually enter it. | 67 // but not actually enter it. |
| 72 if (i::Isolate::CurrentPerIsolateThreadData() == NULL) { | 68 if (i::Isolate::CurrentPerIsolateThreadData() == NULL) { |
| 73 i::Isolate::EnterDefaultIsolate(); | 69 i::Isolate::EnterDefaultIsolate(); |
| 74 } | 70 } |
| 75 | 71 |
| 76 ASSERT(i::Isolate::CurrentPerIsolateThreadData() != NULL); | 72 ASSERT(i::Isolate::CurrentPerIsolateThreadData() != NULL); |
| 77 ASSERT(i::Isolate::CurrentPerIsolateThreadData()->thread_id().Equals( | 73 ASSERT(i::Isolate::CurrentPerIsolateThreadData()->thread_id().Equals( |
| 78 i::ThreadId::Current())); | 74 i::ThreadId::Current())); |
| 79 ASSERT(i::Isolate::CurrentPerIsolateThreadData()->isolate() == | 75 ASSERT(i::Isolate::CurrentPerIsolateThreadData()->isolate() == |
| 80 i::Isolate::Current()); | 76 i::Isolate::Current()); |
| 81 | 77 |
| 82 if (IsDead()) return false; | |
| 83 | |
| 84 Isolate* isolate = Isolate::Current(); | 78 Isolate* isolate = Isolate::Current(); |
| 79 if (isolate->IsDead()) return false; |
| 85 if (isolate->IsInitialized()) return true; | 80 if (isolate->IsInitialized()) return true; |
| 86 | 81 |
| 87 has_been_set_up_ = true; | |
| 88 has_fatal_error_ = false; | |
| 89 has_been_disposed_ = false; | |
| 90 | |
| 91 return isolate->Init(des); | 82 return isolate->Init(des); |
| 92 } | 83 } |
| 93 | 84 |
| 94 | 85 |
| 95 void V8::SetFatalError() { | |
| 96 has_fatal_error_ = true; | |
| 97 } | |
| 98 | |
| 99 | |
| 100 void V8::TearDown() { | 86 void V8::TearDown() { |
| 101 Isolate* isolate = Isolate::Current(); | 87 Isolate* isolate = Isolate::Current(); |
| 102 ASSERT(isolate->IsDefaultIsolate()); | 88 ASSERT(isolate->IsDefaultIsolate()); |
| 103 | 89 if (!isolate->IsInitialized()) return; |
| 104 if (!has_been_set_up_ || has_been_disposed_) return; | |
| 105 | 90 |
| 106 // The isolate has to be torn down before clearing the LOperand | 91 // The isolate has to be torn down before clearing the LOperand |
| 107 // caches so that the optimizing compiler thread (if running) | 92 // caches so that the optimizing compiler thread (if running) |
| 108 // doesn't see an inconsistent view of the lithium instructions. | 93 // doesn't see an inconsistent view of the lithium instructions. |
| 109 isolate->TearDown(); | 94 isolate->TearDown(); |
| 110 delete isolate; | 95 delete isolate; |
| 111 | 96 |
| 112 ElementsAccessor::TearDown(); | 97 ElementsAccessor::TearDown(); |
| 113 LOperand::TearDownCaches(); | 98 LOperand::TearDownCaches(); |
| 114 ExternalReference::TearDownMathExpData(); | 99 ExternalReference::TearDownMathExpData(); |
| 115 RegisteredExtension::UnregisterAll(); | 100 RegisteredExtension::UnregisterAll(); |
| 116 Isolate::GlobalTearDown(); | 101 Isolate::GlobalTearDown(); |
| 117 | 102 |
| 118 has_been_disposed_ = true; | |
| 119 | |
| 120 delete call_completed_callbacks_; | 103 delete call_completed_callbacks_; |
| 121 call_completed_callbacks_ = NULL; | 104 call_completed_callbacks_ = NULL; |
| 122 | 105 |
| 123 Sampler::TearDown(); | 106 Sampler::TearDown(); |
| 124 OS::TearDown(); | |
| 125 } | 107 } |
| 126 | 108 |
| 127 | 109 |
| 128 static void seed_random(uint32_t* state) { | 110 static void seed_random(uint32_t* state) { |
| 129 for (int i = 0; i < 2; ++i) { | 111 for (int i = 0; i < 2; ++i) { |
| 130 if (FLAG_random_seed != 0) { | 112 if (FLAG_random_seed != 0) { |
| 131 state[i] = FLAG_random_seed; | 113 state[i] = FLAG_random_seed; |
| 132 } else if (entropy_source != NULL) { | 114 } else if (entropy_source != NULL) { |
| 133 uint32_t val; | 115 uint32_t val; |
| 134 LockGuard<Mutex> lock_guard(entropy_mutex.Pointer()); | 116 LockGuard<Mutex> lock_guard(entropy_mutex.Pointer()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 ASSERT(context->IsNativeContext()); | 153 ASSERT(context->IsNativeContext()); |
| 172 ByteArray* seed = context->random_seed(); | 154 ByteArray* seed = context->random_seed(); |
| 173 return random_base(reinterpret_cast<uint32_t*>(seed->GetDataStartAddress())); | 155 return random_base(reinterpret_cast<uint32_t*>(seed->GetDataStartAddress())); |
| 174 } | 156 } |
| 175 | 157 |
| 176 | 158 |
| 177 // Used internally by the JIT and memory allocator for security | 159 // Used internally by the JIT and memory allocator for security |
| 178 // purposes. So, we keep a different state to prevent informations | 160 // purposes. So, we keep a different state to prevent informations |
| 179 // leaks that could be used in an exploit. | 161 // leaks that could be used in an exploit. |
| 180 uint32_t V8::RandomPrivate(Isolate* isolate) { | 162 uint32_t V8::RandomPrivate(Isolate* isolate) { |
| 181 ASSERT(isolate == Isolate::Current()); | |
| 182 return random_base(isolate->private_random_seed()); | 163 return random_base(isolate->private_random_seed()); |
| 183 } | 164 } |
| 184 | 165 |
| 185 | 166 |
| 186 bool V8::IdleNotification(int hint) { | |
| 187 // Returning true tells the caller that there is no need to call | |
| 188 // IdleNotification again. | |
| 189 if (!FLAG_use_idle_notification) return true; | |
| 190 | |
| 191 // Tell the heap that it may want to adjust. | |
| 192 return HEAP->IdleNotification(hint); | |
| 193 } | |
| 194 | |
| 195 | |
| 196 void V8::AddCallCompletedCallback(CallCompletedCallback callback) { | 167 void V8::AddCallCompletedCallback(CallCompletedCallback callback) { |
| 197 if (call_completed_callbacks_ == NULL) { // Lazy init. | 168 if (call_completed_callbacks_ == NULL) { // Lazy init. |
| 198 call_completed_callbacks_ = new List<CallCompletedCallback>(); | 169 call_completed_callbacks_ = new List<CallCompletedCallback>(); |
| 199 } | 170 } |
| 200 for (int i = 0; i < call_completed_callbacks_->length(); i++) { | 171 for (int i = 0; i < call_completed_callbacks_->length(); i++) { |
| 201 if (callback == call_completed_callbacks_->at(i)) return; | 172 if (callback == call_completed_callbacks_->at(i)) return; |
| 202 } | 173 } |
| 203 call_completed_callbacks_->Add(callback); | 174 call_completed_callbacks_->Add(callback); |
| 204 } | 175 } |
| 205 | 176 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 278 |
| 308 if (FLAG_concurrent_recompilation && | 279 if (FLAG_concurrent_recompilation && |
| 309 SystemThreadManager::NumberOfParallelSystemThreads( | 280 SystemThreadManager::NumberOfParallelSystemThreads( |
| 310 SystemThreadManager::PARALLEL_RECOMPILATION) == 0) { | 281 SystemThreadManager::PARALLEL_RECOMPILATION) == 0) { |
| 311 FLAG_concurrent_recompilation = false; | 282 FLAG_concurrent_recompilation = false; |
| 312 } | 283 } |
| 313 | 284 |
| 314 OS::SetUp(); | 285 OS::SetUp(); |
| 315 Sampler::SetUp(); | 286 Sampler::SetUp(); |
| 316 CPU::SetUp(); | 287 CPU::SetUp(); |
| 317 use_crankshaft_ = FLAG_crankshaft | |
| 318 && !Serializer::enabled() | |
| 319 && CPU::SupportsCrankshaft(); | |
| 320 OS::PostSetUp(); | 288 OS::PostSetUp(); |
| 321 ElementsAccessor::InitializeOncePerProcess(); | 289 ElementsAccessor::InitializeOncePerProcess(); |
| 322 LOperand::SetUpCaches(); | 290 LOperand::SetUpCaches(); |
| 323 SetUpJSCallerSavedCodeData(); | 291 SetUpJSCallerSavedCodeData(); |
| 324 ExternalReference::SetUp(); | 292 ExternalReference::SetUp(); |
| 325 Bootstrapper::InitializeOncePerProcess(); | 293 Bootstrapper::InitializeOncePerProcess(); |
| 326 } | 294 } |
| 327 | 295 |
| 328 | 296 |
| 329 void V8::InitializeOncePerProcess() { | 297 void V8::InitializeOncePerProcess() { |
| 330 CallOnce(&init_once, &InitializeOncePerProcessImpl); | 298 CallOnce(&init_once, &InitializeOncePerProcessImpl); |
| 331 } | 299 } |
| 332 | 300 |
| 333 } } // namespace v8::internal | 301 } } // namespace v8::internal |
| OLD | NEW |