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 void SetRange(uint32_t start_index, uint32_t end_index) { |
ulan
2016/07/19 13:23:32
Let's add a comment describing that it sets bits i
Hannes Payer (out of office)
2016/07/19 14:42:53
Done.
| |
110 for (int i = 0; i < CellsCount(); i++) cells()[i] = 0xffffffff; | 110 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2; |
111 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index); | |
112 | |
113 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2; | |
114 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index); | |
115 | |
116 if (start_cell_index != end_cell_index) { | |
117 // Firstly, fill all bits from the start address to the end of the first | |
118 // cell with 1s. | |
119 cells()[start_cell_index] |= ~(start_index_mask - 1); | |
120 // Then fill all in between cells with 1s. | |
121 for (unsigned int i = start_cell_index + 1; i < end_cell_index; i++) { | |
122 cells()[i] = ~0u; | |
123 } | |
124 // Finally, fill all bits until the end address in the last cell with 1s. | |
125 cells()[end_cell_index] |= (end_index_mask - 1); | |
126 } else { | |
127 cells()[start_cell_index] |= end_index_mask - start_index_mask; | |
128 } | |
129 } | |
130 | |
131 void ClearRange(uint32_t start_index, uint32_t end_index) { | |
132 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2; | |
133 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index); | |
134 | |
135 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2; | |
136 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index); | |
137 | |
138 if (start_cell_index != end_cell_index) { | |
139 // Firstly, fill all bits from the start address to the end of the first | |
140 // cell with 0s. | |
141 cells()[start_cell_index] &= (start_index_mask - 1); | |
142 // Then fill all in between cells with 0s. | |
143 for (unsigned int i = start_cell_index + 1; i < end_cell_index; i++) { | |
144 cells()[i] = 0; | |
145 } | |
146 // Finally, set all bits until the end address in the last cell with 0s. | |
147 cells()[end_cell_index] &= ~(end_index_mask - 1); | |
148 } else { | |
149 cells()[start_cell_index] &= ~(end_index_mask - start_index_mask); | |
150 } | |
111 } | 151 } |
112 | 152 |
113 static void PrintWord(uint32_t word, uint32_t himask = 0) { | 153 static void PrintWord(uint32_t word, uint32_t himask = 0) { |
114 for (uint32_t mask = 1; mask != 0; mask <<= 1) { | 154 for (uint32_t mask = 1; mask != 0; mask <<= 1) { |
115 if ((mask & himask) != 0) PrintF("["); | 155 if ((mask & himask) != 0) PrintF("["); |
116 PrintF((mask & word) ? "1" : "0"); | 156 PrintF((mask & word) ? "1" : "0"); |
117 if ((mask & himask) != 0) PrintF("]"); | 157 if ((mask & himask) != 0) PrintF("]"); |
118 } | 158 } |
119 } | 159 } |
120 | 160 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 } | 208 } |
169 | 209 |
170 bool IsClean() { | 210 bool IsClean() { |
171 for (int i = 0; i < CellsCount(); i++) { | 211 for (int i = 0; i < CellsCount(); i++) { |
172 if (cells()[i] != 0) { | 212 if (cells()[i] != 0) { |
173 return false; | 213 return false; |
174 } | 214 } |
175 } | 215 } |
176 return true; | 216 return true; |
177 } | 217 } |
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 }; | 218 }; |
196 | 219 |
197 class Marking : public AllStatic { | 220 class Marking : public AllStatic { |
198 public: | 221 public: |
199 // Impossible markbits: 01 | 222 // Impossible markbits: 01 |
200 static const char* kImpossibleBitPattern; | 223 static const char* kImpossibleBitPattern; |
201 INLINE(static bool IsImpossible(MarkBit mark_bit)) { | 224 INLINE(static bool IsImpossible(MarkBit mark_bit)) { |
202 return !mark_bit.Get() && mark_bit.Next().Get(); | 225 return !mark_bit.Get() && mark_bit.Next().Get(); |
203 } | 226 } |
204 | 227 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 } | 326 } |
304 | 327 |
305 private: | 328 private: |
306 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); | 329 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); |
307 }; | 330 }; |
308 | 331 |
309 } // namespace internal | 332 } // namespace internal |
310 } // namespace v8 | 333 } // namespace v8 |
311 | 334 |
312 #endif // V8_MARKING_H_ | 335 #endif // V8_MARKING_H_ |
OLD | NEW |