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

Unified Diff: runtime/vm/service.cc

Issue 242493007: Register existing isolates when service isolate is started (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/vm/service/vmservice.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/service.cc
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc
index 5ca1df3257194e98d2653d3c7d30197438abd828..11548e5bcf5a138228da2a619c2d62ace3968954 100644
--- a/runtime/vm/service.cc
+++ b/runtime/vm/service.cc
@@ -251,6 +251,81 @@ static Dart_Port ExtractPort(Dart_Handle receivePort) {
}
+// These must be kept in sync with service/constants.dart
+#define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1
+#define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2
+
+
+static RawArray* MakeServiceControlMessage(Dart_Port port_id, intptr_t code,
+ const String& name) {
+ const Array& list = Array::Handle(Array::New(4));
+ ASSERT(!list.IsNull());
+ const Integer& code_int = Integer::Handle(Integer::New(code));
+ const Integer& port_int = Integer::Handle(Integer::New(port_id));
+ const Object& send_port = Object::Handle(
+ DartLibraryCalls::NewSendPort(port_id));
+ ASSERT(!send_port.IsNull());
+ list.SetAt(0, code_int);
+ list.SetAt(1, port_int);
+ list.SetAt(2, send_port);
+ list.SetAt(3, name);
+ return list.raw();
+}
+
+
+class RegisterRunningIsolatesVisitor : public IsolateVisitor {
+ public:
+ explicit RegisterRunningIsolatesVisitor(Isolate* service_isolate)
+ : IsolateVisitor(),
+ register_function_(Function::Handle(service_isolate)),
+ service_isolate_(service_isolate) {
+ ASSERT(Isolate::Current() == service_isolate_);
+ // Get library.
+ const String& library_url = Symbols::DartVMService();
+ ASSERT(!library_url.IsNull());
+ const Library& library =
+ Library::Handle(Library::LookupLibrary(library_url));
+ ASSERT(!library.IsNull());
+ // Get function.
+ const String& function_name =
+ String::Handle(String::New("_registerIsolate"));
+ ASSERT(!function_name.IsNull());
+ register_function_ = library.LookupFunctionAllowPrivate(function_name);
+ ASSERT(!register_function_.IsNull());
+ }
+
+ virtual void VisitIsolate(Isolate* isolate) {
+ ASSERT(Isolate::Current() == service_isolate_);
+ if ((isolate == service_isolate_) ||
+ (isolate == Dart::vm_isolate())) {
+ // We do not register the service or vm isolate.
+ return;
+ }
+ // Setup arguments for call.
+ intptr_t port_id = isolate->main_port();
+ const Integer& port_int = Integer::Handle(Integer::New(port_id));
+ ASSERT(!port_int.IsNull());
+ const Object& send_port = Object::Handle(
+ DartLibraryCalls::NewSendPort(port_id));
+ ASSERT(!send_port.IsNull());
+ const String& name = String::Handle(String::New(isolate->name()));
+ ASSERT(!name.IsNull());
+ const Array& args = Array::Handle(Array::New(3));
+ ASSERT(!args.IsNull());
+ args.SetAt(0, port_int);
+ args.SetAt(1, send_port);
+ args.SetAt(2, name);
+ Object& r = Object::Handle(service_isolate_);
+ r = DartEntry::InvokeFunction(register_function_, args);
+ ASSERT(!r.IsError());
+ }
+
+ private:
+ Function& register_function_;
+ Isolate* service_isolate_;
+};
+
+
Isolate* Service::GetServiceIsolate(void* callback_data) {
if (service_isolate_ != NULL) {
// Already initialized, return service isolate.
@@ -328,34 +403,19 @@ Isolate* Service::GetServiceIsolate(void* callback_data) {
ASSERT(port_ != ILLEGAL_PORT);
Dart_ExitScope();
}
+ {
+ // Register existing isolates.
+ StackZone zone(isolate);
+ HANDLESCOPE(isolate);
+ RegisterRunningIsolatesVisitor register_isolates(isolate);
+ Isolate::VisitIsolates(&register_isolates);
+ }
Isolate::SetCurrent(NULL);
service_isolate_ = reinterpret_cast<Isolate*>(isolate);
return service_isolate_;
}
-// These must be kept in sync with service/constants.dart
-#define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1
-#define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2
-
-
-static RawArray* MakeServiceControlMessage(Dart_Port port_id, intptr_t code,
- const String& name) {
- const Array& list = Array::Handle(Array::New(4));
- ASSERT(!list.IsNull());
- const Integer& code_int = Integer::Handle(Integer::New(code));
- const Integer& port_int = Integer::Handle(Integer::New(port_id));
- const Object& send_port = Object::Handle(
- DartLibraryCalls::NewSendPort(port_id));
- ASSERT(!send_port.IsNull());
- list.SetAt(0, code_int);
- list.SetAt(1, port_int);
- list.SetAt(2, send_port);
- list.SetAt(3, name);
- return list.raw();
-}
-
-
bool Service::SendIsolateStartupMessage() {
if (!IsRunning()) {
return false;
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/vm/service/vmservice.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698