| 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 #ifndef V8_REMEMBERED_SET_H | 5 #ifndef V8_REMEMBERED_SET_H |
| 6 #define V8_REMEMBERED_SET_H | 6 #define V8_REMEMBERED_SET_H |
| 7 | 7 |
| 8 #include "src/heap/heap.h" | 8 #include "src/heap/heap.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" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 int new_count = 0; | 91 int new_count = 0; |
| 92 for (size_t page = 0; page < pages; page++) { | 92 for (size_t page = 0; page < pages; page++) { |
| 93 new_count += slots[page].Iterate(callback); | 93 new_count += slots[page].Iterate(callback); |
| 94 } | 94 } |
| 95 if (new_count == 0) { | 95 if (new_count == 0) { |
| 96 ReleaseSlotSet(chunk); | 96 ReleaseSlotSet(chunk); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Iterates and filters the remembered set with the given callback. | |
| 102 // The callback should take (HeapObject** slot, HeapObject* target) and | |
| 103 // update the slot. | |
| 104 // A special wrapper takes care of filtering the slots based on their values. | |
| 105 // For OLD_TO_NEW case: slots that do not point to the ToSpace after | |
| 106 // callback invocation will be removed from the set. | |
| 107 template <typename Callback> | |
| 108 static void IterateWithWrapper(Heap* heap, Callback callback) { | |
| 109 Iterate(heap, [heap, callback](Address addr) { | |
| 110 return Wrapper(heap, addr, callback); | |
| 111 }); | |
| 112 } | |
| 113 | |
| 114 template <typename Callback> | |
| 115 static void IterateWithWrapper(Heap* heap, MemoryChunk* chunk, | |
| 116 Callback callback) { | |
| 117 Iterate(chunk, [heap, callback](Address addr) { | |
| 118 return Wrapper(heap, addr, callback); | |
| 119 }); | |
| 120 } | |
| 121 | |
| 122 // Given a page and a typed slot in that page, this function adds the slot | 101 // Given a page and a typed slot in that page, this function adds the slot |
| 123 // to the remembered set. | 102 // to the remembered set. |
| 124 static void InsertTyped(Page* page, SlotType slot_type, Address slot_addr) { | 103 static void InsertTyped(Page* page, SlotType slot_type, Address slot_addr) { |
| 125 STATIC_ASSERT(direction == OLD_TO_OLD); | 104 STATIC_ASSERT(direction == OLD_TO_OLD); |
| 126 TypedSlotSet* slot_set = page->typed_old_to_old_slots(); | 105 TypedSlotSet* slot_set = page->typed_old_to_old_slots(); |
| 127 if (slot_set == nullptr) { | 106 if (slot_set == nullptr) { |
| 128 page->AllocateTypedOldToOldSlots(); | 107 page->AllocateTypedOldToOldSlots(); |
| 129 slot_set = page->typed_old_to_old_slots(); | 108 slot_set = page->typed_old_to_old_slots(); |
| 130 } | 109 } |
| 131 uintptr_t offset = slot_addr - page->address(); | 110 uintptr_t offset = slot_addr - page->address(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 static SlotSet* AllocateSlotSet(MemoryChunk* chunk) { | 184 static SlotSet* AllocateSlotSet(MemoryChunk* chunk) { |
| 206 if (direction == OLD_TO_OLD) { | 185 if (direction == OLD_TO_OLD) { |
| 207 chunk->AllocateOldToOldSlots(); | 186 chunk->AllocateOldToOldSlots(); |
| 208 return chunk->old_to_old_slots(); | 187 return chunk->old_to_old_slots(); |
| 209 } else { | 188 } else { |
| 210 chunk->AllocateOldToNewSlots(); | 189 chunk->AllocateOldToNewSlots(); |
| 211 return chunk->old_to_new_slots(); | 190 return chunk->old_to_new_slots(); |
| 212 } | 191 } |
| 213 } | 192 } |
| 214 | 193 |
| 215 template <typename Callback> | |
| 216 static SlotCallbackResult Wrapper(Heap* heap, Address slot_address, | |
| 217 Callback slot_callback) { | |
| 218 STATIC_ASSERT(direction == OLD_TO_NEW); | |
| 219 Object** slot = reinterpret_cast<Object**>(slot_address); | |
| 220 Object* object = *slot; | |
| 221 if (heap->InFromSpace(object)) { | |
| 222 HeapObject* heap_object = reinterpret_cast<HeapObject*>(object); | |
| 223 DCHECK(heap_object->IsHeapObject()); | |
| 224 slot_callback(reinterpret_cast<HeapObject**>(slot), heap_object); | |
| 225 object = *slot; | |
| 226 // If the object was in from space before and is after executing the | |
| 227 // callback in to space, the object is still live. | |
| 228 // Unfortunately, we do not know about the slot. It could be in a | |
| 229 // just freed free space object. | |
| 230 if (heap->InToSpace(object)) { | |
| 231 return KEEP_SLOT; | |
| 232 } | |
| 233 } else { | |
| 234 DCHECK(!heap->InNewSpace(object)); | |
| 235 } | |
| 236 return REMOVE_SLOT; | |
| 237 } | |
| 238 | |
| 239 static bool IsValidSlot(Heap* heap, MemoryChunk* chunk, Object** slot); | 194 static bool IsValidSlot(Heap* heap, MemoryChunk* chunk, Object** slot); |
| 240 }; | 195 }; |
| 241 | 196 |
| 242 } // namespace internal | 197 } // namespace internal |
| 243 } // namespace v8 | 198 } // namespace v8 |
| 244 | 199 |
| 245 #endif // V8_REMEMBERED_SET_H | 200 #endif // V8_REMEMBERED_SET_H |
| OLD | NEW |