| OLD | NEW |
| 1 // Copyright 2006-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2010 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 28 matching lines...) Expand all Loading... |
| 39 #include "oprofile-agent.h" | 39 #include "oprofile-agent.h" |
| 40 | 40 |
| 41 namespace v8 { | 41 namespace v8 { |
| 42 namespace internal { | 42 namespace internal { |
| 43 | 43 |
| 44 | 44 |
| 45 Isolate* Isolate::global_isolate = NULL; | 45 Isolate* Isolate::global_isolate = NULL; |
| 46 int Isolate::number_of_isolates_ = 0; | 46 int Isolate::number_of_isolates_ = 0; |
| 47 | 47 |
| 48 | 48 |
| 49 class IsolateInitializer { |
| 50 public: |
| 51 IsolateInitializer() { |
| 52 Isolate::InitOnce(); |
| 53 } |
| 54 }; |
| 55 |
| 56 |
| 57 static IsolateInitializer isolate_initializer; |
| 58 |
| 59 |
| 49 void Isolate::InitOnce() { | 60 void Isolate::InitOnce() { |
| 61 ASSERT(global_isolate == NULL); |
| 62 global_isolate = new Isolate(); |
| 63 ASSERT(global_isolate->PreInit()); |
| 50 } | 64 } |
| 51 | 65 |
| 52 | 66 |
| 53 Isolate* Isolate::Create(Deserializer* des) { | 67 Isolate* Isolate::Create(Deserializer* des) { |
| 54 // While we're still building out support for isolates, only support | 68 // While we're still building out support for isolates, only support |
| 55 // one single global isolate. | 69 // one single global isolate. |
| 56 ASSERT(global_isolate == NULL); | 70 |
| 57 global_isolate = new Isolate(); | 71 if (global_isolate != NULL) { |
| 72 // Allow for two-phase initialization. |
| 73 ASSERT(global_isolate->state_ != INITIALIZED); |
| 74 } else { |
| 75 global_isolate = new Isolate(); |
| 76 } |
| 77 |
| 58 if (global_isolate->Init(des)) { | 78 if (global_isolate->Init(des)) { |
| 59 ++number_of_isolates_; | 79 ++number_of_isolates_; |
| 60 return global_isolate; | 80 return global_isolate; |
| 61 } else { | 81 } else { |
| 62 delete global_isolate; | 82 delete global_isolate; |
| 63 global_isolate = NULL; | 83 global_isolate = NULL; |
| 64 return NULL; | 84 return NULL; |
| 65 } | 85 } |
| 66 } | 86 } |
| 67 | 87 |
| 68 | 88 |
| 69 Isolate::Isolate() | 89 Isolate::Isolate() |
| 70 : initialized_(false), | 90 : state_(UNINITIALIZED), |
| 71 bootstrapper_(NULL), | 91 bootstrapper_(NULL), |
| 92 break_access_(OS::CreateMutex()), |
| 72 stub_cache_(NULL), | 93 stub_cache_(NULL), |
| 73 handle_scope_implementer_(NULL) { | 94 handle_scope_implementer_(NULL) { |
| 95 heap_.isolate_ = this; |
| 96 stack_guard_.isolate_ = this; |
| 97 |
| 74 handle_scope_data_.Initialize(); | 98 handle_scope_data_.Initialize(); |
| 99 |
| 75 #define ISOLATE_INIT_EXECUTE(type, name, initial_value) \ | 100 #define ISOLATE_INIT_EXECUTE(type, name, initial_value) \ |
| 76 name##_ = (initial_value); | 101 name##_ = (initial_value); |
| 77 ISOLATE_INIT_LIST(ISOLATE_INIT_EXECUTE) | 102 ISOLATE_INIT_LIST(ISOLATE_INIT_EXECUTE) |
| 78 #undef ISOLATE_INIT_EXECUTE | 103 #undef ISOLATE_INIT_EXECUTE |
| 79 | 104 |
| 80 #define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \ | 105 #define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \ |
| 81 memset(name##_, 0, sizeof(type) * length); | 106 memset(name##_, 0, sizeof(type) * length); |
| 82 ISOLATE_INIT_ARRAY_LIST(ISOLATE_INIT_ARRAY_EXECUTE) | 107 ISOLATE_INIT_ARRAY_LIST(ISOLATE_INIT_ARRAY_EXECUTE) |
| 83 #undef ISOLATE_INIT_ARRAY_EXECUTE | 108 #undef ISOLATE_INIT_ARRAY_EXECUTE |
| 84 } | 109 } |
| 85 | 110 |
| 86 | 111 |
| 87 Isolate::~Isolate() { | 112 Isolate::~Isolate() { |
| 88 delete stub_cache_; | 113 delete stub_cache_; |
| 89 stub_cache_ = NULL; | 114 stub_cache_ = NULL; |
| 90 delete bootstrapper_; | 115 delete bootstrapper_; |
| 91 bootstrapper_ = NULL; | 116 bootstrapper_ = NULL; |
| 92 | 117 |
| 93 if (initialized_) --number_of_isolates_; | 118 if (state_ == INITIALIZED) --number_of_isolates_; |
| 119 } |
| 120 |
| 121 |
| 122 bool Isolate::PreInit() { |
| 123 if (state_ != UNINITIALIZED) return true; |
| 124 ASSERT(global_isolate == this); |
| 125 |
| 126 // Safe after setting Heap::isolate_, initializing StackGuard and |
| 127 // ensuring that Isolate::Current() == this. |
| 128 heap()->SetStackLimits(); |
| 129 |
| 130 #ifdef DEBUG |
| 131 DisallowAllocationFailure disallow_allocation_failure; |
| 132 #endif |
| 133 bootstrapper_ = new Bootstrapper(); |
| 134 handle_scope_implementer_ = new HandleScopeImplementer(); |
| 135 stub_cache_ = new StubCache(); |
| 136 state_ = PREINITIALIZED; |
| 137 return true; |
| 94 } | 138 } |
| 95 | 139 |
| 96 | 140 |
| 97 bool Isolate::Init(Deserializer* des) { | 141 bool Isolate::Init(Deserializer* des) { |
| 98 ASSERT(global_isolate == this); | 142 ASSERT(global_isolate == this); |
| 99 | 143 |
| 100 bool create_heap_objects = des == NULL; | 144 bool create_heap_objects = des == NULL; |
| 101 | 145 |
| 102 #ifdef DEBUG | 146 #ifdef DEBUG |
| 103 // The initialization process does not handle memory exhaustion. | 147 // The initialization process does not handle memory exhaustion. |
| 104 DisallowAllocationFailure disallow_allocation_failure; | 148 DisallowAllocationFailure disallow_allocation_failure; |
| 105 #endif | 149 #endif |
| 106 | 150 |
| 107 // Allocate per-isolate globals early. | 151 if (state_ == UNINITIALIZED && !PreInit()) return false; |
| 108 bootstrapper_ = new Bootstrapper(); | |
| 109 handle_scope_implementer_ = new HandleScopeImplementer(); | |
| 110 stub_cache_ = new StubCache(); | |
| 111 | 152 |
| 112 // Enable logging before setting up the heap | 153 // Enable logging before setting up the heap |
| 113 Logger::Setup(); | 154 Logger::Setup(); |
| 114 | 155 |
| 115 CpuProfiler::Setup(); | 156 CpuProfiler::Setup(); |
| 116 | 157 |
| 117 // Setup the platform OS support. | 158 // Setup the platform OS support. |
| 118 OS::Setup(); | 159 OS::Setup(); |
| 119 | 160 |
| 120 // Initialize other runtime facilities | 161 // Initialize other runtime facilities |
| 121 #if !V8_HOST_ARCH_ARM && V8_TARGET_ARCH_ARM | 162 #if !V8_HOST_ARCH_ARM && V8_TARGET_ARCH_ARM |
| 122 ::assembler::arm::Simulator::Initialize(); | 163 ::assembler::arm::Simulator::Initialize(); |
| 123 #endif | 164 #endif |
| 124 | 165 |
| 125 { // NOLINT | 166 { // NOLINT |
| 126 // Ensure that the thread has a valid stack guard. The v8::Locker object | 167 // Ensure that the thread has a valid stack guard. The v8::Locker object |
| 127 // will ensure this too, but we don't have to use lockers if we are only | 168 // will ensure this too, but we don't have to use lockers if we are only |
| 128 // using one thread. | 169 // using one thread. |
| 129 ExecutionAccess lock; | 170 ExecutionAccess lock; |
| 130 StackGuard::InitThread(lock); | 171 stack_guard_.InitThread(lock); |
| 131 } | 172 } |
| 132 | 173 |
| 133 // Setup the object heap | 174 // Setup the object heap |
| 134 ASSERT(!Heap::HasBeenSetup()); | 175 ASSERT(!Heap::HasBeenSetup()); |
| 135 if (!Heap::Setup(create_heap_objects)) { | 176 if (!Heap::Setup(create_heap_objects)) { |
| 136 V8::SetFatalError(); | 177 V8::SetFatalError(); |
| 137 return false; | 178 return false; |
| 138 } | 179 } |
| 139 | 180 |
| 140 bootstrapper_->Initialize(create_heap_objects); | 181 bootstrapper_->Initialize(create_heap_objects); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 152 stub_cache_->Initialize(create_heap_objects); | 193 stub_cache_->Initialize(create_heap_objects); |
| 153 | 194 |
| 154 // If we are deserializing, read the state into the now-empty heap. | 195 // If we are deserializing, read the state into the now-empty heap. |
| 155 if (des != NULL) { | 196 if (des != NULL) { |
| 156 des->Deserialize(); | 197 des->Deserialize(); |
| 157 stub_cache_->Clear(); | 198 stub_cache_->Clear(); |
| 158 } | 199 } |
| 159 | 200 |
| 160 // Deserializing may put strange things in the root array's copy of the | 201 // Deserializing may put strange things in the root array's copy of the |
| 161 // stack guard. | 202 // stack guard. |
| 162 Heap::SetStackLimits(); | 203 heap_.SetStackLimits(); |
| 163 | 204 |
| 164 // Setup the CPU support. Must be done after heap setup and after | 205 // Setup the CPU support. Must be done after heap setup and after |
| 165 // any deserialization because we have to have the initial heap | 206 // any deserialization because we have to have the initial heap |
| 166 // objects in place for creating the code object used for probing. | 207 // objects in place for creating the code object used for probing. |
| 167 CPU::Setup(); | 208 CPU::Setup(); |
| 168 | 209 |
| 169 OProfileAgent::Initialize(); | 210 OProfileAgent::Initialize(); |
| 170 | 211 |
| 171 // If we are deserializing, log non-function code objects and compiled | 212 // If we are deserializing, log non-function code objects and compiled |
| 172 // functions found in the snapshot. | 213 // functions found in the snapshot. |
| 173 if (des != NULL && FLAG_log_code) { | 214 if (des != NULL && FLAG_log_code) { |
| 174 HandleScope scope; | 215 HandleScope scope; |
| 175 LOG(LogCodeObjects()); | 216 LOG(LogCodeObjects()); |
| 176 LOG(LogCompiledFunctions()); | 217 LOG(LogCompiledFunctions()); |
| 177 } | 218 } |
| 178 | 219 |
| 179 initialized_ = true; | 220 state_ = INITIALIZED; |
| 180 | |
| 181 return true; | 221 return true; |
| 182 } | 222 } |
| 183 | 223 |
| 184 | 224 |
| 185 } } // namespace v8::internal | 225 } } // namespace v8::internal |
| OLD | NEW |