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" |
17 #include "vm/metrics.h" | 18 #include "vm/metrics.h" |
18 #include "vm/object.h" | 19 #include "vm/object.h" |
19 #include "vm/object_store.h" | 20 #include "vm/object_store.h" |
20 #include "vm/object_id_ring.h" | 21 #include "vm/object_id_ring.h" |
21 #include "vm/port.h" | 22 #include "vm/port.h" |
22 #include "vm/profiler.h" | 23 #include "vm/profiler.h" |
23 #include "vm/service_isolate.h" | 24 #include "vm/service_isolate.h" |
24 #include "vm/simulator.h" | 25 #include "vm/simulator.h" |
25 #include "vm/snapshot.h" | 26 #include "vm/snapshot.h" |
26 #include "vm/stub_code.h" | 27 #include "vm/stub_code.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 Isolate::SetUnhandledExceptionCallback(unhandled); | 192 Isolate::SetUnhandledExceptionCallback(unhandled); |
192 Isolate::SetShutdownCallback(shutdown); | 193 Isolate::SetShutdownCallback(shutdown); |
193 | 194 |
194 ServiceIsolate::Run(); | 195 ServiceIsolate::Run(); |
195 | 196 |
196 return NULL; | 197 return NULL; |
197 } | 198 } |
198 | 199 |
199 | 200 |
200 const char* Dart::Cleanup() { | 201 const char* Dart::Cleanup() { |
201 // Shutdown the service isolate before shutting down the thread pool. | 202 ASSERT(Isolate::Current() == NULL); |
202 ServiceIsolate::Shutdown(); | |
203 #if 0 | |
204 // Ideally we should shutdown the VM isolate here, but the thread pool | |
205 // shutdown does not seem to ensure that all the threads have stopped | |
206 // execution before it terminates, this results in racing isolates. | |
207 if (vm_isolate_ == NULL) { | 203 if (vm_isolate_ == NULL) { |
208 return "VM already terminated."; | 204 return "VM already terminated."; |
209 } | 205 } |
210 | 206 |
211 ASSERT(Isolate::Current() == NULL); | 207 // Disable the creation of new isolates. |
| 208 Isolate::DisableIsolateCreation(); |
212 | 209 |
| 210 // Send the OOB Kill message to all remaining isolates. |
| 211 Isolate::KillAllIsolates(); |
| 212 |
| 213 // Shutdown the service isolate before shutting down the thread pool. |
| 214 ServiceIsolate::Shutdown(); |
| 215 |
| 216 // Shutdown the thread pool. On return, all thread pool threads have exited. |
213 delete thread_pool_; | 217 delete thread_pool_; |
214 thread_pool_ = NULL; | 218 thread_pool_ = NULL; |
215 | 219 |
216 // Set the VM isolate as current isolate. | 220 // Set the VM isolate as current isolate. |
217 Thread::EnsureInit(); | 221 Thread::EnsureInit(); |
218 Thread::EnterIsolate(vm_isolate_); | 222 Thread::EnterIsolate(vm_isolate_); |
219 | 223 |
220 // There is a planned and known asymmetry here: We exit one scope for the VM | |
221 // isolate to account for the scope that was entered in Dart_InitOnce. | |
222 Dart_ExitScope(); | |
223 | |
224 ShutdownIsolate(); | 224 ShutdownIsolate(); |
225 vm_isolate_ = NULL; | 225 vm_isolate_ = NULL; |
226 | 226 |
227 TargetCPUFeatures::Cleanup(); | 227 TargetCPUFeatures::Cleanup(); |
228 #endif | |
229 | |
230 Profiler::Shutdown(); | 228 Profiler::Shutdown(); |
231 CodeObservers::DeleteAll(); | 229 CodeObservers::DeleteAll(); |
232 | 230 |
| 231 ASSERT(Isolate::IsolateCount() == 0); |
233 return NULL; | 232 return NULL; |
234 } | 233 } |
235 | 234 |
236 | 235 |
237 Isolate* Dart::CreateIsolate(const char* name_prefix, | 236 Isolate* Dart::CreateIsolate(const char* name_prefix, |
238 const Dart_IsolateFlags& api_flags) { | 237 const Dart_IsolateFlags& api_flags) { |
239 // Create a new isolate. | 238 // Create a new isolate. |
240 Isolate* isolate = Isolate::Init(name_prefix, api_flags); | 239 Isolate* isolate = Isolate::Init(name_prefix, api_flags); |
241 ASSERT(isolate != NULL); | |
242 return isolate; | 240 return isolate; |
243 } | 241 } |
244 | 242 |
245 | 243 |
246 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { | 244 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { |
247 // Initialize the new isolate. | 245 // Initialize the new isolate. |
248 Isolate* isolate = Isolate::Current(); | 246 Isolate* isolate = Isolate::Current(); |
249 TIMERSCOPE(isolate, time_isolate_initialization); | 247 TIMERSCOPE(isolate, time_isolate_initialization); |
250 ASSERT(isolate != NULL); | 248 ASSERT(isolate != NULL); |
251 StackZone zone(isolate); | 249 StackZone zone(isolate); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 return predefined_handles_->handles_.IsValidScopedHandle(address); | 371 return predefined_handles_->handles_.IsValidScopedHandle(address); |
374 } | 372 } |
375 | 373 |
376 | 374 |
377 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 375 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
378 ASSERT(predefined_handles_ != NULL); | 376 ASSERT(predefined_handles_ != NULL); |
379 return predefined_handles_->api_handles_.IsValidHandle(handle); | 377 return predefined_handles_->api_handles_.IsValidHandle(handle); |
380 } | 378 } |
381 | 379 |
382 } // namespace dart | 380 } // namespace dart |
OLD | NEW |