Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: src/heap/marking.h

Issue 2183383004: Revert of [heap] Reland "Remove black pages and use black areas instead." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/mark-compact-inl.h ('k') | src/heap/scavenger.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Sets all bits in the range [start_index, end_index). 109 void SetAllBits() {
110 void SetRange(uint32_t start_index, uint32_t end_index) { 110 for (int i = 0; i < CellsCount(); i++) cells()[i] = 0xffffffff;
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 }
201 } 111 }
202 112
203 static void PrintWord(uint32_t word, uint32_t himask = 0) { 113 static void PrintWord(uint32_t word, uint32_t himask = 0) {
204 for (uint32_t mask = 1; mask != 0; mask <<= 1) { 114 for (uint32_t mask = 1; mask != 0; mask <<= 1) {
205 if ((mask & himask) != 0) PrintF("["); 115 if ((mask & himask) != 0) PrintF("[");
206 PrintF((mask & word) ? "1" : "0"); 116 PrintF((mask & word) ? "1" : "0");
207 if ((mask & himask) != 0) PrintF("]"); 117 if ((mask & himask) != 0) PrintF("]");
208 } 118 }
209 } 119 }
210 120
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 168 }
259 169
260 bool IsClean() { 170 bool IsClean() {
261 for (int i = 0; i < CellsCount(); i++) { 171 for (int i = 0; i < CellsCount(); i++) {
262 if (cells()[i] != 0) { 172 if (cells()[i] != 0) {
263 return false; 173 return false;
264 } 174 }
265 } 175 }
266 return true; 176 return true;
267 } 177 }
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 }
268 }; 195 };
269 196
270 class Marking : public AllStatic { 197 class Marking : public AllStatic {
271 public: 198 public:
272 // Impossible markbits: 01 199 // Impossible markbits: 01
273 static const char* kImpossibleBitPattern; 200 static const char* kImpossibleBitPattern;
274 INLINE(static bool IsImpossible(MarkBit mark_bit)) { 201 INLINE(static bool IsImpossible(MarkBit mark_bit)) {
275 return !mark_bit.Get() && mark_bit.Next().Get(); 202 return !mark_bit.Get() && mark_bit.Next().Get();
276 } 203 }
277 204
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 303 }
377 304
378 private: 305 private:
379 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); 306 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking);
380 }; 307 };
381 308
382 } // namespace internal 309 } // namespace internal
383 } // namespace v8 310 } // namespace v8
384 311
385 #endif // V8_MARKING_H_ 312 #endif // V8_MARKING_H_
OLDNEW
« no previous file with comments | « src/heap/mark-compact-inl.h ('k') | src/heap/scavenger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698