| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_HEAP_SPACES_H_ | 5 #ifndef V8_HEAP_SPACES_H_ |
| 6 #define V8_HEAP_SPACES_H_ | 6 #define V8_HEAP_SPACES_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/atomic-utils.h" | 9 #include "src/atomic-utils.h" |
| 10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 int CellsCount() { return CellsForLength(kLength); } | 158 int CellsCount() { return CellsForLength(kLength); } |
| 159 | 159 |
| 160 static int SizeFor(int cells_count) { | 160 static int SizeFor(int cells_count) { |
| 161 return sizeof(MarkBit::CellType) * cells_count; | 161 return sizeof(MarkBit::CellType) * cells_count; |
| 162 } | 162 } |
| 163 | 163 |
| 164 INLINE(static uint32_t IndexToCell(uint32_t index)) { | 164 INLINE(static uint32_t IndexToCell(uint32_t index)) { |
| 165 return index >> kBitsPerCellLog2; | 165 return index >> kBitsPerCellLog2; |
| 166 } | 166 } |
| 167 | 167 |
| 168 V8_INLINE static uint32_t IndexInCell(uint32_t index) { |
| 169 return index & kBitIndexMask; |
| 170 } |
| 171 |
| 168 INLINE(static uint32_t CellToIndex(uint32_t index)) { | 172 INLINE(static uint32_t CellToIndex(uint32_t index)) { |
| 169 return index << kBitsPerCellLog2; | 173 return index << kBitsPerCellLog2; |
| 170 } | 174 } |
| 171 | 175 |
| 172 INLINE(static uint32_t CellAlignIndex(uint32_t index)) { | 176 INLINE(static uint32_t CellAlignIndex(uint32_t index)) { |
| 173 return (index + kBitIndexMask) & ~kBitIndexMask; | 177 return (index + kBitIndexMask) & ~kBitIndexMask; |
| 174 } | 178 } |
| 175 | 179 |
| 176 INLINE(MarkBit::CellType* cells()) { | 180 INLINE(MarkBit::CellType* cells()) { |
| 177 return reinterpret_cast<MarkBit::CellType*>(this); | 181 return reinterpret_cast<MarkBit::CellType*>(this); |
| 178 } | 182 } |
| 179 | 183 |
| 180 INLINE(Address address()) { return reinterpret_cast<Address>(this); } | 184 INLINE(Address address()) { return reinterpret_cast<Address>(this); } |
| 181 | 185 |
| 182 INLINE(static Bitmap* FromAddress(Address addr)) { | 186 INLINE(static Bitmap* FromAddress(Address addr)) { |
| 183 return reinterpret_cast<Bitmap*>(addr); | 187 return reinterpret_cast<Bitmap*>(addr); |
| 184 } | 188 } |
| 185 | 189 |
| 186 inline MarkBit MarkBitFromIndex(uint32_t index) { | 190 inline MarkBit MarkBitFromIndex(uint32_t index) { |
| 187 MarkBit::CellType mask = 1 << (index & kBitIndexMask); | 191 MarkBit::CellType mask = 1u << IndexInCell(index); |
| 188 MarkBit::CellType* cell = this->cells() + (index >> kBitsPerCellLog2); | 192 MarkBit::CellType* cell = this->cells() + (index >> kBitsPerCellLog2); |
| 189 return MarkBit(cell, mask); | 193 return MarkBit(cell, mask); |
| 190 } | 194 } |
| 191 | 195 |
| 192 static inline void Clear(MemoryChunk* chunk); | 196 static inline void Clear(MemoryChunk* chunk); |
| 193 | 197 |
| 194 static void PrintWord(uint32_t word, uint32_t himask = 0) { | 198 static void PrintWord(uint32_t word, uint32_t himask = 0) { |
| 195 for (uint32_t mask = 1; mask != 0; mask <<= 1) { | 199 for (uint32_t mask = 1; mask != 0; mask <<= 1) { |
| 196 if ((mask & himask) != 0) PrintF("["); | 200 if ((mask & himask) != 0) PrintF("["); |
| 197 PrintF((mask & word) ? "1" : "0"); | 201 PrintF((mask & word) ? "1" : "0"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 253 } |
| 250 | 254 |
| 251 bool IsClean() { | 255 bool IsClean() { |
| 252 for (int i = 0; i < CellsCount(); i++) { | 256 for (int i = 0; i < CellsCount(); i++) { |
| 253 if (cells()[i] != 0) { | 257 if (cells()[i] != 0) { |
| 254 return false; | 258 return false; |
| 255 } | 259 } |
| 256 } | 260 } |
| 257 return true; | 261 return true; |
| 258 } | 262 } |
| 263 |
| 264 // Clears all bits starting from {cell_base_index} up to and excluding |
| 265 // {index}. Note that {cell_base_index} is required to be cell aligned. |
| 266 void ClearRange(uint32_t cell_base_index, uint32_t index) { |
| 267 DCHECK_EQ(IndexInCell(cell_base_index), 0); |
| 268 DCHECK_GE(index, cell_base_index); |
| 269 uint32_t start_cell_index = IndexToCell(cell_base_index); |
| 270 uint32_t end_cell_index = IndexToCell(index); |
| 271 DCHECK_GE(end_cell_index, start_cell_index); |
| 272 // Clear all cells till the cell containing the last index. |
| 273 for (uint32_t i = start_cell_index; i < end_cell_index; i++) { |
| 274 cells()[i] = 0; |
| 275 } |
| 276 // Clear all bits in the last cell till the last bit before index. |
| 277 uint32_t clear_mask = ~((1u << IndexInCell(index)) - 1); |
| 278 cells()[end_cell_index] &= clear_mask; |
| 279 } |
| 259 }; | 280 }; |
| 260 | 281 |
| 261 | 282 |
| 262 class SkipList; | 283 class SkipList; |
| 263 class SlotsBuffer; | 284 class SlotsBuffer; |
| 264 | 285 |
| 265 // MemoryChunk represents a memory region owned by a specific space. | 286 // MemoryChunk represents a memory region owned by a specific space. |
| 266 // It is divided into the header and the body. Chunk start is always | 287 // It is divided into the header and the body. Chunk start is always |
| 267 // 1MB aligned. Start of the body is aligned so it can accommodate | 288 // 1MB aligned. Start of the body is aligned so it can accommodate |
| 268 // any heap object. | 289 // any heap object. |
| (...skipping 2724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2993 count = 0; | 3014 count = 0; |
| 2994 } | 3015 } |
| 2995 // Must be small, since an iteration is used for lookup. | 3016 // Must be small, since an iteration is used for lookup. |
| 2996 static const int kMaxComments = 64; | 3017 static const int kMaxComments = 64; |
| 2997 }; | 3018 }; |
| 2998 #endif | 3019 #endif |
| 2999 } // namespace internal | 3020 } // namespace internal |
| 3000 } // namespace v8 | 3021 } // namespace v8 |
| 3001 | 3022 |
| 3002 #endif // V8_HEAP_SPACES_H_ | 3023 #endif // V8_HEAP_SPACES_H_ |
| OLD | NEW |