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 "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/text_buffer.h" | 10 #include "platform/text_buffer.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 NoOOBMessageScope::NoOOBMessageScope(Thread* thread) : StackResource(thread) { | 137 NoOOBMessageScope::NoOOBMessageScope(Thread* thread) : StackResource(thread) { |
138 thread->DeferOOBMessageInterrupts(); | 138 thread->DeferOOBMessageInterrupts(); |
139 } | 139 } |
140 | 140 |
141 NoOOBMessageScope::~NoOOBMessageScope() { | 141 NoOOBMessageScope::~NoOOBMessageScope() { |
142 thread()->RestoreOOBMessageInterrupts(); | 142 thread()->RestoreOOBMessageInterrupts(); |
143 } | 143 } |
144 | 144 |
145 NoReloadScope::NoReloadScope(Isolate* isolate, Thread* thread) | 145 NoReloadScope::NoReloadScope(Isolate* isolate, Thread* thread) |
146 : StackResource(thread), isolate_(isolate) { | 146 : StackResource(thread), isolate_(isolate) { |
| 147 #if !defined(PRODUCT) |
147 ASSERT(isolate_ != NULL); | 148 ASSERT(isolate_ != NULL); |
148 AtomicOperations::FetchAndIncrement(&(isolate_->no_reload_scope_depth_)); | 149 AtomicOperations::FetchAndIncrement(&(isolate_->no_reload_scope_depth_)); |
149 ASSERT(AtomicOperations::LoadRelaxed(&(isolate_->no_reload_scope_depth_)) >= | 150 ASSERT(AtomicOperations::LoadRelaxed(&(isolate_->no_reload_scope_depth_)) >= |
150 0); | 151 0); |
| 152 #endif // !defined(PRODUCT) |
151 } | 153 } |
152 | 154 |
153 NoReloadScope::~NoReloadScope() { | 155 NoReloadScope::~NoReloadScope() { |
| 156 #if !defined(PRODUCT) |
154 AtomicOperations::FetchAndDecrement(&(isolate_->no_reload_scope_depth_)); | 157 AtomicOperations::FetchAndDecrement(&(isolate_->no_reload_scope_depth_)); |
155 ASSERT(AtomicOperations::LoadRelaxed(&(isolate_->no_reload_scope_depth_)) >= | 158 ASSERT(AtomicOperations::LoadRelaxed(&(isolate_->no_reload_scope_depth_)) >= |
156 0); | 159 0); |
| 160 #endif // !defined(PRODUCT) |
157 } | 161 } |
158 | 162 |
159 void Isolate::RegisterClass(const Class& cls) { | 163 void Isolate::RegisterClass(const Class& cls) { |
160 #if !defined(PRODUCT) | 164 #if !defined(PRODUCT) |
161 if (IsReloading()) { | 165 if (IsReloading()) { |
162 reload_context()->RegisterClass(cls); | 166 reload_context()->RegisterClass(cls); |
163 return; | 167 return; |
164 } | 168 } |
165 #endif // !defined(PRODUCT) | 169 #endif // !defined(PRODUCT) |
166 class_table()->Register(cls); | 170 class_table()->Register(cls); |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 // that shared monitor. | 739 // that shared monitor. |
736 Isolate::Isolate(const Dart_IsolateFlags& api_flags) | 740 Isolate::Isolate(const Dart_IsolateFlags& api_flags) |
737 : store_buffer_(new StoreBuffer()), | 741 : store_buffer_(new StoreBuffer()), |
738 heap_(NULL), | 742 heap_(NULL), |
739 user_tag_(0), | 743 user_tag_(0), |
740 current_tag_(UserTag::null()), | 744 current_tag_(UserTag::null()), |
741 default_tag_(UserTag::null()), | 745 default_tag_(UserTag::null()), |
742 object_store_(NULL), | 746 object_store_(NULL), |
743 class_table_(), | 747 class_table_(), |
744 single_step_(false), | 748 single_step_(false), |
| 749 errors_fatal_(true), |
| 750 is_runnable_(false), |
| 751 is_service_isolate_(false), |
| 752 compilation_allowed_(true), |
| 753 all_classes_finalized_(false), |
| 754 remapping_cids_(false), |
| 755 #if !defined(PRODUCT) |
| 756 resume_request_(false), |
| 757 has_attempted_reload_(false), |
| 758 should_pause_post_service_request_(false), |
| 759 debugger_name_(NULL), |
| 760 debugger_(NULL), |
| 761 last_resume_timestamp_(OS::GetCurrentTimeMillis()), |
| 762 last_allocationprofile_accumulator_reset_timestamp_(0), |
| 763 last_allocationprofile_gc_timestamp_(0), |
| 764 pending_service_extension_calls_(GrowableObjectArray::null()), |
| 765 registered_service_extension_handlers_(GrowableObjectArray::null()), |
| 766 metrics_list_head_(NULL), |
| 767 pause_loop_monitor_(NULL), |
| 768 #define ISOLATE_METRIC_CONSTRUCTORS(type, variable, name, unit) \ |
| 769 metric_##variable##_(), |
| 770 ISOLATE_METRIC_LIST(ISOLATE_METRIC_CONSTRUCTORS) |
| 771 #undef ISOLATE_METRIC_CONSTRUCTORS |
| 772 no_reload_scope_depth_(0), |
| 773 reload_every_n_stack_overflow_checks_(FLAG_reload_every), |
| 774 reload_context_(NULL), |
| 775 last_reload_timestamp_(OS::GetCurrentTimeMillis()), |
| 776 object_id_ring_(NULL), |
| 777 #endif // !defined(PRODUCT) |
745 thread_registry_(new ThreadRegistry()), | 778 thread_registry_(new ThreadRegistry()), |
746 safepoint_handler_(new SafepointHandler(this)), | 779 safepoint_handler_(new SafepointHandler(this)), |
747 message_notify_callback_(NULL), | 780 message_notify_callback_(NULL), |
748 name_(NULL), | 781 name_(NULL), |
749 debugger_name_(NULL), | |
750 start_time_micros_(OS::GetCurrentMonotonicMicros()), | |
751 main_port_(0), | 782 main_port_(0), |
752 origin_id_(0), | 783 origin_id_(0), |
753 pause_capability_(0), | 784 pause_capability_(0), |
754 terminate_capability_(0), | 785 terminate_capability_(0), |
755 errors_fatal_(true), | |
756 init_callback_data_(NULL), | 786 init_callback_data_(NULL), |
757 environment_callback_(NULL), | 787 environment_callback_(NULL), |
758 library_tag_handler_(NULL), | 788 library_tag_handler_(NULL), |
759 api_state_(NULL), | 789 api_state_(NULL), |
760 #if !defined(PRODUCT) | |
761 debugger_(NULL), | |
762 resume_request_(false), | |
763 last_resume_timestamp_(OS::GetCurrentTimeMillis()), | |
764 #endif | |
765 random_(), | 790 random_(), |
766 simulator_(NULL), | 791 simulator_(NULL), |
767 mutex_(new Mutex()), | 792 mutex_(new Mutex()), |
768 symbols_mutex_(new Mutex()), | 793 symbols_mutex_(new Mutex()), |
769 type_canonicalization_mutex_(new Mutex()), | 794 type_canonicalization_mutex_(new Mutex()), |
770 constant_canonicalization_mutex_(new Mutex()), | 795 constant_canonicalization_mutex_(new Mutex()), |
771 megamorphic_lookup_mutex_(new Mutex()), | 796 megamorphic_lookup_mutex_(new Mutex()), |
772 message_handler_(NULL), | 797 message_handler_(NULL), |
773 spawn_state_(NULL), | 798 spawn_state_(NULL), |
774 is_runnable_(false), | |
775 gc_prologue_callback_(NULL), | 799 gc_prologue_callback_(NULL), |
776 gc_epilogue_callback_(NULL), | 800 gc_epilogue_callback_(NULL), |
777 defer_finalization_count_(0), | 801 defer_finalization_count_(0), |
778 pending_deopts_(new MallocGrowableArray<PendingLazyDeopt>), | 802 pending_deopts_(new MallocGrowableArray<PendingLazyDeopt>), |
779 deopt_context_(NULL), | 803 deopt_context_(NULL), |
780 is_service_isolate_(false), | |
781 last_allocationprofile_accumulator_reset_timestamp_(0), | |
782 last_allocationprofile_gc_timestamp_(0), | |
783 object_id_ring_(NULL), | |
784 tag_table_(GrowableObjectArray::null()), | 804 tag_table_(GrowableObjectArray::null()), |
785 deoptimized_code_array_(GrowableObjectArray::null()), | 805 deoptimized_code_array_(GrowableObjectArray::null()), |
786 sticky_error_(Error::null()), | 806 sticky_error_(Error::null()), |
787 background_compiler_(NULL), | 807 background_compiler_(NULL), |
788 background_compiler_disabled_depth_(0), | 808 background_compiler_disabled_depth_(0), |
789 pending_service_extension_calls_(GrowableObjectArray::null()), | |
790 registered_service_extension_handlers_(GrowableObjectArray::null()), | |
791 metrics_list_head_(NULL), | |
792 compilation_allowed_(true), | |
793 all_classes_finalized_(false), | |
794 remapping_cids_(false), | |
795 next_(NULL), | 809 next_(NULL), |
796 pause_loop_monitor_(NULL), | |
797 loading_invalidation_gen_(kInvalidGen), | 810 loading_invalidation_gen_(kInvalidGen), |
798 top_level_parsing_count_(0), | 811 top_level_parsing_count_(0), |
799 field_list_mutex_(new Mutex()), | 812 field_list_mutex_(new Mutex()), |
800 boxed_field_list_(GrowableObjectArray::null()), | 813 boxed_field_list_(GrowableObjectArray::null()), |
801 spawn_count_monitor_(new Monitor()), | 814 spawn_count_monitor_(new Monitor()), |
802 spawn_count_(0), | 815 spawn_count_(0), |
803 #define ISOLATE_METRIC_CONSTRUCTORS(type, variable, name, unit) \ | |
804 metric_##variable##_(), | |
805 ISOLATE_METRIC_LIST(ISOLATE_METRIC_CONSTRUCTORS) | |
806 #undef ISOLATE_METRIC_CONSTRUCTORS | |
807 has_attempted_reload_(false), | |
808 no_reload_scope_depth_(0), | |
809 reload_every_n_stack_overflow_checks_(FLAG_reload_every), | |
810 reload_context_(NULL), | |
811 last_reload_timestamp_(OS::GetCurrentTimeMillis()), | |
812 should_pause_post_service_request_(false), | |
813 handler_info_cache_() { | 816 handler_info_cache_() { |
814 NOT_IN_PRODUCT(FlagsCopyFrom(api_flags)); | 817 NOT_IN_PRODUCT(FlagsCopyFrom(api_flags)); |
815 // TODO(asiva): A Thread is not available here, need to figure out | 818 // TODO(asiva): A Thread is not available here, need to figure out |
816 // how the vm_tag (kEmbedderTagId) can be set, these tags need to | 819 // how the vm_tag (kEmbedderTagId) can be set, these tags need to |
817 // move to the OSThread structure. | 820 // move to the OSThread structure. |
818 set_user_tag(UserTags::kDefaultUserTag); | 821 set_user_tag(UserTags::kDefaultUserTag); |
819 } | 822 } |
820 | 823 |
821 #undef REUSABLE_HANDLE_SCOPE_INIT | 824 #undef REUSABLE_HANDLE_SCOPE_INIT |
822 #undef REUSABLE_HANDLE_INITIALIZERS | 825 #undef REUSABLE_HANDLE_INITIALIZERS |
823 | 826 |
824 Isolate::~Isolate() { | 827 Isolate::~Isolate() { |
| 828 #if !defined(PRODUCT) |
| 829 free(debugger_name_); |
| 830 delete debugger_; |
| 831 if (FLAG_support_service) { |
| 832 delete object_id_ring_; |
| 833 } |
| 834 object_id_ring_ = NULL; |
| 835 delete pause_loop_monitor_; |
| 836 pause_loop_monitor_ = NULL; |
| 837 #endif // !defined(PRODUCT) |
| 838 |
825 free(name_); | 839 free(name_); |
826 free(debugger_name_); | |
827 delete store_buffer_; | 840 delete store_buffer_; |
828 delete heap_; | 841 delete heap_; |
829 delete object_store_; | 842 delete object_store_; |
830 delete api_state_; | 843 delete api_state_; |
831 #ifndef PRODUCT | |
832 delete debugger_; | |
833 #endif // !PRODUCT | |
834 #if defined(USING_SIMULATOR) | 844 #if defined(USING_SIMULATOR) |
835 delete simulator_; | 845 delete simulator_; |
836 #endif | 846 #endif |
837 delete mutex_; | 847 delete mutex_; |
838 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. | 848 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. |
839 delete symbols_mutex_; | 849 delete symbols_mutex_; |
840 symbols_mutex_ = NULL; | 850 symbols_mutex_ = NULL; |
841 delete type_canonicalization_mutex_; | 851 delete type_canonicalization_mutex_; |
842 type_canonicalization_mutex_ = NULL; | 852 type_canonicalization_mutex_ = NULL; |
843 delete constant_canonicalization_mutex_; | 853 delete constant_canonicalization_mutex_; |
844 constant_canonicalization_mutex_ = NULL; | 854 constant_canonicalization_mutex_ = NULL; |
845 delete megamorphic_lookup_mutex_; | 855 delete megamorphic_lookup_mutex_; |
846 megamorphic_lookup_mutex_ = NULL; | 856 megamorphic_lookup_mutex_ = NULL; |
847 delete pending_deopts_; | 857 delete pending_deopts_; |
848 pending_deopts_ = NULL; | 858 pending_deopts_ = NULL; |
849 delete message_handler_; | 859 delete message_handler_; |
850 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. | 860 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. |
851 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. | 861 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. |
852 delete spawn_state_; | 862 delete spawn_state_; |
853 #ifndef PRODUCT | |
854 if (FLAG_support_service) { | |
855 delete object_id_ring_; | |
856 } | |
857 #endif // !PRODUCT | |
858 object_id_ring_ = NULL; | |
859 delete pause_loop_monitor_; | |
860 pause_loop_monitor_ = NULL; | |
861 delete field_list_mutex_; | 863 delete field_list_mutex_; |
862 field_list_mutex_ = NULL; | 864 field_list_mutex_ = NULL; |
863 ASSERT(spawn_count_ == 0); | 865 ASSERT(spawn_count_ == 0); |
864 delete spawn_count_monitor_; | 866 delete spawn_count_monitor_; |
865 delete safepoint_handler_; | 867 delete safepoint_handler_; |
866 delete thread_registry_; | 868 delete thread_registry_; |
867 } | 869 } |
868 | 870 |
869 void Isolate::InitOnce() { | 871 void Isolate::InitOnce() { |
870 create_callback_ = NULL; | 872 create_callback_ = NULL; |
871 isolates_list_monitor_ = new Monitor(); | 873 isolates_list_monitor_ = new Monitor(); |
872 ASSERT(isolates_list_monitor_ != NULL); | 874 ASSERT(isolates_list_monitor_ != NULL); |
873 EnableIsolateCreation(); | 875 EnableIsolateCreation(); |
874 } | 876 } |
875 | 877 |
876 Isolate* Isolate::Init(const char* name_prefix, | 878 Isolate* Isolate::Init(const char* name_prefix, |
877 const Dart_IsolateFlags& api_flags, | 879 const Dart_IsolateFlags& api_flags, |
878 bool is_vm_isolate) { | 880 bool is_vm_isolate) { |
879 Isolate* result = new Isolate(api_flags); | 881 Isolate* result = new Isolate(api_flags); |
880 ASSERT(result != NULL); | 882 ASSERT(result != NULL); |
881 | 883 |
| 884 #if !defined(PRODUCT) |
882 // Initialize metrics. | 885 // Initialize metrics. |
883 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \ | 886 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \ |
884 result->metric_##variable##_.Init(result, name, NULL, Metric::unit); | 887 result->metric_##variable##_.Init(result, name, NULL, Metric::unit); |
885 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); | 888 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); |
886 #undef ISOLATE_METRIC_INIT | 889 #undef ISOLATE_METRIC_INIT |
| 890 #endif // !defined(PRODUCT) |
887 | 891 |
888 Heap::Init(result, | 892 Heap::Init(result, |
889 is_vm_isolate | 893 is_vm_isolate |
890 ? 0 // New gen size 0; VM isolate should only allocate in old. | 894 ? 0 // New gen size 0; VM isolate should only allocate in old. |
891 : FLAG_new_gen_semi_max_size * MBInWords, | 895 : FLAG_new_gen_semi_max_size * MBInWords, |
892 FLAG_old_gen_heap_size * MBInWords, | 896 FLAG_old_gen_heap_size * MBInWords, |
893 FLAG_external_max_size * MBInWords); | 897 FLAG_external_max_size * MBInWords); |
894 | 898 |
895 // TODO(5411455): For now just set the recently created isolate as | 899 // TODO(5411455): For now just set the recently created isolate as |
896 // the current isolate. | 900 // the current isolate. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 void Isolate::ScheduleMessageInterrupts() { | 970 void Isolate::ScheduleMessageInterrupts() { |
967 // We take the threads lock here to ensure that the mutator thread does not | 971 // We take the threads lock here to ensure that the mutator thread does not |
968 // exit the isolate while we are trying to schedule interrupts on it. | 972 // exit the isolate while we are trying to schedule interrupts on it. |
969 MonitorLocker ml(threads_lock()); | 973 MonitorLocker ml(threads_lock()); |
970 Thread* mthread = mutator_thread(); | 974 Thread* mthread = mutator_thread(); |
971 if (mthread != NULL) { | 975 if (mthread != NULL) { |
972 mthread->ScheduleInterrupts(Thread::kMessageInterrupt); | 976 mthread->ScheduleInterrupts(Thread::kMessageInterrupt); |
973 } | 977 } |
974 } | 978 } |
975 | 979 |
| 980 #if !defined(PRODUCT) |
976 void Isolate::set_debugger_name(const char* name) { | 981 void Isolate::set_debugger_name(const char* name) { |
977 free(debugger_name_); | 982 free(debugger_name_); |
978 debugger_name_ = strdup(name); | 983 debugger_name_ = strdup(name); |
979 } | 984 } |
980 | 985 |
981 int64_t Isolate::UptimeMicros() const { | 986 int64_t Isolate::UptimeMicros() const { |
982 return OS::GetCurrentMonotonicMicros() - start_time_micros_; | 987 return OS::GetCurrentMonotonicMicros() - start_time_micros_; |
983 } | 988 } |
| 989 #endif |
984 | 990 |
985 bool Isolate::IsPaused() const { | 991 bool Isolate::IsPaused() const { |
986 #if defined(PRODUCT) | 992 #if defined(PRODUCT) |
987 return false; | 993 return false; |
988 #else | 994 #else |
989 return (debugger_ != NULL) && (debugger_->PauseEvent() != NULL); | 995 return (debugger_ != NULL) && (debugger_->PauseEvent() != NULL); |
990 #endif | 996 #endif |
991 } | 997 } |
992 | 998 |
993 RawError* Isolate::PausePostRequest() { | 999 RawError* Isolate::PausePostRequest() { |
(...skipping 13 matching lines...) Expand all Loading... |
1007 } | 1013 } |
1008 #endif | 1014 #endif |
1009 return Error::null(); | 1015 return Error::null(); |
1010 } | 1016 } |
1011 | 1017 |
1012 void Isolate::BuildName(const char* name_prefix) { | 1018 void Isolate::BuildName(const char* name_prefix) { |
1013 ASSERT(name_ == NULL); | 1019 ASSERT(name_ == NULL); |
1014 if (name_prefix == NULL) { | 1020 if (name_prefix == NULL) { |
1015 name_prefix = "isolate"; | 1021 name_prefix = "isolate"; |
1016 } | 1022 } |
| 1023 #if !defined(PRODUCT) |
1017 set_debugger_name(name_prefix); | 1024 set_debugger_name(name_prefix); |
| 1025 #endif |
1018 if (ServiceIsolate::NameEquals(name_prefix)) { | 1026 if (ServiceIsolate::NameEquals(name_prefix)) { |
1019 name_ = strdup(name_prefix); | 1027 name_ = strdup(name_prefix); |
1020 return; | 1028 return; |
1021 } | 1029 } |
1022 name_ = OS::SCreate(NULL, "%s-%" Pd64 "", name_prefix, main_port()); | 1030 name_ = OS::SCreate(NULL, "%s-%" Pd64 "", name_prefix, main_port()); |
1023 } | 1031 } |
1024 | 1032 |
1025 void Isolate::DoneLoading() { | 1033 void Isolate::DoneLoading() { |
1026 GrowableObjectArray& libs = | 1034 GrowableObjectArray& libs = |
1027 GrowableObjectArray::Handle(current_zone(), object_store()->libraries()); | 1035 GrowableObjectArray::Handle(current_zone(), object_store()->libraries()); |
1028 Library& lib = Library::Handle(current_zone()); | 1036 Library& lib = Library::Handle(current_zone()); |
1029 intptr_t num_libs = libs.Length(); | 1037 intptr_t num_libs = libs.Length(); |
1030 for (intptr_t i = 0; i < num_libs; i++) { | 1038 for (intptr_t i = 0; i < num_libs; i++) { |
1031 lib ^= libs.At(i); | 1039 lib ^= libs.At(i); |
1032 // If this library was loaded with Dart_LoadLibrary, it was marked | 1040 // If this library was loaded with Dart_LoadLibrary, it was marked |
1033 // as 'load in progres'. Set the status to 'loaded'. | 1041 // as 'load in progres'. Set the status to 'loaded'. |
1034 if (lib.LoadInProgress()) { | 1042 if (lib.LoadInProgress()) { |
1035 lib.SetLoaded(); | 1043 lib.SetLoaded(); |
1036 } | 1044 } |
1037 } | 1045 } |
1038 TokenStream::CloseSharedTokenList(this); | 1046 TokenStream::CloseSharedTokenList(this); |
1039 } | 1047 } |
1040 | 1048 |
| 1049 #if !defined(PRODUCT) |
1041 bool Isolate::CanReload() const { | 1050 bool Isolate::CanReload() const { |
1042 #ifndef PRODUCT | |
1043 return !ServiceIsolate::IsServiceIsolateDescendant(this) && is_runnable() && | 1051 return !ServiceIsolate::IsServiceIsolateDescendant(this) && is_runnable() && |
1044 !IsReloading() && | 1052 !IsReloading() && |
1045 (AtomicOperations::LoadRelaxed(&no_reload_scope_depth_) == 0) && | 1053 (AtomicOperations::LoadRelaxed(&no_reload_scope_depth_) == 0) && |
1046 IsolateCreationEnabled(); | 1054 IsolateCreationEnabled(); |
1047 #else | |
1048 return false; | |
1049 #endif | |
1050 } | 1055 } |
1051 | 1056 |
1052 #ifndef PRODUCT | |
1053 bool Isolate::ReloadSources(JSONStream* js, | 1057 bool Isolate::ReloadSources(JSONStream* js, |
1054 bool force_reload, | 1058 bool force_reload, |
1055 const char* root_script_url, | 1059 const char* root_script_url, |
1056 const char* packages_url, | 1060 const char* packages_url, |
1057 bool dont_delete_reload_context) { | 1061 bool dont_delete_reload_context) { |
1058 ASSERT(!IsReloading()); | 1062 ASSERT(!IsReloading()); |
1059 has_attempted_reload_ = true; | 1063 has_attempted_reload_ = true; |
1060 reload_context_ = new IsolateReloadContext(this, js); | 1064 reload_context_ = new IsolateReloadContext(this, js); |
1061 reload_context_->Reload(force_reload, root_script_url, packages_url); | 1065 reload_context_->Reload(force_reload, root_script_url, packages_url); |
1062 bool success = !reload_context_->reload_aborted(); | 1066 bool success = !reload_context_->reload_aborted(); |
1063 if (!dont_delete_reload_context) { | 1067 if (!dont_delete_reload_context) { |
1064 DeleteReloadContext(); | 1068 DeleteReloadContext(); |
1065 } | 1069 } |
1066 return success; | 1070 return success; |
1067 } | 1071 } |
1068 | 1072 |
1069 void Isolate::DeleteReloadContext() { | 1073 void Isolate::DeleteReloadContext() { |
1070 // Another thread may be in the middle of GetClassForHeapWalkAt. | 1074 // Another thread may be in the middle of GetClassForHeapWalkAt. |
1071 Thread* thread = Thread::Current(); | 1075 Thread* thread = Thread::Current(); |
1072 SafepointOperationScope safepoint_scope(thread); | 1076 SafepointOperationScope safepoint_scope(thread); |
1073 | 1077 |
1074 delete reload_context_; | 1078 delete reload_context_; |
1075 reload_context_ = NULL; | 1079 reload_context_ = NULL; |
1076 } | 1080 } |
1077 #endif // !PRODUCT | 1081 #endif // !defined(PRODUCT) |
1078 | 1082 |
1079 void Isolate::DoneFinalizing() { | 1083 void Isolate::DoneFinalizing() { |
1080 #if !defined(PRODUCT) | 1084 #if !defined(PRODUCT) |
1081 if (IsReloading()) { | 1085 if (IsReloading()) { |
1082 reload_context_->FinalizeLoading(); | 1086 reload_context_->FinalizeLoading(); |
1083 } | 1087 } |
1084 #endif // !defined(PRODUCT) | 1088 #endif // !defined(PRODUCT) |
1085 } | 1089 } |
1086 | 1090 |
1087 bool Isolate::MakeRunnable() { | 1091 bool Isolate::MakeRunnable() { |
(...skipping 28 matching lines...) Expand all Loading... |
1116 TimelineEvent* event = stream->StartEvent(); | 1120 TimelineEvent* event = stream->StartEvent(); |
1117 if (event != NULL) { | 1121 if (event != NULL) { |
1118 event->Instant("Runnable"); | 1122 event->Instant("Runnable"); |
1119 event->Complete(); | 1123 event->Complete(); |
1120 } | 1124 } |
1121 } | 1125 } |
1122 if (FLAG_support_service && Service::isolate_stream.enabled()) { | 1126 if (FLAG_support_service && Service::isolate_stream.enabled()) { |
1123 ServiceEvent runnableEvent(this, ServiceEvent::kIsolateRunnable); | 1127 ServiceEvent runnableEvent(this, ServiceEvent::kIsolateRunnable); |
1124 Service::HandleEvent(&runnableEvent); | 1128 Service::HandleEvent(&runnableEvent); |
1125 } | 1129 } |
1126 #endif // !PRODUCT | |
1127 GetRunnableLatencyMetric()->set_value(UptimeMicros()); | 1130 GetRunnableLatencyMetric()->set_value(UptimeMicros()); |
1128 if (FLAG_print_benchmarking_metrics) { | 1131 if (FLAG_print_benchmarking_metrics) { |
1129 { | 1132 { |
1130 StartIsolateScope scope(this); | 1133 StartIsolateScope scope(this); |
1131 heap()->CollectAllGarbage(); | 1134 heap()->CollectAllGarbage(); |
1132 } | 1135 } |
1133 int64_t heap_size = (heap()->UsedInWords(Heap::kNew) * kWordSize) + | 1136 int64_t heap_size = (heap()->UsedInWords(Heap::kNew) * kWordSize) + |
1134 (heap()->UsedInWords(Heap::kOld) * kWordSize); | 1137 (heap()->UsedInWords(Heap::kOld) * kWordSize); |
1135 GetRunnableHeapSizeMetric()->set_value(heap_size); | 1138 GetRunnableHeapSizeMetric()->set_value(heap_size); |
1136 } | 1139 } |
| 1140 #endif // !PRODUCT |
1137 return true; | 1141 return true; |
1138 } | 1142 } |
1139 | 1143 |
1140 bool Isolate::VerifyPauseCapability(const Object& capability) const { | 1144 bool Isolate::VerifyPauseCapability(const Object& capability) const { |
1141 return !capability.IsNull() && capability.IsCapability() && | 1145 return !capability.IsNull() && capability.IsCapability() && |
1142 (pause_capability() == Capability::Cast(capability).Id()); | 1146 (pause_capability() == Capability::Cast(capability).Id()); |
1143 } | 1147 } |
1144 | 1148 |
1145 bool Isolate::VerifyTerminateCapability(const Object& capability) const { | 1149 bool Isolate::VerifyTerminateCapability(const Object& capability) const { |
1146 return !capability.IsNull() && capability.IsCapability() && | 1150 return !capability.IsNull() && capability.IsCapability() && |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 if (FLAG_support_timeline && FLAG_timing) { | 1594 if (FLAG_support_timeline && FLAG_timing) { |
1591 TimelinePauseTrace tpt; | 1595 TimelinePauseTrace tpt; |
1592 tpt.Print(); | 1596 tpt.Print(); |
1593 } | 1597 } |
1594 #endif // !PRODUCT | 1598 #endif // !PRODUCT |
1595 | 1599 |
1596 // Finalize any weak persistent handles with a non-null referent. | 1600 // Finalize any weak persistent handles with a non-null referent. |
1597 FinalizeWeakPersistentHandlesVisitor visitor; | 1601 FinalizeWeakPersistentHandlesVisitor visitor; |
1598 api_state()->weak_persistent_handles().VisitHandles(&visitor); | 1602 api_state()->weak_persistent_handles().VisitHandles(&visitor); |
1599 | 1603 |
| 1604 #if !defined(PRODUCT) |
1600 if (FLAG_dump_megamorphic_stats) { | 1605 if (FLAG_dump_megamorphic_stats) { |
1601 MegamorphicCacheTable::PrintSizes(this); | 1606 MegamorphicCacheTable::PrintSizes(this); |
1602 } | 1607 } |
1603 if (FLAG_dump_symbol_stats) { | 1608 if (FLAG_dump_symbol_stats) { |
1604 Symbols::DumpStats(this); | 1609 Symbols::DumpStats(this); |
1605 } | 1610 } |
1606 if (FLAG_trace_isolates) { | 1611 if (FLAG_trace_isolates) { |
1607 heap()->PrintSizes(); | 1612 heap()->PrintSizes(); |
1608 OS::Print( | 1613 OS::Print( |
1609 "[-] Stopping isolate:\n" | 1614 "[-] Stopping isolate:\n" |
1610 "\tisolate: %s\n", | 1615 "\tisolate: %s\n", |
1611 name()); | 1616 name()); |
1612 } | 1617 } |
1613 if (FLAG_print_metrics || FLAG_print_benchmarking_metrics) { | 1618 if (FLAG_print_metrics || FLAG_print_benchmarking_metrics) { |
1614 LogBlock lb; | 1619 LogBlock lb; |
1615 OS::PrintErr("Printing metrics for %s\n", name()); | 1620 OS::PrintErr("Printing metrics for %s\n", name()); |
1616 #define ISOLATE_METRIC_PRINT(type, variable, name, unit) \ | 1621 #define ISOLATE_METRIC_PRINT(type, variable, name, unit) \ |
1617 OS::PrintErr("%s\n", metric_##variable##_.ToString()); | 1622 OS::PrintErr("%s\n", metric_##variable##_.ToString()); |
1618 ISOLATE_METRIC_LIST(ISOLATE_METRIC_PRINT) | 1623 ISOLATE_METRIC_LIST(ISOLATE_METRIC_PRINT) |
1619 #undef ISOLATE_METRIC_PRINT | 1624 #undef ISOLATE_METRIC_PRINT |
1620 OS::PrintErr("\n"); | 1625 OS::PrintErr("\n"); |
1621 } | 1626 } |
| 1627 #endif // !defined(PRODUCT) |
1622 } | 1628 } |
1623 | 1629 |
1624 void Isolate::StopBackgroundCompiler() { | 1630 void Isolate::StopBackgroundCompiler() { |
1625 // Wait until all background compilation has finished. | 1631 // Wait until all background compilation has finished. |
1626 if (background_compiler_ != NULL) { | 1632 if (background_compiler_ != NULL) { |
1627 BackgroundCompiler::Stop(this); | 1633 BackgroundCompiler::Stop(this); |
1628 } | 1634 } |
1629 } | 1635 } |
1630 | 1636 |
| 1637 #if !defined(PRODUCT) |
1631 void Isolate::MaybeIncreaseReloadEveryNStackOverflowChecks() { | 1638 void Isolate::MaybeIncreaseReloadEveryNStackOverflowChecks() { |
1632 if (FLAG_reload_every_back_off) { | 1639 if (FLAG_reload_every_back_off) { |
1633 if (reload_every_n_stack_overflow_checks_ < 5000) { | 1640 if (reload_every_n_stack_overflow_checks_ < 5000) { |
1634 reload_every_n_stack_overflow_checks_ += 99; | 1641 reload_every_n_stack_overflow_checks_ += 99; |
1635 } else { | 1642 } else { |
1636 reload_every_n_stack_overflow_checks_ *= 2; | 1643 reload_every_n_stack_overflow_checks_ *= 2; |
1637 } | 1644 } |
1638 // Cap the value. | 1645 // Cap the value. |
1639 if (reload_every_n_stack_overflow_checks_ > 1000000) { | 1646 if (reload_every_n_stack_overflow_checks_ > 1000000) { |
1640 reload_every_n_stack_overflow_checks_ = 1000000; | 1647 reload_every_n_stack_overflow_checks_ = 1000000; |
1641 } | 1648 } |
1642 } | 1649 } |
1643 } | 1650 } |
| 1651 #endif // !defined(PRODUCT) |
1644 | 1652 |
1645 void Isolate::Shutdown() { | 1653 void Isolate::Shutdown() { |
1646 ASSERT(this == Isolate::Current()); | 1654 ASSERT(this == Isolate::Current()); |
1647 StopBackgroundCompiler(); | 1655 StopBackgroundCompiler(); |
1648 | 1656 |
1649 #if defined(DEBUG) | 1657 #if defined(DEBUG) |
1650 if (heap_ != NULL && FLAG_verify_on_transition) { | 1658 if (heap_ != NULL && FLAG_verify_on_transition) { |
1651 // The VM isolate keeps all objects marked. | 1659 // The VM isolate keeps all objects marked. |
1652 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); | 1660 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); |
1653 } | 1661 } |
(...skipping 25 matching lines...) Expand all Loading... |
1679 if (heap_ != NULL) { | 1687 if (heap_ != NULL) { |
1680 // Wait for any concurrent GC tasks to finish before shutting down. | 1688 // Wait for any concurrent GC tasks to finish before shutting down. |
1681 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). | 1689 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). |
1682 PageSpace* old_space = heap_->old_space(); | 1690 PageSpace* old_space = heap_->old_space(); |
1683 MonitorLocker ml(old_space->tasks_lock()); | 1691 MonitorLocker ml(old_space->tasks_lock()); |
1684 while (old_space->tasks() > 0) { | 1692 while (old_space->tasks() > 0) { |
1685 ml.Wait(); | 1693 ml.Wait(); |
1686 } | 1694 } |
1687 } | 1695 } |
1688 | 1696 |
| 1697 #if !defined(PRODUCT) |
1689 if (FLAG_check_reloaded && is_runnable() && (this != Dart::vm_isolate()) && | 1698 if (FLAG_check_reloaded && is_runnable() && (this != Dart::vm_isolate()) && |
1690 !ServiceIsolate::IsServiceIsolateDescendant(this)) { | 1699 !ServiceIsolate::IsServiceIsolateDescendant(this)) { |
1691 if (!HasAttemptedReload()) { | 1700 if (!HasAttemptedReload()) { |
1692 FATAL( | 1701 FATAL( |
1693 "Isolate did not reload before exiting and " | 1702 "Isolate did not reload before exiting and " |
1694 "--check-reloaded is enabled.\n"); | 1703 "--check-reloaded is enabled.\n"); |
1695 } | 1704 } |
1696 } | 1705 } |
| 1706 #endif // !defined(PRODUCT) |
1697 | 1707 |
1698 // Then, proceed with low-level teardown. | 1708 // Then, proceed with low-level teardown. |
1699 LowLevelShutdown(); | 1709 LowLevelShutdown(); |
1700 | 1710 |
1701 #if defined(DEBUG) | 1711 #if defined(DEBUG) |
1702 // No concurrent sweeper tasks should be running at this point. | 1712 // No concurrent sweeper tasks should be running at this point. |
1703 if (heap_ != NULL) { | 1713 if (heap_ != NULL) { |
1704 PageSpace* old_space = heap_->old_space(); | 1714 PageSpace* old_space = heap_->old_space(); |
1705 MonitorLocker ml(old_space->tasks_lock()); | 1715 MonitorLocker ml(old_space->tasks_lock()); |
1706 ASSERT(old_space->tasks() == 0); | 1716 ASSERT(old_space->tasks() == 0); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1767 if (background_compiler() != NULL) { | 1777 if (background_compiler() != NULL) { |
1768 background_compiler()->VisitPointers(visitor); | 1778 background_compiler()->VisitPointers(visitor); |
1769 } | 1779 } |
1770 | 1780 |
1771 // Visit the deoptimized code array which is stored in the isolate. | 1781 // Visit the deoptimized code array which is stored in the isolate. |
1772 visitor->VisitPointer( | 1782 visitor->VisitPointer( |
1773 reinterpret_cast<RawObject**>(&deoptimized_code_array_)); | 1783 reinterpret_cast<RawObject**>(&deoptimized_code_array_)); |
1774 | 1784 |
1775 visitor->VisitPointer(reinterpret_cast<RawObject**>(&sticky_error_)); | 1785 visitor->VisitPointer(reinterpret_cast<RawObject**>(&sticky_error_)); |
1776 | 1786 |
| 1787 #if !defined(PRODUCT) |
1777 // Visit the pending service extension calls. | 1788 // Visit the pending service extension calls. |
1778 visitor->VisitPointer( | 1789 visitor->VisitPointer( |
1779 reinterpret_cast<RawObject**>(&pending_service_extension_calls_)); | 1790 reinterpret_cast<RawObject**>(&pending_service_extension_calls_)); |
1780 | 1791 |
1781 // Visit the registered service extension handlers. | 1792 // Visit the registered service extension handlers. |
1782 visitor->VisitPointer( | 1793 visitor->VisitPointer( |
1783 reinterpret_cast<RawObject**>(®istered_service_extension_handlers_)); | 1794 reinterpret_cast<RawObject**>(®istered_service_extension_handlers_)); |
| 1795 #endif // !defined(PRODUCT) |
1784 | 1796 |
1785 // Visit the boxed_field_list_. | 1797 // Visit the boxed_field_list_. |
1786 // 'boxed_field_list_' access via mutator and background compilation threads | 1798 // 'boxed_field_list_' access via mutator and background compilation threads |
1787 // is guarded with a monitor. This means that we can visit it only | 1799 // is guarded with a monitor. This means that we can visit it only |
1788 // when at safepoint or the field_list_mutex_ lock has been taken. | 1800 // when at safepoint or the field_list_mutex_ lock has been taken. |
1789 visitor->VisitPointer(reinterpret_cast<RawObject**>(&boxed_field_list_)); | 1801 visitor->VisitPointer(reinterpret_cast<RawObject**>(&boxed_field_list_)); |
1790 | 1802 |
1791 #if !defined(PRODUCT) | 1803 #if !defined(PRODUCT) |
1792 // Visit objects in the debugger. | 1804 // Visit objects in the debugger. |
1793 debugger()->VisitObjectPointers(visitor); | 1805 debugger()->VisitObjectPointers(visitor); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2062 } | 2074 } |
2063 // TODO(johnmccutchan): Scan this array and the isolate's profile before | 2075 // TODO(johnmccutchan): Scan this array and the isolate's profile before |
2064 // old space GC and remove the keep_code flag. | 2076 // old space GC and remove the keep_code flag. |
2065 deoptimized_code.Add(code); | 2077 deoptimized_code.Add(code); |
2066 } | 2078 } |
2067 | 2079 |
2068 void Isolate::clear_sticky_error() { | 2080 void Isolate::clear_sticky_error() { |
2069 sticky_error_ = Error::null(); | 2081 sticky_error_ = Error::null(); |
2070 } | 2082 } |
2071 | 2083 |
| 2084 #if !defined(PRODUCT) |
2072 void Isolate::set_pending_service_extension_calls( | 2085 void Isolate::set_pending_service_extension_calls( |
2073 const GrowableObjectArray& value) { | 2086 const GrowableObjectArray& value) { |
2074 pending_service_extension_calls_ = value.raw(); | 2087 pending_service_extension_calls_ = value.raw(); |
2075 } | 2088 } |
2076 | 2089 |
2077 void Isolate::set_registered_service_extension_handlers( | 2090 void Isolate::set_registered_service_extension_handlers( |
2078 const GrowableObjectArray& value) { | 2091 const GrowableObjectArray& value) { |
2079 registered_service_extension_handlers_ = value.raw(); | 2092 registered_service_extension_handlers_ = value.raw(); |
2080 } | 2093 } |
| 2094 #endif // !defined(PRODUCT) |
2081 | 2095 |
2082 void Isolate::AddDeoptimizingBoxedField(const Field& field) { | 2096 void Isolate::AddDeoptimizingBoxedField(const Field& field) { |
2083 ASSERT(Compiler::IsBackgroundCompilation()); | 2097 ASSERT(Compiler::IsBackgroundCompilation()); |
2084 ASSERT(!field.IsOriginal()); | 2098 ASSERT(!field.IsOriginal()); |
2085 // The enclosed code allocates objects and can potentially trigger a GC, | 2099 // The enclosed code allocates objects and can potentially trigger a GC, |
2086 // ensure that we account for safepoints when grabbing the lock. | 2100 // ensure that we account for safepoints when grabbing the lock. |
2087 SafepointMutexLocker ml(field_list_mutex_); | 2101 SafepointMutexLocker ml(field_list_mutex_); |
2088 if (boxed_field_list_ == GrowableObjectArray::null()) { | 2102 if (boxed_field_list_ == GrowableObjectArray::null()) { |
2089 boxed_field_list_ = GrowableObjectArray::New(Heap::kOld); | 2103 boxed_field_list_ = GrowableObjectArray::New(Heap::kOld); |
2090 } | 2104 } |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2836 void IsolateSpawnState::DecrementSpawnCount() { | 2850 void IsolateSpawnState::DecrementSpawnCount() { |
2837 ASSERT(spawn_count_monitor_ != NULL); | 2851 ASSERT(spawn_count_monitor_ != NULL); |
2838 ASSERT(spawn_count_ != NULL); | 2852 ASSERT(spawn_count_ != NULL); |
2839 MonitorLocker ml(spawn_count_monitor_); | 2853 MonitorLocker ml(spawn_count_monitor_); |
2840 ASSERT(*spawn_count_ > 0); | 2854 ASSERT(*spawn_count_ > 0); |
2841 *spawn_count_ = *spawn_count_ - 1; | 2855 *spawn_count_ = *spawn_count_ - 1; |
2842 ml.Notify(); | 2856 ml.Notify(); |
2843 } | 2857 } |
2844 | 2858 |
2845 } // namespace dart | 2859 } // namespace dart |
OLD | NEW |