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](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, slot) ? SlotSet::KEEP_SLOT |
| 28 : SlotSet::REMOVE_SLOT; |
28 }); | 29 }); |
29 } | 30 } |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
33 template <PointerDirection direction> | 34 template <PointerDirection direction> |
34 void RememberedSet<direction>::VerifyValidSlots(Heap* heap) { | 35 void RememberedSet<direction>::VerifyValidSlots(Heap* heap) { |
| 36 STATIC_ASSERT(direction == OLD_TO_NEW); |
35 Iterate(heap, [heap](Address addr) { | 37 Iterate(heap, [heap](Address addr) { |
36 HeapObject* obj = | 38 Object** slot = reinterpret_cast<Object**>(addr); |
37 heap->mark_compact_collector()->FindBlackObjectBySlotSlow(addr); | 39 Object* object = *slot; |
38 if (obj == nullptr) { | 40 if (Page::FromAddress(addr)->owner() != nullptr && |
39 // The slot is in dead object. | 41 Page::FromAddress(addr)->owner()->identity() == OLD_SPACE) { |
40 MemoryChunk* chunk = MemoryChunk::FromAnyPointerAddress(heap, addr); | 42 CHECK(IsValidSlot(heap, slot)); |
41 AllocationSpace owner = chunk->owner()->identity(); | 43 heap->mark_compact_collector()->VerifyIsSlotInLiveObject( |
42 // The old to old remembered set can have slots in dead objects. This is | 44 reinterpret_cast<Address>(slot), HeapObject::cast(object)); |
43 // OK because the set is cleared after every mark-compact GC. | |
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 spaces cannot | |
46 // have raw untaged pointers. | |
47 CHECK(direction == OLD_TO_OLD || owner == MAP_SPACE || owner == LO_SPACE); | |
48 } else { | |
49 int offset = static_cast<int>(addr - obj->address()); | |
50 CHECK(obj->IsValidSlot(offset)); | |
51 } | 45 } |
52 return KEEP_SLOT; | 46 return SlotSet::KEEP_SLOT; |
53 }); | 47 }); |
54 } | 48 } |
55 | 49 |
56 template <PointerDirection direction> | 50 template <PointerDirection direction> |
57 bool RememberedSet<direction>::IsValidSlot(Heap* heap, Object** slot) { | 51 bool RememberedSet<direction>::IsValidSlot(Heap* heap, Object** slot) { |
58 STATIC_ASSERT(direction == OLD_TO_NEW); | 52 STATIC_ASSERT(direction == OLD_TO_NEW); |
59 Object* object = *slot; | 53 Object* object = *slot; |
60 if (!heap->InNewSpace(object)) { | 54 if (!heap->InNewSpace(object)) { |
61 return false; | 55 return false; |
62 } | 56 } |
63 HeapObject* heap_object = HeapObject::cast(object); | 57 HeapObject* heap_object = HeapObject::cast(object); |
64 // If the target object is not black, the source slot must be part | 58 // If the target object is not black, the source slot must be part |
65 // of a non-black (dead) object. | 59 // of a non-black (dead) object. |
66 return Marking::IsBlack(Marking::MarkBitFrom(heap_object)) && | 60 return Marking::IsBlack(Marking::MarkBitFrom(heap_object)) && |
67 heap->mark_compact_collector()->IsSlotInLiveObject( | 61 heap->mark_compact_collector()->IsSlotInLiveObject( |
68 reinterpret_cast<Address>(slot)); | 62 reinterpret_cast<Address>(slot)); |
69 } | 63 } |
70 | 64 |
71 template void RememberedSet<OLD_TO_NEW>::ClearInvalidSlots(Heap* heap); | 65 template void RememberedSet<OLD_TO_NEW>::ClearInvalidSlots(Heap* heap); |
72 template void RememberedSet<OLD_TO_NEW>::VerifyValidSlots(Heap* heap); | 66 template void RememberedSet<OLD_TO_NEW>::VerifyValidSlots(Heap* heap); |
73 template void RememberedSet<OLD_TO_OLD>::VerifyValidSlots(Heap* heap); | |
74 | 67 |
75 } // namespace internal | 68 } // namespace internal |
76 } // namespace v8 | 69 } // namespace v8 |
OLD | NEW |