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

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

Issue 1279733003: Clean VM thread shutdown: (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 Isolate::SetUnhandledExceptionCallback(unhandled); 179 Isolate::SetUnhandledExceptionCallback(unhandled);
179 Isolate::SetShutdownCallback(shutdown); 180 Isolate::SetShutdownCallback(shutdown);
180 181
181 ServiceIsolate::Run(); 182 ServiceIsolate::Run();
182 183
183 return NULL; 184 return NULL;
184 } 185 }
185 186
186 187
187 const char* Dart::Cleanup() { 188 const char* Dart::Cleanup() {
188 // Shutdown the service isolate before shutting down the thread pool. 189 ASSERT(Isolate::Current() == NULL);
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.
194 if (vm_isolate_ == NULL) { 190 if (vm_isolate_ == NULL) {
195 return "VM already terminated."; 191 return "VM already terminated.";
196 } 192 }
197 193
198 ASSERT(Isolate::Current() == NULL); 194 // Disable the creation of new isolates.
195 Isolate::DisableIsolateCreation();
199 196
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.
200 delete thread_pool_; 204 delete thread_pool_;
201 thread_pool_ = NULL; 205 thread_pool_ = NULL;
202 206
203 // Set the VM isolate as current isolate. 207 // Set the VM isolate as current isolate.
204 Thread::EnsureInit(); 208 Thread::EnsureInit();
205 Thread::EnterIsolate(vm_isolate_); 209 Thread::EnterIsolate(vm_isolate_);
206 210
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
217 Profiler::Shutdown(); 215 Profiler::Shutdown();
218 CodeObservers::DeleteAll(); 216 CodeObservers::DeleteAll();
219 217
218 ASSERT(Isolate::IsolateListLength() == 0);
220 return NULL; 219 return NULL;
221 } 220 }
222 221
223 222
224 Isolate* Dart::CreateIsolate(const char* name_prefix, 223 Isolate* Dart::CreateIsolate(const char* name_prefix,
225 const Dart_IsolateFlags& api_flags) { 224 const Dart_IsolateFlags& api_flags) {
226 // Create a new isolate. 225 // Create a new isolate.
227 Isolate* isolate = Isolate::Init(name_prefix, api_flags); 226 Isolate* isolate = Isolate::Init(name_prefix, api_flags);
228 ASSERT(isolate != NULL);
229 return isolate; 227 return isolate;
230 } 228 }
231 229
232 230
233 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { 231 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) {
234 // Initialize the new isolate. 232 // Initialize the new isolate.
235 Isolate* isolate = Isolate::Current(); 233 Isolate* isolate = Isolate::Current();
236 TIMERSCOPE(isolate, time_isolate_initialization); 234 TIMERSCOPE(isolate, time_isolate_initialization);
237 ASSERT(isolate != NULL); 235 ASSERT(isolate != NULL);
238 StackZone zone(isolate); 236 StackZone zone(isolate);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 return predefined_handles_->handles_.IsValidScopedHandle(address); 359 return predefined_handles_->handles_.IsValidScopedHandle(address);
362 } 360 }
363 361
364 362
365 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { 363 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) {
366 ASSERT(predefined_handles_ != NULL); 364 ASSERT(predefined_handles_ != NULL);
367 return predefined_handles_->api_handles_.IsValidHandle(handle); 365 return predefined_handles_->api_handles_.IsValidHandle(handle);
368 } 366 }
369 367
370 } // namespace dart 368 } // 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