| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 uword addr = reinterpret_cast<uword>(object) - kHeapObjectTag; | 55 uword addr = reinterpret_cast<uword>(object) - kHeapObjectTag; |
| 56 ForwardingCorpse* forwarder = reinterpret_cast<ForwardingCorpse*>(addr); | 56 ForwardingCorpse* forwarder = reinterpret_cast<ForwardingCorpse*>(addr); |
| 57 return forwarder->target(); | 57 return forwarder->target(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 static void ForwardObjectTo(RawObject* before_obj, RawObject* after_obj) { | 61 static void ForwardObjectTo(RawObject* before_obj, RawObject* after_obj) { |
| 62 const intptr_t size_before = before_obj->Size(); | 62 const intptr_t size_before = before_obj->Size(); |
| 63 | 63 |
| 64 uword corpse_addr = reinterpret_cast<uword>(before_obj) - kHeapObjectTag; | 64 uword corpse_addr = reinterpret_cast<uword>(before_obj) - kHeapObjectTag; |
| 65 ForwardingCorpse* forwarder = ForwardingCorpse::AsForwarder(corpse_addr, | 65 ForwardingCorpse* forwarder = |
| 66 size_before); | 66 ForwardingCorpse::AsForwarder(corpse_addr, size_before); |
| 67 forwarder->set_target(after_obj); | 67 forwarder->set_target(after_obj); |
| 68 if (!IsForwardingObject(before_obj)) { | 68 if (!IsForwardingObject(before_obj)) { |
| 69 FATAL("become: ForwardObjectTo failure."); | 69 FATAL("become: ForwardObjectTo failure."); |
| 70 } | 70 } |
| 71 // Still need to be able to iterate over the forwarding corpse. | 71 // Still need to be able to iterate over the forwarding corpse. |
| 72 const intptr_t size_after = before_obj->Size(); | 72 const intptr_t size_after = before_obj->Size(); |
| 73 if (size_before != size_after) { | 73 if (size_before != size_after) { |
| 74 FATAL("become: Before and after sizes do not match."); | 74 FATAL("become: Before and after sizes do not match."); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 | 78 |
| 79 class ForwardPointersVisitor : public ObjectPointerVisitor { | 79 class ForwardPointersVisitor : public ObjectPointerVisitor { |
| 80 public: | 80 public: |
| 81 explicit ForwardPointersVisitor(Isolate* isolate) | 81 explicit ForwardPointersVisitor(Isolate* isolate) |
| 82 : ObjectPointerVisitor(isolate), visiting_object_(NULL), count_(0) { } | 82 : ObjectPointerVisitor(isolate), visiting_object_(NULL), count_(0) {} |
| 83 | 83 |
| 84 virtual void VisitPointers(RawObject** first, RawObject** last) { | 84 virtual void VisitPointers(RawObject** first, RawObject** last) { |
| 85 for (RawObject** p = first; p <= last; p++) { | 85 for (RawObject** p = first; p <= last; p++) { |
| 86 RawObject* old_target = *p; | 86 RawObject* old_target = *p; |
| 87 if (IsForwardingObject(old_target)) { | 87 if (IsForwardingObject(old_target)) { |
| 88 RawObject* new_target = GetForwardedObject(old_target); | 88 RawObject* new_target = GetForwardedObject(old_target); |
| 89 if (visiting_object_ == NULL) { | 89 if (visiting_object_ == NULL) { |
| 90 *p = new_target; | 90 *p = new_target; |
| 91 } else { | 91 } else { |
| 92 visiting_object_->StorePointer(p, new_target); | 92 visiting_object_->StorePointer(p, new_target); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 104 RawObject* visiting_object_; | 104 RawObject* visiting_object_; |
| 105 intptr_t count_; | 105 intptr_t count_; |
| 106 | 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(ForwardPointersVisitor); | 107 DISALLOW_COPY_AND_ASSIGN(ForwardPointersVisitor); |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 | 110 |
| 111 class ForwardHeapPointersVisitor : public ObjectVisitor { | 111 class ForwardHeapPointersVisitor : public ObjectVisitor { |
| 112 public: | 112 public: |
| 113 explicit ForwardHeapPointersVisitor(ForwardPointersVisitor* pointer_visitor) | 113 explicit ForwardHeapPointersVisitor(ForwardPointersVisitor* pointer_visitor) |
| 114 : pointer_visitor_(pointer_visitor) { } | 114 : pointer_visitor_(pointer_visitor) {} |
| 115 | 115 |
| 116 virtual void VisitObject(RawObject* obj) { | 116 virtual void VisitObject(RawObject* obj) { |
| 117 pointer_visitor_->VisitingObject(obj); | 117 pointer_visitor_->VisitingObject(obj); |
| 118 obj->VisitPointers(pointer_visitor_); | 118 obj->VisitPointers(pointer_visitor_); |
| 119 } | 119 } |
| 120 | 120 |
| 121 private: | 121 private: |
| 122 ForwardPointersVisitor* pointer_visitor_; | 122 ForwardPointersVisitor* pointer_visitor_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(ForwardHeapPointersVisitor); | 124 DISALLOW_COPY_AND_ASSIGN(ForwardHeapPointersVisitor); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 | 127 |
| 128 class ForwardHeapPointersHandleVisitor : public HandleVisitor { | 128 class ForwardHeapPointersHandleVisitor : public HandleVisitor { |
| 129 public: | 129 public: |
| 130 ForwardHeapPointersHandleVisitor() | 130 ForwardHeapPointersHandleVisitor() |
| 131 : HandleVisitor(Thread::Current()), count_(0) { } | 131 : HandleVisitor(Thread::Current()), count_(0) {} |
| 132 | 132 |
| 133 virtual void VisitHandle(uword addr) { | 133 virtual void VisitHandle(uword addr) { |
| 134 FinalizablePersistentHandle* handle = | 134 FinalizablePersistentHandle* handle = |
| 135 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 135 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
| 136 if (IsForwardingObject(handle->raw())) { | 136 if (IsForwardingObject(handle->raw())) { |
| 137 *handle->raw_addr() = GetForwardedObject(handle->raw()); | 137 *handle->raw_addr() = GetForwardedObject(handle->raw()); |
| 138 count_++; | 138 count_++; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 166 heap_->WriteProtectCode(true); | 166 heap_->WriteProtectCode(true); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 private: | 170 private: |
| 171 Heap* heap_; | 171 Heap* heap_; |
| 172 }; | 172 }; |
| 173 #else | 173 #else |
| 174 class WritableCodeLiteralsScope : public ValueObject { | 174 class WritableCodeLiteralsScope : public ValueObject { |
| 175 public: | 175 public: |
| 176 explicit WritableCodeLiteralsScope(Heap* heap) { } | 176 explicit WritableCodeLiteralsScope(Heap* heap) {} |
| 177 ~WritableCodeLiteralsScope() { } | 177 ~WritableCodeLiteralsScope() {} |
| 178 }; | 178 }; |
| 179 #endif | 179 #endif |
| 180 | 180 |
| 181 | 181 |
| 182 void Become::MakeDummyObject(const Instance& instance) { | 182 void Become::MakeDummyObject(const Instance& instance) { |
| 183 // Make the forward pointer point to itself. | 183 // Make the forward pointer point to itself. |
| 184 // This is needed to distinguish it from a real forward object. | 184 // This is needed to distinguish it from a real forward object. |
| 185 ForwardObjectTo(instance.raw(), instance.raw()); | 185 ForwardObjectTo(instance.raw(), instance.raw()); |
| 186 } | 186 } |
| 187 | 187 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // Heap pointers (may require updating the remembered set) | 284 // Heap pointers (may require updating the remembered set) |
| 285 { | 285 { |
| 286 WritableCodeLiteralsScope writable_code(heap); | 286 WritableCodeLiteralsScope writable_code(heap); |
| 287 ForwardHeapPointersVisitor object_visitor(&pointer_visitor); | 287 ForwardHeapPointersVisitor object_visitor(&pointer_visitor); |
| 288 heap->VisitObjects(&object_visitor); | 288 heap->VisitObjects(&object_visitor); |
| 289 pointer_visitor.VisitingObject(NULL); | 289 pointer_visitor.VisitingObject(NULL); |
| 290 } | 290 } |
| 291 | 291 |
| 292 #if !defined(PRODUCT) | 292 #if !defined(PRODUCT) |
| 293 tds.SetNumArguments(2); | 293 tds.SetNumArguments(2); |
| 294 tds.FormatArgument(0, "Remapped objects", "%" Pd, before.Length()); | 294 tds.FormatArgument(0, "Remapped objects", "%" Pd, before.Length()); |
| 295 tds.FormatArgument(1, "Remapped references", "%" Pd, | 295 tds.FormatArgument(1, "Remapped references", "%" Pd, |
| 296 pointer_visitor.count() + handle_visitor.count()); | 296 pointer_visitor.count() + handle_visitor.count()); |
| 297 #endif | 297 #endif |
| 298 } | 298 } |
| 299 | 299 |
| 300 #if defined(DEBUG) | 300 #if defined(DEBUG) |
| 301 for (intptr_t i = 0; i < before.Length(); i++) { | 301 for (intptr_t i = 0; i < before.Length(); i++) { |
| 302 ASSERT(before.At(i) == after.At(i)); | 302 ASSERT(before.At(i) == after.At(i)); |
| 303 } | 303 } |
| 304 #endif | 304 #endif |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace dart | 307 } // namespace dart |
| OLD | NEW |