| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/heap/remembered-set.h" | 5 #include "src/heap/remembered-set.h" |
| 6 #include "src/heap/heap-inl.h" | 6 #include "src/heap/heap-inl.h" |
| 7 #include "src/heap/heap.h" | 7 #include "src/heap/heap.h" |
| 8 #include "src/heap/mark-compact.h" | 8 #include "src/heap/mark-compact.h" |
| 9 #include "src/heap/slot-set.h" | 9 #include "src/heap/slot-set.h" |
| 10 #include "src/heap/spaces.h" | 10 #include "src/heap/spaces.h" |
| 11 #include "src/heap/store-buffer.h" | 11 #include "src/heap/store-buffer.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 template <PointerDirection direction> | 16 template <PointerDirection direction> |
| 17 void RememberedSet<direction>::ClearInvalidSlots(Heap* heap) { | 17 void RememberedSet<direction>::ClearInvalidSlots(Heap* heap) { |
| 18 STATIC_ASSERT(direction == OLD_TO_NEW); | 18 STATIC_ASSERT(direction == OLD_TO_NEW); |
| 19 PageIterator it(heap->old_space()); | 19 PageIterator it(heap->old_space()); |
| 20 MemoryChunk* chunk; | 20 MemoryChunk* chunk; |
| 21 while (it.has_next()) { | 21 while (it.has_next()) { |
| 22 chunk = it.next(); | 22 chunk = it.next(); |
| 23 SlotSet* slots = GetSlotSet(chunk); | 23 SlotSet* slots = GetSlotSet(chunk); |
| 24 if (slots != nullptr) { | 24 if (slots != nullptr) { |
| 25 slots->Iterate([heap](Address addr) { | 25 slots->Iterate([heap, chunk](Address addr) { |
| 26 Object** slot = reinterpret_cast<Object**>(addr); | 26 Object** slot = reinterpret_cast<Object**>(addr); |
| 27 return IsValidSlot(heap, slot) ? KEEP_SLOT : REMOVE_SLOT; | 27 return IsValidSlot(heap, chunk, slot) ? KEEP_SLOT : REMOVE_SLOT; |
| 28 }); | 28 }); |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 template <PointerDirection direction> | 33 template <PointerDirection direction> |
| 34 void RememberedSet<direction>::VerifyValidSlots(Heap* heap) { | 34 void RememberedSet<direction>::VerifyValidSlots(Heap* heap) { |
| 35 Iterate(heap, [heap](Address addr) { | 35 Iterate(heap, [heap](Address addr) { |
| 36 HeapObject* obj = | 36 HeapObject* obj = |
| 37 heap->mark_compact_collector()->FindBlackObjectBySlotSlow(addr); | 37 heap->mark_compact_collector()->FindBlackObjectBySlotSlow(addr); |
| 38 if (obj == nullptr) { | 38 if (obj == nullptr) { |
| 39 // The slot is in dead object. | 39 // The slot is in dead object. |
| 40 MemoryChunk* chunk = MemoryChunk::FromAnyPointerAddress(heap, addr); | 40 MemoryChunk* chunk = MemoryChunk::FromAnyPointerAddress(heap, addr); |
| 41 AllocationSpace owner = chunk->owner()->identity(); | 41 AllocationSpace owner = chunk->owner()->identity(); |
| 42 // The old to old remembered set should not have dead slots. | 42 // The old to old remembered set should not have dead slots. |
| 43 CHECK_NE(direction, OLD_TO_OLD); | 43 CHECK_NE(direction, OLD_TO_OLD); |
| 44 // The old to new remembered set is allowed to have slots in dead | 44 // The old to new remembered set is allowed to have slots in dead |
| 45 // objects only in map and large object space because these space | 45 // objects only in map and large object space because these space |
| 46 // cannot have raw untagged pointers. | 46 // cannot have raw untagged pointers. |
| 47 CHECK(owner == MAP_SPACE || owner == LO_SPACE); | 47 CHECK(owner == MAP_SPACE || owner == LO_SPACE); |
| 48 } else { | 48 } else { |
| 49 int offset = static_cast<int>(addr - obj->address()); | 49 int offset = static_cast<int>(addr - obj->address()); |
| 50 CHECK(obj->IsValidSlot(offset)); | 50 CHECK(obj->IsValidSlot(offset)); |
| 51 } | 51 } |
| 52 return KEEP_SLOT; | 52 return KEEP_SLOT; |
| 53 }); | 53 }); |
| 54 } | 54 } |
| 55 | 55 |
| 56 template <PointerDirection direction> | 56 template <PointerDirection direction> |
| 57 bool RememberedSet<direction>::IsValidSlot(Heap* heap, Object** slot) { | 57 bool RememberedSet<direction>::IsValidSlot(Heap* heap, MemoryChunk* chunk, |
| 58 Object** slot) { |
| 58 STATIC_ASSERT(direction == OLD_TO_NEW); | 59 STATIC_ASSERT(direction == OLD_TO_NEW); |
| 59 Object* object = *slot; | 60 Object* object = *slot; |
| 60 if (!heap->InNewSpace(object)) { | 61 if (!heap->InNewSpace(object)) { |
| 61 return false; | 62 return false; |
| 62 } | 63 } |
| 63 HeapObject* heap_object = HeapObject::cast(object); | 64 HeapObject* heap_object = HeapObject::cast(object); |
| 64 // If the target object is not black, the source slot must be part | 65 // If the target object is not black, the source slot must be part |
| 65 // of a non-black (dead) object. | 66 // of a non-black (dead) object. |
| 66 return Marking::IsBlack(Marking::MarkBitFrom(heap_object)) && | 67 return Marking::IsBlack(Marking::MarkBitFrom(heap_object)) && |
| 67 heap->mark_compact_collector()->IsSlotInLiveObject( | 68 heap->mark_compact_collector()->IsSlotInBlackObject( |
| 68 reinterpret_cast<Address>(slot)); | 69 chunk, reinterpret_cast<Address>(slot)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 template void RememberedSet<OLD_TO_NEW>::ClearInvalidSlots(Heap* heap); | 72 template void RememberedSet<OLD_TO_NEW>::ClearInvalidSlots(Heap* heap); |
| 72 template void RememberedSet<OLD_TO_NEW>::VerifyValidSlots(Heap* heap); | 73 template void RememberedSet<OLD_TO_NEW>::VerifyValidSlots(Heap* heap); |
| 73 template void RememberedSet<OLD_TO_OLD>::VerifyValidSlots(Heap* heap); | 74 template void RememberedSet<OLD_TO_OLD>::VerifyValidSlots(Heap* heap); |
| 74 | 75 |
| 75 } // namespace internal | 76 } // namespace internal |
| 76 } // namespace v8 | 77 } // namespace v8 |
| OLD | NEW |