Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: runtime/vm/dart.cc

Issue 1177153005: Enables clean VM shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix error propagation Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/custom_isolate_test.cc ('k') | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 Isolate::SetUnhandledExceptionCallback(unhandled); 178 Isolate::SetUnhandledExceptionCallback(unhandled);
178 Isolate::SetShutdownCallback(shutdown); 179 Isolate::SetShutdownCallback(shutdown);
179 180
180 ServiceIsolate::Run(); 181 ServiceIsolate::Run();
181 182
182 return NULL; 183 return NULL;
183 } 184 }
184 185
185 186
186 const char* Dart::Cleanup() { 187 const char* Dart::Cleanup() {
187 // Shutdown the service isolate before shutting down the thread pool. 188 ASSERT(Isolate::Current() == NULL);
188 ServiceIsolate::Shutdown();
189 #if 0
190 // Ideally we should shutdown the VM isolate here, but the thread pool
191 // shutdown does not seem to ensure that all the threads have stopped
192 // execution before it terminates, this results in racing isolates.
193 if (vm_isolate_ == NULL) { 189 if (vm_isolate_ == NULL) {
194 return "VM already terminated."; 190 return "VM already terminated.";
195 } 191 }
196 192
197 ASSERT(Isolate::Current() == NULL); 193 // Disable the creation of new isolates.
194 Isolate::DisableIsolateCreation();
198 195
196 // Send the OOB Kill message to all remaining isolates.
197 Isolate::KillAllIsolates();
198
199 // Shutdown the service isolate before shutting down the thread pool.
200 ServiceIsolate::Shutdown();
201
202 // Shutdown the thread pool. On return, all thread pool threads have exited.
199 delete thread_pool_; 203 delete thread_pool_;
200 thread_pool_ = NULL; 204 thread_pool_ = NULL;
201 205
202 // Set the VM isolate as current isolate. 206 // Set the VM isolate as current isolate.
203 Thread::EnsureInit(); 207 Thread::EnsureInit();
204 Thread::EnterIsolate(vm_isolate_); 208 Thread::EnterIsolate(vm_isolate_);
205 209
206 // There is a planned and known asymmetry here: We exit one scope for the VM
207 // isolate to account for the scope that was entered in Dart_InitOnce.
208 Dart_ExitScope();
209
210 ShutdownIsolate(); 210 ShutdownIsolate();
211 vm_isolate_ = NULL; 211 vm_isolate_ = NULL;
212 212
213 TargetCPUFeatures::Cleanup(); 213 TargetCPUFeatures::Cleanup();
214 #endif
215
216 Profiler::Shutdown(); 214 Profiler::Shutdown();
217 CodeObservers::DeleteAll(); 215 CodeObservers::DeleteAll();
218 216
217 ASSERT(Isolate::IsolateListLength() == 0);
219 return NULL; 218 return NULL;
220 } 219 }
221 220
222 221
223 Isolate* Dart::CreateIsolate(const char* name_prefix, 222 Isolate* Dart::CreateIsolate(const char* name_prefix,
224 const Dart_IsolateFlags& api_flags) { 223 const Dart_IsolateFlags& api_flags) {
225 // Create a new isolate. 224 // Create a new isolate.
226 Isolate* isolate = Isolate::Init(name_prefix, api_flags); 225 Isolate* isolate = Isolate::Init(name_prefix, api_flags);
227 ASSERT(isolate != NULL);
228 return isolate; 226 return isolate;
229 } 227 }
230 228
231 229
232 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { 230 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) {
233 // Initialize the new isolate. 231 // Initialize the new isolate.
234 Isolate* isolate = Isolate::Current(); 232 Isolate* isolate = Isolate::Current();
235 TIMERSCOPE(isolate, time_isolate_initialization); 233 TIMERSCOPE(isolate, time_isolate_initialization);
236 ASSERT(isolate != NULL); 234 ASSERT(isolate != NULL);
237 StackZone zone(isolate); 235 StackZone zone(isolate);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 return predefined_handles_->handles_.IsValidScopedHandle(address); 353 return predefined_handles_->handles_.IsValidScopedHandle(address);
356 } 354 }
357 355
358 356
359 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { 357 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) {
360 ASSERT(predefined_handles_ != NULL); 358 ASSERT(predefined_handles_ != NULL);
361 return predefined_handles_->api_handles_.IsValidHandle(handle); 359 return predefined_handles_->api_handles_.IsValidHandle(handle);
362 } 360 }
363 361
364 } // namespace dart 362 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/custom_isolate_test.cc ('k') | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698