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

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

Issue 1275353005: VM thread shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge Created 5 years, 3 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/service_isolate.h ('k') | runtime/vm/thread_interrupter.h » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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/service_isolate.h" 5 #include "vm/service_isolate.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 isolate->message_handler()->Run(Dart::thread_pool(), 668 isolate->message_handler()->Run(Dart::thread_pool(),
669 NULL, 669 NULL,
670 ShutdownIsolate, 670 ShutdownIsolate,
671 reinterpret_cast<uword>(isolate)); 671 reinterpret_cast<uword>(isolate));
672 } 672 }
673 673
674 protected: 674 protected:
675 static void ShutdownIsolate(uword parameter) { 675 static void ShutdownIsolate(uword parameter) {
676 Isolate* I = reinterpret_cast<Isolate*>(parameter); 676 Isolate* I = reinterpret_cast<Isolate*>(parameter);
677 ASSERT(ServiceIsolate::IsServiceIsolate(I)); 677 ASSERT(ServiceIsolate::IsServiceIsolate(I));
678 ServiceIsolate::SetServiceIsolate(NULL);
679 ServiceIsolate::SetServicePort(ILLEGAL_PORT);
678 { 680 {
679 // Print the error if there is one. This may execute dart code to 681 // Print the error if there is one. This may execute dart code to
680 // print the exception object, so we need to use a StartIsolateScope. 682 // print the exception object, so we need to use a StartIsolateScope.
681 StartIsolateScope start_scope(I); 683 StartIsolateScope start_scope(I);
682 Thread* T = Thread::Current(); 684 Thread* T = Thread::Current();
683 ASSERT(I == T->isolate()); 685 ASSERT(I == T->isolate());
684 StackZone zone(T); 686 StackZone zone(T);
685 HandleScope handle_scope(T); 687 HandleScope handle_scope(T);
686 Error& error = Error::Handle(Z); 688 Error& error = Error::Handle(Z);
687 error = I->object_store()->sticky_error(); 689 error = I->object_store()->sticky_error();
688 if (!error.IsNull()) { 690 if (!error.IsNull()) {
689 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString()); 691 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString());
690 } 692 }
691 Dart::RunShutdownCallback(); 693 Dart::RunShutdownCallback();
692 } 694 }
693 { 695 {
694 // Shut the isolate down. 696 // Shut the isolate down.
695 SwitchIsolateScope switch_scope(I); 697 SwitchIsolateScope switch_scope(I);
696 Dart::ShutdownIsolate(); 698 Dart::ShutdownIsolate();
697 } 699 }
698 ServiceIsolate::SetServiceIsolate(NULL);
699 ServiceIsolate::SetServicePort(ILLEGAL_PORT);
700 if (FLAG_trace_service) { 700 if (FLAG_trace_service) {
701 OS::Print("vm-service: Shutdown.\n"); 701 OS::Print("vm-service: Shutdown.\n");
702 } 702 }
703 ServiceIsolate::FinishedExiting(); 703 ServiceIsolate::FinishedExiting();
704 } 704 }
705 705
706 void RunMain(Isolate* I) { 706 void RunMain(Isolate* I) {
707 StartIsolateScope iso_scope(I); 707 StartIsolateScope iso_scope(I);
708 Thread* T = Thread::Current(); 708 Thread* T = Thread::Current();
709 ASSERT(I == T->isolate()); 709 ASSERT(I == T->isolate());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 ASSERT(monitor_ == NULL); 755 ASSERT(monitor_ == NULL);
756 monitor_ = new Monitor(); 756 monitor_ = new Monitor();
757 ASSERT(monitor_ != NULL); 757 ASSERT(monitor_ != NULL);
758 // Grab the isolate create callback here to avoid race conditions with tests 758 // Grab the isolate create callback here to avoid race conditions with tests
759 // that change this after Dart_Initialize returns. 759 // that change this after Dart_Initialize returns.
760 create_callback_ = Isolate::CreateCallback(); 760 create_callback_ = Isolate::CreateCallback();
761 Dart::thread_pool()->Run(new RunServiceTask()); 761 Dart::thread_pool()->Run(new RunServiceTask());
762 } 762 }
763 763
764 764
765 void ServiceIsolate::KillServiceIsolate() {
766 {
767 MonitorLocker ml(monitor_);
768 shutting_down_ = true;
769 }
770 Isolate::KillIfExists(isolate_);
771 {
772 MonitorLocker ml(monitor_);
773 while (shutting_down_) {
774 ml.Wait();
775 }
776 }
777 }
778
779
765 void ServiceIsolate::Shutdown() { 780 void ServiceIsolate::Shutdown() {
766 if (!IsRunning()) { 781 if (!IsRunning()) {
782 if (isolate_ != NULL) {
783 // TODO(johnmccutchan,turnidge) When it is possible to properly create
784 // the VMService object and set up its shutdown handler in the service
785 // isolate's main() function, this case will no longer be possible and
786 // can be removed.
787 KillServiceIsolate();
788 }
767 return; 789 return;
768 } 790 }
769 { 791 {
770 MonitorLocker ml(monitor_); 792 MonitorLocker ml(monitor_);
771 shutting_down_ = true; 793 shutting_down_ = true;
772 } 794 }
773 SendServiceExitMessage(); 795 SendServiceExitMessage();
774 { 796 {
775 MonitorLocker ml(monitor_); 797 MonitorLocker ml(monitor_);
776 while (shutting_down_ && (port_ != ILLEGAL_PORT)) { 798 while (shutting_down_ && (port_ != ILLEGAL_PORT)) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 return result; 842 return result;
821 } 843 }
822 Dart_Handle source = GetSource(url_string); 844 Dart_Handle source = GetSource(url_string);
823 if (Dart_IsError(source)) { 845 if (Dart_IsError(source)) {
824 return source; 846 return source;
825 } 847 }
826 return Dart_LoadSource(library, url, source, 0, 0); 848 return Dart_LoadSource(library, url, source, 0, 0);
827 } 849 }
828 850
829 } // namespace dart 851 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service_isolate.h ('k') | runtime/vm/thread_interrupter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698