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/become.h" | 7 #include "vm/become.h" |
8 #include "vm/code_observers.h" | 8 #include "vm/code_observers.h" |
9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 if (FLAG_support_service) { | 303 if (FLAG_support_service) { |
304 Service::SetGetServiceAssetsCallback(get_service_assets); | 304 Service::SetGetServiceAssetsCallback(get_service_assets); |
305 } | 305 } |
306 | 306 |
307 ServiceIsolate::Run(); | 307 ServiceIsolate::Run(); |
308 | 308 |
309 return NULL; | 309 return NULL; |
310 } | 310 } |
311 | 311 |
312 | 312 |
| 313 // This waits until only the VM isolate and the service isolate remains in the |
| 314 // list, i.e. list length == 2. |
| 315 void Dart::WaitForApplicationIsolateShutdown() { |
| 316 ASSERT(!Isolate::creation_enabled_); |
| 317 MonitorLocker ml(Isolate::isolates_list_monitor_); |
| 318 while ((Isolate::isolates_list_head_ != NULL) && |
| 319 (Isolate::isolates_list_head_->next_ != NULL) && |
| 320 (Isolate::isolates_list_head_->next_->next_ != NULL)) { |
| 321 ml.Wait(); |
| 322 } |
| 323 ASSERT( |
| 324 ((Isolate::isolates_list_head_ == Dart::vm_isolate()) && |
| 325 ServiceIsolate::IsServiceIsolate(Isolate::isolates_list_head_->next_)) || |
| 326 ((Isolate::isolates_list_head_->next_ == Dart::vm_isolate()) && |
| 327 ServiceIsolate::IsServiceIsolate(Isolate::isolates_list_head_))); |
| 328 } |
| 329 |
| 330 |
313 // This waits until only the VM isolate remains in the list. | 331 // This waits until only the VM isolate remains in the list. |
314 void Dart::WaitForIsolateShutdown() { | 332 void Dart::WaitForIsolateShutdown() { |
315 ASSERT(!Isolate::creation_enabled_); | 333 ASSERT(!Isolate::creation_enabled_); |
316 MonitorLocker ml(Isolate::isolates_list_monitor_); | 334 MonitorLocker ml(Isolate::isolates_list_monitor_); |
317 while ((Isolate::isolates_list_head_ != NULL) && | 335 while ((Isolate::isolates_list_head_ != NULL) && |
318 (Isolate::isolates_list_head_->next_ != NULL)) { | 336 (Isolate::isolates_list_head_->next_ != NULL)) { |
319 ml.Wait(); | 337 ml.Wait(); |
320 } | 338 } |
321 ASSERT(Isolate::isolates_list_head_ == Dart::vm_isolate()); | 339 ASSERT(Isolate::isolates_list_head_ == Dart::vm_isolate()); |
322 } | 340 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } | 382 } |
365 Isolate::DisableIsolateCreation(); | 383 Isolate::DisableIsolateCreation(); |
366 | 384 |
367 // Send the OOB Kill message to all remaining application isolates. | 385 // Send the OOB Kill message to all remaining application isolates. |
368 if (FLAG_trace_shutdown) { | 386 if (FLAG_trace_shutdown) { |
369 OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Killing all app isolates\n", | 387 OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Killing all app isolates\n", |
370 timestamp()); | 388 timestamp()); |
371 } | 389 } |
372 Isolate::KillAllIsolates(Isolate::kInternalKillMsg); | 390 Isolate::KillAllIsolates(Isolate::kInternalKillMsg); |
373 | 391 |
| 392 // Wait for all isolates, but the service and the vm isolate to shut down. |
| 393 // Only do that if there is a service isolate running. |
| 394 if (ServiceIsolate::IsRunning()) { |
| 395 if (FLAG_trace_shutdown) { |
| 396 OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Shutting down app isolates\n", |
| 397 timestamp()); |
| 398 } |
| 399 WaitForApplicationIsolateShutdown(); |
| 400 } |
| 401 |
374 // Shutdown the service isolate. | 402 // Shutdown the service isolate. |
375 if (FLAG_trace_shutdown) { | 403 if (FLAG_trace_shutdown) { |
376 OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Shutting down service isolate\n", | 404 OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Shutting down service isolate\n", |
377 timestamp()); | 405 timestamp()); |
378 } | 406 } |
379 ServiceIsolate::Shutdown(); | 407 ServiceIsolate::Shutdown(); |
380 | 408 |
381 // Wait for all application isolates and the service isolate to shutdown | 409 // Wait for the remaining isolate (service isolate) to shutdown |
382 // before shutting down the thread pool. | 410 // before shutting down the thread pool. |
383 if (FLAG_trace_shutdown) { | 411 if (FLAG_trace_shutdown) { |
384 OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Waiting for isolate shutdown\n", | 412 OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Waiting for isolate shutdown\n", |
385 timestamp()); | 413 timestamp()); |
386 } | 414 } |
387 WaitForIsolateShutdown(); | 415 WaitForIsolateShutdown(); |
388 | 416 |
389 // Shutdown the thread pool. On return, all thread pool threads have exited. | 417 // Shutdown the thread pool. On return, all thread pool threads have exited. |
390 if (FLAG_trace_shutdown) { | 418 if (FLAG_trace_shutdown) { |
391 OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Deleting thread pool\n", | 419 OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Deleting thread pool\n", |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 return predefined_handles_->handles_.IsValidScopedHandle(address); | 733 return predefined_handles_->handles_.IsValidScopedHandle(address); |
706 } | 734 } |
707 | 735 |
708 | 736 |
709 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 737 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
710 ASSERT(predefined_handles_ != NULL); | 738 ASSERT(predefined_handles_ != NULL); |
711 return predefined_handles_->api_handles_.IsValidHandle(handle); | 739 return predefined_handles_->api_handles_.IsValidHandle(handle); |
712 } | 740 } |
713 | 741 |
714 } // namespace dart | 742 } // namespace dart |
OLD | NEW |