Changeset 52082 in webkit for trunk/JavaScriptCore/runtime/Collector.h
- Timestamp:
- Dec 14, 2009, 12:13:24 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/Collector.h
r52047 r52082 29 29 #include <wtf/Noncopyable.h> 30 30 #include <wtf/OwnPtr.h> 31 #include <wtf/StdLibExtras.h> 31 32 #include <wtf/Threading.h> 32 33 33 // This is supremely lame that we require pthreads to build on windows.34 34 #if ENABLE(JSC_MULTIPLE_THREADS) 35 35 #include <pthread.h> … … 50 50 enum HeapType { PrimaryHeap, NumberHeap }; 51 51 52 template <HeapType> class CollectorHeapIterator;52 template <HeapType> class LiveObjectIterator; 53 53 54 54 struct CollectorHeap { 55 size_t nextBlock; 56 size_t nextCell; 57 55 58 CollectorBlock** blocks; 56 59 size_t numBlocks; 57 60 size_t usedBlocks; 58 size_t firstBlockWithPossibleSpace; 59 60 size_t numLiveObjects; 61 size_t numLiveObjectsAtLastCollect; 61 62 62 size_t extraCost; 63 #if ENABLE(JSC_ZOMBIES) 64 size_t numZombies; 65 #endif 63 64 bool didShrink; 66 65 67 66 OperationInProgress operationInProgress; … … 71 70 public: 72 71 class Thread; 73 typedef CollectorHeapIterator<PrimaryHeap> iterator;74 72 75 73 void destroy(); … … 78 76 void* allocate(size_t); 79 77 80 bool collect();81 78 bool isBusy(); // true if an allocation or collection is in progress 82 83 static const size_t minExtraCostSize = 256; 79 void collectAllGarbage(); 80 81 static const size_t minExtraCost = 256; 82 static const size_t maxExtraCost = 1024 * 1024; 84 83 85 84 void reportExtraMemoryCost(size_t cost); 86 85 87 size_t objectCount() ;86 size_t objectCount() const; 88 87 struct Statistics { 89 88 size_t size; … … 115 114 static bool isNumber(JSCell*); 116 115 117 // Iterators for the object heap. 118 iterator primaryHeapBegin(); 119 iterator primaryHeapEnd(); 116 LiveObjectIterator<PrimaryHeap> primaryHeapBegin(); 117 LiveObjectIterator<PrimaryHeap> primaryHeapEnd(); 120 118 121 119 private: 122 120 template <HeapType heapType> void* heapAllocate(size_t); 123 template <HeapType heapType> size_t sweep(); 121 void reset(); 122 void collectRemainingGarbage(); 123 template <HeapType heapType> void sweep(); 124 124 static CollectorBlock* cellBlock(const JSCell*); 125 125 static size_t cellOffset(const JSCell*); … … 132 132 template <HeapType heapType> NEVER_INLINE void freeBlock(size_t); 133 133 NEVER_INLINE void freeBlock(CollectorBlock*); 134 void freeBlocks(CollectorHeap*); 134 template <HeapType heapType> void freeBlocks(); 135 template <HeapType heapType> void resizeBlocks(); 136 template <HeapType heapType> void growBlocks(size_t neededBlocks); 137 template <HeapType heapType> void shrinkBlocks(size_t neededBlocks); 138 template <HeapType heapType> void clearMarkBits(); 139 template <HeapType heapType> void clearMarkBits(CollectorBlock*); 140 template <HeapType heapType> size_t markedCells(size_t startBlock = 0, size_t startCell = 0) const; 135 141 136 142 void recordExtraCost(size_t); 143 144 template <HeapType heapType> void addToStatistics(Statistics&) const; 145 template <HeapType heapType> size_t objectCount() const; 146 147 void markRoots(); 137 148 void markProtectedObjects(MarkStack&); 138 149 void markCurrentThreadConservatively(MarkStack&); … … 190 201 const size_t CELL_MASK = CELL_SIZE - 1; 191 202 const size_t CELL_ALIGN_MASK = ~CELL_MASK; 192 const size_t CELLS_PER_BLOCK = (BLOCK_SIZE * 8 - sizeof(uint32_t) * 8 - sizeof(void *) * 8 - 2 * (7 + 3 * 8)) / (CELL_SIZE * 8 + 2); 203 const size_t CELLS_PER_BLOCK = (BLOCK_SIZE - sizeof(Heap*) - sizeof(HeapType)) * 8 * CELL_SIZE / (8 * CELL_SIZE + 1) / CELL_SIZE; // one bitmap byte can represent 8 cells. 204 193 205 const size_t SMALL_CELLS_PER_BLOCK = 2 * CELLS_PER_BLOCK; 194 206 const size_t BITMAP_SIZE = (CELLS_PER_BLOCK + 7) / 8; 195 207 const size_t BITMAP_WORDS = (BITMAP_SIZE + 3) / sizeof(uint32_t); 196 208 197 209 struct CollectorBitmap { 198 210 uint32_t bits[BITMAP_WORDS]; … … 201 213 void clear(size_t n) { bits[n >> 5] &= ~(1 << (n & 0x1F)); } 202 214 void clearAll() { memset(bits, 0, sizeof(bits)); } 215 size_t count(size_t startCell = 0) 216 { 217 size_t result = 0; 218 for ( ; (startCell & 0x1F) != 0; ++startCell) { 219 if (get(startCell)) 220 ++result; 221 } 222 for (size_t i = startCell >> 5; i < BITMAP_WORDS; ++i) 223 result += WTF::bitCount(bits[i]); 224 return result; 225 } 226 size_t isEmpty() // Much more efficient than testing count() == 0. 227 { 228 for (size_t i = 0; i < BITMAP_WORDS; ++i) 229 if (bits[i] != 0) 230 return false; 231 return true; 232 } 203 233 }; 204 234 205 235 struct CollectorCell { 206 union { 207 double memory[CELL_ARRAY_LENGTH]; 208 struct { 209 void* zeroIfFree; 210 ptrdiff_t next; 211 } freeCell; 212 } u; 236 double memory[CELL_ARRAY_LENGTH]; 213 237 }; 214 238 215 239 struct SmallCollectorCell { 216 union { 217 double memory[CELL_ARRAY_LENGTH / 2]; 218 struct { 219 void* zeroIfFree; 220 ptrdiff_t next; 221 } freeCell; 222 } u; 240 double memory[CELL_ARRAY_LENGTH / 2]; 223 241 }; 224 242 … … 226 244 public: 227 245 CollectorCell cells[CELLS_PER_BLOCK]; 228 uint32_t usedCells;229 CollectorCell* freeList;230 246 CollectorBitmap marked; 231 247 Heap* heap; … … 236 252 public: 237 253 SmallCollectorCell cells[SMALL_CELLS_PER_BLOCK]; 238 uint32_t usedCells;239 SmallCollectorCell* freeList;240 254 CollectorBitmap marked; 241 255 Heap* heap; … … 288 302 inline void Heap::reportExtraMemoryCost(size_t cost) 289 303 { 290 if (cost > minExtraCost Size)291 recordExtraCost(cost / (CELL_SIZE * 2));304 if (cost > minExtraCost) 305 recordExtraCost(cost); 292 306 } 293 307
Note:
See TracChangeset
for help on using the changeset viewer.