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_MARKING_H | 5 #ifndef V8_MARKING_H |
6 #define V8_MARKING_H | 6 #define V8_MARKING_H |
7 | 7 |
8 #include "src/utils.h" | 8 #include "src/utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 inline MarkBit MarkBitFromIndex(uint32_t index) { | 99 inline MarkBit MarkBitFromIndex(uint32_t index) { |
100 MarkBit::CellType mask = 1u << IndexInCell(index); | 100 MarkBit::CellType mask = 1u << IndexInCell(index); |
101 MarkBit::CellType* cell = this->cells() + (index >> kBitsPerCellLog2); | 101 MarkBit::CellType* cell = this->cells() + (index >> kBitsPerCellLog2); |
102 return MarkBit(cell, mask); | 102 return MarkBit(cell, mask); |
103 } | 103 } |
104 | 104 |
105 void Clear() { | 105 void Clear() { |
106 for (int i = 0; i < CellsCount(); i++) cells()[i] = 0; | 106 for (int i = 0; i < CellsCount(); i++) cells()[i] = 0; |
107 } | 107 } |
108 | 108 |
109 void SetAllBits() { | 109 // Sets all bits in the range [start_index, end_index). |
110 for (int i = 0; i < CellsCount(); i++) cells()[i] = 0xffffffff; | 110 void SetRange(uint32_t start_index, uint32_t end_index) { |
| 111 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2; |
| 112 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index); |
| 113 |
| 114 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2; |
| 115 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index); |
| 116 |
| 117 if (start_cell_index != end_cell_index) { |
| 118 // Firstly, fill all bits from the start address to the end of the first |
| 119 // cell with 1s. |
| 120 cells()[start_cell_index] |= ~(start_index_mask - 1); |
| 121 // Then fill all in between cells with 1s. |
| 122 for (unsigned int i = start_cell_index + 1; i < end_cell_index; i++) { |
| 123 cells()[i] = ~0u; |
| 124 } |
| 125 // Finally, fill all bits until the end address in the last cell with 1s. |
| 126 cells()[end_cell_index] |= (end_index_mask - 1); |
| 127 } else { |
| 128 cells()[start_cell_index] |= end_index_mask - start_index_mask; |
| 129 } |
| 130 } |
| 131 |
| 132 // Clears all bits in the range [start_index, end_index). |
| 133 void ClearRange(uint32_t start_index, uint32_t end_index) { |
| 134 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2; |
| 135 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index); |
| 136 |
| 137 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2; |
| 138 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index); |
| 139 |
| 140 if (start_cell_index != end_cell_index) { |
| 141 // Firstly, fill all bits from the start address to the end of the first |
| 142 // cell with 0s. |
| 143 cells()[start_cell_index] &= (start_index_mask - 1); |
| 144 // Then fill all in between cells with 0s. |
| 145 for (unsigned int i = start_cell_index + 1; i < end_cell_index; i++) { |
| 146 cells()[i] = 0; |
| 147 } |
| 148 // Finally, set all bits until the end address in the last cell with 0s. |
| 149 cells()[end_cell_index] &= ~(end_index_mask - 1); |
| 150 } else { |
| 151 cells()[start_cell_index] &= ~(end_index_mask - start_index_mask); |
| 152 } |
| 153 } |
| 154 |
| 155 // Returns true if all bits in the range [start_index, end_index) are set. |
| 156 bool AllBitsSetInRange(uint32_t start_index, uint32_t end_index) { |
| 157 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2; |
| 158 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index); |
| 159 |
| 160 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2; |
| 161 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index); |
| 162 |
| 163 MarkBit::CellType matching_mask; |
| 164 if (start_cell_index != end_cell_index) { |
| 165 matching_mask = ~(start_index_mask - 1); |
| 166 if ((cells()[start_cell_index] & matching_mask) != matching_mask) { |
| 167 return false; |
| 168 } |
| 169 for (unsigned int i = start_cell_index + 1; i < end_cell_index; i++) { |
| 170 if (cells()[i] != ~0u) return false; |
| 171 } |
| 172 matching_mask = (end_index_mask - 1); |
| 173 return ((cells()[end_cell_index] & matching_mask) == matching_mask); |
| 174 } else { |
| 175 matching_mask = end_index_mask - start_index_mask; |
| 176 return (cells()[end_cell_index] & matching_mask) == matching_mask; |
| 177 } |
| 178 } |
| 179 |
| 180 // Returns true if all bits in the range [start_index, end_index) are cleared. |
| 181 bool AllBitsClearInRange(uint32_t start_index, uint32_t end_index) { |
| 182 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2; |
| 183 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index); |
| 184 |
| 185 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2; |
| 186 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index); |
| 187 |
| 188 MarkBit::CellType matching_mask; |
| 189 if (start_cell_index != end_cell_index) { |
| 190 matching_mask = ~(start_index_mask - 1); |
| 191 if ((cells()[start_cell_index] & matching_mask)) return false; |
| 192 for (unsigned int i = start_cell_index + 1; i < end_cell_index; i++) { |
| 193 if (cells()[i]) return false; |
| 194 } |
| 195 matching_mask = (end_index_mask - 1); |
| 196 return !(cells()[end_cell_index] & matching_mask); |
| 197 } else { |
| 198 matching_mask = end_index_mask - start_index_mask; |
| 199 return !(cells()[end_cell_index] & matching_mask); |
| 200 } |
111 } | 201 } |
112 | 202 |
113 static void PrintWord(uint32_t word, uint32_t himask = 0) { | 203 static void PrintWord(uint32_t word, uint32_t himask = 0) { |
114 for (uint32_t mask = 1; mask != 0; mask <<= 1) { | 204 for (uint32_t mask = 1; mask != 0; mask <<= 1) { |
115 if ((mask & himask) != 0) PrintF("["); | 205 if ((mask & himask) != 0) PrintF("["); |
116 PrintF((mask & word) ? "1" : "0"); | 206 PrintF((mask & word) ? "1" : "0"); |
117 if ((mask & himask) != 0) PrintF("]"); | 207 if ((mask & himask) != 0) PrintF("]"); |
118 } | 208 } |
119 } | 209 } |
120 | 210 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 258 } |
169 | 259 |
170 bool IsClean() { | 260 bool IsClean() { |
171 for (int i = 0; i < CellsCount(); i++) { | 261 for (int i = 0; i < CellsCount(); i++) { |
172 if (cells()[i] != 0) { | 262 if (cells()[i] != 0) { |
173 return false; | 263 return false; |
174 } | 264 } |
175 } | 265 } |
176 return true; | 266 return true; |
177 } | 267 } |
178 | |
179 // Clears all bits starting from {cell_base_index} up to and excluding | |
180 // {index}. Note that {cell_base_index} is required to be cell aligned. | |
181 void ClearRange(uint32_t cell_base_index, uint32_t index) { | |
182 DCHECK_EQ(IndexInCell(cell_base_index), 0u); | |
183 DCHECK_GE(index, cell_base_index); | |
184 uint32_t start_cell_index = IndexToCell(cell_base_index); | |
185 uint32_t end_cell_index = IndexToCell(index); | |
186 DCHECK_GE(end_cell_index, start_cell_index); | |
187 // Clear all cells till the cell containing the last index. | |
188 for (uint32_t i = start_cell_index; i < end_cell_index; i++) { | |
189 cells()[i] = 0; | |
190 } | |
191 // Clear all bits in the last cell till the last bit before index. | |
192 uint32_t clear_mask = ~((1u << IndexInCell(index)) - 1); | |
193 cells()[end_cell_index] &= clear_mask; | |
194 } | |
195 }; | 268 }; |
196 | 269 |
197 class Marking : public AllStatic { | 270 class Marking : public AllStatic { |
198 public: | 271 public: |
199 // Impossible markbits: 01 | 272 // Impossible markbits: 01 |
200 static const char* kImpossibleBitPattern; | 273 static const char* kImpossibleBitPattern; |
201 INLINE(static bool IsImpossible(MarkBit mark_bit)) { | 274 INLINE(static bool IsImpossible(MarkBit mark_bit)) { |
202 return !mark_bit.Get() && mark_bit.Next().Get(); | 275 return !mark_bit.Get() && mark_bit.Next().Get(); |
203 } | 276 } |
204 | 277 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 376 } |
304 | 377 |
305 private: | 378 private: |
306 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); | 379 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); |
307 }; | 380 }; |
308 | 381 |
309 } // namespace internal | 382 } // namespace internal |
310 } // namespace v8 | 383 } // namespace v8 |
311 | 384 |
312 #endif // V8_MARKING_H_ | 385 #endif // V8_MARKING_H_ |
OLD | NEW |