OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 "vm/service_isolate.h" | 5 #include "vm/service_isolate.h" |
6 | 6 |
7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 const Integer& code_int = Integer::Handle(Integer::New(code)); | 142 const Integer& code_int = Integer::Handle(Integer::New(code)); |
143 list.SetAt(0, code_int); | 143 list.SetAt(0, code_int); |
144 return list.raw(); | 144 return list.raw(); |
145 } | 145 } |
146 | 146 |
147 | 147 |
148 const char* ServiceIsolate::kName = "vm-service"; | 148 const char* ServiceIsolate::kName = "vm-service"; |
149 Isolate* ServiceIsolate::isolate_ = NULL; | 149 Isolate* ServiceIsolate::isolate_ = NULL; |
150 Dart_Port ServiceIsolate::port_ = ILLEGAL_PORT; | 150 Dart_Port ServiceIsolate::port_ = ILLEGAL_PORT; |
151 Dart_Port ServiceIsolate::load_port_ = ILLEGAL_PORT; | 151 Dart_Port ServiceIsolate::load_port_ = ILLEGAL_PORT; |
152 Dart_Port ServiceIsolate::origin_ = ILLEGAL_PORT; | |
152 Dart_IsolateCreateCallback ServiceIsolate::create_callback_ = NULL; | 153 Dart_IsolateCreateCallback ServiceIsolate::create_callback_ = NULL; |
153 uint8_t* ServiceIsolate::exit_message_ = NULL; | 154 uint8_t* ServiceIsolate::exit_message_ = NULL; |
154 intptr_t ServiceIsolate::exit_message_length_ = 0; | 155 intptr_t ServiceIsolate::exit_message_length_ = 0; |
155 Monitor* ServiceIsolate::monitor_ = NULL; | 156 Monitor* ServiceIsolate::monitor_ = NULL; |
156 bool ServiceIsolate::initializing_ = true; | 157 bool ServiceIsolate::initializing_ = true; |
157 bool ServiceIsolate::shutting_down_ = false; | 158 bool ServiceIsolate::shutting_down_ = false; |
158 | 159 |
159 | 160 |
160 class RegisterRunningIsolatesVisitor : public IsolateVisitor { | 161 class RegisterRunningIsolatesVisitor : public IsolateVisitor { |
161 public: | 162 public: |
(...skipping 12 matching lines...) Expand all Loading... | |
174 const String& function_name = | 175 const String& function_name = |
175 String::Handle(String::New("_registerIsolate")); | 176 String::Handle(String::New("_registerIsolate")); |
176 ASSERT(!function_name.IsNull()); | 177 ASSERT(!function_name.IsNull()); |
177 register_function_ = library.LookupFunctionAllowPrivate(function_name); | 178 register_function_ = library.LookupFunctionAllowPrivate(function_name); |
178 ASSERT(!register_function_.IsNull()); | 179 ASSERT(!register_function_.IsNull()); |
179 } | 180 } |
180 | 181 |
181 virtual void VisitIsolate(Isolate* isolate) { | 182 virtual void VisitIsolate(Isolate* isolate) { |
182 ASSERT(ServiceIsolate::IsServiceIsolate(Isolate::Current())); | 183 ASSERT(ServiceIsolate::IsServiceIsolate(Isolate::Current())); |
183 if (ServiceIsolate::IsServiceIsolate(isolate) || | 184 if (ServiceIsolate::IsServiceIsolate(isolate) || |
184 (isolate == Dart::vm_isolate())) { | 185 (isolate == Dart::vm_isolate()) || |
185 // We do not register the service or vm isolate. | 186 (isolate->origin_id() == ServiceIsolate::Origin())) { |
turnidge
2015/04/01 19:57:34
Can this whole test get replaces by ServiceIsolate
Cutch
2015/04/01 20:19:04
Done.
| |
187 // We do not register the service (and descendants) or the vm-isolate. | |
186 return; | 188 return; |
187 } | 189 } |
188 // Setup arguments for call. | 190 // Setup arguments for call. |
189 Dart_Port port_id = isolate->main_port(); | 191 Dart_Port port_id = isolate->main_port(); |
190 const Integer& port_int = Integer::Handle(Integer::New(port_id)); | 192 const Integer& port_int = Integer::Handle(Integer::New(port_id)); |
191 ASSERT(!port_int.IsNull()); | 193 ASSERT(!port_int.IsNull()); |
192 const SendPort& send_port = SendPort::Handle(SendPort::New(port_id)); | 194 const SendPort& send_port = SendPort::Handle(SendPort::New(port_id)); |
193 const String& name = String::Handle(String::New(isolate->name())); | 195 const String& name = String::Handle(String::New(isolate->name())); |
194 ASSERT(!name.IsNull()); | 196 ASSERT(!name.IsNull()); |
195 const Array& args = Array::Handle(Array::New(3)); | 197 const Array& args = Array::Handle(Array::New(3)); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 Dart_Handle url_str = | 276 Dart_Handle url_str = |
275 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId)); | 277 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId)); |
276 Dart_Handle library = Dart_LookupLibrary(url_str); | 278 Dart_Handle library = Dart_LookupLibrary(url_str); |
277 ASSERT(Dart_IsLibrary(library)); | 279 ASSERT(Dart_IsLibrary(library)); |
278 Dart_Handle result = | 280 Dart_Handle result = |
279 Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL); | 281 Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL); |
280 ASSERT(!Dart_IsError(result)); | 282 ASSERT(!Dart_IsError(result)); |
281 Dart_Port port = ExtractPort(isolate, result); | 283 Dart_Port port = ExtractPort(isolate, result); |
282 ASSERT(port != ILLEGAL_PORT); | 284 ASSERT(port != ILLEGAL_PORT); |
283 ServiceIsolate::SetServicePort(port); | 285 ServiceIsolate::SetServicePort(port); |
286 ServiceIsolate::SetOrigin(isolate->origin_id()); | |
284 Dart_ExitScope(); | 287 Dart_ExitScope(); |
285 } | 288 } |
286 | 289 |
287 { | 290 { |
288 if (FLAG_trace_service) { | 291 if (FLAG_trace_service) { |
289 OS::Print("vm-service: Registering running isolates.\n"); | 292 OS::Print("vm-service: Registering running isolates.\n"); |
290 } | 293 } |
291 // Register running isolates with service. | 294 // Register running isolates with service. |
292 RegisterRunningIsolatesVisitor register_isolates(isolate); | 295 RegisterRunningIsolatesVisitor register_isolates(isolate); |
293 Isolate::VisitIsolates(®ister_isolates); | 296 Isolate::VisitIsolates(®ister_isolates); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 return (port_ != ILLEGAL_PORT) && (isolate_ != NULL); | 373 return (port_ != ILLEGAL_PORT) && (isolate_ != NULL); |
371 } | 374 } |
372 | 375 |
373 | 376 |
374 bool ServiceIsolate::IsServiceIsolate(Isolate* isolate) { | 377 bool ServiceIsolate::IsServiceIsolate(Isolate* isolate) { |
375 MonitorLocker ml(monitor_); | 378 MonitorLocker ml(monitor_); |
376 return isolate == isolate_; | 379 return isolate == isolate_; |
377 } | 380 } |
378 | 381 |
379 | 382 |
383 bool ServiceIsolate::IsServiceIsolateDescendant(Isolate* isolate) { | |
384 MonitorLocker ml(monitor_); | |
385 return isolate->origin_id() == origin_; | |
386 } | |
387 | |
388 | |
380 Dart_Port ServiceIsolate::Port() { | 389 Dart_Port ServiceIsolate::Port() { |
381 MonitorLocker ml(monitor_); | 390 MonitorLocker ml(monitor_); |
382 return port_; | 391 return port_; |
383 } | 392 } |
384 | 393 |
394 Dart_Port ServiceIsolate::Origin() { | |
395 MonitorLocker ml(monitor_); | |
396 return origin_; | |
397 } | |
398 | |
385 | 399 |
386 Dart_Port ServiceIsolate::WaitForLoadPort() { | 400 Dart_Port ServiceIsolate::WaitForLoadPort() { |
387 MonitorLocker ml(monitor_); | 401 MonitorLocker ml(monitor_); |
388 | 402 |
389 while (initializing_ && (load_port_ == ILLEGAL_PORT)) { | 403 while (initializing_ && (load_port_ == ILLEGAL_PORT)) { |
390 ml.Wait(); | 404 ml.Wait(); |
391 } | 405 } |
392 | 406 |
393 return load_port_; | 407 return load_port_; |
394 } | 408 } |
395 | 409 |
396 | 410 |
397 Dart_Port ServiceIsolate::LoadPort() { | 411 Dart_Port ServiceIsolate::LoadPort() { |
398 MonitorLocker ml(monitor_); | 412 MonitorLocker ml(monitor_); |
399 return load_port_; | 413 return load_port_; |
400 } | 414 } |
401 | 415 |
402 | 416 |
403 bool ServiceIsolate::SendIsolateStartupMessage() { | 417 bool ServiceIsolate::SendIsolateStartupMessage() { |
404 if (!IsRunning()) { | 418 if (!IsRunning()) { |
405 return false; | 419 return false; |
406 } | 420 } |
407 Isolate* isolate = Isolate::Current(); | 421 Isolate* isolate = Isolate::Current(); |
408 if (IsServiceIsolate(isolate)) { | 422 if (IsServiceIsolate(isolate) || IsServiceIsolateDescendant(isolate)) { |
turnidge
2015/04/01 19:57:34
Collapse and ditto below.
Cutch
2015/04/01 20:19:04
Done.
| |
409 return false; | 423 return false; |
410 } | 424 } |
411 ASSERT(isolate != NULL); | 425 ASSERT(isolate != NULL); |
412 HANDLESCOPE(isolate); | 426 HANDLESCOPE(isolate); |
413 const String& name = String::Handle(String::New(isolate->name())); | 427 const String& name = String::Handle(String::New(isolate->name())); |
414 ASSERT(!name.IsNull()); | 428 ASSERT(!name.IsNull()); |
415 const Array& list = Array::Handle( | 429 const Array& list = Array::Handle( |
416 MakeServiceControlMessage(Dart_GetMainPortId(), | 430 MakeServiceControlMessage(Dart_GetMainPortId(), |
417 VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID, | 431 VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID, |
418 name)); | 432 name)); |
(...skipping 10 matching lines...) Expand all Loading... | |
429 return PortMap::PostMessage( | 443 return PortMap::PostMessage( |
430 new Message(port_, data, len, Message::kNormalPriority)); | 444 new Message(port_, data, len, Message::kNormalPriority)); |
431 } | 445 } |
432 | 446 |
433 | 447 |
434 bool ServiceIsolate::SendIsolateShutdownMessage() { | 448 bool ServiceIsolate::SendIsolateShutdownMessage() { |
435 if (!IsRunning()) { | 449 if (!IsRunning()) { |
436 return false; | 450 return false; |
437 } | 451 } |
438 Isolate* isolate = Isolate::Current(); | 452 Isolate* isolate = Isolate::Current(); |
439 if (IsServiceIsolate(isolate)) { | 453 if (IsServiceIsolate(isolate) || IsServiceIsolateDescendant(isolate)) { |
440 return false; | 454 return false; |
441 } | 455 } |
442 ASSERT(isolate != NULL); | 456 ASSERT(isolate != NULL); |
443 HANDLESCOPE(isolate); | 457 HANDLESCOPE(isolate); |
444 const String& name = String::Handle(String::New(isolate->name())); | 458 const String& name = String::Handle(String::New(isolate->name())); |
445 ASSERT(!name.IsNull()); | 459 ASSERT(!name.IsNull()); |
446 const Array& list = Array::Handle( | 460 const Array& list = Array::Handle( |
447 MakeServiceControlMessage(Dart_GetMainPortId(), | 461 MakeServiceControlMessage(Dart_GetMainPortId(), |
448 VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID, | 462 VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID, |
449 name)); | 463 name)); |
(...skipping 22 matching lines...) Expand all Loading... | |
472 if (FLAG_trace_service) { | 486 if (FLAG_trace_service) { |
473 OS::Print("vm-service: sending service exit message.\n"); | 487 OS::Print("vm-service: sending service exit message.\n"); |
474 } | 488 } |
475 PortMap::PostMessage(new Message(port_, | 489 PortMap::PostMessage(new Message(port_, |
476 exit_message_, | 490 exit_message_, |
477 exit_message_length_, | 491 exit_message_length_, |
478 Message::kNormalPriority)); | 492 Message::kNormalPriority)); |
479 } | 493 } |
480 | 494 |
481 | 495 |
496 void ServiceIsolate::SetOrigin(Dart_Port origin) { | |
497 MonitorLocker ml(monitor_); | |
498 origin_ = origin; | |
499 } | |
500 | |
501 | |
482 void ServiceIsolate::SetServicePort(Dart_Port port) { | 502 void ServiceIsolate::SetServicePort(Dart_Port port) { |
483 MonitorLocker ml(monitor_); | 503 MonitorLocker ml(monitor_); |
484 port_ = port; | 504 port_ = port; |
485 } | 505 } |
486 | 506 |
487 | 507 |
488 void ServiceIsolate::SetServiceIsolate(Isolate* isolate) { | 508 void ServiceIsolate::SetServiceIsolate(Isolate* isolate) { |
489 MonitorLocker ml(monitor_); | 509 MonitorLocker ml(monitor_); |
490 isolate_ = isolate; | 510 isolate_ = isolate; |
491 if (isolate_ != NULL) { | 511 if (isolate_ != NULL) { |
(...skipping 11 matching lines...) Expand all Loading... | |
503 ASSERT(isolate != NULL); | 523 ASSERT(isolate != NULL); |
504 ASSERT(isolate->name() != NULL); | 524 ASSERT(isolate->name() != NULL); |
505 if (!ServiceIsolate::NameEquals(isolate->name())) { | 525 if (!ServiceIsolate::NameEquals(isolate->name())) { |
506 // Not service isolate. | 526 // Not service isolate. |
507 return; | 527 return; |
508 } | 528 } |
509 if (Exists()) { | 529 if (Exists()) { |
510 // Service isolate already exists. | 530 // Service isolate already exists. |
511 return; | 531 return; |
512 } | 532 } |
513 SetServiceIsolate(isolate); | 533 SetServiceIsolate(isolate); |
turnidge
2015/04/01 19:57:34
Consider having this call set the origin as well,
Cutch
2015/04/01 20:19:04
Done.
| |
514 | 534 |
515 StackZone zone(isolate); | 535 StackZone zone(isolate); |
516 HANDLESCOPE(isolate); | 536 HANDLESCOPE(isolate); |
517 | 537 |
518 // Register dart:vmservice library. | 538 // Register dart:vmservice library. |
519 const String& url_str = String::Handle(Symbols::DartVMService().raw()); | 539 const String& url_str = String::Handle(Symbols::DartVMService().raw()); |
520 const Library& library = Library::Handle(Library::New(url_str)); | 540 const Library& library = Library::Handle(Library::New(url_str)); |
521 library.Register(); | 541 library.Register(); |
522 library.set_native_entry_resolver(ServiceNativeResolver); | 542 library.set_native_entry_resolver(ServiceNativeResolver); |
523 | 543 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 } | 662 } |
643 Dart::RunShutdownCallback(); | 663 Dart::RunShutdownCallback(); |
644 } | 664 } |
645 { | 665 { |
646 // Shut the isolate down. | 666 // Shut the isolate down. |
647 SwitchIsolateScope switch_scope(isolate); | 667 SwitchIsolateScope switch_scope(isolate); |
648 Dart::ShutdownIsolate(); | 668 Dart::ShutdownIsolate(); |
649 } | 669 } |
650 ServiceIsolate::SetServiceIsolate(NULL); | 670 ServiceIsolate::SetServiceIsolate(NULL); |
651 ServiceIsolate::SetServicePort(ILLEGAL_PORT); | 671 ServiceIsolate::SetServicePort(ILLEGAL_PORT); |
672 ServiceIsolate::SetOrigin(ILLEGAL_PORT); | |
652 if (FLAG_trace_service) { | 673 if (FLAG_trace_service) { |
653 OS::Print("vm-service: Shutdown.\n"); | 674 OS::Print("vm-service: Shutdown.\n"); |
654 } | 675 } |
655 ServiceIsolate::FinishedExiting(); | 676 ServiceIsolate::FinishedExiting(); |
656 } | 677 } |
657 | 678 |
658 void RunMain(Isolate* isolate) { | 679 void RunMain(Isolate* isolate) { |
659 StartIsolateScope iso_scope(isolate); | 680 StartIsolateScope iso_scope(isolate); |
660 StackZone zone(isolate); | 681 StackZone zone(isolate); |
661 HANDLESCOPE(isolate); | 682 HANDLESCOPE(isolate); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 return result; | 794 return result; |
774 } | 795 } |
775 Dart_Handle source = GetSource(url_string); | 796 Dart_Handle source = GetSource(url_string); |
776 if (Dart_IsError(source)) { | 797 if (Dart_IsError(source)) { |
777 return source; | 798 return source; |
778 } | 799 } |
779 return Dart_LoadSource(library, url, source, 0, 0); | 800 return Dart_LoadSource(library, url, source, 0, 0); |
780 } | 801 } |
781 | 802 |
782 } // namespace dart | 803 } // namespace dart |
OLD | NEW |