| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/dart.h" | 5 #include "vm/dart.h" |
| 6 | 6 |
| 7 #include "vm/code_observers.h" | 7 #include "vm/code_observers.h" |
| 8 #include "vm/cpu.h" | 8 #include "vm/cpu.h" |
| 9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| 11 #include "vm/debugger.h" | 11 #include "vm/debugger.h" |
| 12 #include "vm/flags.h" | 12 #include "vm/flags.h" |
| 13 #include "vm/freelist.h" | 13 #include "vm/freelist.h" |
| 14 #include "vm/handles.h" | 14 #include "vm/handles.h" |
| 15 #include "vm/heap.h" | 15 #include "vm/heap.h" |
| 16 #include "vm/isolate.h" | 16 #include "vm/isolate.h" |
| 17 #include "vm/message.h" | |
| 18 #include "vm/metrics.h" | 17 #include "vm/metrics.h" |
| 19 #include "vm/object.h" | 18 #include "vm/object.h" |
| 20 #include "vm/object_store.h" | 19 #include "vm/object_store.h" |
| 21 #include "vm/object_id_ring.h" | 20 #include "vm/object_id_ring.h" |
| 22 #include "vm/port.h" | 21 #include "vm/port.h" |
| 23 #include "vm/profiler.h" | 22 #include "vm/profiler.h" |
| 24 #include "vm/service_isolate.h" | 23 #include "vm/service_isolate.h" |
| 25 #include "vm/simulator.h" | 24 #include "vm/simulator.h" |
| 26 #include "vm/snapshot.h" | 25 #include "vm/snapshot.h" |
| 27 #include "vm/stub_code.h" | 26 #include "vm/stub_code.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 Isolate::SetUnhandledExceptionCallback(unhandled); | 178 Isolate::SetUnhandledExceptionCallback(unhandled); |
| 180 Isolate::SetShutdownCallback(shutdown); | 179 Isolate::SetShutdownCallback(shutdown); |
| 181 | 180 |
| 182 ServiceIsolate::Run(); | 181 ServiceIsolate::Run(); |
| 183 | 182 |
| 184 return NULL; | 183 return NULL; |
| 185 } | 184 } |
| 186 | 185 |
| 187 | 186 |
| 188 const char* Dart::Cleanup() { | 187 const char* Dart::Cleanup() { |
| 189 ASSERT(Isolate::Current() == NULL); | 188 // Shutdown the service isolate before shutting down the thread pool. |
| 189 ServiceIsolate::Shutdown(); |
| 190 #if 0 |
| 191 // Ideally we should shutdown the VM isolate here, but the thread pool |
| 192 // shutdown does not seem to ensure that all the threads have stopped |
| 193 // execution before it terminates, this results in racing isolates. |
| 190 if (vm_isolate_ == NULL) { | 194 if (vm_isolate_ == NULL) { |
| 191 return "VM already terminated."; | 195 return "VM already terminated."; |
| 192 } | 196 } |
| 193 | 197 |
| 194 // Disable the creation of new isolates. | 198 ASSERT(Isolate::Current() == NULL); |
| 195 Isolate::DisableIsolateCreation(); | |
| 196 | 199 |
| 197 // Send the OOB Kill message to all remaining isolates. | |
| 198 Isolate::KillAllIsolates(); | |
| 199 | |
| 200 // Shutdown the service isolate before shutting down the thread pool. | |
| 201 ServiceIsolate::Shutdown(); | |
| 202 | |
| 203 // Shutdown the thread pool. On return, all thread pool threads have exited. | |
| 204 delete thread_pool_; | 200 delete thread_pool_; |
| 205 thread_pool_ = NULL; | 201 thread_pool_ = NULL; |
| 206 | 202 |
| 207 // Set the VM isolate as current isolate. | 203 // Set the VM isolate as current isolate. |
| 208 Thread::EnsureInit(); | 204 Thread::EnsureInit(); |
| 209 Thread::EnterIsolate(vm_isolate_); | 205 Thread::EnterIsolate(vm_isolate_); |
| 210 | 206 |
| 207 // There is a planned and known asymmetry here: We exit one scope for the VM |
| 208 // isolate to account for the scope that was entered in Dart_InitOnce. |
| 209 Dart_ExitScope(); |
| 210 |
| 211 ShutdownIsolate(); | 211 ShutdownIsolate(); |
| 212 vm_isolate_ = NULL; | 212 vm_isolate_ = NULL; |
| 213 | 213 |
| 214 TargetCPUFeatures::Cleanup(); | 214 TargetCPUFeatures::Cleanup(); |
| 215 #endif |
| 216 |
| 215 Profiler::Shutdown(); | 217 Profiler::Shutdown(); |
| 216 CodeObservers::DeleteAll(); | 218 CodeObservers::DeleteAll(); |
| 217 | 219 |
| 218 ASSERT(Isolate::IsolateListLength() == 0); | |
| 219 return NULL; | 220 return NULL; |
| 220 } | 221 } |
| 221 | 222 |
| 222 | 223 |
| 223 Isolate* Dart::CreateIsolate(const char* name_prefix, | 224 Isolate* Dart::CreateIsolate(const char* name_prefix, |
| 224 const Dart_IsolateFlags& api_flags) { | 225 const Dart_IsolateFlags& api_flags) { |
| 225 // Create a new isolate. | 226 // Create a new isolate. |
| 226 Isolate* isolate = Isolate::Init(name_prefix, api_flags); | 227 Isolate* isolate = Isolate::Init(name_prefix, api_flags); |
| 228 ASSERT(isolate != NULL); |
| 227 return isolate; | 229 return isolate; |
| 228 } | 230 } |
| 229 | 231 |
| 230 | 232 |
| 231 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { | 233 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { |
| 232 // Initialize the new isolate. | 234 // Initialize the new isolate. |
| 233 Isolate* isolate = Isolate::Current(); | 235 Isolate* isolate = Isolate::Current(); |
| 234 TIMERSCOPE(isolate, time_isolate_initialization); | 236 TIMERSCOPE(isolate, time_isolate_initialization); |
| 235 ASSERT(isolate != NULL); | 237 ASSERT(isolate != NULL); |
| 236 StackZone zone(isolate); | 238 StackZone zone(isolate); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 return predefined_handles_->handles_.IsValidScopedHandle(address); | 361 return predefined_handles_->handles_.IsValidScopedHandle(address); |
| 360 } | 362 } |
| 361 | 363 |
| 362 | 364 |
| 363 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 365 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
| 364 ASSERT(predefined_handles_ != NULL); | 366 ASSERT(predefined_handles_ != NULL); |
| 365 return predefined_handles_->api_handles_.IsValidHandle(handle); | 367 return predefined_handles_->api_handles_.IsValidHandle(handle); |
| 366 } | 368 } |
| 367 | 369 |
| 368 } // namespace dart | 370 } // namespace dart |
| OLD | NEW |