| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 #ifndef VM_ISOLATE_RELOAD_H_ | 5 #ifndef VM_ISOLATE_RELOAD_H_ |
| 6 #define VM_ISOLATE_RELOAD_H_ | 6 #define VM_ISOLATE_RELOAD_H_ |
| 7 | 7 |
| 8 #include "include/dart_tools_api.h" | 8 #include "include/dart_tools_api.h" |
| 9 | 9 |
| 10 #include "vm/hash_map.h" | 10 #include "vm/hash_map.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 class RawGrowableObjectArray; | 45 class RawGrowableObjectArray; |
| 46 class RawLibrary; | 46 class RawLibrary; |
| 47 class RawObject; | 47 class RawObject; |
| 48 class RawString; | 48 class RawString; |
| 49 class Script; | 49 class Script; |
| 50 class UpdateClassesVisitor; | 50 class UpdateClassesVisitor; |
| 51 | 51 |
| 52 | 52 |
| 53 class InstanceMorpher : public ZoneAllocated { | 53 class InstanceMorpher : public ZoneAllocated { |
| 54 public: | 54 public: |
| 55 InstanceMorpher(const Class& from, const Class& to); | 55 InstanceMorpher(Zone* zone, const Class& from, const Class& to); |
| 56 virtual ~InstanceMorpher() {} | 56 virtual ~InstanceMorpher() {} |
| 57 | 57 |
| 58 // Called on each instance that needs to be morphed. | 58 // Called on each instance that needs to be morphed. |
| 59 RawInstance* Morph(const Instance& instance) const; | 59 RawInstance* Morph(const Instance& instance) const; |
| 60 | 60 |
| 61 // Adds an object to be morphed. | 61 // Adds an object to be morphed. |
| 62 void AddObject(RawObject* object) const; | 62 void AddObject(RawObject* object) const; |
| 63 | 63 |
| 64 // Create the morphed objects based on the before() list. | 64 // Create the morphed objects based on the before() list. |
| 65 void CreateMorphedCopies() const; | 65 void CreateMorphedCopies() const; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 86 ZoneGrowableArray<const Instance*>* after_; | 86 ZoneGrowableArray<const Instance*>* after_; |
| 87 intptr_t cid_; | 87 intptr_t cid_; |
| 88 | 88 |
| 89 void ComputeMapping(); | 89 void ComputeMapping(); |
| 90 void DumpFormatFor(const Class& cls) const; | 90 void DumpFormatFor(const Class& cls) const; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 | 93 |
| 94 class ReasonForCancelling : public ZoneAllocated { | 94 class ReasonForCancelling : public ZoneAllocated { |
| 95 public: | 95 public: |
| 96 ReasonForCancelling() {} | 96 explicit ReasonForCancelling(Zone* zone) {} |
| 97 virtual ~ReasonForCancelling() {} | 97 virtual ~ReasonForCancelling() {} |
| 98 | 98 |
| 99 // Reports a reason for cancelling reload. | 99 // Reports a reason for cancelling reload. |
| 100 void Report(IsolateReloadContext* context); | 100 void Report(IsolateReloadContext* context); |
| 101 | 101 |
| 102 // Conversion to a VM error object. | 102 // Conversion to a VM error object. |
| 103 // Default implementation calls ToString. | 103 // Default implementation calls ToString. |
| 104 virtual RawError* ToError(); | 104 virtual RawError* ToError(); |
| 105 | 105 |
| 106 // Conversion to a string object. | 106 // Conversion to a string object. |
| 107 // Default implementation calls ToError. | 107 // Default implementation calls ToError. |
| 108 virtual RawString* ToString(); | 108 virtual RawString* ToString(); |
| 109 | 109 |
| 110 // Append the reason to JSON array. | 110 // Append the reason to JSON array. |
| 111 virtual void AppendTo(JSONArray* array); | 111 virtual void AppendTo(JSONArray* array); |
| 112 | 112 |
| 113 // Concrete subclasses must override either ToError or ToString. | 113 // Concrete subclasses must override either ToError or ToString. |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 | 116 |
| 117 // Abstract class for also capturing the from_ and to_ class. | 117 // Abstract class for also capturing the from_ and to_ class. |
| 118 class ClassReasonForCancelling : public ReasonForCancelling { | 118 class ClassReasonForCancelling : public ReasonForCancelling { |
| 119 public: | 119 public: |
| 120 ClassReasonForCancelling(const Class& from, const Class& to) | 120 ClassReasonForCancelling(Zone* zone, const Class& from, const Class& to) |
| 121 : from_(from), to_(to) { } | 121 : ReasonForCancelling(zone), from_(from), to_(to) { } |
| 122 | 122 |
| 123 void AppendTo(JSONArray* array); | 123 void AppendTo(JSONArray* array); |
| 124 | 124 |
| 125 protected: | 125 protected: |
| 126 const Class& from_; | 126 const Class& from_; |
| 127 const Class& to_; | 127 const Class& to_; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 | 130 |
| 131 class IsolateReloadContext { | 131 class IsolateReloadContext { |
| 132 public: | 132 public: |
| 133 explicit IsolateReloadContext(Isolate* isolate, JSONStream* js); | 133 explicit IsolateReloadContext(Isolate* isolate, |
| 134 JSONStream* js); |
| 134 ~IsolateReloadContext(); | 135 ~IsolateReloadContext(); |
| 135 | 136 |
| 136 void StartReload(bool force_reload); | 137 void Reload(bool force_reload); |
| 137 void FinishReload(); | |
| 138 void AbortReload(const Error& error); | |
| 139 | 138 |
| 140 RawLibrary* saved_root_library() const; | 139 // All zone allocated objects must be allocated from this zone. |
| 141 | 140 Zone* zone() const { return zone_; } |
| 142 RawGrowableObjectArray* saved_libraries() const; | |
| 143 | |
| 144 // Report back through the observatory channels. | |
| 145 void ReportError(const Error& error); | |
| 146 void ReportSuccess(); | |
| 147 | 141 |
| 148 bool reload_skipped() const { return reload_skipped_; } | 142 bool reload_skipped() const { return reload_skipped_; } |
| 143 bool reload_aborted() const { return reload_aborted_; } |
| 144 RawError* error() const; |
| 145 int64_t reload_timestamp() const { return reload_timestamp_; } |
| 149 | 146 |
| 150 bool has_error() const { return HasReasonsForCancelling(); } | 147 static Dart_FileModifiedCallback file_modified_callback() { |
| 151 RawError* error() const; | 148 return file_modified_callback_; |
| 152 | 149 } |
| 153 int64_t reload_timestamp() const { return reload_timestamp_; } | 150 static void SetFileModifiedCallback(Dart_FileModifiedCallback callback) { |
| 151 file_modified_callback_ = callback; |
| 152 } |
| 154 | 153 |
| 155 static bool IsSameField(const Field& a, const Field& b); | 154 static bool IsSameField(const Field& a, const Field& b); |
| 156 static bool IsSameLibrary(const Library& a_lib, const Library& b_lib); | 155 static bool IsSameLibrary(const Library& a_lib, const Library& b_lib); |
| 157 static bool IsSameClass(const Class& a, const Class& b); | 156 static bool IsSameClass(const Class& a, const Class& b); |
| 158 | 157 |
| 158 private: |
| 159 RawLibrary* saved_root_library() const; |
| 160 |
| 161 RawGrowableObjectArray* saved_libraries() const; |
| 162 |
| 159 RawClass* FindOriginalClass(const Class& cls); | 163 RawClass* FindOriginalClass(const Class& cls); |
| 160 | 164 |
| 161 bool IsDirty(const Library& lib); | 165 bool IsDirty(const Library& lib); |
| 162 | 166 |
| 163 // Prefers old classes when we are in the middle of a reload. | 167 // Prefers old classes when we are in the middle of a reload. |
| 164 RawClass* GetClassForHeapWalkAt(intptr_t cid); | 168 RawClass* GetClassForHeapWalkAt(intptr_t cid); |
| 165 | 169 |
| 166 void RegisterClass(const Class& new_cls); | 170 void RegisterClass(const Class& new_cls); |
| 167 | 171 |
| 168 // Finds the library private key for |replacement_or_new| or return null | 172 // Finds the library private key for |replacement_or_new| or return null |
| (...skipping 17 matching lines...) Expand all Loading... |
| 186 void ReportOnJSON(JSONStream* stream); | 190 void ReportOnJSON(JSONStream* stream); |
| 187 | 191 |
| 188 // Store morphing operation. | 192 // Store morphing operation. |
| 189 void AddInstanceMorpher(InstanceMorpher* morpher); | 193 void AddInstanceMorpher(InstanceMorpher* morpher); |
| 190 | 194 |
| 191 // Tells whether instance in the heap must be morphed. | 195 // Tells whether instance in the heap must be morphed. |
| 192 bool HasInstanceMorphers() const { | 196 bool HasInstanceMorphers() const { |
| 193 return !instance_morphers_.is_empty(); | 197 return !instance_morphers_.is_empty(); |
| 194 } | 198 } |
| 195 | 199 |
| 196 static Dart_FileModifiedCallback file_modified_callback() { | 200 // NOTE: FinalizeLoading will be called *before* Reload() returns. |
| 197 return file_modified_callback_; | 201 void FinalizeLoading(); |
| 198 } | 202 void AbortReload(const Error& error); |
| 199 static void SetFileModifiedCallback(Dart_FileModifiedCallback callback) { | |
| 200 file_modified_callback_ = callback; | |
| 201 } | |
| 202 | 203 |
| 203 private: | 204 // Report back through the observatory channels. |
| 205 void ReportError(const Error& error); |
| 206 void ReportSuccess(); |
| 207 |
| 204 void set_saved_root_library(const Library& value); | 208 void set_saved_root_library(const Library& value); |
| 205 | 209 |
| 206 void set_saved_libraries(const GrowableObjectArray& value); | 210 void set_saved_libraries(const GrowableObjectArray& value); |
| 207 | 211 |
| 208 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 212 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 209 | 213 |
| 210 Isolate* isolate() { return isolate_; } | 214 Isolate* isolate() { return isolate_; } |
| 211 ObjectStore* object_store(); | 215 ObjectStore* object_store(); |
| 212 | 216 |
| 213 void EnsuredUnoptimizedCodeForStack(); | 217 void EnsuredUnoptimizedCodeForStack(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 241 void PostCommit(); | 245 void PostCommit(); |
| 242 | 246 |
| 243 void ClearReplacedObjectBits(); | 247 void ClearReplacedObjectBits(); |
| 244 | 248 |
| 245 // atomic_install: | 249 // atomic_install: |
| 246 void MarkAllFunctionsForRecompilation(); | 250 void MarkAllFunctionsForRecompilation(); |
| 247 void ResetUnoptimizedICsOnStack(); | 251 void ResetUnoptimizedICsOnStack(); |
| 248 void ResetMegamorphicCaches(); | 252 void ResetMegamorphicCaches(); |
| 249 void InvalidateWorld(); | 253 void InvalidateWorld(); |
| 250 | 254 |
| 255 // The zone used for all reload related allocations. |
| 256 Zone* zone_; |
| 257 |
| 251 int64_t start_time_micros_; | 258 int64_t start_time_micros_; |
| 252 int64_t reload_timestamp_; | 259 int64_t reload_timestamp_; |
| 253 Isolate* isolate_; | 260 Isolate* isolate_; |
| 254 bool reload_skipped_; | 261 bool reload_skipped_; |
| 262 bool reload_aborted_; |
| 255 JSONStream* js_; | 263 JSONStream* js_; |
| 256 | 264 |
| 257 intptr_t saved_num_cids_; | 265 intptr_t saved_num_cids_; |
| 258 RawClass** saved_class_table_; | 266 RawClass** saved_class_table_; |
| 259 intptr_t num_saved_libs_; | 267 intptr_t num_saved_libs_; |
| 260 | 268 |
| 261 // Collect the necessary instance transformation for schema changes. | 269 // Collect the necessary instance transformation for schema changes. |
| 262 ZoneGrowableArray<InstanceMorpher*> instance_morphers_; | 270 ZoneGrowableArray<InstanceMorpher*> instance_morphers_; |
| 263 | 271 |
| 264 // Collects the reasons for cancelling the reload. | 272 // Collects the reasons for cancelling the reload. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 RawArray* old_libraries_set_storage_; | 324 RawArray* old_libraries_set_storage_; |
| 317 RawArray* library_map_storage_; | 325 RawArray* library_map_storage_; |
| 318 RawArray* become_map_storage_; | 326 RawArray* become_map_storage_; |
| 319 RawGrowableObjectArray* become_enum_mappings_; | 327 RawGrowableObjectArray* become_enum_mappings_; |
| 320 RawLibrary* saved_root_library_; | 328 RawLibrary* saved_root_library_; |
| 321 RawGrowableObjectArray* saved_libraries_; | 329 RawGrowableObjectArray* saved_libraries_; |
| 322 RawObject** to() { return reinterpret_cast<RawObject**>(&saved_libraries_); } | 330 RawObject** to() { return reinterpret_cast<RawObject**>(&saved_libraries_); } |
| 323 | 331 |
| 324 friend class Isolate; | 332 friend class Isolate; |
| 325 friend class Class; // AddStaticFieldMapping, AddEnumBecomeMapping. | 333 friend class Class; // AddStaticFieldMapping, AddEnumBecomeMapping. |
| 334 friend class Library; |
| 326 friend class ObjectLocator; | 335 friend class ObjectLocator; |
| 336 friend class MarkFunctionsForRecompilation; // IsDirty. |
| 337 friend class ReasonForCancelling; |
| 327 | 338 |
| 328 static Dart_FileModifiedCallback file_modified_callback_; | 339 static Dart_FileModifiedCallback file_modified_callback_; |
| 329 }; | 340 }; |
| 330 | 341 |
| 331 } // namespace dart | 342 } // namespace dart |
| 332 | 343 |
| 333 #endif // VM_ISOLATE_RELOAD_H_ | 344 #endif // VM_ISOLATE_RELOAD_H_ |
| OLD | NEW |