5#ifndef RUNTIME_VM_ISOLATE_RELOAD_H_
6#define RUNTIME_VM_ISOLATE_RELOAD_H_
27#define TIR_Print(format, ...) \
28 if (FLAG_trace_reload) Log::Current()->Print(format, __VA_ARGS__)
30#define TIR_Print(format, ...) \
31 if (FLAG_trace_reload) Log::Current()->Print(format, ##__VA_ARGS__)
36#define VTIR_Print(format, ...) \
37 if (FLAG_trace_reload_verbose) Log::Current()->Print(format, __VA_ARGS__)
39#define VTIR_Print(format, ...) \
40 if (FLAG_trace_reload_verbose) Log::Current()->Print(format, ##__VA_ARGS__)
43#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
48class GrowableObjectArray;
52class ObjectPointerVisitor;
55class UpdateClassesVisitor;
76 const Class& old_class,
77 const Class& new_class,
92 intptr_t
cid()
const {
return cid_; }
100 const Class& old_class_;
101 const Class& new_class_;
149 bool Reload(
bool force_reload,
150 const char* root_script_url =
nullptr,
151 const char* packages_url =
nullptr,
152 const uint8_t* kernel_buffer =
nullptr,
153 intptr_t kernel_buffer_size = 0);
161 ErrorPtr
error()
const;
166 return file_modified_callback_;
174 bool HasReasonsForCancelling()
const {
175 return !reasons_to_cancel_reload_.is_empty();
182 void ReportReasonsForCancelling();
185 void ReportOnJSON(JSONStream*
stream, intptr_t final_library_count);
190 InstanceMorpher* instance_morpher);
193 bool HasInstanceMorphers()
const {
return !instance_morphers_.is_empty(); }
196 void CommonFinalizeTail(intptr_t final_library_count);
199 void ReportError(
const Error&
error);
200 void ReportSuccess();
202 void VisitObjectPointers(ObjectPointerVisitor* visitor);
204 void GetRootLibUrl(
const char* root_script_url);
205 char* CompileToKernel(
bool force_reload,
206 const char* packages_url,
207 const uint8_t** kernel_buffer,
208 intptr_t* kernel_buffer_size);
209 void BuildModifiedLibrariesClosure(BitVector* modified_libs);
210 void FindModifiedSources(
bool force_reload,
213 const char* packages_url);
214 bool ScriptModifiedSince(
const Script&
script, int64_t since);
216 void MorphInstancesPhase1Allocate(
ObjectLocator* locator, Become* become);
217 void MorphInstancesPhase2Become(Become* become);
225 ClassTable* class_table_;
227 int64_t start_time_micros_ = -1;
228 int64_t reload_timestamp_ = -1;
229 bool reload_skipped_ =
false;
230 bool reload_finalized_ =
false;
232 intptr_t num_old_libs_ = -1;
234 intptr_t num_received_libs_ = -1;
235 intptr_t bytes_received_libs_ = -1;
236 intptr_t num_received_classes_ = -1;
237 intptr_t num_received_procedures_ = -1;
238 intptr_t num_saved_libs_ = -1;
241 struct MorpherTrait {
242 typedef InstanceMorpher*
Value;
243 typedef intptr_t
Key;
244 typedef InstanceMorpher*
Pair;
246 static Key KeyOf(
Pair kv) {
return kv->cid(); }
247 static Value ValueOf(
Pair kv) {
return kv; }
249 static bool IsKeyEqual(
Pair kv,
Key key) {
return kv->cid() ==
key; }
253 GrowableArray<InstanceMorpher*> instance_morphers_;
256 GrowableArray<ReasonForCancelling*> reasons_to_cancel_reload_;
259 DirectChainedHashMap<MorpherTrait> instance_morpher_by_cid_;
262 BitVector* modified_libs_ =
nullptr;
266 BitVector* modified_libs_transitive_ =
nullptr;
270 BitVector* saved_libs_transitive_updated_ =
nullptr;
272 String& root_lib_url_;
273 ObjectPtr* from() {
return reinterpret_cast<ObjectPtr*
>(&root_url_prefix_); }
274 StringPtr root_url_prefix_;
275 StringPtr old_root_url_prefix_;
277 return reinterpret_cast<ObjectPtr*
>(&old_root_url_prefix_);
302 return group_reload_context_.get();
309 bool IsDirty(
const Library& lib);
311 void RegisterClass(
const Class& new_cls);
315 StringPtr FindLibraryPrivateKey(
const Library& replacement_or_new);
319 IsolateGroup* isolate_group() {
return isolate_group_; }
320 ObjectStore* object_store();
322 void EnsuredUnoptimizedCodeForStack();
323 void DeoptimizeDependentCode();
325 void ReloadPhase1AllocateStorageMapsAndCheckpoint();
326 void CheckpointClasses();
327 ObjectPtr ReloadPhase2LoadKernel(kernel::Program* program,
328 const String& root_lib_url);
329 void ReloadPhase3FinalizeLoading();
330 void ReloadPhase4CommitPrepare();
331 void ReloadPhase4CommitFinish();
332 void ReloadPhase4Rollback();
334 void CheckpointLibraries();
336 void RollbackLibraries();
342 void CommitBeforeInstanceMorphing();
343 void CommitAfterInstanceMorphing();
346 void RunInvalidationVisitors();
347 void InvalidateKernelInfos(
349 const GrowableArray<const KernelProgramInfo*>& kernel_infos);
350 void InvalidateFunctions(Zone*
zone,
351 const GrowableArray<const Function*>& functions);
352 void InvalidateSuspendStates(
354 const GrowableArray<const SuspendState*>& suspend_states);
355 void InvalidateFields(Zone*
zone,
356 const GrowableArray<const Field*>& fields,
357 const GrowableArray<const Instance*>& instances);
358 void ResetUnoptimizedICsOnStack();
359 void ResetMegamorphicCaches();
360 void InvalidateWorld();
368 std::shared_ptr<IsolateGroupReloadContext> group_reload_context_;
370 MallocGrowableArray<LibraryInfo> library_infos_;
372 ClassPtr OldClassOrNull(
const Class& replacement_or_new);
373 LibraryPtr OldLibraryOrNull(
const Library& replacement_or_new);
374 LibraryPtr OldLibraryOrNullBaseMoved(
const Library& replacement_or_new);
376 void BuildLibraryMapping();
377 void BuildRemovedClassesSet();
378 void ValidateReload();
380 void AddClassMapping(
const Class& replacement_or_new,
const Class& original);
381 void AddLibraryMapping(
const Library& replacement_or_new,
383 void AddStaticFieldMapping(
const Field& old_field,
const Field& new_field);
384 void AddBecomeMapping(
const Object& old,
const Object& neu);
385 void RebuildDirectSubclasses();
390 return reinterpret_cast<ObjectPtr*
>(&old_classes_set_storage_);
392 ArrayPtr old_classes_set_storage_;
393 ArrayPtr class_map_storage_;
394 ArrayPtr removed_class_set_storage_;
395 ArrayPtr old_libraries_set_storage_;
396 ArrayPtr library_map_storage_;
397 LibraryPtr saved_root_library_;
398 GrowableObjectArrayPtr saved_libraries_;
399 ObjectPtr* to() {
return reinterpret_cast<ObjectPtr*
>(&saved_libraries_); }
434 Array& args_desc_array_;
435 Array& ic_data_array_;
436 Array& edge_counters_;
443#define RELOAD_OPERATION_SCOPE(thread_expr) \
444 auto _thread_ = (thread_expr); \
451 NoBackgroundCompilerScope _stop_bg_compiler_(_thread_); \
455 ReloadParticipationScope _allow_reload_(_thread_); \
459 ReloadSafepointOperationScope _safepoint_operation_(_thread_);
void ResetCaches(const Code &code)
void ResetSwitchableCalls(const Code &code)
void Reset(const ICData &ic)
void ZeroEdgeCounters(const Function &function)
CallSiteResetter(Zone *zone)
void AppendTo(JSONArray *array)
ClassReasonForCancelling(Zone *zone, const Class &from, const Class &to)
virtual ~InstanceMorpher()
InstanceMorpher(Zone *zone, classid_t cid, const Class &old_class, const Class &new_class, FieldMappingArray *mapping, FieldOffsetArray *new_fields_offsets)
void AddObject(ObjectPtr object)
void AppendTo(JSONArray *array)
static InstanceMorpher * CreateFromClassDescriptors(Zone *zone, ClassTable *class_table, const Class &from, const Class &to)
void CreateMorphedCopies(Become *become)
friend class ObjectLocator
static Dart_FileModifiedCallback file_modified_callback()
static void SetFileModifiedCallback(Dart_FileModifiedCallback callback)
IsolateGroup * isolate_group() const
IsolateGroupReloadContext(IsolateGroup *isolate, ClassTable *class_table, JSONStream *js)
bool reload_skipped() const
int64_t reload_timestamp() const
bool reload_aborted() const
friend class ReasonForCancelling
int64_t start_time_micros() const
friend class IsolateGroup
~IsolateGroupReloadContext()
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)
static bool IsSameLibrary(const Library &a_lib, const Library &b_lib)
static bool IsSameClass(const Class &a, const Class &b)
ProgramReloadContext(std::shared_ptr< IsolateGroupReloadContext > group_reload_context, IsolateGroup *isolate_group)
friend class IsolateGroup
IsolateGroupReloadContext * group_reload_context()
void Report(IsolateGroupReloadContext *context)
virtual ~ReasonForCancelling()
ReasonForCancelling(Zone *zone)
virtual ErrorPtr ToError()
virtual void AppendTo(JSONArray *array)
virtual StringPtr ToString()
static uint32_t WordHash(intptr_t key)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Dart_NativeFunction function
DECLARE_FLAG(bool, trace_reload)
static uint32_t Hash(uint32_t key)