Changeset 52047 in webkit for trunk/JavaScriptCore/runtime/Collector.h
- Timestamp:
- Dec 11, 2009, 11:20:27 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/Collector.h
r52040 r52047 29 29 #include <wtf/Noncopyable.h> 30 30 #include <wtf/OwnPtr.h> 31 #include <wtf/StdLibExtras.h>32 31 #include <wtf/Threading.h> 33 32 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 LiveObjectIterator;52 template <HeapType> class CollectorHeapIterator; 53 53 54 54 struct CollectorHeap { 55 size_t nextBlock;56 size_t nextCell;57 58 55 CollectorBlock** blocks; 59 56 size_t numBlocks; 60 57 size_t usedBlocks; 61 58 size_t firstBlockWithPossibleSpace; 59 60 size_t numLiveObjects; 61 size_t numLiveObjectsAtLastCollect; 62 62 size_t extraCost; 63 64 bool didShrink; 63 #if ENABLE(JSC_ZOMBIES) 64 size_t numZombies; 65 #endif 65 66 66 67 OperationInProgress operationInProgress; … … 70 71 public: 71 72 class Thread; 73 typedef CollectorHeapIterator<PrimaryHeap> iterator; 72 74 73 75 void destroy(); … … 76 78 void* allocate(size_t); 77 79 80 bool collect(); 78 81 bool isBusy(); // true if an allocation or collection is in progress 79 void collectAllGarbage(); 80 81 static const size_t minExtraCost = 256; 82 static const size_t maxExtraCost = 1024 * 1024; 82 83 static const size_t minExtraCostSize = 256; 83 84 84 85 void reportExtraMemoryCost(size_t cost); 85 86 86 size_t objectCount() const;87 size_t objectCount(); 87 88 struct Statistics { 88 89 size_t size; … … 114 115 static bool isNumber(JSCell*); 115 116 116 LiveObjectIterator<PrimaryHeap> primaryHeapBegin(); 117 LiveObjectIterator<PrimaryHeap> primaryHeapEnd(); 117 // Iterators for the object heap. 118 iterator primaryHeapBegin(); 119 iterator primaryHeapEnd(); 118 120 119 121 private: 120 122 template <HeapType heapType> void* heapAllocate(size_t); 121 void reset(); 122 void collectRemainingGarbage(); 123 template <HeapType heapType> void sweep(); 123 template <HeapType heapType> size_t 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 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; 134 void freeBlocks(CollectorHeap*); 141 135 142 136 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();148 137 void markProtectedObjects(MarkStack&); 149 138 void markCurrentThreadConservatively(MarkStack&); … … 201 190 const size_t CELL_MASK = CELL_SIZE - 1; 202 191 const size_t CELL_ALIGN_MASK = ~CELL_MASK; 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 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); 205 193 const size_t SMALL_CELLS_PER_BLOCK = 2 * CELLS_PER_BLOCK; 206 194 const size_t BITMAP_SIZE = (CELLS_PER_BLOCK + 7) / 8; 207 195 const size_t BITMAP_WORDS = (BITMAP_SIZE + 3) / sizeof(uint32_t); 208 196 209 197 struct CollectorBitmap { 210 198 uint32_t bits[BITMAP_WORDS]; … … 213 201 void clear(size_t n) { bits[n >> 5] &= ~(1 << (n & 0x1F)); } 214 202 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 }233 203 }; 234 204 235 205 struct CollectorCell { 236 double memory[CELL_ARRAY_LENGTH]; 206 union { 207 double memory[CELL_ARRAY_LENGTH]; 208 struct { 209 void* zeroIfFree; 210 ptrdiff_t next; 211 } freeCell; 212 } u; 237 213 }; 238 214 239 215 struct SmallCollectorCell { 240 double memory[CELL_ARRAY_LENGTH / 2]; 216 union { 217 double memory[CELL_ARRAY_LENGTH / 2]; 218 struct { 219 void* zeroIfFree; 220 ptrdiff_t next; 221 } freeCell; 222 } u; 241 223 }; 242 224 … … 244 226 public: 245 227 CollectorCell cells[CELLS_PER_BLOCK]; 228 uint32_t usedCells; 229 CollectorCell* freeList; 246 230 CollectorBitmap marked; 247 231 Heap* heap; … … 252 236 public: 253 237 SmallCollectorCell cells[SMALL_CELLS_PER_BLOCK]; 238 uint32_t usedCells; 239 SmallCollectorCell* freeList; 254 240 CollectorBitmap marked; 255 241 Heap* heap; … … 302 288 inline void Heap::reportExtraMemoryCost(size_t cost) 303 289 { 304 if (cost > minExtraCost )305 recordExtraCost(cost );290 if (cost > minExtraCostSize) 291 recordExtraCost(cost / (CELL_SIZE * 2)); 306 292 } 307 293
Note:
See TracChangeset
for help on using the changeset viewer.