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