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 #include "vm/become.h" | 5 #include "vm/become.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 | 9 |
10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 intptr_t count() const { return count_; } | 142 intptr_t count() const { return count_; } |
143 | 143 |
144 private: | 144 private: |
145 int count_; | 145 int count_; |
146 | 146 |
147 DISALLOW_COPY_AND_ASSIGN(ForwardHeapPointersHandleVisitor); | 147 DISALLOW_COPY_AND_ASSIGN(ForwardHeapPointersHandleVisitor); |
148 }; | 148 }; |
149 | 149 |
150 | 150 |
| 151 // On IA32, object pointers are embedded directly in the instruction stream, |
| 152 // which is normally write-protected, so we need to make it temporarily writable |
| 153 // to forward the pointers. On all other architectures, object pointers are |
| 154 // accessed through ObjectPools. |
| 155 class WritableCodeLiteralsScope : public ValueObject { |
| 156 public: |
| 157 explicit WritableCodeLiteralsScope(Heap* heap) : heap_(heap) { |
| 158 #if defined(TARGET_ARCH_IA32) |
| 159 if (FLAG_write_protect_code) { |
| 160 heap_->WriteProtectCode(false); |
| 161 } |
| 162 #endif |
| 163 } |
| 164 |
| 165 ~WritableCodeLiteralsScope() { |
| 166 #if defined(TARGET_ARCH_IA32) |
| 167 if (FLAG_write_protect_code) { |
| 168 heap_->WriteProtectCode(true); |
| 169 } |
| 170 #endif |
| 171 } |
| 172 |
| 173 private: |
| 174 Heap* heap_; |
| 175 }; |
| 176 |
| 177 |
151 void Become::MakeDummyObject(const Instance& instance) { | 178 void Become::MakeDummyObject(const Instance& instance) { |
152 // Make the forward pointer point to itself. | 179 // Make the forward pointer point to itself. |
153 // This is needed to distinguish it from a real forward object. | 180 // This is needed to distinguish it from a real forward object. |
154 ForwardObjectTo(instance.raw(), instance.raw()); | 181 ForwardObjectTo(instance.raw(), instance.raw()); |
155 } | 182 } |
156 | 183 |
| 184 |
157 static bool IsDummyObject(RawObject* object) { | 185 static bool IsDummyObject(RawObject* object) { |
158 if (!object->IsForwardingCorpse()) return false; | 186 if (!object->IsForwardingCorpse()) return false; |
159 return GetForwardedObject(object) == object; | 187 return GetForwardedObject(object) == object; |
160 } | 188 } |
161 | 189 |
| 190 |
162 void Become::ElementsForwardIdentity(const Array& before, const Array& after) { | 191 void Become::ElementsForwardIdentity(const Array& before, const Array& after) { |
163 Thread* thread = Thread::Current(); | 192 Thread* thread = Thread::Current(); |
164 Isolate* isolate = thread->isolate(); | 193 Isolate* isolate = thread->isolate(); |
165 Heap* heap = isolate->heap(); | 194 Heap* heap = isolate->heap(); |
166 | 195 |
167 TIMELINE_FUNCTION_GC_DURATION(thread, "Become::ElementsForwardIdentity"); | 196 TIMELINE_FUNCTION_GC_DURATION(thread, "Become::ElementsForwardIdentity"); |
168 HeapIterationScope his; | 197 HeapIterationScope his; |
169 | 198 |
170 // Setup forwarding pointers. | 199 // Setup forwarding pointers. |
171 ASSERT(before.Length() == after.Length()); | 200 ASSERT(before.Length() == after.Length()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 232 |
204 // C++ pointers | 233 // C++ pointers |
205 ForwardPointersVisitor pointer_visitor(isolate); | 234 ForwardPointersVisitor pointer_visitor(isolate); |
206 isolate->VisitObjectPointers(&pointer_visitor, true); | 235 isolate->VisitObjectPointers(&pointer_visitor, true); |
207 | 236 |
208 // Weak persistent handles. | 237 // Weak persistent handles. |
209 ForwardHeapPointersHandleVisitor handle_visitor; | 238 ForwardHeapPointersHandleVisitor handle_visitor; |
210 isolate->VisitWeakPersistentHandles(&handle_visitor); | 239 isolate->VisitWeakPersistentHandles(&handle_visitor); |
211 | 240 |
212 // Heap pointers (may require updating the remembered set) | 241 // Heap pointers (may require updating the remembered set) |
213 ForwardHeapPointersVisitor object_visitor(&pointer_visitor); | 242 { |
214 heap->VisitObjects(&object_visitor); | 243 WritableCodeLiteralsScope writable_code(heap); |
215 pointer_visitor.VisitingObject(NULL); | 244 ForwardHeapPointersVisitor object_visitor(&pointer_visitor); |
| 245 heap->VisitObjects(&object_visitor); |
| 246 pointer_visitor.VisitingObject(NULL); |
| 247 } |
216 | 248 |
217 #if !defined(PRODUCT) | 249 #if !defined(PRODUCT) |
218 tds.SetNumArguments(2); | 250 tds.SetNumArguments(2); |
219 tds.FormatArgument(0, "Remapped objects", "%" Pd, before.Length()); | 251 tds.FormatArgument(0, "Remapped objects", "%" Pd, before.Length()); |
220 tds.FormatArgument(1, "Remapped references", "%" Pd, | 252 tds.FormatArgument(1, "Remapped references", "%" Pd, |
221 pointer_visitor.count() + handle_visitor.count()); | 253 pointer_visitor.count() + handle_visitor.count()); |
222 #endif | 254 #endif |
223 } | 255 } |
224 | 256 |
225 #if defined(DEBUG) | 257 #if defined(DEBUG) |
226 for (intptr_t i = 0; i < before.Length(); i++) { | 258 for (intptr_t i = 0; i < before.Length(); i++) { |
227 ASSERT(before.At(i) == after.At(i)); | 259 ASSERT(before.At(i) == after.At(i)); |
228 } | 260 } |
229 #endif | 261 #endif |
230 } | 262 } |
231 | 263 |
232 } // namespace dart | 264 } // namespace dart |
OLD | NEW |