690 {
692
694 ASSERT(thread->OwnsReloadSafepoint());
695
696 Heap* heap =
IG->heap();
697 num_old_libs_ =
699
700
701 GetRootLibUrl(root_script_url);
702
703 std::unique_ptr<kernel::Program> kernel_program;
704
705
706 num_received_libs_ = 0;
707 bytes_received_libs_ = 0;
708 num_received_classes_ = 0;
709 num_received_procedures_ = 0;
710
711 bool did_kernel_compilation = false;
712 bool skip_reload = false;
713 {
714
715 intptr_t* p_num_received_classes = nullptr;
716 intptr_t* p_num_received_procedures = nullptr;
717
718
719
720
721
723 if (kernel_program != nullptr) {
724 num_received_libs_ = kernel_program->library_count();
725 bytes_received_libs_ = kernel_program->binary().LengthInBytes();
726 p_num_received_classes = &num_received_classes_;
727 p_num_received_procedures = &num_received_procedures_;
728 } else {
729 if (kernel_buffer == nullptr || kernel_buffer_size == 0) {
730 char*
error = CompileToKernel(force_reload, packages_url,
731 &kernel_buffer, &kernel_buffer_size);
732 did_kernel_compilation = true;
733 if (
error !=
nullptr) {
734 TIR_Print(
"---- LOAD FAILED, ABORTING RELOAD\n");
738 AddReasonForCancelling(
new Aborted(
Z,
error));
739 ReportReasonsForCancelling();
740 CommonFinalizeTail(num_old_libs_);
741
743 return false;
744 }
745 }
748 const_cast<uint8_t*>(kernel_buffer), kernel_buffer_size));
750 }
751
752 NoActiveIsolateScope no_active_isolate_scope;
753
756 ExternalTypedData::Cast(kernel_program->binary()));
757
758 modified_libs_ =
new (
Z) BitVector(
Z, num_old_libs_);
760 kernel_program.get(),
IG, modified_libs_, force_reload, &skip_reload,
761 p_num_received_classes, p_num_received_procedures);
762 modified_libs_transitive_ =
new (
Z) BitVector(
Z, num_old_libs_);
763 BuildModifiedLibrariesClosure(modified_libs_);
764
765 ASSERT(num_saved_libs_ == -1);
766 num_saved_libs_ = 0;
767 for (intptr_t
i = 0;
i < modified_libs_->
length();
i++) {
769 num_saved_libs_++;
770 }
771 }
772 }
773
774 NoActiveIsolateScope no_active_isolate_scope;
775
776 if (skip_reload) {
778 reload_skipped_ = true;
779 ReportOnJSON(js_, num_old_libs_);
780
781
782
783
784 if (did_kernel_compilation) {
788 AddReasonForCancelling(
new Aborted(
Z,
error));
789 ReportReasonsForCancelling();
790 CommonFinalizeTail(num_old_libs_);
791 return false;
792 }
793 }
794 TIR_Print(
"---- SKIPPING RELOAD (No libraries were modified)\n");
795 return false;
796 }
797
799
800 intptr_t number_of_isolates = 0;
802 [&](
Isolate* isolate) { number_of_isolates++; });
803
804
805
806
807
808 const bool old_concurrent_mark_flag =
809 heap->old_space()->enable_concurrent_mark();
810 if (old_concurrent_mark_flag) {
811 heap->WaitForMarkerTasks(thread);
812 heap->old_space()->set_enable_concurrent_mark(false);
813 }
814
815
816
817
818
819
820 IG->program_reload_context()->EnsuredUnoptimizedCodeForStack();
821 IG->program_reload_context()->DeoptimizeDependentCode();
822 IG->program_reload_context()->ReloadPhase1AllocateStorageMapsAndCheckpoint();
823
824
825 modified_libs_ = nullptr;
826 modified_libs_transitive_ = nullptr;
827
828 if (FLAG_gc_during_reload) {
829
830
832 }
833
834
835 {
837 IG->program_reload_context()->CheckpointClasses();
838 }
839
840 if (FLAG_gc_during_reload) {
841
842
844 }
845
846
847
848
849
850
853 kernel_program.get(), root_lib_url_));
854
856 TIR_Print(
"---- LOAD FAILED, ABORTING RELOAD\n");
857
859 AddReasonForCancelling(
new Aborted(
Z,
error));
860
861 IG->program_reload_context()->ReloadPhase4Rollback();
862 CommonFinalizeTail(num_old_libs_);
863 } else {
864 ASSERT(!reload_skipped_ && !reload_finalized_);
866
867 IG->program_reload_context()->ReloadPhase3FinalizeLoading();
868
869 if (FLAG_gc_during_reload) {
870
871
873 }
874
875
876
877
878 if (did_kernel_compilation) {
883 AddReasonForCancelling(
new Aborted(
Z,
error));
884 }
885 }
886
887 if (!FLAG_reload_force_rollback && !HasReasonsForCancelling()) {
890 bool discard_class_tables = true;
891 if (HasInstanceMorphers()) {
892
893
895 {
897 HeapIterationScope iteration(thread);
898 iteration.IterateObjects(&locator);
899 }
900
901
902 if (FLAG_gc_during_reload) {
903
904
906 }
907 const intptr_t
count = locator.count();
910
911
912
913
914
915
916
917 ForceGrowthScope force_growth(thread);
918
919
921
922 MorphInstancesPhase1Allocate(&locator,
IG->become());
923 {
924
925
926
927
928
930
931
932
933 IG->DropOriginalClassTable();
934 }
935 MorphInstancesPhase2Become(
IG->become());
936
937 discard_class_tables = false;
938 }
939
940 if (FLAG_gc_during_reload) {
941
942
944 }
945 }
946 if (FLAG_identity_reload) {
947 if (!discard_class_tables) {
948 TIR_Print(
"Identity reload failed! Some instances were morphed\n");
949 }
950 if (
IG->heap_walk_class_table()->NumCids() !=
951 IG->class_table()->NumCids()) {
952 TIR_Print(
"Identity reload failed! B#C=%" Pd " A#C=%" Pd "\n",
953 IG->heap_walk_class_table()->NumCids(),
954 IG->class_table()->NumCids());
955 }
956 if (
IG->heap_walk_class_table()->NumTopLevelCids() !=
957 IG->class_table()->NumTopLevelCids()) {
958 TIR_Print(
"Identity reload failed! B#TLC=%" Pd " A#TLC=%" Pd "\n",
959 IG->heap_walk_class_table()->NumTopLevelCids(),
960 IG->class_table()->NumTopLevelCids());
961 }
962 }
963 if (discard_class_tables) {
964 IG->DropOriginalClassTable();
965 }
969 } else {
972 }
973
974
975
976
977 {
978 SafepointWriteRwLocker ml(thread,
IG->program_lock());
979 IG->program_reload_context()->RebuildDirectSubclasses();
980 }
981 const intptr_t final_library_count =
983 .Length();
984 CommonFinalizeTail(final_library_count);
985 }
986
987
988 if (old_concurrent_mark_flag) {
989 heap->old_space()->set_enable_concurrent_mark(true);
990 }
991
992 bool success;
993 if (!
result.IsError() || HasReasonsForCancelling()) {
994 ReportSuccess();
995 success = true;
996 } else {
997 ReportReasonsForCancelling();
998 success = false;
999 }
1000
1002
1003 IG->object_store()->set_uri_to_resolved_uri_map(null_array);
1004 IG->object_store()->set_resolved_uri_to_uri_map(null_array);
1005
1006
1007
1008 if (
result.IsUnwindError()) {
1010 ForEachIsolate([&](
Isolate* isolate) {
1014 });
1015 }
1016
1017 return success;
1018}
bool Contains(intptr_t i) const
static ExternalTypedDataPtr NewFinalizeWithFree(uint8_t *data, intptr_t len)
friend class ObjectLocator
bool Reload(bool force_reload, const char *root_script_url=nullptr, const char *packages_url=nullptr, const uint8_t *kernel_buffer=nullptr, intptr_t kernel_buffer_size=0)
void ForEachIsolate(std::function< void(Isolate *isolate)> function, bool at_safepoint=false)
static IsolateGroup * Current()
void set_last_reload_timestamp(int64_t value)
IsolateGroupSource * source() const
ProgramReloadContext * program_reload_context()
static void KillIfExists(Isolate *isolate, LibMsgId msg_id)
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
static void FindModifiedLibraries(Program *program, IsolateGroup *isolate_group, BitVector *modified_libs, bool force_reload, bool *is_empty_program, intptr_t *p_num_classes, intptr_t *p_num_procedures)
static std::unique_ptr< Program > ReadFromTypedData(const ExternalTypedData &typed_data, const char **error=nullptr)
static std::unique_ptr< Program > ReadFromFile(const char *script_uri, const char **error=nullptr)
#define TIMELINE_SCOPE(name)
#define TIR_Print(format,...)
static ObjectPtr RejectCompilation(Thread *thread)
static ObjectPtr AcceptCompilation(Thread *thread)
static bool HasNoTasks(Heap *heap)
@ ApiError
The Dart error code for an API error.