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" |
11 #include "src/heap/spaces.h" | 11 #include "src/heap/spaces.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
| 16 enum RememberedSetIterationMode { SYNCHRONIZED, NON_SYNCHRONIZED }; |
| 17 |
16 // TODO(ulan): Investigate performance of de-templatizing this class. | 18 // TODO(ulan): Investigate performance of de-templatizing this class. |
17 template <RememberedSetType type> | 19 template <RememberedSetType type> |
18 class RememberedSet : public AllStatic { | 20 class RememberedSet : public AllStatic { |
19 public: | 21 public: |
20 // Given a page and a slot in that page, this function adds the slot to the | 22 // Given a page and a slot in that page, this function adds the slot to the |
21 // remembered set. | 23 // remembered set. |
22 static void Insert(MemoryChunk* chunk, Address slot_addr) { | 24 static void Insert(MemoryChunk* chunk, Address slot_addr) { |
23 DCHECK(chunk->Contains(slot_addr)); | 25 DCHECK(chunk->Contains(slot_addr)); |
24 SlotSet* slot_set = chunk->slot_set<type>(); | 26 SlotSet* slot_set = chunk->slot_set<type>(); |
25 if (slot_set == nullptr) { | 27 if (slot_set == nullptr) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Clear slots from the beginning of the last page to end_offset. | 93 // Clear slots from the beginning of the last page to end_offset. |
92 slot_set[end_chunk].RemoveRange(0, offset_in_end_chunk, mode); | 94 slot_set[end_chunk].RemoveRange(0, offset_in_end_chunk, mode); |
93 } | 95 } |
94 } | 96 } |
95 } | 97 } |
96 } | 98 } |
97 | 99 |
98 // Iterates and filters the remembered set with the given callback. | 100 // Iterates and filters the remembered set with the given callback. |
99 // The callback should take (Address slot) and return SlotCallbackResult. | 101 // The callback should take (Address slot) and return SlotCallbackResult. |
100 template <typename Callback> | 102 template <typename Callback> |
101 static void Iterate(Heap* heap, Callback callback) { | 103 static void Iterate(Heap* heap, RememberedSetIterationMode mode, |
102 IterateMemoryChunks( | 104 Callback callback) { |
103 heap, [callback](MemoryChunk* chunk) { Iterate(chunk, callback); }); | 105 IterateMemoryChunks(heap, [mode, callback](MemoryChunk* chunk) { |
| 106 if (mode == SYNCHRONIZED) chunk->mutex()->Lock(); |
| 107 Iterate(chunk, callback); |
| 108 if (mode == SYNCHRONIZED) chunk->mutex()->Unlock(); |
| 109 }); |
104 } | 110 } |
105 | 111 |
106 // Iterates over all memory chunks that contains non-empty slot sets. | 112 // Iterates over all memory chunks that contains non-empty slot sets. |
107 // The callback should take (MemoryChunk* chunk) and return void. | 113 // The callback should take (MemoryChunk* chunk) and return void. |
108 template <typename Callback> | 114 template <typename Callback> |
109 static void IterateMemoryChunks(Heap* heap, Callback callback) { | 115 static void IterateMemoryChunks(Heap* heap, Callback callback) { |
110 MemoryChunkIterator it(heap); | 116 MemoryChunkIterator it(heap); |
111 MemoryChunk* chunk; | 117 MemoryChunk* chunk; |
112 while ((chunk = it.next()) != nullptr) { | 118 while ((chunk = it.next()) != nullptr) { |
113 SlotSet* slots = chunk->slot_set<type>(); | 119 SlotSet* slots = chunk->slot_set<type>(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 : KEEP_SLOT; | 176 : KEEP_SLOT; |
171 }, | 177 }, |
172 TypedSlotSet::PREFREE_EMPTY_CHUNKS); | 178 TypedSlotSet::PREFREE_EMPTY_CHUNKS); |
173 } | 179 } |
174 } | 180 } |
175 | 181 |
176 // Iterates and filters the remembered set with the given callback. | 182 // Iterates and filters the remembered set with the given callback. |
177 // The callback should take (SlotType slot_type, SlotAddress slot) and return | 183 // The callback should take (SlotType slot_type, SlotAddress slot) and return |
178 // SlotCallbackResult. | 184 // SlotCallbackResult. |
179 template <typename Callback> | 185 template <typename Callback> |
180 static void IterateTyped(Heap* heap, Callback callback) { | 186 static void IterateTyped(Heap* heap, RememberedSetIterationMode mode, |
181 IterateMemoryChunks(heap, [callback](MemoryChunk* chunk) { | 187 Callback callback) { |
| 188 IterateMemoryChunks(heap, [mode, callback](MemoryChunk* chunk) { |
| 189 if (mode == SYNCHRONIZED) chunk->mutex()->Lock(); |
182 IterateTyped(chunk, callback); | 190 IterateTyped(chunk, callback); |
| 191 if (mode == SYNCHRONIZED) chunk->mutex()->Unlock(); |
183 }); | 192 }); |
184 } | 193 } |
185 | 194 |
186 // Iterates and filters typed old to old pointers in the given memory chunk | 195 // Iterates and filters typed old to old pointers in the given memory chunk |
187 // with the given callback. The callback should take (SlotType slot_type, | 196 // with the given callback. The callback should take (SlotType slot_type, |
188 // Address slot_addr) and return SlotCallbackResult. | 197 // Address slot_addr) and return SlotCallbackResult. |
189 template <typename Callback> | 198 template <typename Callback> |
190 static void IterateTyped(MemoryChunk* chunk, Callback callback) { | 199 static void IterateTyped(MemoryChunk* chunk, Callback callback) { |
191 TypedSlotSet* slots = chunk->typed_slot_set<type>(); | 200 TypedSlotSet* slots = chunk->typed_slot_set<type>(); |
192 if (slots != nullptr) { | 201 if (slots != nullptr) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 return DEBUG_TARGET_SLOT; | 356 return DEBUG_TARGET_SLOT; |
348 } | 357 } |
349 UNREACHABLE(); | 358 UNREACHABLE(); |
350 return CLEARED_SLOT; | 359 return CLEARED_SLOT; |
351 } | 360 } |
352 | 361 |
353 } // namespace internal | 362 } // namespace internal |
354 } // namespace v8 | 363 } // namespace v8 |
355 | 364 |
356 #endif // V8_REMEMBERED_SET_H | 365 #endif // V8_REMEMBERED_SET_H |
OLD | NEW |