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 "vm/hash_map.h" |
8 #include "vm/globals.h" | 9 #include "vm/globals.h" |
9 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
10 #include "vm/log.h" | 11 #include "vm/log.h" |
11 | 12 |
12 DECLARE_FLAG(bool, trace_reload); | 13 DECLARE_FLAG(bool, trace_reload); |
13 DECLARE_FLAG(bool, trace_reload_verbose); | 14 DECLARE_FLAG(bool, trace_reload_verbose); |
14 | 15 |
15 // 'Trace Isolate Reload' TIR_Print | 16 // 'Trace Isolate Reload' TIR_Print |
16 #if defined(_MSC_VER) | 17 #if defined(_MSC_VER) |
17 #define TIR_Print(format, ...) \ | 18 #define TIR_Print(format, ...) \ |
(...skipping 19 matching lines...) Expand all Loading... |
37 class Library; | 38 class Library; |
38 class RawError; | 39 class RawError; |
39 class RawGrowableObjectArray; | 40 class RawGrowableObjectArray; |
40 class RawLibrary; | 41 class RawLibrary; |
41 class RawObject; | 42 class RawObject; |
42 class RawString; | 43 class RawString; |
43 class ObjectPointerVisitor; | 44 class ObjectPointerVisitor; |
44 class ObjectStore; | 45 class ObjectStore; |
45 class UpdateClassesVisitor; | 46 class UpdateClassesVisitor; |
46 | 47 |
| 48 |
| 49 class InstanceMorpher : public ZoneAllocated { |
| 50 public: |
| 51 InstanceMorpher(const Class& from, const Class& to); |
| 52 virtual ~InstanceMorpher() {} |
| 53 |
| 54 // Called on each instance that needs to be morphed. |
| 55 RawInstance* Morph(const Instance& instance) const; |
| 56 |
| 57 // Adds an object to be morphed. |
| 58 void AddObject(RawObject* object) const; |
| 59 |
| 60 // Create the morphed objects based on the before() list. |
| 61 void CreateMorphedCopies() const; |
| 62 |
| 63 // Dump the state of the morpher. |
| 64 void Dump() const; |
| 65 |
| 66 // Returns the list of objects that need to be morphed. |
| 67 ZoneGrowableArray<const Instance*>* before() const { return before_; } |
| 68 // Returns the list of morphed objects (matches order in before()). |
| 69 ZoneGrowableArray<const Instance*>* after() const { return after_; } |
| 70 |
| 71 // Returns the cid associated with the from_ and to_ class. |
| 72 intptr_t cid() const { return cid_; } |
| 73 |
| 74 private: |
| 75 const Class& from_; |
| 76 const Class& to_; |
| 77 ZoneGrowableArray<intptr_t> mapping_; |
| 78 ZoneGrowableArray<const Instance*>* before_; |
| 79 ZoneGrowableArray<const Instance*>* after_; |
| 80 intptr_t cid_; |
| 81 |
| 82 void ComputeMapping(); |
| 83 void DumpFormatFor(const Class& cls) const; |
| 84 }; |
| 85 |
| 86 |
| 87 class ReasonForCancelling : public ZoneAllocated { |
| 88 public: |
| 89 ReasonForCancelling() {} |
| 90 virtual ~ReasonForCancelling() {} |
| 91 |
| 92 // Reports a reason for cancelling reload. |
| 93 void Report(IsolateReloadContext* context); |
| 94 |
| 95 // Conversion to a VM error object. |
| 96 // Default implementation calls ToString. |
| 97 virtual RawError* ToError(); |
| 98 |
| 99 // Conversion to a string object. |
| 100 // Default implementation calls ToError. |
| 101 virtual RawString* ToString(); |
| 102 |
| 103 // Concrete subclasses must override either ToError or ToString. |
| 104 }; |
| 105 |
| 106 |
| 107 // Abstract class for also capturing the from_ and to_ class. |
| 108 class ClassReasonForCancelling : public ReasonForCancelling { |
| 109 public: |
| 110 ClassReasonForCancelling(const Class& from, const Class& to) |
| 111 : from_(from), to_(to) { } |
| 112 |
| 113 protected: |
| 114 const Class& from_; |
| 115 const Class& to_; |
| 116 }; |
| 117 |
| 118 |
47 class IsolateReloadContext { | 119 class IsolateReloadContext { |
48 public: | 120 public: |
49 explicit IsolateReloadContext(Isolate* isolate); | 121 explicit IsolateReloadContext(Isolate* isolate); |
50 ~IsolateReloadContext(); | 122 ~IsolateReloadContext(); |
51 | 123 |
52 void StartReload(); | 124 void StartReload(); |
53 void FinishReload(); | 125 void FinishReload(); |
54 void AbortReload(const Error& error); | 126 void AbortReload(const Error& error); |
55 | 127 |
56 RawLibrary* saved_root_library() const; | 128 RawLibrary* saved_root_library() const; |
57 | 129 |
58 RawGrowableObjectArray* saved_libraries() const; | 130 RawGrowableObjectArray* saved_libraries() const; |
59 | 131 |
| 132 // Report back through the observatory channels. |
60 void ReportError(const Error& error); | 133 void ReportError(const Error& error); |
61 void ReportError(const String& error_msg); | |
62 void ReportSuccess(); | 134 void ReportSuccess(); |
63 | 135 |
64 bool has_error() const { return has_error_; } | 136 bool has_error() const { return HasReasonsForCancelling(); } |
65 RawError* error() const { return error_; } | 137 RawError* error() const; |
66 | 138 |
67 static bool IsSameField(const Field& a, const Field& b); | 139 static bool IsSameField(const Field& a, const Field& b); |
68 static bool IsSameLibrary(const Library& a_lib, const Library& b_lib); | 140 static bool IsSameLibrary(const Library& a_lib, const Library& b_lib); |
69 static bool IsSameClass(const Class& a, const Class& b); | 141 static bool IsSameClass(const Class& a, const Class& b); |
70 | 142 |
71 RawClass* FindOriginalClass(const Class& cls); | 143 RawClass* FindOriginalClass(const Class& cls); |
72 | 144 |
73 bool IsDirty(const Library& lib); | 145 bool IsDirty(const Library& lib); |
74 | 146 |
75 // Prefers old classes when we are in the middle of a reload. | 147 // Prefers old classes when we are in the middle of a reload. |
76 RawClass* GetClassForHeapWalkAt(intptr_t cid); | 148 RawClass* GetClassForHeapWalkAt(intptr_t cid); |
77 | 149 |
78 void RegisterClass(const Class& new_cls); | 150 void RegisterClass(const Class& new_cls); |
79 | 151 |
80 // Finds the library private key for |replacement_or_new| or return null | 152 // Finds the library private key for |replacement_or_new| or return null |
81 // if |replacement_or_new| is new. | 153 // if |replacement_or_new| is new. |
82 RawString* FindLibraryPrivateKey(const Library& replacement_or_new); | 154 RawString* FindLibraryPrivateKey(const Library& replacement_or_new); |
83 | 155 |
84 int64_t start_time_micros() const { return start_time_micros_; } | 156 int64_t start_time_micros() const { return start_time_micros_; } |
85 | 157 |
| 158 // Tells whether there are reasons for cancelling the reload. |
| 159 bool HasReasonsForCancelling() const { |
| 160 return !reasons_to_cancel_reload_.is_empty(); |
| 161 } |
| 162 |
| 163 // Record problem for this reload. |
| 164 void AddReasonForCancelling(ReasonForCancelling* reason); |
| 165 |
| 166 // Report all reasons for cancelling reload. |
| 167 void ReportReasonsForCancelling(); |
| 168 |
| 169 // Store morphing operation. |
| 170 void AddInstanceMorpher(InstanceMorpher* morpher); |
| 171 |
| 172 // Tells whether instance in the heap must be morphed. |
| 173 bool HasInstanceMorphers() const { |
| 174 return !instance_morphers_.is_empty(); |
| 175 } |
| 176 |
86 private: | 177 private: |
87 void set_saved_root_library(const Library& value); | 178 void set_saved_root_library(const Library& value); |
88 | 179 |
89 void set_saved_libraries(const GrowableObjectArray& value); | 180 void set_saved_libraries(const GrowableObjectArray& value); |
90 | 181 |
91 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 182 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
92 | 183 |
93 Isolate* isolate() { return isolate_; } | 184 Isolate* isolate() { return isolate_; } |
94 ObjectStore* object_store(); | 185 ObjectStore* object_store(); |
95 | 186 |
96 void EnsuredUnoptimizedCodeForStack(); | 187 void EnsuredUnoptimizedCodeForStack(); |
97 void DeoptimizeDependentCode(); | 188 void DeoptimizeDependentCode(); |
98 | 189 |
99 void Checkpoint(); | 190 void Checkpoint(); |
100 | 191 |
101 void CheckpointClasses(); | 192 void CheckpointClasses(); |
102 | 193 |
103 // Is |lib| a library whose sources have not changed? | 194 // Is |lib| a library whose sources have not changed? |
104 bool IsCleanLibrary(const Library& lib); | 195 bool IsCleanLibrary(const Library& lib); |
105 void CheckpointLibraries(); | 196 void CheckpointLibraries(); |
106 | 197 |
| 198 // Transforms the heap based on instance_morphers_. |
| 199 void MorphInstances(); |
| 200 |
107 bool ValidateReload(); | 201 bool ValidateReload(); |
108 | 202 |
109 void Rollback(); | 203 void Rollback(); |
110 | 204 |
111 void RollbackClasses(); | 205 void RollbackClasses(); |
112 void RollbackLibraries(); | 206 void RollbackLibraries(); |
113 | 207 |
114 #ifdef DEBUG | 208 #ifdef DEBUG |
115 void VerifyMaps(); | 209 void VerifyMaps(); |
116 #endif | 210 #endif |
117 | 211 |
118 void Commit(); | 212 void Commit(); |
119 | 213 |
120 void PostCommit(); | 214 void PostCommit(); |
121 | 215 |
122 void ClearReplacedObjectBits(); | 216 void ClearReplacedObjectBits(); |
123 | 217 |
124 // atomic_install: | 218 // atomic_install: |
125 void MarkAllFunctionsForRecompilation(); | 219 void MarkAllFunctionsForRecompilation(); |
126 void ResetUnoptimizedICsOnStack(); | 220 void ResetUnoptimizedICsOnStack(); |
127 void ResetMegamorphicCaches(); | 221 void ResetMegamorphicCaches(); |
128 void InvalidateWorld(); | 222 void InvalidateWorld(); |
129 | 223 |
130 int64_t start_time_micros_; | 224 int64_t start_time_micros_; |
131 Isolate* isolate_; | 225 Isolate* isolate_; |
132 bool has_error_; | |
133 | 226 |
134 intptr_t saved_num_cids_; | 227 intptr_t saved_num_cids_; |
135 RawClass** saved_class_table_; | 228 RawClass** saved_class_table_; |
| 229 intptr_t num_saved_libs_; |
136 | 230 |
137 intptr_t num_saved_libs_; | 231 // Collect the necessary instance transformation for schema changes. |
| 232 ZoneGrowableArray<InstanceMorpher*> instance_morphers_; |
| 233 |
| 234 // Collects the reasons for cancelling the reload. |
| 235 ZoneGrowableArray<ReasonForCancelling*> reasons_to_cancel_reload_; |
| 236 |
| 237 // Required trait for the cid_mapper_; |
| 238 struct MorpherTrait { |
| 239 typedef InstanceMorpher* Value; |
| 240 typedef intptr_t Key; |
| 241 typedef InstanceMorpher* Pair; |
| 242 |
| 243 static Key KeyOf(Pair kv) { return kv->cid(); } |
| 244 static Value ValueOf(Pair kv) { return kv; } |
| 245 static intptr_t Hashcode(Key key) { return key; } |
| 246 static bool IsKeyEqual(Pair kv, Key key) { return kv->cid() == key; } |
| 247 }; |
| 248 |
| 249 // Hash map from cid to InstanceMorpher. |
| 250 DirectChainedHashMap<MorpherTrait> cid_mapper_; |
| 251 |
138 struct LibraryInfo { | 252 struct LibraryInfo { |
139 bool dirty; | 253 bool dirty; |
140 }; | 254 }; |
141 MallocGrowableArray<LibraryInfo> library_infos_; | 255 MallocGrowableArray<LibraryInfo> library_infos_; |
142 | 256 |
143 RawClass* OldClassOrNull(const Class& replacement_or_new); | 257 RawClass* OldClassOrNull(const Class& replacement_or_new); |
144 | 258 |
145 RawLibrary* OldLibraryOrNull(const Library& replacement_or_new); | 259 RawLibrary* OldLibraryOrNull(const Library& replacement_or_new); |
146 void BuildLibraryMapping(); | 260 void BuildLibraryMapping(); |
147 | 261 |
(...skipping 21 matching lines...) Expand all Loading... |
169 RawArray* old_libraries_set_storage_; | 283 RawArray* old_libraries_set_storage_; |
170 RawArray* library_map_storage_; | 284 RawArray* library_map_storage_; |
171 RawArray* become_map_storage_; | 285 RawArray* become_map_storage_; |
172 RawGrowableObjectArray* become_enum_mappings_; | 286 RawGrowableObjectArray* become_enum_mappings_; |
173 RawLibrary* saved_root_library_; | 287 RawLibrary* saved_root_library_; |
174 RawGrowableObjectArray* saved_libraries_; | 288 RawGrowableObjectArray* saved_libraries_; |
175 RawObject** to() { return reinterpret_cast<RawObject**>(&saved_libraries_); } | 289 RawObject** to() { return reinterpret_cast<RawObject**>(&saved_libraries_); } |
176 | 290 |
177 friend class Isolate; | 291 friend class Isolate; |
178 friend class Class; // AddStaticFieldMapping, AddEnumBecomeMapping. | 292 friend class Class; // AddStaticFieldMapping, AddEnumBecomeMapping. |
| 293 friend class ObjectLocator; |
179 }; | 294 }; |
180 | 295 |
181 } // namespace dart | 296 } // namespace dart |
182 | 297 |
183 #endif // VM_ISOLATE_RELOAD_H_ | 298 #endif // VM_ISOLATE_RELOAD_H_ |
OLD | NEW |