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