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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 102 |
103 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 103 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
104 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 104 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
105 return reinterpret_cast<uint8_t*>(new_ptr); | 105 return reinterpret_cast<uint8_t*>(new_ptr); |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 static Dart_Port ExtractPort(Isolate* isolate, Dart_Handle receivePort) { | 109 static Dart_Port ExtractPort(Isolate* isolate, Dart_Handle receivePort) { |
110 const ReceivePort& rp = Api::UnwrapReceivePortHandle(isolate, receivePort); | 110 const ReceivePort& rp = Api::UnwrapReceivePortHandle(isolate, receivePort); |
111 if (rp.IsNull()) { | 111 if (rp.IsNull()) { |
112 return ILLEGAL_PORT; | 112 return DART_ILLEGAL_PORT; |
113 } | 113 } |
114 return rp.Id(); | 114 return rp.Id(); |
115 } | 115 } |
116 | 116 |
117 | 117 |
118 // These must be kept in sync with service/constants.dart | 118 // These must be kept in sync with service/constants.dart |
119 #define VM_SERVICE_ISOLATE_EXIT_MESSAGE_ID 0 | 119 #define VM_SERVICE_ISOLATE_EXIT_MESSAGE_ID 0 |
120 #define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1 | 120 #define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1 |
121 #define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2 | 121 #define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2 |
122 | 122 |
(...skipping 17 matching lines...) Expand all Loading... |
140 ASSERT(!list.IsNull()); | 140 ASSERT(!list.IsNull()); |
141 const intptr_t code = VM_SERVICE_ISOLATE_EXIT_MESSAGE_ID; | 141 const intptr_t code = VM_SERVICE_ISOLATE_EXIT_MESSAGE_ID; |
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_ = DART_ILLEGAL_PORT; |
151 Dart_Port ServiceIsolate::load_port_ = ILLEGAL_PORT; | 151 Dart_Port ServiceIsolate::load_port_ = DART_ILLEGAL_PORT; |
152 Dart_Port ServiceIsolate::origin_ = ILLEGAL_PORT; | 152 Dart_Port ServiceIsolate::origin_ = DART_ILLEGAL_PORT; |
153 Dart_IsolateCreateCallback ServiceIsolate::create_callback_ = NULL; | 153 Dart_IsolateCreateCallback ServiceIsolate::create_callback_ = NULL; |
154 uint8_t* ServiceIsolate::exit_message_ = NULL; | 154 uint8_t* ServiceIsolate::exit_message_ = NULL; |
155 intptr_t ServiceIsolate::exit_message_length_ = 0; | 155 intptr_t ServiceIsolate::exit_message_length_ = 0; |
156 Monitor* ServiceIsolate::monitor_ = NULL; | 156 Monitor* ServiceIsolate::monitor_ = NULL; |
157 bool ServiceIsolate::initializing_ = true; | 157 bool ServiceIsolate::initializing_ = true; |
158 bool ServiceIsolate::shutting_down_ = false; | 158 bool ServiceIsolate::shutting_down_ = false; |
159 | 159 |
160 | 160 |
161 class RegisterRunningIsolatesVisitor : public IsolateVisitor { | 161 class RegisterRunningIsolatesVisitor : public IsolateVisitor { |
162 public: | 162 public: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // Boot the dart:vmservice library. | 263 // Boot the dart:vmservice library. |
264 Dart_EnterScope(); | 264 Dart_EnterScope(); |
265 Dart_Handle url_str = | 265 Dart_Handle url_str = |
266 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId)); | 266 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId)); |
267 Dart_Handle library = Dart_LookupLibrary(url_str); | 267 Dart_Handle library = Dart_LookupLibrary(url_str); |
268 ASSERT(Dart_IsLibrary(library)); | 268 ASSERT(Dart_IsLibrary(library)); |
269 Dart_Handle result = | 269 Dart_Handle result = |
270 Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL); | 270 Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL); |
271 ASSERT(!Dart_IsError(result)); | 271 ASSERT(!Dart_IsError(result)); |
272 Dart_Port port = ExtractPort(isolate, result); | 272 Dart_Port port = ExtractPort(isolate, result); |
273 ASSERT(port != ILLEGAL_PORT); | 273 ASSERT(port != DART_ILLEGAL_PORT); |
274 ServiceIsolate::SetServicePort(port); | 274 ServiceIsolate::SetServicePort(port); |
275 Dart_ExitScope(); | 275 Dart_ExitScope(); |
276 } | 276 } |
277 | 277 |
278 { | 278 { |
279 if (FLAG_trace_service) { | 279 if (FLAG_trace_service) { |
280 OS::Print("vm-service: Registering running isolates.\n"); | 280 OS::Print("vm-service: Registering running isolates.\n"); |
281 } | 281 } |
282 // Register running isolates with service. | 282 // Register running isolates with service. |
283 RegisterRunningIsolatesVisitor register_isolates(isolate); | 283 RegisterRunningIsolatesVisitor register_isolates(isolate); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 349 |
350 | 350 |
351 bool ServiceIsolate::Exists() { | 351 bool ServiceIsolate::Exists() { |
352 MonitorLocker ml(monitor_); | 352 MonitorLocker ml(monitor_); |
353 return isolate_ != NULL; | 353 return isolate_ != NULL; |
354 } | 354 } |
355 | 355 |
356 | 356 |
357 bool ServiceIsolate::IsRunning() { | 357 bool ServiceIsolate::IsRunning() { |
358 MonitorLocker ml(monitor_); | 358 MonitorLocker ml(monitor_); |
359 return (port_ != ILLEGAL_PORT) && (isolate_ != NULL); | 359 return (port_ != DART_ILLEGAL_PORT) && (isolate_ != NULL); |
360 } | 360 } |
361 | 361 |
362 | 362 |
363 bool ServiceIsolate::IsServiceIsolate(Isolate* isolate) { | 363 bool ServiceIsolate::IsServiceIsolate(Isolate* isolate) { |
364 MonitorLocker ml(monitor_); | 364 MonitorLocker ml(monitor_); |
365 return isolate == isolate_; | 365 return isolate == isolate_; |
366 } | 366 } |
367 | 367 |
368 | 368 |
369 bool ServiceIsolate::IsServiceIsolateDescendant(Isolate* isolate) { | 369 bool ServiceIsolate::IsServiceIsolateDescendant(Isolate* isolate) { |
370 MonitorLocker ml(monitor_); | 370 MonitorLocker ml(monitor_); |
371 return isolate->origin_id() == origin_; | 371 return isolate->origin_id() == origin_; |
372 } | 372 } |
373 | 373 |
374 | 374 |
375 Dart_Port ServiceIsolate::Port() { | 375 Dart_Port ServiceIsolate::Port() { |
376 MonitorLocker ml(monitor_); | 376 MonitorLocker ml(monitor_); |
377 return port_; | 377 return port_; |
378 } | 378 } |
379 | 379 |
380 | 380 |
381 Dart_Port ServiceIsolate::WaitForLoadPort() { | 381 Dart_Port ServiceIsolate::WaitForLoadPort() { |
382 MonitorLocker ml(monitor_); | 382 MonitorLocker ml(monitor_); |
383 | 383 |
384 while (initializing_ && (load_port_ == ILLEGAL_PORT)) { | 384 while (initializing_ && (load_port_ == DART_ILLEGAL_PORT)) { |
385 ml.Wait(); | 385 ml.Wait(); |
386 } | 386 } |
387 | 387 |
388 return load_port_; | 388 return load_port_; |
389 } | 389 } |
390 | 390 |
391 | 391 |
392 Dart_Port ServiceIsolate::LoadPort() { | 392 Dart_Port ServiceIsolate::LoadPort() { |
393 MonitorLocker ml(monitor_); | 393 MonitorLocker ml(monitor_); |
394 return load_port_; | 394 return load_port_; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 } | 480 } |
481 | 481 |
482 | 482 |
483 void ServiceIsolate::SetServiceIsolate(Isolate* isolate) { | 483 void ServiceIsolate::SetServiceIsolate(Isolate* isolate) { |
484 MonitorLocker ml(monitor_); | 484 MonitorLocker ml(monitor_); |
485 isolate_ = isolate; | 485 isolate_ = isolate; |
486 if (isolate_ != NULL) { | 486 if (isolate_ != NULL) { |
487 isolate_->is_service_isolate_ = true; | 487 isolate_->is_service_isolate_ = true; |
488 origin_ = isolate_->origin_id(); | 488 origin_ = isolate_->origin_id(); |
489 } else { | 489 } else { |
490 origin_ = ILLEGAL_PORT; | 490 origin_ = DART_ILLEGAL_PORT; |
491 } | 491 } |
492 } | 492 } |
493 | 493 |
494 void ServiceIsolate::SetLoadPort(Dart_Port port) { | 494 void ServiceIsolate::SetLoadPort(Dart_Port port) { |
495 MonitorLocker ml(monitor_); | 495 MonitorLocker ml(monitor_); |
496 load_port_ = port; | 496 load_port_ = port; |
497 } | 497 } |
498 | 498 |
499 | 499 |
500 void ServiceIsolate::MaybeInjectVMServiceLibrary(Isolate* isolate) { | 500 void ServiceIsolate::MaybeInjectVMServiceLibrary(Isolate* isolate) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 590 |
591 Dart_IsolateCreateCallback create_callback = | 591 Dart_IsolateCreateCallback create_callback = |
592 ServiceIsolate::create_callback(); | 592 ServiceIsolate::create_callback(); |
593 // TODO(johnmccutchan): Support starting up service isolate without embedder | 593 // TODO(johnmccutchan): Support starting up service isolate without embedder |
594 // provided isolate creation callback. | 594 // provided isolate creation callback. |
595 if (create_callback == NULL) { | 595 if (create_callback == NULL) { |
596 ServiceIsolate::FinishedInitializing(); | 596 ServiceIsolate::FinishedInitializing(); |
597 return; | 597 return; |
598 } | 598 } |
599 | 599 |
600 isolate = | 600 isolate = Api::CastIsolate(create_callback(ServiceIsolate::kName, |
601 reinterpret_cast<Isolate*>(create_callback(ServiceIsolate::kName, | 601 NULL, |
602 NULL, | 602 NULL, |
603 NULL, | 603 NULL, |
604 NULL, | 604 &error)); |
605 &error)); | |
606 if (isolate == NULL) { | 605 if (isolate == NULL) { |
607 OS::PrintErr("vm-service: Isolate creation error: %s\n", error); | 606 OS::PrintErr("vm-service: Isolate creation error: %s\n", error); |
608 ServiceIsolate::FinishedInitializing(); | 607 ServiceIsolate::FinishedInitializing(); |
609 return; | 608 return; |
610 } | 609 } |
611 | 610 |
612 Thread::ExitIsolate(); | 611 Thread::ExitIsolate(); |
613 | 612 |
614 ServiceIsolate::ConstructExitMessageAndCache(isolate); | 613 ServiceIsolate::ConstructExitMessageAndCache(isolate); |
615 | 614 |
(...skipping 23 matching lines...) Expand all Loading... |
639 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString()); | 638 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString()); |
640 } | 639 } |
641 Dart::RunShutdownCallback(); | 640 Dart::RunShutdownCallback(); |
642 } | 641 } |
643 { | 642 { |
644 // Shut the isolate down. | 643 // Shut the isolate down. |
645 SwitchIsolateScope switch_scope(isolate); | 644 SwitchIsolateScope switch_scope(isolate); |
646 Dart::ShutdownIsolate(); | 645 Dart::ShutdownIsolate(); |
647 } | 646 } |
648 ServiceIsolate::SetServiceIsolate(NULL); | 647 ServiceIsolate::SetServiceIsolate(NULL); |
649 ServiceIsolate::SetServicePort(ILLEGAL_PORT); | 648 ServiceIsolate::SetServicePort(DART_ILLEGAL_PORT); |
650 if (FLAG_trace_service) { | 649 if (FLAG_trace_service) { |
651 OS::Print("vm-service: Shutdown.\n"); | 650 OS::Print("vm-service: Shutdown.\n"); |
652 } | 651 } |
653 ServiceIsolate::FinishedExiting(); | 652 ServiceIsolate::FinishedExiting(); |
654 } | 653 } |
655 | 654 |
656 void RunMain(Isolate* isolate) { | 655 void RunMain(Isolate* isolate) { |
657 StartIsolateScope iso_scope(isolate); | 656 StartIsolateScope iso_scope(isolate); |
658 StackZone zone(isolate); | 657 StackZone zone(isolate); |
659 HANDLESCOPE(isolate); | 658 HANDLESCOPE(isolate); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 if (!IsRunning()) { | 716 if (!IsRunning()) { |
718 return; | 717 return; |
719 } | 718 } |
720 { | 719 { |
721 MonitorLocker ml(monitor_); | 720 MonitorLocker ml(monitor_); |
722 shutting_down_ = true; | 721 shutting_down_ = true; |
723 } | 722 } |
724 SendServiceExitMessage(); | 723 SendServiceExitMessage(); |
725 { | 724 { |
726 MonitorLocker ml(monitor_); | 725 MonitorLocker ml(monitor_); |
727 while (shutting_down_ && (port_ != ILLEGAL_PORT)) { | 726 while (shutting_down_ && (port_ != DART_ILLEGAL_PORT)) { |
728 ml.Wait(); | 727 ml.Wait(); |
729 } | 728 } |
730 } | 729 } |
731 } | 730 } |
732 | 731 |
733 | 732 |
734 Dart_Handle ServiceIsolate::GetSource(const char* name) { | 733 Dart_Handle ServiceIsolate::GetSource(const char* name) { |
735 ASSERT(name != NULL); | 734 ASSERT(name != NULL); |
736 int i = 0; | 735 int i = 0; |
737 while (true) { | 736 while (true) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 return result; | 770 return result; |
772 } | 771 } |
773 Dart_Handle source = GetSource(url_string); | 772 Dart_Handle source = GetSource(url_string); |
774 if (Dart_IsError(source)) { | 773 if (Dart_IsError(source)) { |
775 return source; | 774 return source; |
776 } | 775 } |
777 return Dart_LoadSource(library, url, source, 0, 0); | 776 return Dart_LoadSource(library, url, source, 0, 0); |
778 } | 777 } |
779 | 778 |
780 } // namespace dart | 779 } // namespace dart |
OLD | NEW |