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

Unified Diff: runtime/bin/vmservice_impl.cc

Issue 38703009: Update VM service to new isolate API (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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/bin/vmservice_impl.cc
diff --git a/runtime/bin/vmservice_impl.cc b/runtime/bin/vmservice_impl.cc
index 7da20cc6b9a043b302b563d3ad4223d58cbe4cad..3e5453013a748f45f1ba0eb39214299d5f1eb064 100644
--- a/runtime/bin/vmservice_impl.cc
+++ b/runtime/bin/vmservice_impl.cc
@@ -143,20 +143,42 @@ bool VmService::_Start(intptr_t server_port) {
Dart_Handle library = Dart_RootLibrary();
- // Set requested port.
+ // Set requested TCP port.
DartUtils::SetIntegerField(library, "_port", server_port);
result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL);
SHUTDOWN_ON_ERROR(result);
+ // Retrieve the ReceivePort that the service is waiting on. The _receivePort
+ // variable is setup in the call to main.
+ Dart_Handle receivePort = Dart_GetField(library,
+ DartUtils::NewString("_receivePort"));
+ SHUTDOWN_ON_ERROR(receivePort);
+
+ {
+ // Extract the Dart_Port from the receive port.
+ HANDLESCOPE(Isolate::Current());
+ const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort));
+ const Instance& rp = Instance::Cast(unwrapped_rp);
+ // Extract ReceivePort port id.
+ const Object& rp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(rp));
+ if (rp_id_obj.IsError()) {
+ const Error& error = Error::Cast(rp_id_obj);
+ error_msg_ = strdup(error.ToErrorCString());
+ Dart_ExitScope();
+ Dart_ShutdownIsolate();
+ return false;
+ }
+ ASSERT(rp_id_obj.IsSmi() || rp_id_obj.IsMint());
+ Integer& id = Integer::Handle();
+ id ^= rp_id_obj.raw();
+ port_ = static_cast<Dart_Port>(id.AsInt64Value());
+ }
+
Dart_Handle library_name = Dart_NewStringFromCString(kVMServiceLibraryName);
library = Dart_LookupLibrary(library_name);
SHUTDOWN_ON_ERROR(library);
result = LoadResources(library);
SHUTDOWN_ON_ERROR(result);
- result = Dart_CompileAll();
- SHUTDOWN_ON_ERROR(result);
-
- port_ = Dart_GetMainPortId();
Dart_ExitScope();
Dart_ExitIsolate();
@@ -392,47 +414,54 @@ void VmService::ThreadMain(uword parameters) {
}
-static Dart_Handle MakeServiceControlMessage(Dart_Port port, intptr_t code) {
+static Dart_Handle MakeServiceControlMessage(Dart_Port port_id, intptr_t code) {
Dart_Handle result;
- Dart_Handle list = Dart_NewList(3);
+ Dart_Handle list = Dart_NewList(4);
Ivan Posva 2013/10/29 03:35:50 You only set 3 values in an array of 4 elements. I
Cutch 2013/10/29 05:24:57 Done.
ASSERT(!Dart_IsError(list));
- Dart_Handle codeHandle = Dart_NewInteger(code);
- ASSERT(!Dart_IsError(codeHandle));
- result = Dart_ListSetAt(list, 0, codeHandle);
+ Dart_Handle code_handle = Dart_NewInteger(code);
+ ASSERT(!Dart_IsError(code_handle));
+ result = Dart_ListSetAt(list, 0, code_handle);
+ ASSERT(!Dart_IsError(result));
+ Dart_Handle port_id_handle = Dart_NewInteger(port_id);
+ ASSERT(!Dart_IsError(port_id_handle));
+ result = Dart_ListSetAt(list, 1, port_id_handle);
Ivan Posva 2013/10/29 03:35:50 Why are you sending both the port_id and the SendP
Cutch 2013/10/29 05:24:57 Discussed offline: port_id is the unique key that
ASSERT(!Dart_IsError(result));
- Dart_Handle sendPort = Dart_NewSendPort(port);
+ Dart_Handle sendPort = Dart_NewSendPort(port_id);
ASSERT(!Dart_IsError(sendPort));
- result = Dart_ListSetAt(list, 1, sendPort);
+ result = Dart_ListSetAt(list, 2, sendPort);
ASSERT(!Dart_IsError(result));
return list;
}
-bool VmService::SendIsolateStartupMessage(Dart_Port port, Dart_Handle name) {
+bool VmService::SendIsolateStartupMessage() {
if (!IsRunning()) {
return false;
}
- Dart_Isolate isolate = Dart_CurrentIsolate();
+ Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL);
- ASSERT(Dart_GetMainPortId() == port);
+ HANDLESCOPE(isolate);
Dart_Handle list =
- MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID);
+ MakeServiceControlMessage(Dart_GetMainPortId(),
+ VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID);
ASSERT(!Dart_IsError(list));
- Dart_Handle result = Dart_ListSetAt(list, 2, name);
+ Dart_Handle name = Api::NewHandle(isolate, String::New(isolate->name()));
+ Dart_Handle result = Dart_ListSetAt(list, 3, name);
ASSERT(!Dart_IsError(result));
return Dart_Post(port_, list);
}
-bool VmService::SendIsolateShutdownMessage(Dart_Port port) {
+bool VmService::SendIsolateShutdownMessage() {
if (!IsRunning()) {
return false;
}
- Dart_Isolate isolate = Dart_CurrentIsolate();
+ Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL);
- ASSERT(Dart_GetMainPortId() == port);
+ HANDLESCOPE(isolate);
Dart_Handle list =
- MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID);
+ MakeServiceControlMessage(Dart_GetMainPortId(),
+ VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID);
ASSERT(!Dart_IsError(list));
return Dart_Post(port_, list);
}
@@ -441,7 +470,7 @@ bool VmService::SendIsolateShutdownMessage(Dart_Port port) {
void VmService::VmServiceShutdownCallback(void* callback_data) {
ASSERT(Dart_CurrentIsolate() != NULL);
Dart_EnterScope();
- VmService::SendIsolateShutdownMessage(Dart_GetMainPortId());
+ VmService::SendIsolateShutdownMessage();
Dart_ExitScope();
}

Powered by Google App Engine
This is Rietveld 408576698