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

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

Issue 1555643002: Thread fixes for shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 11 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 | « no previous file | runtime/vm/os_thread.cc » ('j') | runtime/vm/os_thread.cc » ('J')
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"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 ASSERT(Isolate::isolates_list_head_ == Dart::vm_isolate()); 215 ASSERT(Isolate::isolates_list_head_ == Dart::vm_isolate());
216 } 216 }
217 217
218 218
219 const char* Dart::Cleanup() { 219 const char* Dart::Cleanup() {
220 ASSERT(Isolate::Current() == NULL); 220 ASSERT(Isolate::Current() == NULL);
221 if (vm_isolate_ == NULL) { 221 if (vm_isolate_ == NULL) {
222 return "VM already terminated."; 222 return "VM already terminated.";
223 } 223 }
224 224
225 // Disable creation of any new OSThread structures which means no more new
226 // threads can do an EnterIsolate.
227 OSThread::DisableOSThreadCreation();
228
229 // Shut down profiling. 225 // Shut down profiling.
230 Profiler::Shutdown(); 226 Profiler::Shutdown();
231 227
232 { 228 {
233 // Set the VM isolate as current isolate when shutting down 229 // Set the VM isolate as current isolate when shutting down
234 // Metrics so that we can use a StackZone. 230 // Metrics so that we can use a StackZone.
235 bool result = Thread::EnterIsolate(vm_isolate_); 231 bool result = Thread::EnterIsolate(vm_isolate_);
236 ASSERT(result); 232 ASSERT(result);
237 Metric::Cleanup(); 233 Metric::Cleanup();
238 Thread::ExitIsolate(); 234 Thread::ExitIsolate();
239 } 235 }
240 236
241 if (FLAG_shutdown) { 237 if (FLAG_shutdown) {
242 // Disable the creation of new isolates. 238 // Disable the creation of new isolates.
243 Isolate::DisableIsolateCreation(); 239 Isolate::DisableIsolateCreation();
244 240
245 // Send the OOB Kill message to all remaining application isolates. 241 // Send the OOB Kill message to all remaining application isolates.
246 Isolate::KillAllIsolates(Isolate::kInternalKillMsg); 242 Isolate::KillAllIsolates(Isolate::kInternalKillMsg);
247 243
248 // Shutdown the service isolate. 244 // Shutdown the service isolate.
249 ServiceIsolate::Shutdown(); 245 ServiceIsolate::Shutdown();
250 246
251 // Wait for all application isolates and the service isolate to shutdown 247 // Wait for all application isolates and the service isolate to shutdown
252 // before shutting down the thread pool. 248 // before shutting down the thread pool.
253 WaitForIsolateShutdown(); 249 WaitForIsolateShutdown();
254 250
251 // Disable creation of any new OSThread structures which means no more new
252 // threads can do an EnterIsolate. This must come after isolate shutdown
253 // because new threads may need to be spawned to shutdown the isolates.
254 OSThread::DisableOSThreadCreation();
255
255 // Shutdown the thread pool. On return, all thread pool threads have exited. 256 // Shutdown the thread pool. On return, all thread pool threads have exited.
256 delete thread_pool_; 257 delete thread_pool_;
257 thread_pool_ = NULL; 258 thread_pool_ = NULL;
258 259
259 // Set the VM isolate as current isolate. 260 // Set the VM isolate as current isolate.
260 bool result = Thread::EnterIsolate(vm_isolate_); 261 bool result = Thread::EnterIsolate(vm_isolate_);
261 ASSERT(result); 262 ASSERT(result);
262 263
263 ShutdownIsolate(); 264 ShutdownIsolate();
264 vm_isolate_ = NULL; 265 vm_isolate_ = NULL;
265 ASSERT(Isolate::IsolateListLength() == 0); 266 ASSERT(Isolate::IsolateListLength() == 0);
266 267
267 TargetCPUFeatures::Cleanup(); 268 TargetCPUFeatures::Cleanup();
268 StoreBuffer::ShutDown(); 269 StoreBuffer::ShutDown();
269 270
270 // Delete the current thread's TLS and set it's TLS to null. 271 // Delete the current thread's TLS and set it's TLS to null.
271 // If it is the last thread then the destructor would call 272 // If it is the last thread then the destructor would call
272 // OSThread::Cleanup. 273 // OSThread::Cleanup.
273 OSThread* os_thread = OSThread::Current(); 274 OSThread* os_thread = OSThread::Current();
274 OSThread::SetCurrent(NULL); 275 OSThread::SetCurrent(NULL);
275 delete os_thread; 276 delete os_thread;
276 } else { 277 } else {
277 // Shutdown the service isolate. 278 // Shutdown the service isolate.
278 ServiceIsolate::Shutdown(); 279 ServiceIsolate::Shutdown();
280
281 // Disable thread creation.
282 OSThread::DisableOSThreadCreation();
279 } 283 }
280 284
281 CodeObservers::DeleteAll(); 285 CodeObservers::DeleteAll();
282 Timeline::Shutdown(); 286 Timeline::Shutdown();
283 287
284 return NULL; 288 return NULL;
285 } 289 }
286 290
287 291
288 Isolate* Dart::CreateIsolate(const char* name_prefix, 292 Isolate* Dart::CreateIsolate(const char* name_prefix,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 return predefined_handles_->handles_.IsValidScopedHandle(address); 452 return predefined_handles_->handles_.IsValidScopedHandle(address);
449 } 453 }
450 454
451 455
452 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { 456 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) {
453 ASSERT(predefined_handles_ != NULL); 457 ASSERT(predefined_handles_ != NULL);
454 return predefined_handles_->api_handles_.IsValidHandle(handle); 458 return predefined_handles_->api_handles_.IsValidHandle(handle);
455 } 459 }
456 460
457 } // namespace dart 461 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/os_thread.cc » ('j') | runtime/vm/os_thread.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698