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 "vm/isolate.h" | 5 #include "vm/isolate.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "platform/json.h" | 9 #include "platform/json.h" |
10 #include "vm/code_observers.h" | 10 #include "vm/code_observers.h" |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 void Isolate::InitOnce() { | 617 void Isolate::InitOnce() { |
618 ASSERT(isolate_key == OSThread::kUnsetThreadLocalKey); | 618 ASSERT(isolate_key == OSThread::kUnsetThreadLocalKey); |
619 isolate_key = OSThread::CreateThreadLocal(); | 619 isolate_key = OSThread::CreateThreadLocal(); |
620 ASSERT(isolate_key != OSThread::kUnsetThreadLocalKey); | 620 ASSERT(isolate_key != OSThread::kUnsetThreadLocalKey); |
621 create_callback_ = NULL; | 621 create_callback_ = NULL; |
622 isolates_list_monitor_ = new Monitor(); | 622 isolates_list_monitor_ = new Monitor(); |
623 ASSERT(isolates_list_monitor_ != NULL); | 623 ASSERT(isolates_list_monitor_ != NULL); |
624 } | 624 } |
625 | 625 |
626 | 626 |
627 Isolate* Isolate::Init(const char* name_prefix) { | 627 Isolate* Isolate::Init(const char* name_prefix, bool is_vm_isolate) { |
628 Isolate* result = new Isolate(); | 628 Isolate* result = new Isolate(); |
629 ASSERT(result != NULL); | 629 ASSERT(result != NULL); |
630 | 630 |
631 // Initialize metrics. | 631 // Initialize metrics. |
632 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \ | 632 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \ |
633 result->metric_##variable##_.Init(result, name, NULL, Metric::unit); | 633 result->metric_##variable##_.Init(result, name, NULL, Metric::unit); |
634 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); | 634 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); |
635 #undef ISOLATE_METRIC_INIT | 635 #undef ISOLATE_METRIC_INIT |
636 | 636 |
637 // TODO(5411455): For now just set the recently created isolate as | 637 // TODO(5411455): For now just set the recently created isolate as |
638 // the current isolate. | 638 // the current isolate. |
639 SetCurrent(result); | 639 SetCurrent(result); |
640 | 640 |
641 // Setup the isolate specific resuable handles. | 641 // Setup the isolate specific resuable handles. |
642 #define REUSABLE_HANDLE_ALLOCATION(object) \ | 642 #define REUSABLE_HANDLE_ALLOCATION(object) \ |
643 result->object##_handle_ = result->AllocateReusableHandle<object>(); | 643 result->object##_handle_ = result->AllocateReusableHandle<object>(); |
644 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) | 644 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) |
645 #undef REUSABLE_HANDLE_ALLOCATION | 645 #undef REUSABLE_HANDLE_ALLOCATION |
646 | 646 |
647 // Setup the isolate message handler. | 647 // Setup the isolate message handler. |
648 MessageHandler* handler = new IsolateMessageHandler(result); | 648 MessageHandler* handler = new IsolateMessageHandler(result); |
649 ASSERT(handler != NULL); | 649 ASSERT(handler != NULL); |
650 result->set_message_handler(handler); | 650 result->set_message_handler(handler); |
651 | 651 |
652 // Setup the Dart API state. | 652 // Setup the Dart API state. |
653 ApiState* state = new ApiState(); | 653 ApiState* state = new ApiState(); |
654 ASSERT(state != NULL); | 654 ASSERT(state != NULL); |
655 result->set_api_state(state); | 655 result->set_api_state(state); |
656 | 656 |
657 // Initialize stack top and limit in case we are running the isolate in the | 657 // Initialize stack limit (wait until later for the VM isolate, since the |
658 // main thread. | 658 // needed GetStackPointer stub has not yet been generated in that case). |
659 // TODO(5411455): Need to figure out how to set the stack limit for the | 659 if (!is_vm_isolate) { |
660 // main thread. | 660 result->InitializeStackLimit(); |
661 result->SetStackLimitFromStackBase(reinterpret_cast<uword>(&result)); | 661 } |
662 result->set_main_port(PortMap::CreatePort(result->message_handler())); | 662 result->set_main_port(PortMap::CreatePort(result->message_handler())); |
663 #if defined(DEBUG) | 663 #if defined(DEBUG) |
664 // Verify that we are never reusing a live origin id. | 664 // Verify that we are never reusing a live origin id. |
665 VerifyOriginId id_verifier(result->main_port()); | 665 VerifyOriginId id_verifier(result->main_port()); |
666 Isolate::VisitIsolates(&id_verifier); | 666 Isolate::VisitIsolates(&id_verifier); |
667 #endif | 667 #endif |
668 result->set_origin_id(result->main_port()); | 668 result->set_origin_id(result->main_port()); |
669 result->set_pause_capability(result->random()->NextUInt64()); | 669 result->set_pause_capability(result->random()->NextUInt64()); |
670 result->set_terminate_capability(result->random()->NextUInt64()); | 670 result->set_terminate_capability(result->random()->NextUInt64()); |
671 | 671 |
672 result->BuildName(name_prefix); | 672 result->BuildName(name_prefix); |
673 | 673 |
674 result->debugger_ = new Debugger(); | 674 result->debugger_ = new Debugger(); |
675 result->debugger_->Initialize(result); | 675 result->debugger_->Initialize(result); |
676 if (FLAG_trace_isolates) { | 676 if (FLAG_trace_isolates) { |
677 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { | 677 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { |
678 OS::Print("[+] Starting isolate:\n" | 678 OS::Print("[+] Starting isolate:\n" |
679 "\tisolate: %s\n", result->name()); | 679 "\tisolate: %s\n", result->name()); |
680 } | 680 } |
681 } | 681 } |
682 | 682 |
683 // Add to isolate list. | 683 // Add to isolate list. |
684 AddIsolateTolist(result); | 684 AddIsolateTolist(result); |
685 | 685 |
686 return result; | 686 return result; |
687 } | 687 } |
688 | 688 |
689 | 689 |
| 690 void Isolate::InitializeStackLimit() { |
| 691 SetStackLimitFromStackBase(Isolate::GetCurrentStackPointer()); |
| 692 } |
| 693 |
| 694 |
| 695 /* static */ |
| 696 uword Isolate::GetCurrentStackPointer() { |
| 697 // Since AddressSanitizer's detect_stack_use_after_return instruments the |
| 698 // C++ code to give out fake stack addresses, we call a stub in that case. |
| 699 uword (*func)() = |
| 700 reinterpret_cast<uword (*)()>(StubCode::GetStackPointerEntryPoint()); |
| 701 // But for performance (and to support simulators), we normally use a local. |
| 702 uword stack_allocated_local_address = reinterpret_cast<uword>(&func); |
| 703 #if defined(__has_feature) |
| 704 #if __has_feature(address_sanitizer) |
| 705 uword current_sp = func(); |
| 706 return current_sp; |
| 707 #else |
| 708 return stack_allocated_local_address; |
| 709 #endif |
| 710 #else |
| 711 return stack_allocated_local_address; |
| 712 #endif |
| 713 } |
| 714 |
| 715 |
690 void Isolate::BuildName(const char* name_prefix) { | 716 void Isolate::BuildName(const char* name_prefix) { |
691 ASSERT(name_ == NULL); | 717 ASSERT(name_ == NULL); |
692 if (name_prefix == NULL) { | 718 if (name_prefix == NULL) { |
693 name_prefix = "isolate"; | 719 name_prefix = "isolate"; |
694 } | 720 } |
695 if (ServiceIsolate::NameEquals(name_prefix)) { | 721 if (ServiceIsolate::NameEquals(name_prefix)) { |
696 name_ = strdup(name_prefix); | 722 name_ = strdup(name_prefix); |
697 return; | 723 return; |
698 } | 724 } |
699 const char* kFormat = "%s-%lld"; | 725 const char* kFormat = "%s-%lld"; |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 serialized_message_, serialized_message_len_); | 1699 serialized_message_, serialized_message_len_); |
1674 } | 1700 } |
1675 | 1701 |
1676 | 1702 |
1677 void IsolateSpawnState::Cleanup() { | 1703 void IsolateSpawnState::Cleanup() { |
1678 SwitchIsolateScope switch_scope(I); | 1704 SwitchIsolateScope switch_scope(I); |
1679 Dart::ShutdownIsolate(); | 1705 Dart::ShutdownIsolate(); |
1680 } | 1706 } |
1681 | 1707 |
1682 } // namespace dart | 1708 } // namespace dart |
OLD | NEW |