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

Side by Side 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, 1 month 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
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 "bin/vmservice_impl.h" 5 #include "bin/vmservice_impl.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 Dart_ShutdownIsolate(); 134 Dart_ShutdownIsolate();
135 error_msg_ = "Invalid isolate state - Unable to make it runnable."; 135 error_msg_ = "Invalid isolate state - Unable to make it runnable.";
136 return false; 136 return false;
137 } 137 }
138 138
139 Dart_EnterIsolate(isolate_); 139 Dart_EnterIsolate(isolate_);
140 Dart_EnterScope(); 140 Dart_EnterScope();
141 141
142 142
143 Dart_Handle library = Dart_RootLibrary(); 143 Dart_Handle library = Dart_RootLibrary();
144 // Set requested port. 144 // Set requested TCP port.
145 DartUtils::SetIntegerField(library, "_port", server_port); 145 DartUtils::SetIntegerField(library, "_port", server_port);
146 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); 146 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL);
147 SHUTDOWN_ON_ERROR(result); 147 SHUTDOWN_ON_ERROR(result);
148 // Retrieve the ReceivePort that the service is waiting on. The _receivePort
149 // variable is setup in the call to main.
150 Dart_Handle receivePort = Dart_GetField(library,
Ivan Posva 2013/10/25 00:30:27 I generally find this mix of external C API and in
Cutch 2013/10/25 01:21:57 The external API does not offer functionality to m
151 DartUtils::NewString("_receivePort"));
152 SHUTDOWN_ON_ERROR(receivePort);
153
154 {
155 // Extract the Dart_Port from the receive port.
156 HANDLESCOPE(Isolate::Current());
157 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort));
158 const Instance& rp = Instance::Cast(unwrapped_rp);
159 // Extract ReceivePort port id.
160 const Object& rp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(rp));
161 if (rp_id_obj.IsError()) {
162 const Error& error = Error::Cast(rp_id_obj);
163 error_msg_ = strdup(error.ToErrorCString());
164 Dart_ExitScope();
165 Dart_ShutdownIsolate();
166 return false;
167 }
168 ASSERT(rp_id_obj.IsSmi() || rp_id_obj.IsMint());
169 Integer& id = Integer::Handle();
170 id ^= rp_id_obj.raw();
171 port_ = static_cast<Dart_Port>(id.AsInt64Value());
172 }
173
148 174
149 Dart_Handle library_name = Dart_NewStringFromCString(kVMServiceLibraryName); 175 Dart_Handle library_name = Dart_NewStringFromCString(kVMServiceLibraryName);
150 library = Dart_LookupLibrary(library_name); 176 library = Dart_LookupLibrary(library_name);
151 SHUTDOWN_ON_ERROR(library); 177 SHUTDOWN_ON_ERROR(library);
152 result = LoadResources(library); 178 result = LoadResources(library);
153 SHUTDOWN_ON_ERROR(result); 179 SHUTDOWN_ON_ERROR(result);
154 result = Dart_CompileAll(); 180 result = Dart_CompileAll();
Ivan Posva 2013/10/25 00:30:27 Please remove this or at least make it optional ba
Cutch 2013/10/25 01:21:57 Done.
155 SHUTDOWN_ON_ERROR(result); 181 SHUTDOWN_ON_ERROR(result);
156 182
157 port_ = Dart_GetMainPortId();
158
159 Dart_ExitScope(); 183 Dart_ExitScope();
160 Dart_ExitIsolate(); 184 Dart_ExitIsolate();
161 185
162 return true; 186 return true;
163 } 187 }
164 188
165 189
166 void VmService::_Stop() { 190 void VmService::_Stop() {
167 port_ = ILLEGAL_PORT; 191 port_ = ILLEGAL_PORT;
168 } 192 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 result = Dart_ListSetAt(list, 0, codeHandle); 423 result = Dart_ListSetAt(list, 0, codeHandle);
400 ASSERT(!Dart_IsError(result)); 424 ASSERT(!Dart_IsError(result));
401 Dart_Handle sendPort = Dart_NewSendPort(port); 425 Dart_Handle sendPort = Dart_NewSendPort(port);
402 ASSERT(!Dart_IsError(sendPort)); 426 ASSERT(!Dart_IsError(sendPort));
403 result = Dart_ListSetAt(list, 1, sendPort); 427 result = Dart_ListSetAt(list, 1, sendPort);
404 ASSERT(!Dart_IsError(result)); 428 ASSERT(!Dart_IsError(result));
405 return list; 429 return list;
406 } 430 }
407 431
408 432
409 bool VmService::SendIsolateStartupMessage(Dart_Port port, Dart_Handle name) { 433 bool VmService::SendIsolateStartupMessage() {
410 if (!IsRunning()) { 434 if (!IsRunning()) {
411 return false; 435 return false;
412 } 436 }
413 Dart_Isolate isolate = Dart_CurrentIsolate(); 437 Isolate* isolate = Isolate::Current();
414 ASSERT(isolate != NULL); 438 ASSERT(isolate != NULL);
415 ASSERT(Dart_GetMainPortId() == port); 439 StackZone zone(isolate);
Ivan Posva 2013/10/25 00:30:27 ditto.
Cutch 2013/10/25 01:21:57 Done.
440 HANDLESCOPE(isolate);
441 Dart_Port service_port = isolate->service_port();
416 Dart_Handle list = 442 Dart_Handle list =
417 MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID); 443 MakeServiceControlMessage(service_port,
444 VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID);
418 ASSERT(!Dart_IsError(list)); 445 ASSERT(!Dart_IsError(list));
446 Dart_Handle name = Api::NewHandle(isolate, String::New(isolate->name()));
419 Dart_Handle result = Dart_ListSetAt(list, 2, name); 447 Dart_Handle result = Dart_ListSetAt(list, 2, name);
420 ASSERT(!Dart_IsError(result)); 448 ASSERT(!Dart_IsError(result));
421 return Dart_Post(port_, list); 449 return Dart_Post(port_, list);
422 } 450 }
423 451
424 452
425 bool VmService::SendIsolateShutdownMessage(Dart_Port port) { 453 bool VmService::SendIsolateShutdownMessage() {
426 if (!IsRunning()) { 454 if (!IsRunning()) {
427 return false; 455 return false;
428 } 456 }
429 Dart_Isolate isolate = Dart_CurrentIsolate(); 457 Isolate* isolate = Isolate::Current();
430 ASSERT(isolate != NULL); 458 ASSERT(isolate != NULL);
431 ASSERT(Dart_GetMainPortId() == port); 459 StackZone zone(isolate);
460 HANDLESCOPE(isolate);
461 Dart_Port service_port = isolate->service_port();
432 Dart_Handle list = 462 Dart_Handle list =
433 MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID); 463 MakeServiceControlMessage(service_port,
464 VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID);
434 ASSERT(!Dart_IsError(list)); 465 ASSERT(!Dart_IsError(list));
435 return Dart_Post(port_, list); 466 return Dart_Post(port_, list);
436 } 467 }
437 468
438 469
439 void VmService::VmServiceShutdownCallback(void* callback_data) { 470 void VmService::VmServiceShutdownCallback(void* callback_data) {
440 ASSERT(Dart_CurrentIsolate() != NULL); 471 ASSERT(Dart_CurrentIsolate() != NULL);
441 Dart_EnterScope(); 472 Dart_EnterScope();
442 VmService::SendIsolateShutdownMessage(Dart_GetMainPortId()); 473 VmService::SendIsolateShutdownMessage();
443 Dart_ExitScope(); 474 Dart_ExitScope();
444 } 475 }
445 476
446 477
447 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 478 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
448 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 479 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
449 return reinterpret_cast<uint8_t*>(new_ptr); 480 return reinterpret_cast<uint8_t*>(new_ptr);
450 } 481 }
451 482
452 483
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 if (!strcmp(function_name, entry.name) && 550 if (!strcmp(function_name, entry.name) &&
520 (num_arguments == entry.num_arguments)) { 551 (num_arguments == entry.num_arguments)) {
521 return entry.function; 552 return entry.function;
522 } 553 }
523 } 554 }
524 return NULL; 555 return NULL;
525 } 556 }
526 557
527 } // namespace bin 558 } // namespace bin
528 } // namespace dart 559 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698