| 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/assembler.h" | 8 #include "src/assembler.h" |
| 9 #include "src/heap/heap.h" | 9 #include "src/heap/heap.h" |
| 10 #include "src/heap/slot-set.h" | 10 #include "src/heap/slot-set.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 DCHECK_LT(host_offset, static_cast<uintptr_t>(TypedSlotSet::kMaxOffset)); | 142 DCHECK_LT(host_offset, static_cast<uintptr_t>(TypedSlotSet::kMaxOffset)); |
| 143 slot_set->Insert(slot_type, static_cast<uint32_t>(host_offset), | 143 slot_set->Insert(slot_type, static_cast<uint32_t>(host_offset), |
| 144 static_cast<uint32_t>(offset)); | 144 static_cast<uint32_t>(offset)); |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Given a page and a range of typed slots in that page, this function removes | 147 // Given a page and a range of typed slots in that page, this function removes |
| 148 // the slots from the remembered set. | 148 // the slots from the remembered set. |
| 149 static void RemoveRangeTyped(MemoryChunk* page, Address start, Address end) { | 149 static void RemoveRangeTyped(MemoryChunk* page, Address start, Address end) { |
| 150 TypedSlotSet* slots = GetTypedSlotSet(page); | 150 TypedSlotSet* slots = GetTypedSlotSet(page); |
| 151 if (slots != nullptr) { | 151 if (slots != nullptr) { |
| 152 slots->Iterate([start, end](SlotType slot_type, Address host_addr, | 152 slots->Iterate( |
| 153 Address slot_addr) { | 153 [start, end](SlotType slot_type, Address host_addr, |
| 154 return start <= slot_addr && slot_addr < end ? REMOVE_SLOT : KEEP_SLOT; | 154 Address slot_addr) { |
| 155 }); | 155 return start <= slot_addr && slot_addr < end ? REMOVE_SLOT |
| 156 : KEEP_SLOT; |
| 157 }, |
| 158 TypedSlotSet::PREFREE_EMPTY_CHUNKS); |
| 156 } | 159 } |
| 157 } | 160 } |
| 158 | 161 |
| 159 // Iterates and filters the remembered set with the given callback. | 162 // Iterates and filters the remembered set with the given callback. |
| 160 // The callback should take (SlotType slot_type, SlotAddress slot) and return | 163 // The callback should take (SlotType slot_type, SlotAddress slot) and return |
| 161 // SlotCallbackResult. | 164 // SlotCallbackResult. |
| 162 template <typename Callback> | 165 template <typename Callback> |
| 163 static void IterateTyped(Heap* heap, Callback callback) { | 166 static void IterateTyped(Heap* heap, Callback callback) { |
| 164 IterateMemoryChunks(heap, [callback](MemoryChunk* chunk) { | 167 IterateMemoryChunks(heap, [callback](MemoryChunk* chunk) { |
| 165 IterateTyped(chunk, callback); | 168 IterateTyped(chunk, callback); |
| 166 }); | 169 }); |
| 167 } | 170 } |
| 168 | 171 |
| 169 // Iterates and filters typed old to old pointers in the given memory chunk | 172 // Iterates and filters typed old to old pointers in the given memory chunk |
| 170 // with the given callback. The callback should take (SlotType slot_type, | 173 // with the given callback. The callback should take (SlotType slot_type, |
| 171 // Address slot_addr) and return SlotCallbackResult. | 174 // Address slot_addr) and return SlotCallbackResult. |
| 172 template <typename Callback> | 175 template <typename Callback> |
| 173 static void IterateTyped(MemoryChunk* chunk, Callback callback) { | 176 static void IterateTyped(MemoryChunk* chunk, Callback callback) { |
| 174 TypedSlotSet* slots = GetTypedSlotSet(chunk); | 177 TypedSlotSet* slots = GetTypedSlotSet(chunk); |
| 175 if (slots != nullptr) { | 178 if (slots != nullptr) { |
| 176 int new_count = slots->Iterate(callback); | 179 int new_count = slots->Iterate(callback, TypedSlotSet::KEEP_EMPTY_CHUNKS); |
| 177 if (new_count == 0) { | 180 if (new_count == 0) { |
| 178 ReleaseTypedSlotSet(chunk); | 181 ReleaseTypedSlotSet(chunk); |
| 179 } | 182 } |
| 180 } | 183 } |
| 181 } | 184 } |
| 182 | 185 |
| 183 // Clear all old to old slots from the remembered set. | 186 // Clear all old to old slots from the remembered set. |
| 184 static void ClearAll(Heap* heap) { | 187 static void ClearAll(Heap* heap) { |
| 185 STATIC_ASSERT(direction == OLD_TO_OLD); | 188 STATIC_ASSERT(direction == OLD_TO_OLD); |
| 186 MemoryChunkIterator it(heap); | 189 MemoryChunkIterator it(heap); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (direction == OLD_TO_OLD) { | 223 if (direction == OLD_TO_OLD) { |
| 221 chunk->ReleaseOldToOldSlots(); | 224 chunk->ReleaseOldToOldSlots(); |
| 222 } else { | 225 } else { |
| 223 chunk->ReleaseOldToNewSlots(); | 226 chunk->ReleaseOldToNewSlots(); |
| 224 } | 227 } |
| 225 } | 228 } |
| 226 | 229 |
| 227 static void ReleaseTypedSlotSet(MemoryChunk* chunk) { | 230 static void ReleaseTypedSlotSet(MemoryChunk* chunk) { |
| 228 if (direction == OLD_TO_OLD) { | 231 if (direction == OLD_TO_OLD) { |
| 229 chunk->ReleaseTypedOldToOldSlots(); | 232 chunk->ReleaseTypedOldToOldSlots(); |
| 230 } else { | |
| 231 chunk->ReleaseTypedOldToNewSlots(); | |
| 232 } | 233 } |
| 233 } | 234 } |
| 234 | 235 |
| 235 static SlotSet* AllocateSlotSet(MemoryChunk* chunk) { | 236 static SlotSet* AllocateSlotSet(MemoryChunk* chunk) { |
| 236 if (direction == OLD_TO_OLD) { | 237 if (direction == OLD_TO_OLD) { |
| 237 chunk->AllocateOldToOldSlots(); | 238 chunk->AllocateOldToOldSlots(); |
| 238 return chunk->old_to_old_slots(); | 239 return chunk->old_to_old_slots(); |
| 239 } else { | 240 } else { |
| 240 chunk->AllocateOldToNewSlots(); | 241 chunk->AllocateOldToNewSlots(); |
| 241 return chunk->old_to_new_slots(); | 242 return chunk->old_to_new_slots(); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 return DEBUG_TARGET_SLOT; | 383 return DEBUG_TARGET_SLOT; |
| 383 } | 384 } |
| 384 UNREACHABLE(); | 385 UNREACHABLE(); |
| 385 return CLEARED_SLOT; | 386 return CLEARED_SLOT; |
| 386 } | 387 } |
| 387 | 388 |
| 388 } // namespace internal | 389 } // namespace internal |
| 389 } // namespace v8 | 390 } // namespace v8 |
| 390 | 391 |
| 391 #endif // V8_REMEMBERED_SET_H | 392 #endif // V8_REMEMBERED_SET_H |
| OLD | NEW |