@@ -142,6 +142,37 @@ void BytecodeMetadataHelper::ReadLibrary(const Library& library) {
142142 library, bytecode_component.GetNumLibraries ());
143143}
144144
145+ bool BytecodeMetadataHelper::FindModifiedLibrariesForHotReload (
146+ BitVector* modified_libs,
147+ bool * is_empty_program,
148+ intptr_t * p_num_classes,
149+ intptr_t * p_num_procedures) {
150+ ASSERT (Thread::Current ()->IsMutatorThread ());
151+
152+ if (translation_helper_.GetBytecodeComponent () == Array::null ()) {
153+ return false ;
154+ }
155+
156+ BytecodeComponentData bytecode_component (
157+ &Array::Handle (helper_->zone_ , GetBytecodeComponent ()));
158+ BytecodeReaderHelper bytecode_reader (&H, active_class_, &bytecode_component);
159+ AlternativeReadingScope alt (&bytecode_reader.reader (),
160+ bytecode_component.GetLibraryIndexOffset ());
161+ bytecode_reader.FindModifiedLibrariesForHotReload (
162+ modified_libs, bytecode_component.GetNumLibraries ());
163+
164+ if (is_empty_program != nullptr ) {
165+ *is_empty_program = (bytecode_component.GetNumLibraries () == 0 );
166+ }
167+ if (p_num_classes != nullptr ) {
168+ *p_num_classes = (bytecode_component.GetNumClasses () == 0 );
169+ }
170+ if (p_num_procedures != nullptr ) {
171+ *p_num_procedures = (bytecode_component.GetNumCodes () == 0 );
172+ }
173+ return true ;
174+ }
175+
145176RawLibrary* BytecodeMetadataHelper::GetMainLibrary () {
146177 const intptr_t md_offset = GetComponentMetadataPayloadOffset ();
147178 if (md_offset < 0 ) {
@@ -1148,6 +1179,7 @@ RawArray* BytecodeReaderHelper::ReadBytecodeComponent(intptr_t md_offset) {
11481179 intptr_t num_libraries = 0 ;
11491180 intptr_t library_index_offset = 0 ;
11501181 intptr_t libraries_offset = 0 ;
1182+ intptr_t num_classes = 0 ;
11511183 intptr_t classes_offset = 0 ;
11521184 static_assert (KernelBytecode::kMinSupportedBytecodeFormatVersion < 10 ,
11531185 " Cleanup condition" );
@@ -1158,14 +1190,14 @@ RawArray* BytecodeReaderHelper::ReadBytecodeComponent(intptr_t md_offset) {
11581190 reader_.ReadUInt32 (); // Skip libraries.numItems
11591191 libraries_offset = start_offset + reader_.ReadUInt32 ();
11601192
1161- reader_.ReadUInt32 (); // Skip classes.numItems
1193+ num_classes = reader_.ReadUInt32 ();
11621194 classes_offset = start_offset + reader_.ReadUInt32 ();
11631195 }
11641196
11651197 reader_.ReadUInt32 (); // Skip members.numItems
11661198 const intptr_t members_offset = start_offset + reader_.ReadUInt32 ();
11671199
1168- reader_.ReadUInt32 (); // Skip codes.numItems
1200+ const intptr_t num_codes = reader_.ReadUInt32 ();
11691201 const intptr_t codes_offset = start_offset + reader_.ReadUInt32 ();
11701202
11711203 reader_.ReadUInt32 (); // Skip sourcePositions.numItems
@@ -1214,8 +1246,8 @@ RawArray* BytecodeReaderHelper::ReadBytecodeComponent(intptr_t md_offset) {
12141246 Z, BytecodeComponentData::New (
12151247 Z, version, num_objects, string_table_offset,
12161248 strings_contents_offset, objects_contents_offset, main_offset,
1217- num_libraries, library_index_offset, libraries_offset,
1218- classes_offset, members_offset, codes_offset,
1249+ num_libraries, library_index_offset, libraries_offset, num_classes,
1250+ classes_offset, members_offset, num_codes, codes_offset,
12191251 source_positions_offset, source_files_offset, line_starts_offset,
12201252 local_variables_offset, annotations_offset, Heap::kOld ));
12211253
@@ -2663,6 +2695,23 @@ void BytecodeReaderHelper::FindAndReadSpecificLibrary(const Library& library,
26632695 }
26642696}
26652697
2698+ void BytecodeReaderHelper::FindModifiedLibrariesForHotReload (
2699+ BitVector* modified_libs,
2700+ intptr_t num_libraries) {
2701+ auto & uri = String::Handle (Z);
2702+ auto & lib = Library::Handle (Z);
2703+ for (intptr_t i = 0 ; i < num_libraries; ++i) {
2704+ uri ^= ReadObject ();
2705+ reader_.ReadUInt (); // Skip offset.
2706+
2707+ lib = Library::LookupLibrary (thread_, uri);
2708+ if (!lib.IsNull () && !lib.is_dart_scheme ()) {
2709+ // This is a library that already exists so mark it as being modified.
2710+ modified_libs->Add (lib.index ());
2711+ }
2712+ }
2713+ }
2714+
26662715void BytecodeReaderHelper::ReadParameterCovariance (
26672716 const Function& function,
26682717 BitVector* is_covariant,
@@ -3028,6 +3077,10 @@ intptr_t BytecodeComponentData::GetLibrariesOffset() const {
30283077 return Smi::Value (Smi::RawCast (data_.At (kLibrariesOffset )));
30293078}
30303079
3080+ intptr_t BytecodeComponentData::GetNumClasses () const {
3081+ return Smi::Value (Smi::RawCast (data_.At (kNumClasses )));
3082+ }
3083+
30313084intptr_t BytecodeComponentData::GetClassesOffset () const {
30323085 return Smi::Value (Smi::RawCast (data_.At (kClassesOffset )));
30333086}
@@ -3036,6 +3089,10 @@ intptr_t BytecodeComponentData::GetMembersOffset() const {
30363089 return Smi::Value (Smi::RawCast (data_.At (kMembersOffset )));
30373090}
30383091
3092+ intptr_t BytecodeComponentData::GetNumCodes () const {
3093+ return Smi::Value (Smi::RawCast (data_.At (kNumCodes )));
3094+ }
3095+
30393096intptr_t BytecodeComponentData::GetCodesOffset () const {
30403097 return Smi::Value (Smi::RawCast (data_.At (kCodesOffset )));
30413098}
@@ -3078,8 +3135,10 @@ RawArray* BytecodeComponentData::New(Zone* zone,
30783135 intptr_t num_libraries,
30793136 intptr_t library_index_offset,
30803137 intptr_t libraries_offset,
3138+ intptr_t num_classes,
30813139 intptr_t classes_offset,
30823140 intptr_t members_offset,
3141+ intptr_t num_codes,
30833142 intptr_t codes_offset,
30843143 intptr_t source_positions_offset,
30853144 intptr_t source_files_offset,
@@ -3115,12 +3174,18 @@ RawArray* BytecodeComponentData::New(Zone* zone,
31153174 smi_handle = Smi::New (libraries_offset);
31163175 data.SetAt (kLibrariesOffset , smi_handle);
31173176
3177+ smi_handle = Smi::New (num_classes);
3178+ data.SetAt (kNumClasses , smi_handle);
3179+
31183180 smi_handle = Smi::New (classes_offset);
31193181 data.SetAt (kClassesOffset , smi_handle);
31203182
31213183 smi_handle = Smi::New (members_offset);
31223184 data.SetAt (kMembersOffset , smi_handle);
31233185
3186+ smi_handle = Smi::New (num_codes);
3187+ data.SetAt (kNumCodes , smi_handle);
3188+
31243189 smi_handle = Smi::New (codes_offset);
31253190 data.SetAt (kCodesOffset , smi_handle);
31263191
0 commit comments