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 <map> | 8 #include <map> |
9 #include <stack> | 9 #include <stack> |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 if (current_bucket == nullptr) { | 59 if (current_bucket == nullptr) { |
60 current_bucket = AllocateBucket(); | 60 current_bucket = AllocateBucket(); |
61 bucket[bucket_index].SetValue(current_bucket); | 61 bucket[bucket_index].SetValue(current_bucket); |
62 } | 62 } |
63 if (!(current_bucket[cell_index].Value() & (1u << bit_index))) { | 63 if (!(current_bucket[cell_index].Value() & (1u << bit_index))) { |
64 current_bucket[cell_index].SetBit(bit_index); | 64 current_bucket[cell_index].SetBit(bit_index); |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 // The slot offset specifies a slot at address page_start_ + slot_offset. | 68 // The slot offset specifies a slot at address page_start_ + slot_offset. |
| 69 // Returns true if the set contains the slot. |
| 70 bool Contains(int slot_offset) { |
| 71 int bucket_index, cell_index, bit_index; |
| 72 SlotToIndices(slot_offset, &bucket_index, &cell_index, &bit_index); |
| 73 base::AtomicValue<uint32_t>* current_bucket = bucket[bucket_index].Value(); |
| 74 if (current_bucket == nullptr) { |
| 75 return false; |
| 76 } |
| 77 return (current_bucket[cell_index].Value() & (1u << bit_index)) != 0; |
| 78 } |
| 79 |
| 80 // The slot offset specifies a slot at address page_start_ + slot_offset. |
69 void Remove(int slot_offset) { | 81 void Remove(int slot_offset) { |
70 int bucket_index, cell_index, bit_index; | 82 int bucket_index, cell_index, bit_index; |
71 SlotToIndices(slot_offset, &bucket_index, &cell_index, &bit_index); | 83 SlotToIndices(slot_offset, &bucket_index, &cell_index, &bit_index); |
72 base::AtomicValue<uint32_t>* current_bucket = bucket[bucket_index].Value(); | 84 base::AtomicValue<uint32_t>* current_bucket = bucket[bucket_index].Value(); |
73 if (current_bucket != nullptr) { | 85 if (current_bucket != nullptr) { |
74 uint32_t cell = current_bucket[cell_index].Value(); | 86 uint32_t cell = current_bucket[cell_index].Value(); |
75 if (cell) { | 87 if (cell) { |
76 uint32_t bit_mask = 1u << bit_index; | 88 uint32_t bit_mask = 1u << bit_index; |
77 if (cell & bit_mask) { | 89 if (cell & bit_mask) { |
78 current_bucket[cell_index].ClearBit(bit_index); | 90 current_bucket[cell_index].ClearBit(bit_index); |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 Address page_start_; | 534 Address page_start_; |
523 base::AtomicValue<Chunk*> chunk_; | 535 base::AtomicValue<Chunk*> chunk_; |
524 base::Mutex to_be_freed_chunks_mutex_; | 536 base::Mutex to_be_freed_chunks_mutex_; |
525 std::stack<Chunk*> to_be_freed_chunks_; | 537 std::stack<Chunk*> to_be_freed_chunks_; |
526 }; | 538 }; |
527 | 539 |
528 } // namespace internal | 540 } // namespace internal |
529 } // namespace v8 | 541 } // namespace v8 |
530 | 542 |
531 #endif // V8_SLOT_SET_H | 543 #endif // V8_SLOT_SET_H |
OLD | NEW |