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 // !defined(PRODUCT) |
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 // !defined(PRODUCT) |
991 } | 997 } |
992 | 998 |
993 RawError* Isolate::PausePostRequest() { | 999 RawError* Isolate::PausePostRequest() { |
994 #if !defined(PRODUCT) | 1000 #if !defined(PRODUCT) |
995 if (debugger_ == NULL) { | 1001 if (debugger_ == NULL) { |
996 return Error::null(); | 1002 return Error::null(); |
997 } | 1003 } |
998 ASSERT(!IsPaused()); | 1004 ASSERT(!IsPaused()); |
999 const Error& error = Error::Handle(debugger_->PausePostRequest()); | 1005 const Error& error = Error::Handle(debugger_->PausePostRequest()); |
1000 if (!error.IsNull()) { | 1006 if (!error.IsNull()) { |
1001 if (Thread::Current()->top_exit_frame_info() == 0) { | 1007 if (Thread::Current()->top_exit_frame_info() == 0) { |
1002 return error.raw(); | 1008 return error.raw(); |
1003 } else { | 1009 } else { |
1004 Exceptions::PropagateError(error); | 1010 Exceptions::PropagateError(error); |
1005 UNREACHABLE(); | 1011 UNREACHABLE(); |
1006 } | 1012 } |
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 } |
1017 set_debugger_name(name_prefix); | 1023 NOT_IN_PRODUCT(set_debugger_name(name_prefix)); |
1018 if (ServiceIsolate::NameEquals(name_prefix)) { | 1024 if (ServiceIsolate::NameEquals(name_prefix)) { |
1019 name_ = strdup(name_prefix); | 1025 name_ = strdup(name_prefix); |
1020 return; | 1026 return; |
1021 } | 1027 } |
1022 name_ = OS::SCreate(NULL, "%s-%" Pd64 "", name_prefix, main_port()); | 1028 name_ = OS::SCreate(NULL, "%s-%" Pd64 "", name_prefix, main_port()); |
1023 } | 1029 } |
1024 | 1030 |
1025 void Isolate::DoneLoading() { | 1031 void Isolate::DoneLoading() { |
1026 GrowableObjectArray& libs = | 1032 GrowableObjectArray& libs = |
1027 GrowableObjectArray::Handle(current_zone(), object_store()->libraries()); | 1033 GrowableObjectArray::Handle(current_zone(), object_store()->libraries()); |
1028 Library& lib = Library::Handle(current_zone()); | 1034 Library& lib = Library::Handle(current_zone()); |
1029 intptr_t num_libs = libs.Length(); | 1035 intptr_t num_libs = libs.Length(); |
1030 for (intptr_t i = 0; i < num_libs; i++) { | 1036 for (intptr_t i = 0; i < num_libs; i++) { |
1031 lib ^= libs.At(i); | 1037 lib ^= libs.At(i); |
1032 // If this library was loaded with Dart_LoadLibrary, it was marked | 1038 // If this library was loaded with Dart_LoadLibrary, it was marked |
1033 // as 'load in progres'. Set the status to 'loaded'. | 1039 // as 'load in progres'. Set the status to 'loaded'. |
1034 if (lib.LoadInProgress()) { | 1040 if (lib.LoadInProgress()) { |
1035 lib.SetLoaded(); | 1041 lib.SetLoaded(); |
1036 } | 1042 } |
1037 } | 1043 } |
1038 TokenStream::CloseSharedTokenList(this); | 1044 TokenStream::CloseSharedTokenList(this); |
1039 } | 1045 } |
1040 | 1046 |
| 1047 #if !defined(PRODUCT) |
1041 bool Isolate::CanReload() const { | 1048 bool Isolate::CanReload() const { |
1042 #ifndef PRODUCT | |
1043 return !ServiceIsolate::IsServiceIsolateDescendant(this) && is_runnable() && | 1049 return !ServiceIsolate::IsServiceIsolateDescendant(this) && is_runnable() && |
1044 !IsReloading() && | 1050 !IsReloading() && |
1045 (AtomicOperations::LoadRelaxed(&no_reload_scope_depth_) == 0) && | 1051 (AtomicOperations::LoadRelaxed(&no_reload_scope_depth_) == 0) && |
1046 IsolateCreationEnabled(); | 1052 IsolateCreationEnabled(); |
1047 #else | |
1048 return false; | |
1049 #endif | |
1050 } | 1053 } |
1051 | 1054 |
1052 #ifndef PRODUCT | |
1053 bool Isolate::ReloadSources(JSONStream* js, | 1055 bool Isolate::ReloadSources(JSONStream* js, |
1054 bool force_reload, | 1056 bool force_reload, |
1055 const char* root_script_url, | 1057 const char* root_script_url, |
1056 const char* packages_url, | 1058 const char* packages_url, |
1057 bool dont_delete_reload_context) { | 1059 bool dont_delete_reload_context) { |
1058 ASSERT(!IsReloading()); | 1060 ASSERT(!IsReloading()); |
1059 has_attempted_reload_ = true; | 1061 has_attempted_reload_ = true; |
1060 reload_context_ = new IsolateReloadContext(this, js); | 1062 reload_context_ = new IsolateReloadContext(this, js); |
1061 reload_context_->Reload(force_reload, root_script_url, packages_url); | 1063 reload_context_->Reload(force_reload, root_script_url, packages_url); |
1062 bool success = !reload_context_->reload_aborted(); | 1064 bool success = !reload_context_->reload_aborted(); |
1063 if (!dont_delete_reload_context) { | 1065 if (!dont_delete_reload_context) { |
1064 DeleteReloadContext(); | 1066 DeleteReloadContext(); |
1065 } | 1067 } |
1066 return success; | 1068 return success; |
1067 } | 1069 } |
1068 | 1070 |
1069 void Isolate::DeleteReloadContext() { | 1071 void Isolate::DeleteReloadContext() { |
1070 // Another thread may be in the middle of GetClassForHeapWalkAt. | 1072 // Another thread may be in the middle of GetClassForHeapWalkAt. |
1071 Thread* thread = Thread::Current(); | 1073 Thread* thread = Thread::Current(); |
1072 SafepointOperationScope safepoint_scope(thread); | 1074 SafepointOperationScope safepoint_scope(thread); |
1073 | 1075 |
1074 delete reload_context_; | 1076 delete reload_context_; |
1075 reload_context_ = NULL; | 1077 reload_context_ = NULL; |
1076 } | 1078 } |
1077 #endif // !PRODUCT | 1079 #endif // !defined(PRODUCT) |
1078 | 1080 |
1079 void Isolate::DoneFinalizing() { | 1081 void Isolate::DoneFinalizing() { |
1080 #if !defined(PRODUCT) | 1082 #if !defined(PRODUCT) |
1081 if (IsReloading()) { | 1083 if (IsReloading()) { |
1082 reload_context_->FinalizeLoading(); | 1084 reload_context_->FinalizeLoading(); |
1083 } | 1085 } |
1084 #endif // !defined(PRODUCT) | 1086 #endif // !defined(PRODUCT) |
1085 } | 1087 } |
1086 | 1088 |
1087 bool Isolate::MakeRunnable() { | 1089 bool Isolate::MakeRunnable() { |
(...skipping 28 matching lines...) Expand all Loading... |
1116 TimelineEvent* event = stream->StartEvent(); | 1118 TimelineEvent* event = stream->StartEvent(); |
1117 if (event != NULL) { | 1119 if (event != NULL) { |
1118 event->Instant("Runnable"); | 1120 event->Instant("Runnable"); |
1119 event->Complete(); | 1121 event->Complete(); |
1120 } | 1122 } |
1121 } | 1123 } |
1122 if (FLAG_support_service && Service::isolate_stream.enabled()) { | 1124 if (FLAG_support_service && Service::isolate_stream.enabled()) { |
1123 ServiceEvent runnableEvent(this, ServiceEvent::kIsolateRunnable); | 1125 ServiceEvent runnableEvent(this, ServiceEvent::kIsolateRunnable); |
1124 Service::HandleEvent(&runnableEvent); | 1126 Service::HandleEvent(&runnableEvent); |
1125 } | 1127 } |
1126 #endif // !PRODUCT | |
1127 GetRunnableLatencyMetric()->set_value(UptimeMicros()); | 1128 GetRunnableLatencyMetric()->set_value(UptimeMicros()); |
1128 if (FLAG_print_benchmarking_metrics) { | 1129 if (FLAG_print_benchmarking_metrics) { |
1129 { | 1130 { |
1130 StartIsolateScope scope(this); | 1131 StartIsolateScope scope(this); |
1131 heap()->CollectAllGarbage(); | 1132 heap()->CollectAllGarbage(); |
1132 } | 1133 } |
1133 int64_t heap_size = (heap()->UsedInWords(Heap::kNew) * kWordSize) + | 1134 int64_t heap_size = (heap()->UsedInWords(Heap::kNew) * kWordSize) + |
1134 (heap()->UsedInWords(Heap::kOld) * kWordSize); | 1135 (heap()->UsedInWords(Heap::kOld) * kWordSize); |
1135 GetRunnableHeapSizeMetric()->set_value(heap_size); | 1136 GetRunnableHeapSizeMetric()->set_value(heap_size); |
1136 } | 1137 } |
| 1138 #endif // !PRODUCT |
1137 return true; | 1139 return true; |
1138 } | 1140 } |
1139 | 1141 |
1140 bool Isolate::VerifyPauseCapability(const Object& capability) const { | 1142 bool Isolate::VerifyPauseCapability(const Object& capability) const { |
1141 return !capability.IsNull() && capability.IsCapability() && | 1143 return !capability.IsNull() && capability.IsCapability() && |
1142 (pause_capability() == Capability::Cast(capability).Id()); | 1144 (pause_capability() == Capability::Cast(capability).Id()); |
1143 } | 1145 } |
1144 | 1146 |
1145 bool Isolate::VerifyTerminateCapability(const Object& capability) const { | 1147 bool Isolate::VerifyTerminateCapability(const Object& capability) const { |
1146 return !capability.IsNull() && capability.IsCapability() && | 1148 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) { | 1592 if (FLAG_support_timeline && FLAG_timing) { |
1591 TimelinePauseTrace tpt; | 1593 TimelinePauseTrace tpt; |
1592 tpt.Print(); | 1594 tpt.Print(); |
1593 } | 1595 } |
1594 #endif // !PRODUCT | 1596 #endif // !PRODUCT |
1595 | 1597 |
1596 // Finalize any weak persistent handles with a non-null referent. | 1598 // Finalize any weak persistent handles with a non-null referent. |
1597 FinalizeWeakPersistentHandlesVisitor visitor; | 1599 FinalizeWeakPersistentHandlesVisitor visitor; |
1598 api_state()->weak_persistent_handles().VisitHandles(&visitor); | 1600 api_state()->weak_persistent_handles().VisitHandles(&visitor); |
1599 | 1601 |
| 1602 #if !defined(PRODUCT) |
1600 if (FLAG_dump_megamorphic_stats) { | 1603 if (FLAG_dump_megamorphic_stats) { |
1601 MegamorphicCacheTable::PrintSizes(this); | 1604 MegamorphicCacheTable::PrintSizes(this); |
1602 } | 1605 } |
1603 if (FLAG_dump_symbol_stats) { | 1606 if (FLAG_dump_symbol_stats) { |
1604 Symbols::DumpStats(this); | 1607 Symbols::DumpStats(this); |
1605 } | 1608 } |
1606 if (FLAG_trace_isolates) { | 1609 if (FLAG_trace_isolates) { |
1607 heap()->PrintSizes(); | 1610 heap()->PrintSizes(); |
1608 OS::Print( | 1611 OS::Print( |
1609 "[-] Stopping isolate:\n" | 1612 "[-] Stopping isolate:\n" |
1610 "\tisolate: %s\n", | 1613 "\tisolate: %s\n", |
1611 name()); | 1614 name()); |
1612 } | 1615 } |
1613 if (FLAG_print_metrics || FLAG_print_benchmarking_metrics) { | 1616 if (FLAG_print_metrics || FLAG_print_benchmarking_metrics) { |
1614 LogBlock lb; | 1617 LogBlock lb; |
1615 OS::PrintErr("Printing metrics for %s\n", name()); | 1618 OS::PrintErr("Printing metrics for %s\n", name()); |
1616 #define ISOLATE_METRIC_PRINT(type, variable, name, unit) \ | 1619 #define ISOLATE_METRIC_PRINT(type, variable, name, unit) \ |
1617 OS::PrintErr("%s\n", metric_##variable##_.ToString()); | 1620 OS::PrintErr("%s\n", metric_##variable##_.ToString()); |
1618 ISOLATE_METRIC_LIST(ISOLATE_METRIC_PRINT) | 1621 ISOLATE_METRIC_LIST(ISOLATE_METRIC_PRINT) |
1619 #undef ISOLATE_METRIC_PRINT | 1622 #undef ISOLATE_METRIC_PRINT |
1620 OS::PrintErr("\n"); | 1623 OS::PrintErr("\n"); |
1621 } | 1624 } |
| 1625 #endif // !defined(PRODUCT) |
1622 } | 1626 } |
1623 | 1627 |
1624 void Isolate::StopBackgroundCompiler() { | 1628 void Isolate::StopBackgroundCompiler() { |
1625 // Wait until all background compilation has finished. | 1629 // Wait until all background compilation has finished. |
1626 if (background_compiler_ != NULL) { | 1630 if (background_compiler_ != NULL) { |
1627 BackgroundCompiler::Stop(this); | 1631 BackgroundCompiler::Stop(this); |
1628 } | 1632 } |
1629 } | 1633 } |
1630 | 1634 |
| 1635 #if !defined(PRODUCT) |
1631 void Isolate::MaybeIncreaseReloadEveryNStackOverflowChecks() { | 1636 void Isolate::MaybeIncreaseReloadEveryNStackOverflowChecks() { |
1632 if (FLAG_reload_every_back_off) { | 1637 if (FLAG_reload_every_back_off) { |
1633 if (reload_every_n_stack_overflow_checks_ < 5000) { | 1638 if (reload_every_n_stack_overflow_checks_ < 5000) { |
1634 reload_every_n_stack_overflow_checks_ += 99; | 1639 reload_every_n_stack_overflow_checks_ += 99; |
1635 } else { | 1640 } else { |
1636 reload_every_n_stack_overflow_checks_ *= 2; | 1641 reload_every_n_stack_overflow_checks_ *= 2; |
1637 } | 1642 } |
1638 // Cap the value. | 1643 // Cap the value. |
1639 if (reload_every_n_stack_overflow_checks_ > 1000000) { | 1644 if (reload_every_n_stack_overflow_checks_ > 1000000) { |
1640 reload_every_n_stack_overflow_checks_ = 1000000; | 1645 reload_every_n_stack_overflow_checks_ = 1000000; |
1641 } | 1646 } |
1642 } | 1647 } |
1643 } | 1648 } |
| 1649 #endif // !defined(PRODUCT) |
1644 | 1650 |
1645 void Isolate::Shutdown() { | 1651 void Isolate::Shutdown() { |
1646 ASSERT(this == Isolate::Current()); | 1652 ASSERT(this == Isolate::Current()); |
1647 StopBackgroundCompiler(); | 1653 StopBackgroundCompiler(); |
1648 | 1654 |
1649 #if defined(DEBUG) | 1655 #if defined(DEBUG) |
1650 if (heap_ != NULL && FLAG_verify_on_transition) { | 1656 if (heap_ != NULL && FLAG_verify_on_transition) { |
1651 // The VM isolate keeps all objects marked. | 1657 // The VM isolate keeps all objects marked. |
1652 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); | 1658 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); |
1653 } | 1659 } |
(...skipping 25 matching lines...) Expand all Loading... |
1679 if (heap_ != NULL) { | 1685 if (heap_ != NULL) { |
1680 // Wait for any concurrent GC tasks to finish before shutting down. | 1686 // Wait for any concurrent GC tasks to finish before shutting down. |
1681 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). | 1687 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). |
1682 PageSpace* old_space = heap_->old_space(); | 1688 PageSpace* old_space = heap_->old_space(); |
1683 MonitorLocker ml(old_space->tasks_lock()); | 1689 MonitorLocker ml(old_space->tasks_lock()); |
1684 while (old_space->tasks() > 0) { | 1690 while (old_space->tasks() > 0) { |
1685 ml.Wait(); | 1691 ml.Wait(); |
1686 } | 1692 } |
1687 } | 1693 } |
1688 | 1694 |
| 1695 #if !defined(PRODUCT) |
1689 if (FLAG_check_reloaded && is_runnable() && (this != Dart::vm_isolate()) && | 1696 if (FLAG_check_reloaded && is_runnable() && (this != Dart::vm_isolate()) && |
1690 !ServiceIsolate::IsServiceIsolateDescendant(this)) { | 1697 !ServiceIsolate::IsServiceIsolateDescendant(this)) { |
1691 if (!HasAttemptedReload()) { | 1698 if (!HasAttemptedReload()) { |
1692 FATAL( | 1699 FATAL( |
1693 "Isolate did not reload before exiting and " | 1700 "Isolate did not reload before exiting and " |
1694 "--check-reloaded is enabled.\n"); | 1701 "--check-reloaded is enabled.\n"); |
1695 } | 1702 } |
1696 } | 1703 } |
| 1704 #endif // !defined(PRODUCT) |
1697 | 1705 |
1698 // Then, proceed with low-level teardown. | 1706 // Then, proceed with low-level teardown. |
1699 LowLevelShutdown(); | 1707 LowLevelShutdown(); |
1700 | 1708 |
1701 #if defined(DEBUG) | 1709 #if defined(DEBUG) |
1702 // No concurrent sweeper tasks should be running at this point. | 1710 // No concurrent sweeper tasks should be running at this point. |
1703 if (heap_ != NULL) { | 1711 if (heap_ != NULL) { |
1704 PageSpace* old_space = heap_->old_space(); | 1712 PageSpace* old_space = heap_->old_space(); |
1705 MonitorLocker ml(old_space->tasks_lock()); | 1713 MonitorLocker ml(old_space->tasks_lock()); |
1706 ASSERT(old_space->tasks() == 0); | 1714 ASSERT(old_space->tasks() == 0); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1767 if (background_compiler() != NULL) { | 1775 if (background_compiler() != NULL) { |
1768 background_compiler()->VisitPointers(visitor); | 1776 background_compiler()->VisitPointers(visitor); |
1769 } | 1777 } |
1770 | 1778 |
1771 // Visit the deoptimized code array which is stored in the isolate. | 1779 // Visit the deoptimized code array which is stored in the isolate. |
1772 visitor->VisitPointer( | 1780 visitor->VisitPointer( |
1773 reinterpret_cast<RawObject**>(&deoptimized_code_array_)); | 1781 reinterpret_cast<RawObject**>(&deoptimized_code_array_)); |
1774 | 1782 |
1775 visitor->VisitPointer(reinterpret_cast<RawObject**>(&sticky_error_)); | 1783 visitor->VisitPointer(reinterpret_cast<RawObject**>(&sticky_error_)); |
1776 | 1784 |
| 1785 #if !defined(PRODUCT) |
1777 // Visit the pending service extension calls. | 1786 // Visit the pending service extension calls. |
1778 visitor->VisitPointer( | 1787 visitor->VisitPointer( |
1779 reinterpret_cast<RawObject**>(&pending_service_extension_calls_)); | 1788 reinterpret_cast<RawObject**>(&pending_service_extension_calls_)); |
1780 | 1789 |
1781 // Visit the registered service extension handlers. | 1790 // Visit the registered service extension handlers. |
1782 visitor->VisitPointer( | 1791 visitor->VisitPointer( |
1783 reinterpret_cast<RawObject**>(®istered_service_extension_handlers_)); | 1792 reinterpret_cast<RawObject**>(®istered_service_extension_handlers_)); |
| 1793 #endif // !defined(PRODUCT) |
1784 | 1794 |
1785 // Visit the boxed_field_list_. | 1795 // Visit the boxed_field_list_. |
1786 // 'boxed_field_list_' access via mutator and background compilation threads | 1796 // 'boxed_field_list_' access via mutator and background compilation threads |
1787 // is guarded with a monitor. This means that we can visit it only | 1797 // 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. | 1798 // when at safepoint or the field_list_mutex_ lock has been taken. |
1789 visitor->VisitPointer(reinterpret_cast<RawObject**>(&boxed_field_list_)); | 1799 visitor->VisitPointer(reinterpret_cast<RawObject**>(&boxed_field_list_)); |
1790 | 1800 |
1791 #if !defined(PRODUCT) | 1801 #if !defined(PRODUCT) |
1792 // Visit objects in the debugger. | 1802 // Visit objects in the debugger. |
1793 debugger()->VisitObjectPointers(visitor); | 1803 debugger()->VisitObjectPointers(visitor); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2062 } | 2072 } |
2063 // TODO(johnmccutchan): Scan this array and the isolate's profile before | 2073 // TODO(johnmccutchan): Scan this array and the isolate's profile before |
2064 // old space GC and remove the keep_code flag. | 2074 // old space GC and remove the keep_code flag. |
2065 deoptimized_code.Add(code); | 2075 deoptimized_code.Add(code); |
2066 } | 2076 } |
2067 | 2077 |
2068 void Isolate::clear_sticky_error() { | 2078 void Isolate::clear_sticky_error() { |
2069 sticky_error_ = Error::null(); | 2079 sticky_error_ = Error::null(); |
2070 } | 2080 } |
2071 | 2081 |
| 2082 #if !defined(PRODUCT) |
2072 void Isolate::set_pending_service_extension_calls( | 2083 void Isolate::set_pending_service_extension_calls( |
2073 const GrowableObjectArray& value) { | 2084 const GrowableObjectArray& value) { |
2074 pending_service_extension_calls_ = value.raw(); | 2085 pending_service_extension_calls_ = value.raw(); |
2075 } | 2086 } |
2076 | 2087 |
2077 void Isolate::set_registered_service_extension_handlers( | 2088 void Isolate::set_registered_service_extension_handlers( |
2078 const GrowableObjectArray& value) { | 2089 const GrowableObjectArray& value) { |
2079 registered_service_extension_handlers_ = value.raw(); | 2090 registered_service_extension_handlers_ = value.raw(); |
2080 } | 2091 } |
| 2092 #endif // !defined(PRODUCT) |
2081 | 2093 |
2082 void Isolate::AddDeoptimizingBoxedField(const Field& field) { | 2094 void Isolate::AddDeoptimizingBoxedField(const Field& field) { |
2083 ASSERT(Compiler::IsBackgroundCompilation()); | 2095 ASSERT(Compiler::IsBackgroundCompilation()); |
2084 ASSERT(!field.IsOriginal()); | 2096 ASSERT(!field.IsOriginal()); |
2085 // The enclosed code allocates objects and can potentially trigger a GC, | 2097 // The enclosed code allocates objects and can potentially trigger a GC, |
2086 // ensure that we account for safepoints when grabbing the lock. | 2098 // ensure that we account for safepoints when grabbing the lock. |
2087 SafepointMutexLocker ml(field_list_mutex_); | 2099 SafepointMutexLocker ml(field_list_mutex_); |
2088 if (boxed_field_list_ == GrowableObjectArray::null()) { | 2100 if (boxed_field_list_ == GrowableObjectArray::null()) { |
2089 boxed_field_list_ = GrowableObjectArray::New(Heap::kOld); | 2101 boxed_field_list_ = GrowableObjectArray::New(Heap::kOld); |
2090 } | 2102 } |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2836 void IsolateSpawnState::DecrementSpawnCount() { | 2848 void IsolateSpawnState::DecrementSpawnCount() { |
2837 ASSERT(spawn_count_monitor_ != NULL); | 2849 ASSERT(spawn_count_monitor_ != NULL); |
2838 ASSERT(spawn_count_ != NULL); | 2850 ASSERT(spawn_count_ != NULL); |
2839 MonitorLocker ml(spawn_count_monitor_); | 2851 MonitorLocker ml(spawn_count_monitor_); |
2840 ASSERT(*spawn_count_ > 0); | 2852 ASSERT(*spawn_count_ > 0); |
2841 *spawn_count_ = *spawn_count_ - 1; | 2853 *spawn_count_ = *spawn_count_ - 1; |
2842 ml.Notify(); | 2854 ml.Notify(); |
2843 } | 2855 } |
2844 | 2856 |
2845 } // namespace dart | 2857 } // namespace dart |
OLD | NEW |