| 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 20 matching lines...) Expand all Loading... |
| 31 #include "debug.h" | 31 #include "debug.h" |
| 32 #include "serialize.h" | 32 #include "serialize.h" |
| 33 #include "simulator.h" | 33 #include "simulator.h" |
| 34 #include "stub-cache.h" | 34 #include "stub-cache.h" |
| 35 #include "oprofile-agent.h" | 35 #include "oprofile-agent.h" |
| 36 #include "log.h" | 36 #include "log.h" |
| 37 | 37 |
| 38 namespace v8 { | 38 namespace v8 { |
| 39 namespace internal { | 39 namespace internal { |
| 40 | 40 |
| 41 bool V8::is_running_ = false; | 41 V8Data::V8Data() |
| 42 bool V8::has_been_setup_ = false; | 42 :is_running_(false), |
| 43 bool V8::has_been_disposed_ = false; | 43 has_been_setup_(false), |
| 44 bool V8::has_fatal_error_ = false; | 44 has_been_disposed_(false), |
| 45 has_fatal_error_(false), |
| 46 active_(false), |
| 47 exception_behavior_(NULL) { |
| 48 } |
| 45 | 49 |
| 46 bool V8::Initialize(Deserializer *des) { | 50 bool V8::Initialize(Deserializer *des) { |
| 47 bool create_heap_objects = des == NULL; | 51 bool create_heap_objects = des == NULL; |
| 48 if (has_been_disposed_ || has_fatal_error_) return false; | 52 V8Data& v8_data = v8_context()->v8_data_; |
| 53 if (v8_data.has_been_disposed_ || v8_data.has_fatal_error_) return false; |
| 49 if (IsRunning()) return true; | 54 if (IsRunning()) return true; |
| 50 | 55 |
| 51 is_running_ = true; | 56 v8_data.is_running_ = true; |
| 52 has_been_setup_ = true; | 57 v8_data.has_been_setup_ = true; |
| 53 has_fatal_error_ = false; | 58 v8_data.has_fatal_error_ = false; |
| 54 has_been_disposed_ = false; | 59 v8_data.has_been_disposed_ = false; |
| 55 #ifdef DEBUG | 60 #ifdef DEBUG |
| 56 // The initialization process does not handle memory exhaustion. | 61 // The initialization process does not handle memory exhaustion. |
| 57 DisallowAllocationFailure disallow_allocation_failure; | 62 DisallowAllocationFailure disallow_allocation_failure; |
| 58 #endif | 63 #endif |
| 59 | 64 |
| 60 // Enable logging before setting up the heap | 65 // Enable logging before setting up the heap |
| 61 Logger::Setup(); | 66 Logger::Setup(); |
| 62 | 67 |
| 63 // Setup the platform OS support. | 68 // Setup the platform OS support. |
| 64 OS::Setup(); | 69 OS::Setup(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (FLAG_log_code) { | 122 if (FLAG_log_code) { |
| 118 HandleScope scope; | 123 HandleScope scope; |
| 119 LOG(LogCompiledFunctions()); | 124 LOG(LogCompiledFunctions()); |
| 120 } | 125 } |
| 121 | 126 |
| 122 return true; | 127 return true; |
| 123 } | 128 } |
| 124 | 129 |
| 125 | 130 |
| 126 void V8::SetFatalError() { | 131 void V8::SetFatalError() { |
| 127 is_running_ = false; | 132 V8Data& v8_data = v8_context()->v8_data_; |
| 128 has_fatal_error_ = true; | 133 v8_data.is_running_ = false; |
| 134 v8_data.has_fatal_error_ = true; |
| 129 } | 135 } |
| 130 | 136 |
| 131 | 137 |
| 132 void V8::TearDown() { | 138 void V8::TearDown() { |
| 133 if (!has_been_setup_ || has_been_disposed_) return; | 139 V8Data& v8_data = v8_context()->v8_data_; |
| 140 if (!v8_data.has_been_setup_ || v8_data.has_been_disposed_) return; |
| 134 | 141 |
| 135 OProfileAgent::TearDown(); | 142 OProfileAgent::TearDown(); |
| 136 | 143 |
| 137 if (FLAG_preemption) { | 144 if (FLAG_preemption) { |
| 138 v8::Locker locker; | 145 v8::Locker locker; |
| 139 v8::Locker::StopPreemption(); | 146 v8::Locker::StopPreemption(); |
| 140 } | 147 } |
| 141 | 148 |
| 142 Builtins::TearDown(); | 149 Builtins::TearDown(); |
| 143 Bootstrapper::TearDown(); | 150 Bootstrapper::TearDown(); |
| 144 | 151 |
| 145 Top::TearDown(); | 152 Top::TearDown(); |
| 146 | 153 |
| 147 Heap::TearDown(); | 154 Heap::TearDown(); |
| 148 Logger::TearDown(); | 155 Logger::TearDown(); |
| 149 | 156 |
| 150 is_running_ = false; | 157 v8_data.is_running_ = false; |
| 151 has_been_disposed_ = true; | 158 v8_data.has_been_disposed_ = true; |
| 152 } | 159 } |
| 153 | 160 |
| 154 | 161 |
| 155 uint32_t V8::Random() { | 162 uint32_t V8::Random() { |
| 156 // Random number generator using George Marsaglia's MWC algorithm. | 163 // Random number generator using George Marsaglia's MWC algorithm. |
| 157 static uint32_t hi = 0; | 164 static uint32_t hi = 0; |
| 158 static uint32_t lo = 0; | 165 static uint32_t lo = 0; |
| 159 | 166 |
| 160 // Initialize seed using the system random(). If one of the seeds | 167 // Initialize seed using the system random(). If one of the seeds |
| 161 // should ever become zero again, or if random() returns zero, we | 168 // should ever become zero again, or if random() returns zero, we |
| (...skipping 22 matching lines...) Expand all Loading... |
| 184 | 191 |
| 185 Smi* V8::RandomPositiveSmi() { | 192 Smi* V8::RandomPositiveSmi() { |
| 186 uint32_t random = Random(); | 193 uint32_t random = Random(); |
| 187 ASSERT(static_cast<uint32_t>(Smi::kMaxValue) >= kRandomPositiveSmiMax); | 194 ASSERT(static_cast<uint32_t>(Smi::kMaxValue) >= kRandomPositiveSmiMax); |
| 188 // kRandomPositiveSmiMax must match the value being divided | 195 // kRandomPositiveSmiMax must match the value being divided |
| 189 // by in math.js. | 196 // by in math.js. |
| 190 return Smi::FromInt(random & kRandomPositiveSmiMax); | 197 return Smi::FromInt(random & kRandomPositiveSmiMax); |
| 191 } | 198 } |
| 192 | 199 |
| 193 } } // namespace v8::internal | 200 } } // namespace v8::internal |
| OLD | NEW |