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

Side by Side Diff: runtime/vm/service_isolate.cc

Issue 1130753006: Hide Isolate pointer from embedder (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/port.cc ('k') | runtime/vm/unit_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 594
595 Dart_IsolateCreateCallback create_callback = 595 Dart_IsolateCreateCallback create_callback =
596 ServiceIsolate::create_callback(); 596 ServiceIsolate::create_callback();
597 // TODO(johnmccutchan): Support starting up service isolate without embedder 597 // TODO(johnmccutchan): Support starting up service isolate without embedder
598 // provided isolate creation callback. 598 // provided isolate creation callback.
599 if (create_callback == NULL) { 599 if (create_callback == NULL) {
600 ServiceIsolate::FinishedInitializing(); 600 ServiceIsolate::FinishedInitializing();
601 return; 601 return;
602 } 602 }
603 603
604 isolate = 604 isolate = Api::CastIsolate(create_callback(ServiceIsolate::kName,
605 reinterpret_cast<Isolate*>(create_callback(ServiceIsolate::kName, 605 NULL,
606 NULL, 606 NULL,
607 NULL, 607 NULL,
608 NULL, 608 &error));
609 &error));
610 if (isolate == NULL) { 609 if (isolate == NULL) {
611 OS::PrintErr("vm-service: Isolate creation error: %s\n", error); 610 OS::PrintErr("vm-service: Isolate creation error: %s\n", error);
612 ServiceIsolate::FinishedInitializing(); 611 ServiceIsolate::FinishedInitializing();
613 return; 612 return;
614 } 613 }
615 614
616 Thread::ExitIsolate(); 615 Thread::ExitIsolate();
617 616
618 ServiceIsolate::ConstructExitMessageAndCache(isolate); 617 ServiceIsolate::ConstructExitMessageAndCache(isolate);
619 618
(...skipping 23 matching lines...) Expand all
643 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString()); 642 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString());
644 } 643 }
645 Dart::RunShutdownCallback(); 644 Dart::RunShutdownCallback();
646 } 645 }
647 { 646 {
648 // Shut the isolate down. 647 // Shut the isolate down.
649 SwitchIsolateScope switch_scope(isolate); 648 SwitchIsolateScope switch_scope(isolate);
650 Dart::ShutdownIsolate(); 649 Dart::ShutdownIsolate();
651 } 650 }
652 ServiceIsolate::SetServiceIsolate(NULL); 651 ServiceIsolate::SetServiceIsolate(NULL);
653 ServiceIsolate::SetServicePort(ILLEGAL_PORT); 652 ServiceIsolate::SetServicePort(DART_ILLEGAL_PORT);
654 if (FLAG_trace_service) { 653 if (FLAG_trace_service) {
655 OS::Print("vm-service: Shutdown.\n"); 654 OS::Print("vm-service: Shutdown.\n");
656 } 655 }
657 ServiceIsolate::FinishedExiting(); 656 ServiceIsolate::FinishedExiting();
658 } 657 }
659 658
660 void RunMain(Isolate* isolate) { 659 void RunMain(Isolate* isolate) {
661 StartIsolateScope iso_scope(isolate); 660 StartIsolateScope iso_scope(isolate);
662 StackZone zone(isolate); 661 StackZone zone(isolate);
663 HANDLESCOPE(isolate); 662 HANDLESCOPE(isolate);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 if (!IsRunning()) { 720 if (!IsRunning()) {
722 return; 721 return;
723 } 722 }
724 { 723 {
725 MonitorLocker ml(monitor_); 724 MonitorLocker ml(monitor_);
726 shutting_down_ = true; 725 shutting_down_ = true;
727 } 726 }
728 SendServiceExitMessage(); 727 SendServiceExitMessage();
729 { 728 {
730 MonitorLocker ml(monitor_); 729 MonitorLocker ml(monitor_);
731 while (shutting_down_ && (port_ != ILLEGAL_PORT)) { 730 while (shutting_down_ && (port_ != DART_ILLEGAL_PORT)) {
732 ml.Wait(); 731 ml.Wait();
733 } 732 }
734 } 733 }
735 } 734 }
736 735
737 736
738 Dart_Handle ServiceIsolate::GetSource(const char* name) { 737 Dart_Handle ServiceIsolate::GetSource(const char* name) {
739 ASSERT(name != NULL); 738 ASSERT(name != NULL);
740 int i = 0; 739 int i = 0;
741 while (true) { 740 while (true) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 return result; 774 return result;
776 } 775 }
777 Dart_Handle source = GetSource(url_string); 776 Dart_Handle source = GetSource(url_string);
778 if (Dart_IsError(source)) { 777 if (Dart_IsError(source)) {
779 return source; 778 return source;
780 } 779 }
781 return Dart_LoadSource(library, url, source, 0, 0); 780 return Dart_LoadSource(library, url, source, 0, 0);
782 } 781 }
783 782
784 } // namespace dart 783 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/port.cc ('k') | runtime/vm/unit_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698