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 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 | 16 |
16 template <PointerDirection direction> | 17 template <PointerDirection direction> |
17 void RememberedSet<direction>::ClearInvalidSlots(Heap* heap) { | 18 void RememberedSet<direction>::ClearInvalidSlots(Heap* heap) { |
18 STATIC_ASSERT(direction == OLD_TO_NEW); | 19 STATIC_ASSERT(direction == OLD_TO_NEW); |
19 PageIterator it(heap->old_space()); | 20 { |
20 MemoryChunk* chunk; | 21 PageIterator it(heap->old_space()); |
21 while (it.has_next()) { | 22 MemoryChunk* chunk; |
22 chunk = it.next(); | 23 while (it.has_next()) { |
23 SlotSet* slots = GetSlotSet(chunk); | 24 chunk = it.next(); |
24 if (slots != nullptr) { | 25 { |
25 slots->Iterate([heap, chunk](Address addr) { | 26 SlotSet* slots = GetSlotSet(chunk); |
26 Object** slot = reinterpret_cast<Object**>(addr); | 27 if (slots != nullptr) { |
27 return IsValidSlot(heap, chunk, slot) ? KEEP_SLOT : REMOVE_SLOT; | 28 slots->Iterate([heap, chunk](Address addr) { |
28 }); | 29 Object** slot = reinterpret_cast<Object**>(addr); |
30 return IsValidSlot(heap, chunk, slot) ? KEEP_SLOT : REMOVE_SLOT; | |
31 }); | |
32 } | |
33 } | |
34 } | |
35 } | |
36 { | |
37 PageIterator it(heap->code_space()); | |
38 MemoryChunk* chunk; | |
39 while (it.has_next()) { | |
40 chunk = it.next(); | |
41 TypedSlotSet* slots = GetTypedSlotSet(chunk); | |
42 if (slots != nullptr) { | |
43 slots->Iterate( | |
44 [heap, chunk](SlotType type, Address host_addr, Address addr) { | |
45 if (IsValidTypedSlot(heap, chunk, type, host_addr, addr)) { | |
ulan
2016/06/08 14:37:00
Just use Marking::IsBlack(Marking::MarkBitFrom(hos
ahaas
2016/06/09 10:34:32
Done.
| |
46 return KEEP_SLOT; | |
47 } else { | |
48 return REMOVE_SLOT; | |
49 } | |
50 }); | |
51 } | |
29 } | 52 } |
30 } | 53 } |
31 } | 54 } |
32 | 55 |
33 template <PointerDirection direction> | 56 template <PointerDirection direction> |
34 void RememberedSet<direction>::VerifyValidSlots(Heap* heap) { | 57 void RememberedSet<direction>::VerifyValidSlots(Heap* heap) { |
35 Iterate(heap, [heap](Address addr) { | 58 Iterate(heap, [heap](Address addr) { |
36 HeapObject* obj = | 59 HeapObject* obj = |
37 heap->mark_compact_collector()->FindBlackObjectBySlotSlow(addr); | 60 heap->mark_compact_collector()->FindBlackObjectBySlotSlow(addr); |
38 if (obj == nullptr) { | 61 if (obj == nullptr) { |
(...skipping 23 matching lines...) Expand all Loading... | |
62 return false; | 85 return false; |
63 } | 86 } |
64 HeapObject* heap_object = HeapObject::cast(object); | 87 HeapObject* heap_object = HeapObject::cast(object); |
65 // If the target object is not black, the source slot must be part | 88 // If the target object is not black, the source slot must be part |
66 // of a non-black (dead) object. | 89 // of a non-black (dead) object. |
67 return Marking::IsBlack(Marking::MarkBitFrom(heap_object)) && | 90 return Marking::IsBlack(Marking::MarkBitFrom(heap_object)) && |
68 heap->mark_compact_collector()->IsSlotInBlackObject( | 91 heap->mark_compact_collector()->IsSlotInBlackObject( |
69 chunk, reinterpret_cast<Address>(slot)); | 92 chunk, reinterpret_cast<Address>(slot)); |
70 } | 93 } |
71 | 94 |
95 template <PointerDirection direction> | |
96 bool RememberedSet<direction>::IsValidTypedSlot(Heap* heap, MemoryChunk* chunk, | |
97 SlotType slot_type, | |
98 Address host_addr, | |
99 Address slot) { | |
100 STATIC_ASSERT(direction == OLD_TO_NEW); | |
101 Object* object; | |
102 Code* code = reinterpret_cast<Code*>(host_addr); | |
103 switch (slot_type) { | |
104 case CODE_TARGET_SLOT: { | |
105 RelocInfo rinfo(heap->isolate(), slot, RelocInfo::CODE_TARGET, 0, code); | |
106 object = rinfo.target_object(); | |
107 break; | |
108 } | |
109 case CELL_TARGET_SLOT: { | |
110 RelocInfo rinfo(heap->isolate(), slot, RelocInfo::CELL, 0, code); | |
111 object = rinfo.target_object(); | |
112 break; | |
113 } | |
114 case EMBEDDED_OBJECT_SLOT: { | |
115 RelocInfo rinfo(heap->isolate(), slot, RelocInfo::EMBEDDED_OBJECT, 0, | |
116 code); | |
117 object = rinfo.target_object(); | |
118 break; | |
119 } | |
120 case OBJECT_SLOT: { | |
121 object = *reinterpret_cast<Object**>(slot); | |
122 break; | |
123 } | |
124 default: | |
125 printf("Slot type: %d\n", slot_type); | |
126 UNREACHABLE(); | |
127 break; | |
128 } | |
129 | |
130 if (!heap->InNewSpace(object)) { | |
131 return false; | |
132 } | |
133 HeapObject* heap_object = HeapObject::cast(object); | |
134 // If the target object is not black, the source slot must be part | |
135 // of a non-black (dead) object. | |
136 return Marking::IsBlack(Marking::MarkBitFrom(heap_object)) && | |
137 Marking::IsBlack(Marking::MarkBitFrom(host_addr)); | |
138 } | |
139 | |
72 template void RememberedSet<OLD_TO_NEW>::ClearInvalidSlots(Heap* heap); | 140 template void RememberedSet<OLD_TO_NEW>::ClearInvalidSlots(Heap* heap); |
73 template void RememberedSet<OLD_TO_NEW>::VerifyValidSlots(Heap* heap); | 141 template void RememberedSet<OLD_TO_NEW>::VerifyValidSlots(Heap* heap); |
74 template void RememberedSet<OLD_TO_OLD>::VerifyValidSlots(Heap* heap); | 142 template void RememberedSet<OLD_TO_OLD>::VerifyValidSlots(Heap* heap); |
75 | 143 |
76 } // namespace internal | 144 } // namespace internal |
77 } // namespace v8 | 145 } // namespace v8 |
OLD | NEW |