| OLD | NEW |
| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 Dart_ShutdownIsolate(); | 136 Dart_ShutdownIsolate(); |
| 137 error_msg_ = "Invalid isolate state - Unable to make it runnable."; | 137 error_msg_ = "Invalid isolate state - Unable to make it runnable."; |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 | 140 |
| 141 Dart_EnterIsolate(isolate_); | 141 Dart_EnterIsolate(isolate_); |
| 142 Dart_EnterScope(); | 142 Dart_EnterScope(); |
| 143 | 143 |
| 144 | 144 |
| 145 Dart_Handle library = Dart_RootLibrary(); | 145 Dart_Handle library = Dart_RootLibrary(); |
| 146 // Set requested port. | 146 // Set requested TCP port. |
| 147 DartUtils::SetIntegerField(library, "_port", server_port); | 147 DartUtils::SetIntegerField(library, "_port", server_port); |
| 148 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); | 148 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| 149 SHUTDOWN_ON_ERROR(result); | 149 SHUTDOWN_ON_ERROR(result); |
| 150 | 150 |
| 151 // Retrieve the ReceivePort that the service is waiting on. The _receivePort |
| 152 // variable is setup in the call to main. |
| 153 Dart_Handle receivePort = Dart_GetField(library, |
| 154 DartUtils::NewString("_receivePort")); |
| 155 SHUTDOWN_ON_ERROR(receivePort); |
| 156 |
| 157 { |
| 158 // Extract the Dart_Port from the receive port. |
| 159 HANDLESCOPE(Isolate::Current()); |
| 160 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); |
| 161 const Instance& rp = Instance::Cast(unwrapped_rp); |
| 162 // Extract ReceivePort port id. |
| 163 const Object& rp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(rp)); |
| 164 if (rp_id_obj.IsError()) { |
| 165 const Error& error = Error::Cast(rp_id_obj); |
| 166 error_msg_ = strdup(error.ToErrorCString()); |
| 167 Dart_ExitScope(); |
| 168 Dart_ShutdownIsolate(); |
| 169 return false; |
| 170 } |
| 171 ASSERT(rp_id_obj.IsSmi() || rp_id_obj.IsMint()); |
| 172 Integer& id = Integer::Handle(); |
| 173 id ^= rp_id_obj.raw(); |
| 174 port_ = static_cast<Dart_Port>(id.AsInt64Value()); |
| 175 } |
| 176 |
| 151 Dart_Handle library_name = Dart_NewStringFromCString(kVMServiceLibraryName); | 177 Dart_Handle library_name = Dart_NewStringFromCString(kVMServiceLibraryName); |
| 152 library = Dart_LookupLibrary(library_name); | 178 library = Dart_LookupLibrary(library_name); |
| 153 SHUTDOWN_ON_ERROR(library); | 179 SHUTDOWN_ON_ERROR(library); |
| 154 result = LoadResources(library); | 180 result = LoadResources(library); |
| 155 SHUTDOWN_ON_ERROR(result); | 181 SHUTDOWN_ON_ERROR(result); |
| 156 result = Dart_CompileAll(); | |
| 157 SHUTDOWN_ON_ERROR(result); | |
| 158 | |
| 159 port_ = Dart_GetMainPortId(); | |
| 160 | 182 |
| 161 Dart_ExitScope(); | 183 Dart_ExitScope(); |
| 162 Dart_ExitIsolate(); | 184 Dart_ExitIsolate(); |
| 163 | 185 |
| 164 return true; | 186 return true; |
| 165 } | 187 } |
| 166 | 188 |
| 167 | 189 |
| 168 void VmService::_Stop() { | 190 void VmService::_Stop() { |
| 169 port_ = ILLEGAL_PORT; | 191 port_ = ILLEGAL_PORT; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 printf("VmService has exited with an error:\n%s\n", Dart_GetError(result)); | 407 printf("VmService has exited with an error:\n%s\n", Dart_GetError(result)); |
| 386 } | 408 } |
| 387 | 409 |
| 388 _Stop(); | 410 _Stop(); |
| 389 | 411 |
| 390 Dart_ExitScope(); | 412 Dart_ExitScope(); |
| 391 Dart_ExitIsolate(); | 413 Dart_ExitIsolate(); |
| 392 } | 414 } |
| 393 | 415 |
| 394 | 416 |
| 395 static Dart_Handle MakeServiceControlMessage(Dart_Port port, intptr_t code) { | 417 static Dart_Handle MakeServiceControlMessage(Dart_Port port_id, intptr_t code, |
| 418 Dart_Handle name) { |
| 396 Dart_Handle result; | 419 Dart_Handle result; |
| 397 Dart_Handle list = Dart_NewList(3); | 420 Dart_Handle list = Dart_NewList(4); |
| 398 ASSERT(!Dart_IsError(list)); | 421 ASSERT(!Dart_IsError(list)); |
| 399 Dart_Handle codeHandle = Dart_NewInteger(code); | 422 Dart_Handle code_handle = Dart_NewInteger(code); |
| 400 ASSERT(!Dart_IsError(codeHandle)); | 423 ASSERT(!Dart_IsError(code_handle)); |
| 401 result = Dart_ListSetAt(list, 0, codeHandle); | 424 result = Dart_ListSetAt(list, 0, code_handle); |
| 402 ASSERT(!Dart_IsError(result)); | 425 ASSERT(!Dart_IsError(result)); |
| 403 Dart_Handle sendPort = Dart_NewSendPort(port); | 426 Dart_Handle port_id_handle = Dart_NewInteger(port_id); |
| 427 ASSERT(!Dart_IsError(port_id_handle)); |
| 428 result = Dart_ListSetAt(list, 1, port_id_handle); |
| 429 ASSERT(!Dart_IsError(result)); |
| 430 Dart_Handle sendPort = Dart_NewSendPort(port_id); |
| 404 ASSERT(!Dart_IsError(sendPort)); | 431 ASSERT(!Dart_IsError(sendPort)); |
| 405 result = Dart_ListSetAt(list, 1, sendPort); | 432 result = Dart_ListSetAt(list, 2, sendPort); |
| 433 ASSERT(!Dart_IsError(result)); |
| 434 result = Dart_ListSetAt(list, 3, name); |
| 406 ASSERT(!Dart_IsError(result)); | 435 ASSERT(!Dart_IsError(result)); |
| 407 return list; | 436 return list; |
| 408 } | 437 } |
| 409 | 438 |
| 410 | 439 |
| 411 bool VmService::SendIsolateStartupMessage(Dart_Port port, Dart_Handle name) { | 440 bool VmService::SendIsolateStartupMessage() { |
| 412 if (!IsRunning()) { | 441 if (!IsRunning()) { |
| 413 return false; | 442 return false; |
| 414 } | 443 } |
| 415 Dart_Isolate isolate = Dart_CurrentIsolate(); | 444 Isolate* isolate = Isolate::Current(); |
| 416 ASSERT(isolate != NULL); | 445 ASSERT(isolate != NULL); |
| 417 ASSERT(Dart_GetMainPortId() == port); | 446 HANDLESCOPE(isolate); |
| 447 Dart_Handle name = Api::NewHandle(isolate, String::New(isolate->name())); |
| 448 ASSERT(!Dart_IsError(name)); |
| 418 Dart_Handle list = | 449 Dart_Handle list = |
| 419 MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID); | 450 MakeServiceControlMessage(Dart_GetMainPortId(), |
| 451 VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID, |
| 452 name); |
| 420 ASSERT(!Dart_IsError(list)); | 453 ASSERT(!Dart_IsError(list)); |
| 421 Dart_Handle result = Dart_ListSetAt(list, 2, name); | |
| 422 ASSERT(!Dart_IsError(result)); | |
| 423 return Dart_Post(port_, list); | 454 return Dart_Post(port_, list); |
| 424 } | 455 } |
| 425 | 456 |
| 426 | 457 |
| 427 bool VmService::SendIsolateShutdownMessage(Dart_Port port) { | 458 bool VmService::SendIsolateShutdownMessage() { |
| 428 if (!IsRunning()) { | 459 if (!IsRunning()) { |
| 429 return false; | 460 return false; |
| 430 } | 461 } |
| 431 Dart_Isolate isolate = Dart_CurrentIsolate(); | 462 Isolate* isolate = Isolate::Current(); |
| 432 ASSERT(isolate != NULL); | 463 ASSERT(isolate != NULL); |
| 433 ASSERT(Dart_GetMainPortId() == port); | 464 HANDLESCOPE(isolate); |
| 434 Dart_Handle list = | 465 Dart_Handle list = |
| 435 MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID); | 466 MakeServiceControlMessage(Dart_GetMainPortId(), |
| 467 VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID, |
| 468 Dart_Null()); |
| 436 ASSERT(!Dart_IsError(list)); | 469 ASSERT(!Dart_IsError(list)); |
| 437 return Dart_Post(port_, list); | 470 return Dart_Post(port_, list); |
| 438 } | 471 } |
| 439 | 472 |
| 440 | 473 |
| 441 void VmService::VmServiceShutdownCallback(void* callback_data) { | 474 void VmService::VmServiceShutdownCallback(void* callback_data) { |
| 442 ASSERT(Dart_CurrentIsolate() != NULL); | 475 ASSERT(Dart_CurrentIsolate() != NULL); |
| 443 Dart_EnterScope(); | 476 Dart_EnterScope(); |
| 444 VmService::SendIsolateShutdownMessage(Dart_GetMainPortId()); | 477 VmService::SendIsolateShutdownMessage(); |
| 445 Dart_ExitScope(); | 478 Dart_ExitScope(); |
| 446 } | 479 } |
| 447 | 480 |
| 448 | 481 |
| 449 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 482 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 450 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 483 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 451 return reinterpret_cast<uint8_t*>(new_ptr); | 484 return reinterpret_cast<uint8_t*>(new_ptr); |
| 452 } | 485 } |
| 453 | 486 |
| 454 | 487 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 if (!strcmp(function_name, entry.name) && | 554 if (!strcmp(function_name, entry.name) && |
| 522 (num_arguments == entry.num_arguments)) { | 555 (num_arguments == entry.num_arguments)) { |
| 523 return entry.function; | 556 return entry.function; |
| 524 } | 557 } |
| 525 } | 558 } |
| 526 return NULL; | 559 return NULL; |
| 527 } | 560 } |
| 528 | 561 |
| 529 } // namespace bin | 562 } // namespace bin |
| 530 } // namespace dart | 563 } // namespace dart |
| OLD | NEW |