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 #include "src/macro-assembler.h" | 12 #include "src/macro-assembler.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 template <PointerDirection direction> | 17 template <PointerDirection direction> |
18 void RememberedSet<direction>::ClearInvalidSlots(Heap* heap) { | 18 void RememberedSet<direction>::ClearInvalidSlots(Heap* heap, |
19 MemoryChunk* chunk) { | |
19 STATIC_ASSERT(direction == OLD_TO_NEW); | 20 STATIC_ASSERT(direction == OLD_TO_NEW); |
20 for (MemoryChunk* chunk : *heap->old_space()) { | 21 AllocationSpace identity = chunk->owner()->identity(); |
22 DCHECK(identity == OLD_SPACE || identity == MAP_SPACE); | |
23 if (identity == OLD_SPACE) { | |
ulan
2016/10/06 12:52:13
Both old and map space should clear untyped slots.
Hannes Payer (out of office)
2016/10/06 13:22:40
Done.
| |
21 SlotSet* slots = GetSlotSet(chunk); | 24 SlotSet* slots = GetSlotSet(chunk); |
22 if (slots != nullptr) { | 25 if (slots != nullptr) { |
23 slots->Iterate( | 26 slots->Iterate( |
24 [heap, chunk](Address addr) { | 27 [heap, chunk](Address addr) { |
25 Object** slot = reinterpret_cast<Object**>(addr); | 28 Object** slot = reinterpret_cast<Object**>(addr); |
26 return IsValidSlot(heap, chunk, slot) ? KEEP_SLOT : REMOVE_SLOT; | 29 return IsValidSlot(heap, chunk, slot) ? KEEP_SLOT : REMOVE_SLOT; |
27 }, | 30 }, |
28 SlotSet::PREFREE_EMPTY_BUCKETS); | 31 SlotSet::KEEP_EMPTY_BUCKETS); |
29 } | 32 } |
30 } | 33 } else if (identity == MAP_SPACE) { |
ulan
2016/10/06 12:52:13
This branch is not needed.
Michael Lippautz
2016/10/06 13:02:19
and the top branch should also apply for map space
Hannes Payer (out of office)
2016/10/06 13:22:40
Done.
| |
31 for (MemoryChunk* chunk : *heap->code_space()) { | |
32 TypedSlotSet* slots = GetTypedSlotSet(chunk); | 34 TypedSlotSet* slots = GetTypedSlotSet(chunk); |
33 if (slots != nullptr) { | 35 if (slots != nullptr) { |
34 slots->Iterate( | 36 slots->Iterate( |
35 [heap, chunk](SlotType type, Address host_addr, Address addr) { | 37 [heap, chunk](SlotType type, Address host_addr, Address addr) { |
36 if (Marking::IsBlack(ObjectMarking::MarkBitFrom(host_addr))) { | 38 if (Marking::IsBlack(ObjectMarking::MarkBitFrom(host_addr))) { |
37 return KEEP_SLOT; | 39 return KEEP_SLOT; |
38 } else { | 40 } else { |
39 return REMOVE_SLOT; | 41 return REMOVE_SLOT; |
40 } | 42 } |
41 }, | 43 }, |
42 TypedSlotSet::PREFREE_EMPTY_CHUNKS); | 44 TypedSlotSet::KEEP_EMPTY_CHUNKS); |
43 } | |
44 } | |
45 for (MemoryChunk* chunk : *heap->map_space()) { | |
46 SlotSet* slots = GetSlotSet(chunk); | |
47 if (slots != nullptr) { | |
48 slots->Iterate( | |
49 [heap, chunk](Address addr) { | |
50 Object** slot = reinterpret_cast<Object**>(addr); | |
51 // TODO(mlippautz): In map space all allocations would ideally be | |
52 // map | |
53 // aligned. After establishing this invariant IsValidSlot could just | |
54 // refer to the containing object using alignment and check the mark | |
55 // bits. | |
56 return IsValidSlot(heap, chunk, slot) ? KEEP_SLOT : REMOVE_SLOT; | |
57 }, | |
58 SlotSet::PREFREE_EMPTY_BUCKETS); | |
59 } | 45 } |
60 } | 46 } |
61 } | 47 } |
62 | 48 |
63 template <PointerDirection direction> | 49 template <PointerDirection direction> |
64 void RememberedSet<direction>::VerifyValidSlots(Heap* heap) { | 50 void RememberedSet<direction>::ClearInvalidTypedSlots(Heap* heap, |
65 Iterate(heap, [heap](Address addr) { | 51 MemoryChunk* chunk) { |
66 HeapObject* obj = | 52 STATIC_ASSERT(direction == OLD_TO_NEW); |
67 heap->mark_compact_collector()->FindBlackObjectBySlotSlow(addr); | 53 DCHECK(chunk->owner()->identity() == CODE_SPACE); |
68 if (obj == nullptr) { | 54 TypedSlotSet* slots = GetTypedSlotSet(chunk); |
69 // The slot is in dead object. | 55 if (slots != nullptr) { |
70 MemoryChunk* chunk = MemoryChunk::FromAnyPointerAddress(heap, addr); | 56 slots->Iterate( |
71 AllocationSpace owner = chunk->owner()->identity(); | 57 [heap, chunk](SlotType type, Address host_addr, Address addr) { |
72 // The old to old remembered set should not have dead slots. | 58 if (Marking::IsBlack(ObjectMarking::MarkBitFrom(host_addr))) { |
73 CHECK_NE(direction, OLD_TO_OLD); | 59 return KEEP_SLOT; |
74 // The old to new remembered set is allowed to have slots in dead | 60 } else { |
75 // objects only in map and large object space because these space | 61 return REMOVE_SLOT; |
76 // cannot have raw untagged pointers. | 62 } |
77 CHECK(owner == MAP_SPACE || owner == LO_SPACE); | 63 }, |
78 } else { | 64 TypedSlotSet::KEEP_EMPTY_CHUNKS); |
79 int offset = static_cast<int>(addr - obj->address()); | 65 } |
80 CHECK(obj->IsValidSlot(offset)); | |
81 } | |
82 return KEEP_SLOT; | |
83 }); | |
84 } | 66 } |
85 | 67 |
86 template <PointerDirection direction> | 68 template <PointerDirection direction> |
87 bool RememberedSet<direction>::IsValidSlot(Heap* heap, MemoryChunk* chunk, | 69 bool RememberedSet<direction>::IsValidSlot(Heap* heap, MemoryChunk* chunk, |
88 Object** slot) { | 70 Object** slot) { |
89 STATIC_ASSERT(direction == OLD_TO_NEW); | 71 STATIC_ASSERT(direction == OLD_TO_NEW); |
90 Object* object = *slot; | |
91 if (!heap->InNewSpace(object)) { | |
92 return false; | |
93 } | |
94 HeapObject* heap_object = HeapObject::cast(object); | |
95 // If the target object is not black, the source slot must be part | 72 // If the target object is not black, the source slot must be part |
96 // of a non-black (dead) object. | 73 // of a non-black (dead) object. |
97 return Marking::IsBlack(ObjectMarking::MarkBitFrom(heap_object)) && | 74 return heap->mark_compact_collector()->IsSlotInBlackObject( |
98 heap->mark_compact_collector()->IsSlotInBlackObject( | 75 chunk, reinterpret_cast<Address>(slot)); |
99 chunk, reinterpret_cast<Address>(slot)); | |
100 } | 76 } |
101 | 77 |
102 template void RememberedSet<OLD_TO_NEW>::ClearInvalidSlots(Heap* heap); | 78 template void RememberedSet<OLD_TO_NEW>::ClearInvalidSlots(Heap* heap, |
103 template void RememberedSet<OLD_TO_NEW>::VerifyValidSlots(Heap* heap); | 79 MemoryChunk* chunk); |
104 template void RememberedSet<OLD_TO_OLD>::VerifyValidSlots(Heap* heap); | 80 template void RememberedSet<OLD_TO_NEW>::ClearInvalidTypedSlots( |
81 Heap* heap, MemoryChunk* chunk); | |
105 | 82 |
106 } // namespace internal | 83 } // namespace internal |
107 } // namespace v8 | 84 } // namespace v8 |
OLD | NEW |