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

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
Index: runtime/vm/service.cc
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc
index 5ca1df3257194e98d2653d3c7d30197438abd828..78286613199a7e7390105676d57ebdf475ea2853 100644
--- a/runtime/vm/service.cc
+++ b/runtime/vm/service.cc
@@ -251,6 +251,75 @@ 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(),
+ service_isolate_(service_isolate) {
+ }
+
+ virtual void VisitIsolate(Isolate* isolate) {
+ if ((isolate == service_isolate_) ||
+ (isolate == Dart::vm_isolate())) {
+ // We do not register ourselves or the vm isolate.
+ return;
+ }
+ 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());
+ const Function& function =
+ Function::Handle(library.LookupFunctionAllowPrivate(function_name));
+ ASSERT(!function.IsNull());
siva 2014/04/21 21:27:53 Can the lookup of this top level function _registe
Cutch 2014/04/21 22:00:40 Done.
+ // Create ServiceControlMessage.
+ const String& name = String::Handle(String::New(isolate->name()));
+ ASSERT(!name.IsNull());
+ const Array& list = Array::Handle(
+ MakeServiceControlMessage(isolate->main_port(),
+ VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID,
+ name));
+ // Setup arguments for call.
+ const Array& args = Array::Handle(Array::New(1));
+ ASSERT(!args.IsNull());
+ args.SetAt(0, list);
+ const Object& r = Object::Handle(DartEntry::InvokeFunction(function, args));
+ ASSERT(!r.IsError());
+ }
+
+ private:
+ Isolate* service_isolate_;
+};
+
+
Isolate* Service::GetServiceIsolate(void* callback_data) {
if (service_isolate_ != NULL) {
// Already initialized, return service isolate.
@@ -328,34 +397,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;

Powered by Google App Engine
This is Rietveld 408576698