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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "vm/thread_pool.h" | 30 #include "vm/thread_pool.h" |
31 #include "vm/virtual_memory.h" | 31 #include "vm/virtual_memory.h" |
32 #include "vm/zone.h" | 32 #include "vm/zone.h" |
33 | 33 |
34 namespace dart { | 34 namespace dart { |
35 | 35 |
36 DECLARE_FLAG(bool, print_class_table); | 36 DECLARE_FLAG(bool, print_class_table); |
37 DECLARE_FLAG(bool, trace_isolates); | 37 DECLARE_FLAG(bool, trace_isolates); |
38 DEFINE_FLAG(bool, keep_code, false, | 38 DEFINE_FLAG(bool, keep_code, false, |
39 "Keep deoptimized code for profiling."); | 39 "Keep deoptimized code for profiling."); |
| 40 DEFINE_FLAG(bool, shutdown, true, "Do a clean shutdown of the VM"); |
40 | 41 |
41 Isolate* Dart::vm_isolate_ = NULL; | 42 Isolate* Dart::vm_isolate_ = NULL; |
42 ThreadPool* Dart::thread_pool_ = NULL; | 43 ThreadPool* Dart::thread_pool_ = NULL; |
43 DebugInfo* Dart::pprof_symbol_generator_ = NULL; | 44 DebugInfo* Dart::pprof_symbol_generator_ = NULL; |
44 ReadOnlyHandles* Dart::predefined_handles_ = NULL; | 45 ReadOnlyHandles* Dart::predefined_handles_ = NULL; |
45 | 46 |
46 // Structure for managing read-only global handles allocation used for | 47 // Structure for managing read-only global handles allocation used for |
47 // creating global read-only handles that are pre created and initialized | 48 // creating global read-only handles that are pre created and initialized |
48 // for use across all isolates. Having these global pre created handles | 49 // for use across all isolates. Having these global pre created handles |
49 // stored in the vm isolate ensures that we don't constantly create and | 50 // stored in the vm isolate ensures that we don't constantly create and |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 Isolate::SetInterruptCallback(interrupt); | 189 Isolate::SetInterruptCallback(interrupt); |
189 Isolate::SetUnhandledExceptionCallback(unhandled); | 190 Isolate::SetUnhandledExceptionCallback(unhandled); |
190 Isolate::SetShutdownCallback(shutdown); | 191 Isolate::SetShutdownCallback(shutdown); |
191 | 192 |
192 ServiceIsolate::Run(); | 193 ServiceIsolate::Run(); |
193 | 194 |
194 return NULL; | 195 return NULL; |
195 } | 196 } |
196 | 197 |
197 | 198 |
| 199 // This waits until only the VM isolate remains in the list. |
| 200 void Dart::WaitForIsolateShutdown() { |
| 201 ASSERT(!Isolate::creation_enabled_); |
| 202 MonitorLocker ml(Isolate::isolates_list_monitor_); |
| 203 while ((Isolate::isolates_list_head_ != NULL) && |
| 204 (Isolate::isolates_list_head_->next_ != NULL)) { |
| 205 ml.Wait(); |
| 206 } |
| 207 ASSERT(Isolate::isolates_list_head_ == Dart::vm_isolate()); |
| 208 } |
| 209 |
| 210 |
198 const char* Dart::Cleanup() { | 211 const char* Dart::Cleanup() { |
199 // Shutdown the service isolate before shutting down the thread pool. | 212 ASSERT(Isolate::Current() == NULL); |
200 ServiceIsolate::Shutdown(); | |
201 #if 0 | |
202 // Ideally we should shutdown the VM isolate here, but the thread pool | |
203 // shutdown does not seem to ensure that all the threads have stopped | |
204 // execution before it terminates, this results in racing isolates. | |
205 if (vm_isolate_ == NULL) { | 213 if (vm_isolate_ == NULL) { |
206 return "VM already terminated."; | 214 return "VM already terminated."; |
207 } | 215 } |
208 | 216 |
209 ASSERT(Isolate::Current() == NULL); | 217 // Shut dwon profiling. |
| 218 Profiler::Shutdown(); |
210 | 219 |
211 delete thread_pool_; | 220 if (FLAG_shutdown) { |
212 thread_pool_ = NULL; | 221 // Disable the creation of new isolates. |
| 222 Isolate::DisableIsolateCreation(); |
213 | 223 |
214 // Set the VM isolate as current isolate. | 224 // Send the OOB Kill message to all remaining application isolates. |
215 Thread::EnsureInit(); | 225 Isolate::KillAllIsolates(); |
216 Thread::EnterIsolate(vm_isolate_); | |
217 | 226 |
218 // There is a planned and known asymmetry here: We exit one scope for the VM | 227 // Shutdown the service isolate. |
219 // isolate to account for the scope that was entered in Dart_InitOnce. | 228 ServiceIsolate::Shutdown(); |
220 Dart_ExitScope(); | |
221 | 229 |
222 ShutdownIsolate(); | 230 // Wait for all application isolates and the service isolate to shutdown |
223 vm_isolate_ = NULL; | 231 // before shutting down the thread pool. |
| 232 WaitForIsolateShutdown(); |
224 | 233 |
225 TargetCPUFeatures::Cleanup(); | 234 // Shutdown the thread pool. On return, all thread pool threads have exited. |
226 StoreBuffer::ShutDown(); | 235 delete thread_pool_; |
227 #endif | 236 thread_pool_ = NULL; |
228 | 237 |
229 Profiler::Shutdown(); | 238 // Set the VM isolate as current isolate. |
| 239 Thread::EnsureInit(); |
| 240 Thread::EnterIsolate(vm_isolate_); |
| 241 |
| 242 ShutdownIsolate(); |
| 243 vm_isolate_ = NULL; |
| 244 ASSERT(Isolate::IsolateListLength() == 0); |
| 245 |
| 246 TargetCPUFeatures::Cleanup(); |
| 247 StoreBuffer::ShutDown(); |
| 248 } else { |
| 249 // Shutdown the service isolate. |
| 250 ServiceIsolate::Shutdown(); |
| 251 } |
| 252 |
230 CodeObservers::DeleteAll(); | 253 CodeObservers::DeleteAll(); |
231 Timeline::Shutdown(); | 254 Timeline::Shutdown(); |
232 Metric::Cleanup(); | 255 Metric::Cleanup(); |
233 | 256 |
234 return NULL; | 257 return NULL; |
235 } | 258 } |
236 | 259 |
237 | 260 |
238 Isolate* Dart::CreateIsolate(const char* name_prefix, | 261 Isolate* Dart::CreateIsolate(const char* name_prefix, |
239 const Dart_IsolateFlags& api_flags) { | 262 const Dart_IsolateFlags& api_flags) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 return predefined_handles_->handles_.IsValidScopedHandle(address); | 403 return predefined_handles_->handles_.IsValidScopedHandle(address); |
381 } | 404 } |
382 | 405 |
383 | 406 |
384 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 407 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
385 ASSERT(predefined_handles_ != NULL); | 408 ASSERT(predefined_handles_ != NULL); |
386 return predefined_handles_->api_handles_.IsValidHandle(handle); | 409 return predefined_handles_->api_handles_.IsValidHandle(handle); |
387 } | 410 } |
388 | 411 |
389 } // namespace dart | 412 } // namespace dart |
OLD | NEW |