| 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 void Become::MakeDummyObject(const Instance& instance) { |
| 152 // Make the forward pointer point to itself. |
| 153 // This is needed to distinguish it from a real forward object. |
| 154 ForwardObjectTo(instance.raw(), instance.raw()); |
| 155 } |
| 156 |
| 157 static bool IsDummyObject(RawObject* object) { |
| 158 if (!object->IsForwardingCorpse()) return false; |
| 159 return GetForwardedObject(object) == object; |
| 160 } |
| 161 |
| 151 void Become::ElementsForwardIdentity(const Array& before, const Array& after) { | 162 void Become::ElementsForwardIdentity(const Array& before, const Array& after) { |
| 152 Thread* thread = Thread::Current(); | 163 Thread* thread = Thread::Current(); |
| 153 Isolate* isolate = thread->isolate(); | 164 Isolate* isolate = thread->isolate(); |
| 154 Heap* heap = isolate->heap(); | 165 Heap* heap = isolate->heap(); |
| 155 | 166 |
| 156 TIMELINE_FUNCTION_GC_DURATION(thread, "Become::ElementsForwardIdentity"); | 167 TIMELINE_FUNCTION_GC_DURATION(thread, "Become::ElementsForwardIdentity"); |
| 157 HeapIterationScope his; | 168 HeapIterationScope his; |
| 158 | 169 |
| 159 // Setup forwarding pointers. | 170 // Setup forwarding pointers. |
| 160 ASSERT(before.Length() == after.Length()); | 171 ASSERT(before.Length() == after.Length()); |
| 161 for (intptr_t i = 0; i < before.Length(); i++) { | 172 for (intptr_t i = 0; i < before.Length(); i++) { |
| 162 RawObject* before_obj = before.At(i); | 173 RawObject* before_obj = before.At(i); |
| 163 RawObject* after_obj = after.At(i); | 174 RawObject* after_obj = after.At(i); |
| 164 | 175 |
| 165 if (before_obj == after_obj) { | 176 if (before_obj == after_obj) { |
| 166 FATAL("become: Cannot self-forward"); | 177 FATAL("become: Cannot self-forward"); |
| 167 } | 178 } |
| 168 if (!before_obj->IsHeapObject()) { | 179 if (!before_obj->IsHeapObject()) { |
| 169 FATAL("become: Cannot forward immediates"); | 180 FATAL("become: Cannot forward immediates"); |
| 170 } | 181 } |
| 171 if (!after_obj->IsHeapObject()) { | 182 if (!after_obj->IsHeapObject()) { |
| 172 FATAL("become: Cannot become an immediates"); | 183 FATAL("become: Cannot become an immediates"); |
| 173 } | 184 } |
| 174 if (before_obj->IsVMHeapObject()) { | 185 if (before_obj->IsVMHeapObject()) { |
| 175 FATAL("become: Cannot forward VM heap objects"); | 186 FATAL("become: Cannot forward VM heap objects"); |
| 176 } | 187 } |
| 177 if (before_obj->IsForwardingCorpse()) { | 188 if (before_obj->IsForwardingCorpse() && !IsDummyObject(before_obj)) { |
| 178 FATAL("become: Cannot forward to multiple targets"); | 189 FATAL("become: Cannot forward to multiple targets"); |
| 179 } | 190 } |
| 180 if (after_obj->IsForwardingCorpse()) { | 191 if (after_obj->IsForwardingCorpse()) { |
| 181 // The Smalltalk become does allow this, and for very special cases | 192 // The Smalltalk become does allow this, and for very special cases |
| 182 // it is important (shape changes to Class or Mixin), but as these | 193 // it is important (shape changes to Class or Mixin), but as these |
| 183 // cases do not arise in Dart, better to prohibit it. | 194 // cases do not arise in Dart, better to prohibit it. |
| 184 FATAL("become: No indirect chains of forwarding"); | 195 FATAL("become: No indirect chains of forwarding"); |
| 185 } | 196 } |
| 186 | 197 |
| 187 ForwardObjectTo(before_obj, after_obj); | 198 ForwardObjectTo(before_obj, after_obj); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 212 } | 223 } |
| 213 | 224 |
| 214 #if defined(DEBUG) | 225 #if defined(DEBUG) |
| 215 for (intptr_t i = 0; i < before.Length(); i++) { | 226 for (intptr_t i = 0; i < before.Length(); i++) { |
| 216 ASSERT(before.At(i) == after.At(i)); | 227 ASSERT(before.At(i) == after.At(i)); |
| 217 } | 228 } |
| 218 #endif | 229 #endif |
| 219 } | 230 } |
| 220 | 231 |
| 221 } // namespace dart | 232 } // namespace dart |
| OLD | NEW |