| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "bootstrapper.h" | 30 #include "bootstrapper.h" |
| 31 #include "debug.h" | 31 #include "debug.h" |
| 32 #include "isolate.h" |
| 32 #include "serialize.h" | 33 #include "serialize.h" |
| 33 #include "simulator.h" | 34 #include "simulator.h" |
| 34 #include "stub-cache.h" | 35 #include "stub-cache.h" |
| 35 #include "oprofile-agent.h" | 36 #include "oprofile-agent.h" |
| 36 #include "log.h" | 37 #include "log.h" |
| 37 | 38 |
| 38 namespace v8 { | 39 namespace v8 { |
| 39 namespace internal { | 40 namespace internal { |
| 40 | 41 |
| 41 bool V8::is_running_ = false; | 42 bool V8::is_running_ = false; |
| 42 bool V8::has_been_setup_ = false; | 43 bool V8::has_been_setup_ = false; |
| 43 bool V8::has_been_disposed_ = false; | 44 bool V8::has_been_disposed_ = false; |
| 44 bool V8::has_fatal_error_ = false; | 45 bool V8::has_fatal_error_ = false; |
| 45 | 46 |
| 46 bool V8::Initialize(Deserializer* des) { | 47 bool V8::Initialize(Deserializer* des) { |
| 47 bool create_heap_objects = des == NULL; | |
| 48 if (has_been_disposed_ || has_fatal_error_) return false; | 48 if (has_been_disposed_ || has_fatal_error_) return false; |
| 49 if (IsRunning()) return true; | 49 if (IsRunning()) return true; |
| 50 | 50 |
| 51 is_running_ = true; | 51 is_running_ = true; |
| 52 has_been_setup_ = true; | 52 has_been_setup_ = true; |
| 53 has_fatal_error_ = false; | 53 has_fatal_error_ = false; |
| 54 has_been_disposed_ = false; | 54 has_been_disposed_ = false; |
| 55 #ifdef DEBUG | |
| 56 // The initialization process does not handle memory exhaustion. | |
| 57 DisallowAllocationFailure disallow_allocation_failure; | |
| 58 #endif | |
| 59 | 55 |
| 60 // Enable logging before setting up the heap | 56 Isolate::InitOnce(); |
| 61 Logger::Setup(); | 57 return (Isolate::Create(des) != NULL); |
| 62 | |
| 63 CpuProfiler::Setup(); | |
| 64 | |
| 65 // Setup the platform OS support. | |
| 66 OS::Setup(); | |
| 67 | |
| 68 // Initialize other runtime facilities | |
| 69 #if !V8_HOST_ARCH_ARM && V8_TARGET_ARCH_ARM | |
| 70 ::assembler::arm::Simulator::Initialize(); | |
| 71 #endif | |
| 72 | |
| 73 { // NOLINT | |
| 74 // Ensure that the thread has a valid stack guard. The v8::Locker object | |
| 75 // will ensure this too, but we don't have to use lockers if we are only | |
| 76 // using one thread. | |
| 77 ExecutionAccess lock; | |
| 78 StackGuard::InitThread(lock); | |
| 79 } | |
| 80 | |
| 81 // Setup the object heap | |
| 82 ASSERT(!Heap::HasBeenSetup()); | |
| 83 if (!Heap::Setup(create_heap_objects)) { | |
| 84 SetFatalError(); | |
| 85 return false; | |
| 86 } | |
| 87 | |
| 88 Bootstrapper::Initialize(create_heap_objects); | |
| 89 Builtins::Setup(create_heap_objects); | |
| 90 Top::Initialize(); | |
| 91 | |
| 92 if (FLAG_preemption) { | |
| 93 v8::Locker locker; | |
| 94 v8::Locker::StartPreemption(100); | |
| 95 } | |
| 96 | |
| 97 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 98 Debug::Setup(create_heap_objects); | |
| 99 #endif | |
| 100 StubCache::Initialize(create_heap_objects); | |
| 101 | |
| 102 // If we are deserializing, read the state into the now-empty heap. | |
| 103 if (des != NULL) { | |
| 104 des->Deserialize(); | |
| 105 StubCache::Clear(); | |
| 106 } | |
| 107 | |
| 108 // Deserializing may put strange things in the root array's copy of the | |
| 109 // stack guard. | |
| 110 Heap::SetStackLimits(); | |
| 111 | |
| 112 // Setup the CPU support. Must be done after heap setup and after | |
| 113 // any deserialization because we have to have the initial heap | |
| 114 // objects in place for creating the code object used for probing. | |
| 115 CPU::Setup(); | |
| 116 | |
| 117 OProfileAgent::Initialize(); | |
| 118 | |
| 119 // If we are deserializing, log non-function code objects and compiled | |
| 120 // functions found in the snapshot. | |
| 121 if (des != NULL && FLAG_log_code) { | |
| 122 HandleScope scope; | |
| 123 LOG(LogCodeObjects()); | |
| 124 LOG(LogCompiledFunctions()); | |
| 125 } | |
| 126 | |
| 127 return true; | |
| 128 } | 58 } |
| 129 | 59 |
| 130 | 60 |
| 131 void V8::SetFatalError() { | 61 void V8::SetFatalError() { |
| 132 is_running_ = false; | 62 is_running_ = false; |
| 133 has_fatal_error_ = true; | 63 has_fatal_error_ = true; |
| 134 } | 64 } |
| 135 | 65 |
| 136 | 66 |
| 137 void V8::TearDown() { | 67 void V8::TearDown() { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | 145 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 216 const double binary_million = 1048576.0; | 146 const double binary_million = 1048576.0; |
| 217 r->double_value = binary_million; | 147 r->double_value = binary_million; |
| 218 r->uint64_t_value |= random_bits; | 148 r->uint64_t_value |= random_bits; |
| 219 r->double_value -= binary_million; | 149 r->double_value -= binary_million; |
| 220 | 150 |
| 221 return heap_number; | 151 return heap_number; |
| 222 } | 152 } |
| 223 | 153 |
| 224 } } // namespace v8::internal | 154 } } // namespace v8::internal |
| OLD | NEW |