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

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

Issue 891343006: Always use isolate creation callback passed to Dart_Initialize for service isolate startup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/service.h ('k') | no next file » | 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/service.h" 5 #include "vm/service.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 for (intptr_t i = 0; i < n; i++) { 490 for (intptr_t i = 0; i < n; i++) {
491 VmServiceNativeEntry entry = _VmServiceNativeEntries[i]; 491 VmServiceNativeEntry entry = _VmServiceNativeEntries[i];
492 if ((strcmp(function_name, entry.name) == 0) && 492 if ((strcmp(function_name, entry.name) == 0) &&
493 (num_arguments == entry.num_arguments)) { 493 (num_arguments == entry.num_arguments)) {
494 return entry.function; 494 return entry.function;
495 } 495 }
496 } 496 }
497 return NULL; 497 return NULL;
498 } 498 }
499 499
500 const char* Service::kServiceIsolateName = "vm-service"; 500 const char* Service::kIsolateName = "vm-service";
501 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; 501 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL;
502 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; 502 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL;
503 Isolate* Service::service_isolate_ = NULL; 503 Isolate* Service::service_isolate_ = NULL;
504 Dart_Port Service::service_port_ = ILLEGAL_PORT; 504 Dart_Port Service::service_port_ = ILLEGAL_PORT;
505 Dart_Port Service::load_port_ = ILLEGAL_PORT; 505 Dart_Port Service::load_port_ = ILLEGAL_PORT;
506 Dart_IsolateCreateCallback Service::create_callback_ = NULL;
506 Monitor* Service::monitor_ = NULL; 507 Monitor* Service::monitor_ = NULL;
507 bool Service::initializing_ = true; 508 bool Service::initializing_ = true;
508 uint32_t Service::event_mask_ = 0; 509 uint32_t Service::event_mask_ = 0;
509 510
510 511
511 bool Service::IsServiceIsolateName(const char* name) { 512 bool Service::IsServiceIsolateName(const char* name) {
512 ASSERT(name != NULL); 513 ASSERT(name != NULL);
513 return strcmp(name, kServiceIsolateName) == 0; 514 return strcmp(name, kIsolateName) == 0;
514 } 515 }
515 516
516 517
517 bool Service::SendIsolateStartupMessage() { 518 bool Service::SendIsolateStartupMessage() {
518 if (!IsRunning()) { 519 if (!IsRunning()) {
519 return false; 520 return false;
520 } 521 }
521 Isolate* isolate = Isolate::Current(); 522 Isolate* isolate = Isolate::Current();
522 if (IsServiceIsolate(isolate)) { 523 if (IsServiceIsolate(isolate)) {
523 return false; 524 return false;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 } 711 }
711 712
712 713
713 class RunServiceTask : public ThreadPool::Task { 714 class RunServiceTask : public ThreadPool::Task {
714 public: 715 public:
715 virtual void Run() { 716 virtual void Run() {
716 ASSERT(Isolate::Current() == NULL); 717 ASSERT(Isolate::Current() == NULL);
717 char* error = NULL; 718 char* error = NULL;
718 Isolate* isolate = NULL; 719 Isolate* isolate = NULL;
719 720
720 Dart_IsolateCreateCallback create_callback = Isolate::CreateCallback(); 721 Dart_IsolateCreateCallback create_callback = Service::create_callback();
722 // TODO(johnmccutchan): Support starting up service isolate without embedder
723 // provided isolate creation callback.
721 if (create_callback == NULL) { 724 if (create_callback == NULL) {
722 Service::FinishedInitializing(); 725 Service::FinishedInitializing();
723 return; 726 return;
724 } 727 }
725 728
726 isolate = 729 isolate =
727 reinterpret_cast<Isolate*>(create_callback(Service::kServiceIsolateName, 730 reinterpret_cast<Isolate*>(create_callback(Service::kIsolateName,
728 NULL, 731 NULL,
729 NULL, 732 NULL,
730 NULL, 733 NULL,
731 &error)); 734 &error));
732 Isolate::SetCurrent(NULL);
733
734 if (isolate == NULL) { 735 if (isolate == NULL) {
735 OS::PrintErr("vm-service: Isolate creation error: %s\n", error); 736 OS::PrintErr("vm-service: Isolate creation error: %s\n", error);
736 Service::FinishedInitializing(); 737 Service::FinishedInitializing();
737 return; 738 return;
738 } 739 }
739 740
741 Isolate::SetCurrent(NULL);
742
740 RunMain(isolate); 743 RunMain(isolate);
741 744
742 Service::FinishedInitializing(); 745 Service::FinishedInitializing();
743 746
744 isolate->message_handler()->Run(Dart::thread_pool(), 747 isolate->message_handler()->Run(Dart::thread_pool(),
745 NULL, 748 NULL,
746 ShutdownIsolate, 749 ShutdownIsolate,
747 reinterpret_cast<uword>(isolate)); 750 reinterpret_cast<uword>(isolate));
748 } 751 }
749 752
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 const ReceivePort& rp = ReceivePort::Cast(result); 797 const ReceivePort& rp = ReceivePort::Cast(result);
795 Service::SetLoadPort(rp.Id()); 798 Service::SetLoadPort(rp.Id());
796 } 799 }
797 }; 800 };
798 801
799 802
800 void Service::RunService() { 803 void Service::RunService() {
801 ASSERT(monitor_ == NULL); 804 ASSERT(monitor_ == NULL);
802 monitor_ = new Monitor(); 805 monitor_ = new Monitor();
803 ASSERT(monitor_ != NULL); 806 ASSERT(monitor_ != NULL);
807 // Grab the isolate create callback here to avoid race conditions with tests
808 // that change this after Dart_Initialize returns.
809 create_callback_ = Isolate::CreateCallback();
804 Dart::thread_pool()->Run(new RunServiceTask()); 810 Dart::thread_pool()->Run(new RunServiceTask());
805 } 811 }
806 812
807 // A handler for a per-isolate request. 813 // A handler for a per-isolate request.
808 // 814 //
809 // If a handler returns true, the reply is complete and ready to be 815 // If a handler returns true, the reply is complete and ready to be
810 // posted. If a handler returns false, then it is responsible for 816 // posted. If a handler returns false, then it is responsible for
811 // posting the reply (this can be used for asynchronous delegation of 817 // posting the reply (this can be used for asynchronous delegation of
812 // the response handling). 818 // the response handling).
813 typedef bool (*IsolateMessageHandler)(Isolate* isolate, JSONStream* stream); 819 typedef bool (*IsolateMessageHandler)(Isolate* isolate, JSONStream* stream);
(...skipping 2177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2991 while (current != NULL) { 2997 while (current != NULL) {
2992 if (strcmp(name, current->name()) == 0) { 2998 if (strcmp(name, current->name()) == 0) {
2993 return current; 2999 return current;
2994 } 3000 }
2995 current = current->next(); 3001 current = current->next();
2996 } 3002 }
2997 return NULL; 3003 return NULL;
2998 } 3004 }
2999 3005
3000 } // namespace dart 3006 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698