Chromium Code Reviews| 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" |
| 11 #include "vm/lockers.h" | 11 #include "vm/lockers.h" |
| 12 #include "vm/message.h" | 12 #include "vm/message.h" |
| 13 #include "vm/message_handler.h" | 13 #include "vm/message_handler.h" |
| 14 #include "vm/native_entry.h" | 14 #include "vm/native_entry.h" |
| 15 #include "vm/native_arguments.h" | 15 #include "vm/native_arguments.h" |
| 16 #include "vm/object.h" | 16 #include "vm/object.h" |
| 17 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
| 18 #include "vm/port.h" | 18 #include "vm/port.h" |
| 19 #include "vm/service.h" | 19 #include "vm/service.h" |
| 20 #include "vm/symbols.h" | 20 #include "vm/symbols.h" |
| 21 #include "vm/thread_pool.h" | 21 #include "vm/thread_pool.h" |
| 22 | 22 |
| 23 namespace dart { | 23 namespace dart { |
| 24 | 24 |
| 25 #define Z (T->zone()) | |
| 26 | |
| 27 | |
| 25 DEFINE_FLAG(bool, trace_service, false, "Trace VM service requests."); | 28 DEFINE_FLAG(bool, trace_service, false, "Trace VM service requests."); |
| 26 DEFINE_FLAG(bool, trace_service_pause_events, false, | 29 DEFINE_FLAG(bool, trace_service_pause_events, false, |
| 27 "Trace VM service isolate pause events."); | 30 "Trace VM service isolate pause events."); |
| 28 | 31 |
| 29 struct ResourcesEntry { | 32 struct ResourcesEntry { |
| 30 const char* path_; | 33 const char* path_; |
| 31 const char* resource_; | 34 const char* resource_; |
| 32 int length_; | 35 int length_; |
| 33 }; | 36 }; |
| 34 | 37 |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 origin_ = ILLEGAL_PORT; | 522 origin_ = ILLEGAL_PORT; |
| 520 } | 523 } |
| 521 } | 524 } |
| 522 | 525 |
| 523 void ServiceIsolate::SetLoadPort(Dart_Port port) { | 526 void ServiceIsolate::SetLoadPort(Dart_Port port) { |
| 524 MonitorLocker ml(monitor_); | 527 MonitorLocker ml(monitor_); |
| 525 load_port_ = port; | 528 load_port_ = port; |
| 526 } | 529 } |
| 527 | 530 |
| 528 | 531 |
| 529 void ServiceIsolate::MaybeInjectVMServiceLibrary(Isolate* isolate) { | 532 void ServiceIsolate::MaybeInjectVMServiceLibrary(Isolate* I) { |
| 530 Thread* thread = Thread::Current(); | 533 Thread* T = Thread::Current(); |
| 531 ASSERT(isolate == thread->isolate()); | 534 ASSERT(I == T->isolate()); |
| 532 ASSERT(isolate != NULL); | 535 ASSERT(I != NULL); |
| 533 ASSERT(isolate->name() != NULL); | 536 ASSERT(I->name() != NULL); |
| 534 if (!ServiceIsolate::NameEquals(isolate->name())) { | 537 if (!ServiceIsolate::NameEquals(I->name())) { |
| 535 // Not service isolate. | 538 // Not service isolate. |
| 536 return; | 539 return; |
| 537 } | 540 } |
| 538 if (Exists()) { | 541 if (Exists()) { |
| 539 // Service isolate already exists. | 542 // Service isolate already exists. |
| 540 return; | 543 return; |
| 541 } | 544 } |
| 542 SetServiceIsolate(isolate); | 545 SetServiceIsolate(I); |
| 543 | 546 |
| 544 StackZone zone(isolate); | 547 StackZone zone(T); |
| 545 HANDLESCOPE(thread); | 548 HANDLESCOPE(T); |
| 546 | 549 |
| 547 // Register dart:vmservice library. | 550 // Register dart:vmservice library. |
| 548 const String& url_str = String::Handle(Symbols::DartVMService().raw()); | 551 const String& url_str = String::Handle(Z, Symbols::DartVMService().raw()); |
|
srdjan
2015/09/02 22:24:09
ditto
Ivan Posva
2015/09/02 22:59:26
ditto
| |
| 549 const Library& library = Library::Handle(Library::New(url_str)); | 552 const Library& library = Library::Handle(Z, Library::New(url_str)); |
| 550 library.Register(); | 553 library.Register(); |
| 551 library.set_native_entry_resolver(ServiceNativeResolver); | 554 library.set_native_entry_resolver(ServiceNativeResolver); |
| 552 | 555 |
| 553 // Temporarily install our library tag handler. | 556 // Temporarily install our library tag handler. |
| 554 isolate->set_library_tag_handler(LibraryTagHandler); | 557 I->set_library_tag_handler(LibraryTagHandler); |
| 555 | 558 |
| 556 // Get script source. | 559 // Get script source. |
| 557 const char* resource = NULL; | 560 const char* resource = NULL; |
| 558 const char* path = "/vmservice.dart"; | 561 const char* path = "/vmservice.dart"; |
| 559 intptr_t r = Resources::ResourceLookup(path, &resource); | 562 intptr_t r = Resources::ResourceLookup(path, &resource); |
| 560 ASSERT(r != Resources::kNoSuchInstance); | 563 ASSERT(r != Resources::kNoSuchInstance); |
| 561 ASSERT(resource != NULL); | 564 ASSERT(resource != NULL); |
| 562 const String& source_str = String::Handle( | 565 const String& source_str = String::Handle(Z, |
| 563 String::FromUTF8(reinterpret_cast<const uint8_t*>(resource), r)); | 566 String::FromUTF8(reinterpret_cast<const uint8_t*>(resource), r)); |
| 564 ASSERT(!source_str.IsNull()); | 567 ASSERT(!source_str.IsNull()); |
| 565 const Script& script = Script::Handle( | 568 const Script& script = Script::Handle(Z, |
| 566 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag)); | 569 Script::New(url_str, source_str, RawScript::kLibraryTag)); |
| 567 | 570 |
| 568 // Compile script. | 571 // Compile script. |
| 569 Dart_EnterScope(); // Need to enter scope for tag handler. | 572 Dart_EnterScope(); // Need to enter scope for tag handler. |
| 570 library.SetLoadInProgress(); | 573 library.SetLoadInProgress(); |
| 571 const Error& error = Error::Handle(isolate, | 574 const Error& error = Error::Handle(Z, Compiler::Compile(library, script)); |
| 572 Compiler::Compile(library, script)); | |
| 573 if (!error.IsNull()) { | 575 if (!error.IsNull()) { |
| 574 OS::PrintErr("vm-service: Isolate creation error: %s\n", | 576 OS::PrintErr("vm-service: Isolate creation error: %s\n", |
| 575 error.ToErrorCString()); | 577 error.ToErrorCString()); |
| 576 } | 578 } |
| 577 ASSERT(error.IsNull()); | 579 ASSERT(error.IsNull()); |
| 578 Dart_Handle result = Dart_FinalizeLoading(false); | 580 Dart_Handle result = Dart_FinalizeLoading(false); |
| 579 ASSERT(!Dart_IsError(result)); | 581 ASSERT(!Dart_IsError(result)); |
| 580 Dart_ExitScope(); | 582 Dart_ExitScope(); |
| 581 | 583 |
| 582 // Uninstall our library tag handler. | 584 // Uninstall our library tag handler. |
| 583 isolate->set_library_tag_handler(NULL); | 585 I->set_library_tag_handler(NULL); |
| 584 } | 586 } |
| 585 | 587 |
| 586 | 588 |
| 587 void ServiceIsolate::ConstructExitMessageAndCache(Isolate* isolate) { | 589 void ServiceIsolate::ConstructExitMessageAndCache(Isolate* I) { |
| 588 // Construct and cache exit message here so we can send it without needing an | 590 // Construct and cache exit message here so we can send it without needing an |
| 589 // isolate. | 591 // isolate. |
| 590 StartIsolateScope iso_scope(isolate); | 592 StartIsolateScope iso_scope(I); |
| 591 Thread* thread = Thread::Current(); | 593 Thread* T = Thread::Current(); |
| 592 ASSERT(isolate == thread->isolate()); | 594 ASSERT(I == T->isolate()); |
| 593 ASSERT(isolate != NULL); | 595 ASSERT(I != NULL); |
| 594 StackZone zone(isolate); | 596 StackZone zone(T); |
| 595 HANDLESCOPE(thread); | 597 HANDLESCOPE(T); |
| 596 ASSERT(exit_message_ == NULL); | 598 ASSERT(exit_message_ == NULL); |
| 597 ASSERT(exit_message_length_ == 0); | 599 ASSERT(exit_message_length_ == 0); |
| 598 const Array& list = Array::Handle(MakeServiceExitMessage()); | 600 const Array& list = Array::Handle(Z, MakeServiceExitMessage()); |
| 599 ASSERT(!list.IsNull()); | 601 ASSERT(!list.IsNull()); |
| 600 MessageWriter writer(&exit_message_, &allocator, false); | 602 MessageWriter writer(&exit_message_, &allocator, false); |
| 601 writer.WriteMessage(list); | 603 writer.WriteMessage(list); |
| 602 exit_message_length_ = writer.BytesWritten(); | 604 exit_message_length_ = writer.BytesWritten(); |
| 603 ASSERT(exit_message_ != NULL); | 605 ASSERT(exit_message_ != NULL); |
| 604 ASSERT(exit_message_length_ != 0); | 606 ASSERT(exit_message_length_ != 0); |
| 605 } | 607 } |
| 606 | 608 |
| 607 | 609 |
| 608 void ServiceIsolate::FinishedExiting() { | 610 void ServiceIsolate::FinishedExiting() { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 ServiceIsolate::FinishedInitializing(); | 666 ServiceIsolate::FinishedInitializing(); |
| 665 | 667 |
| 666 isolate->message_handler()->Run(Dart::thread_pool(), | 668 isolate->message_handler()->Run(Dart::thread_pool(), |
| 667 NULL, | 669 NULL, |
| 668 ShutdownIsolate, | 670 ShutdownIsolate, |
| 669 reinterpret_cast<uword>(isolate)); | 671 reinterpret_cast<uword>(isolate)); |
| 670 } | 672 } |
| 671 | 673 |
| 672 protected: | 674 protected: |
| 673 static void ShutdownIsolate(uword parameter) { | 675 static void ShutdownIsolate(uword parameter) { |
| 674 Isolate* isolate = reinterpret_cast<Isolate*>(parameter); | 676 Isolate* I = reinterpret_cast<Isolate*>(parameter); |
| 675 ASSERT(ServiceIsolate::IsServiceIsolate(isolate)); | 677 ASSERT(ServiceIsolate::IsServiceIsolate(I)); |
| 676 { | 678 { |
| 677 // Print the error if there is one. This may execute dart code to | 679 // Print the error if there is one. This may execute dart code to |
| 678 // print the exception object, so we need to use a StartIsolateScope. | 680 // print the exception object, so we need to use a StartIsolateScope. |
| 679 StartIsolateScope start_scope(isolate); | 681 StartIsolateScope start_scope(I); |
| 680 Thread* thread = Thread::Current(); | 682 Thread* T = Thread::Current(); |
| 681 ASSERT(isolate == thread->isolate()); | 683 ASSERT(I == T->isolate()); |
| 682 StackZone zone(isolate); | 684 StackZone zone(T); |
| 683 HandleScope handle_scope(thread); | 685 HandleScope handle_scope(T); |
| 684 Error& error = Error::Handle(); | 686 Error& error = Error::Handle(Z); |
| 685 error = isolate->object_store()->sticky_error(); | 687 error = I->object_store()->sticky_error(); |
| 686 if (!error.IsNull()) { | 688 if (!error.IsNull()) { |
| 687 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString()); | 689 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString()); |
| 688 } | 690 } |
| 689 Dart::RunShutdownCallback(); | 691 Dart::RunShutdownCallback(); |
| 690 } | 692 } |
| 691 { | 693 { |
| 692 // Shut the isolate down. | 694 // Shut the isolate down. |
| 693 SwitchIsolateScope switch_scope(isolate); | 695 SwitchIsolateScope switch_scope(I); |
| 694 Dart::ShutdownIsolate(); | 696 Dart::ShutdownIsolate(); |
| 695 } | 697 } |
| 696 ServiceIsolate::SetServiceIsolate(NULL); | 698 ServiceIsolate::SetServiceIsolate(NULL); |
| 697 ServiceIsolate::SetServicePort(ILLEGAL_PORT); | 699 ServiceIsolate::SetServicePort(ILLEGAL_PORT); |
| 698 if (FLAG_trace_service) { | 700 if (FLAG_trace_service) { |
| 699 OS::Print("vm-service: Shutdown.\n"); | 701 OS::Print("vm-service: Shutdown.\n"); |
| 700 } | 702 } |
| 701 ServiceIsolate::FinishedExiting(); | 703 ServiceIsolate::FinishedExiting(); |
| 702 } | 704 } |
| 703 | 705 |
| 704 void RunMain(Isolate* isolate) { | 706 void RunMain(Isolate* I) { |
| 705 StartIsolateScope iso_scope(isolate); | 707 StartIsolateScope iso_scope(I); |
| 706 Thread* thread = Thread::Current(); | 708 Thread* T = Thread::Current(); |
| 707 ASSERT(isolate == thread->isolate()); | 709 ASSERT(I == T->isolate()); |
| 708 StackZone zone(isolate); | 710 StackZone zone(T); |
| 709 HANDLESCOPE(thread); | 711 HANDLESCOPE(T); |
| 710 // Invoke main which will return the loadScriptPort. | 712 // Invoke main which will return the loadScriptPort. |
| 711 const Library& root_library = | 713 const Library& root_library = Library::Handle(Z, |
| 712 Library::Handle(isolate, isolate->object_store()->root_library()); | 714 I->object_store()->root_library()); |
| 713 if (root_library.IsNull()) { | 715 if (root_library.IsNull()) { |
| 714 if (FLAG_trace_service) { | 716 if (FLAG_trace_service) { |
| 715 OS::Print("vm-service: Embedder did not install a script."); | 717 OS::Print("vm-service: Embedder did not install a script."); |
| 716 } | 718 } |
| 717 // Service isolate is not supported by embedder. | 719 // Service isolate is not supported by embedder. |
| 718 return; | 720 return; |
| 719 } | 721 } |
| 720 ASSERT(!root_library.IsNull()); | 722 ASSERT(!root_library.IsNull()); |
| 721 const String& entry_name = String::Handle(isolate, String::New("main")); | 723 const String& entry_name = String::Handle(Z, String::New("main")); |
| 722 ASSERT(!entry_name.IsNull()); | 724 ASSERT(!entry_name.IsNull()); |
| 723 const Function& entry = | 725 const Function& entry = Function::Handle(Z, |
| 724 Function::Handle(isolate, | 726 root_library.LookupFunctionAllowPrivate(entry_name)); |
| 725 root_library.LookupFunctionAllowPrivate(entry_name)); | |
| 726 if (entry.IsNull()) { | 727 if (entry.IsNull()) { |
| 727 // Service isolate is not supported by embedder. | 728 // Service isolate is not supported by embedder. |
| 728 if (FLAG_trace_service) { | 729 if (FLAG_trace_service) { |
| 729 OS::Print("vm-service: Embedder did not provide a main function."); | 730 OS::Print("vm-service: Embedder did not provide a main function."); |
| 730 } | 731 } |
| 731 return; | 732 return; |
| 732 } | 733 } |
| 733 ASSERT(!entry.IsNull()); | 734 ASSERT(!entry.IsNull()); |
| 734 const Object& result = | 735 const Object& result = Object::Handle(Z, |
| 735 Object::Handle(isolate, | 736 DartEntry::InvokeFunction(entry, Object::empty_array())); |
| 736 DartEntry::InvokeFunction(entry, | |
| 737 Object::empty_array())); | |
| 738 ASSERT(!result.IsNull()); | 737 ASSERT(!result.IsNull()); |
| 739 if (result.IsError()) { | 738 if (result.IsError()) { |
| 740 // Service isolate did not initialize properly. | 739 // Service isolate did not initialize properly. |
| 741 if (FLAG_trace_service) { | 740 if (FLAG_trace_service) { |
| 742 const Error& error = Error::Cast(result); | 741 const Error& error = Error::Cast(result); |
| 743 OS::Print("vm-service: Calling main resulted in an error: %s", | 742 OS::Print("vm-service: Calling main resulted in an error: %s", |
| 744 error.ToErrorCString()); | 743 error.ToErrorCString()); |
| 745 } | 744 } |
| 746 return; | 745 return; |
| 747 } | 746 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 return result; | 820 return result; |
| 822 } | 821 } |
| 823 Dart_Handle source = GetSource(url_string); | 822 Dart_Handle source = GetSource(url_string); |
| 824 if (Dart_IsError(source)) { | 823 if (Dart_IsError(source)) { |
| 825 return source; | 824 return source; |
| 826 } | 825 } |
| 827 return Dart_LoadSource(library, url, source, 0, 0); | 826 return Dart_LoadSource(library, url, source, 0, 0); |
| 828 } | 827 } |
| 829 | 828 |
| 830 } // namespace dart | 829 } // namespace dart |
| OLD | NEW |