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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 Metric::InitOnce(); | 107 Metric::InitOnce(); |
108 StoreBuffer::InitOnce(); | 108 StoreBuffer::InitOnce(); |
109 | 109 |
110 #if defined(USING_SIMULATOR) | 110 #if defined(USING_SIMULATOR) |
111 Simulator::InitOnce(); | 111 Simulator::InitOnce(); |
112 #endif | 112 #endif |
113 // Create the read-only handles area. | 113 // Create the read-only handles area. |
114 ASSERT(predefined_handles_ == NULL); | 114 ASSERT(predefined_handles_ == NULL); |
115 predefined_handles_ = new ReadOnlyHandles(); | 115 predefined_handles_ = new ReadOnlyHandles(); |
116 // Create the VM isolate and finish the VM initialization. | 116 // Create the VM isolate and finish the VM initialization. |
117 ASSERT(thread_pool_ == NULL); | |
118 thread_pool_ = new ThreadPool(); | |
119 { | 117 { |
120 ASSERT(vm_isolate_ == NULL); | 118 ASSERT(vm_isolate_ == NULL); |
121 ASSERT(Flags::Initialized()); | 119 ASSERT(Flags::Initialized()); |
122 const bool is_vm_isolate = true; | 120 const bool is_vm_isolate = true; |
123 Thread::EnsureInit(); | 121 Thread::EnsureInit(); |
124 | 122 |
125 // Setup default flags for the VM isolate. | 123 // Setup default flags for the VM isolate. |
126 Isolate::Flags vm_flags; | 124 Isolate::Flags vm_flags; |
127 Dart_IsolateFlags api_flags; | 125 Dart_IsolateFlags api_flags; |
128 vm_flags.CopyTo(&api_flags); | 126 vm_flags.CopyTo(&api_flags); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 Isolate::SetUnhandledExceptionCallback(unhandled); | 189 Isolate::SetUnhandledExceptionCallback(unhandled); |
192 Isolate::SetShutdownCallback(shutdown); | 190 Isolate::SetShutdownCallback(shutdown); |
193 | 191 |
194 ServiceIsolate::Run(); | 192 ServiceIsolate::Run(); |
195 | 193 |
196 return NULL; | 194 return NULL; |
197 } | 195 } |
198 | 196 |
199 | 197 |
200 const char* Dart::Cleanup() { | 198 const char* Dart::Cleanup() { |
201 // Shutdown the service isolate before shutting down the thread pool. | 199 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) { | 200 if (vm_isolate_ == NULL) { |
208 return "VM already terminated."; | 201 return "VM already terminated."; |
209 } | 202 } |
210 | 203 |
211 ASSERT(Isolate::Current() == NULL); | 204 // Shutdown the service isolate before shutting down the thread pool. |
| 205 ServiceIsolate::Shutdown(); |
212 | 206 |
213 delete thread_pool_; | 207 // Shutdown the thread pool. On return, all thread pool threads have exited. |
214 thread_pool_ = NULL; | 208 ThreadPool::Shutdown(); |
215 | 209 |
216 // Set the VM isolate as current isolate. | 210 // Set the VM isolate as current isolate. |
217 Thread::EnsureInit(); | 211 Thread::EnsureInit(); |
218 Thread::EnterIsolate(vm_isolate_); | 212 Thread::EnterIsolate(vm_isolate_); |
219 | 213 |
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(); | 214 ShutdownIsolate(); |
225 vm_isolate_ = NULL; | 215 vm_isolate_ = NULL; |
226 | 216 |
227 TargetCPUFeatures::Cleanup(); | 217 TargetCPUFeatures::Cleanup(); |
228 #endif | |
229 | 218 |
230 Profiler::Shutdown(); | 219 Profiler::Shutdown(); |
231 CodeObservers::DeleteAll(); | 220 CodeObservers::DeleteAll(); |
232 | 221 |
233 return NULL; | 222 return NULL; |
234 } | 223 } |
235 | 224 |
236 | 225 |
237 Isolate* Dart::CreateIsolate(const char* name_prefix, | 226 Isolate* Dart::CreateIsolate(const char* name_prefix, |
238 const Dart_IsolateFlags& api_flags) { | 227 const Dart_IsolateFlags& api_flags) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 return predefined_handles_->handles_.IsValidScopedHandle(address); | 362 return predefined_handles_->handles_.IsValidScopedHandle(address); |
374 } | 363 } |
375 | 364 |
376 | 365 |
377 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 366 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
378 ASSERT(predefined_handles_ != NULL); | 367 ASSERT(predefined_handles_ != NULL); |
379 return predefined_handles_->api_handles_.IsValidHandle(handle); | 368 return predefined_handles_->api_handles_.IsValidHandle(handle); |
380 } | 369 } |
381 | 370 |
382 } // namespace dart | 371 } // namespace dart |
OLD | NEW |