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_SLOT_SET_H | 5 #ifndef V8_SLOT_SET_H |
6 #define V8_SLOT_SET_H | 6 #define V8_SLOT_SET_H |
7 | 7 |
8 #include <stack> | 8 #include <stack> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 for (int bucket_index = 0; bucket_index < kBuckets; bucket_index++) { | 172 for (int bucket_index = 0; bucket_index < kBuckets; bucket_index++) { |
173 base::AtomicValue<uint32_t>* current_bucket = | 173 base::AtomicValue<uint32_t>* current_bucket = |
174 bucket[bucket_index].Value(); | 174 bucket[bucket_index].Value(); |
175 if (current_bucket != nullptr) { | 175 if (current_bucket != nullptr) { |
176 int in_bucket_count = 0; | 176 int in_bucket_count = 0; |
177 int cell_offset = bucket_index * kBitsPerBucket; | 177 int cell_offset = bucket_index * kBitsPerBucket; |
178 for (int i = 0; i < kCellsPerBucket; i++, cell_offset += kBitsPerCell) { | 178 for (int i = 0; i < kCellsPerBucket; i++, cell_offset += kBitsPerCell) { |
179 if (current_bucket[i].Value()) { | 179 if (current_bucket[i].Value()) { |
180 uint32_t cell = current_bucket[i].Value(); | 180 uint32_t cell = current_bucket[i].Value(); |
181 uint32_t old_cell = cell; | 181 uint32_t old_cell = cell; |
182 uint32_t new_cell = cell; | 182 uint32_t mask = 0; |
183 while (cell) { | 183 while (cell) { |
184 int bit_offset = base::bits::CountTrailingZeros32(cell); | 184 int bit_offset = base::bits::CountTrailingZeros32(cell); |
185 uint32_t bit_mask = 1u << bit_offset; | 185 uint32_t bit_mask = 1u << bit_offset; |
186 uint32_t slot = (cell_offset + bit_offset) << kPointerSizeLog2; | 186 uint32_t slot = (cell_offset + bit_offset) << kPointerSizeLog2; |
187 if (callback(page_start_ + slot) == KEEP_SLOT) { | 187 if (callback(page_start_ + slot) == KEEP_SLOT) { |
188 ++in_bucket_count; | 188 ++in_bucket_count; |
189 } else { | 189 } else { |
190 new_cell ^= bit_mask; | 190 mask |= bit_mask; |
191 } | 191 } |
192 cell ^= bit_mask; | 192 cell ^= bit_mask; |
193 } | 193 } |
| 194 uint32_t new_cell = old_cell & ~mask; |
194 if (old_cell != new_cell) { | 195 if (old_cell != new_cell) { |
195 while (!current_bucket[i].TrySetValue(old_cell, new_cell)) { | 196 while (!current_bucket[i].TrySetValue(old_cell, new_cell)) { |
196 // If TrySetValue fails, the cell must have changed. We just | 197 // If TrySetValue fails, the cell must have changed. We just |
197 // have to read the current value of the cell, & it with the | 198 // have to read the current value of the cell, & it with the |
198 // computed value, and retry. We can do this, because this | 199 // computed value, and retry. We can do this, because this |
199 // method will only be called on the main thread and filtering | 200 // method will only be called on the main thread and filtering |
200 // threads will only remove slots. | 201 // threads will only remove slots. |
201 old_cell = current_bucket[i].Value(); | 202 old_cell = current_bucket[i].Value(); |
202 new_cell &= old_cell; | 203 new_cell = old_cell & ~mask; |
203 } | 204 } |
204 } | 205 } |
205 } | 206 } |
206 } | 207 } |
207 if (mode == PREFREE_EMPTY_BUCKETS && in_bucket_count == 0) { | 208 if (mode == PREFREE_EMPTY_BUCKETS && in_bucket_count == 0) { |
208 PreFreeEmptyBucket(bucket_index); | 209 PreFreeEmptyBucket(bucket_index); |
209 } | 210 } |
210 new_count += in_bucket_count; | 211 new_count += in_bucket_count; |
211 } | 212 } |
212 } | 213 } |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 Address page_start_; | 484 Address page_start_; |
484 base::AtomicValue<Chunk*> chunk_; | 485 base::AtomicValue<Chunk*> chunk_; |
485 base::Mutex to_be_freed_chunks_mutex_; | 486 base::Mutex to_be_freed_chunks_mutex_; |
486 std::stack<Chunk*> to_be_freed_chunks_; | 487 std::stack<Chunk*> to_be_freed_chunks_; |
487 }; | 488 }; |
488 | 489 |
489 } // namespace internal | 490 } // namespace internal |
490 } // namespace v8 | 491 } // namespace v8 |
491 | 492 |
492 #endif // V8_SLOT_SET_H | 493 #endif // V8_SLOT_SET_H |
OLD | NEW |