Changeset 21015 in webkit for trunk/JavaScriptCore/kjs/collector.cpp
- Timestamp:
- Apr 22, 2007, 8:28:45 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r20971 r21015 26 26 #include <wtf/FastMallocInternal.h> 27 27 #include <wtf/HashCountedSet.h> 28 #include <wtf/UnusedParam.h> 28 29 #include "internal.h" 29 30 #include "list.h" … … 59 60 namespace KJS { 60 61 62 63 61 64 // tunable parameters 62 const size_t MINIMUM_CELL_SIZE = 48; 65 66 template<size_t bytesPerWord> struct CellSize; 67 template<> struct CellSize<sizeof(uint32_t)> { static const size_t m_value = 48; }; // 32-bit 68 template<> struct CellSize<sizeof(uint64_t)> { static const size_t m_value = 80; }; // 64-bit 69 63 70 const size_t BLOCK_SIZE = (8 * 4096); 64 71 const size_t SPARE_EMPTY_BLOCKS = 2; … … 69 76 70 77 // derived constants 71 const size_t CELL_ARRAY_LENGTH = (MINIMUM_CELL_SIZE / sizeof(double)) + (MINIMUM_CELL_SIZE % sizeof(double) != 0 ? sizeof(double) : 0); 78 const size_t MINIMUM_CELL_SIZE = CellSize<sizeof(void*)>::m_value; 79 const size_t CELL_ARRAY_LENGTH = (MINIMUM_CELL_SIZE / sizeof(double)) + (MINIMUM_CELL_SIZE % sizeof(double) != 0 ? 1 : 0); 72 80 const size_t CELL_SIZE = CELL_ARRAY_LENGTH * sizeof(double); 73 const size_t CELLS_PER_BLOCK = ((BLOCK_SIZE * 8 - sizeof(uint32_t) * 8 - sizeof(void *) * 8) / (CELL_SIZE * 8)); 74 81 const size_t CELLS_PER_BLOCK = ((BLOCK_SIZE * 8 - sizeof(uint32_t) * 8 - sizeof(void*) * 8) / (CELL_SIZE * 8)); 75 82 76 83 … … 98 105 size_t firstBlockWithPossibleSpace; 99 106 100 CollectorCell **oversizeCells;101 size_t numOversizeCells;102 size_t usedOversizeCells;103 104 107 size_t numLiveObjects; 105 108 size_t numLiveObjectsAtLastCollect; 106 109 }; 107 110 108 static CollectorHeap heap = {NULL, 0, 0, 0, NULL, 0, 0,0, 0};111 static CollectorHeap heap = {NULL, 0, 0, 0, 0, 0}; 109 112 110 113 size_t Collector::mainThreadOnlyObjectCount = 0; … … 137 140 ASSERT(JSLock::lockCount() > 0); 138 141 ASSERT(JSLock::currentThreadIsHoldingLock()); 142 ASSERT(s <= CELL_SIZE); 143 UNUSED_PARAM(s); // s is now only used for the above assert 139 144 140 145 // collect if needed … … 151 156 GCLock lock; 152 157 #endif 153 154 if (s > CELL_SIZE) {155 // oversize allocator156 size_t usedOversizeCells = heap.usedOversizeCells;157 size_t numOversizeCells = heap.numOversizeCells;158 159 if (usedOversizeCells == numOversizeCells) {160 numOversizeCells = max(MIN_ARRAY_SIZE, numOversizeCells * GROWTH_FACTOR);161 heap.numOversizeCells = numOversizeCells;162 heap.oversizeCells = static_cast<CollectorCell **>(fastRealloc(heap.oversizeCells, numOversizeCells * sizeof(CollectorCell *)));163 }164 165 void *newCell = fastMalloc(s);166 heap.oversizeCells[usedOversizeCells] = static_cast<CollectorCell *>(newCell);167 heap.usedOversizeCells = usedOversizeCells + 1;168 heap.numLiveObjects = numLiveObjects + 1;169 170 return newCell;171 }172 158 173 159 // slab allocator … … 387 373 size_t usedBlocks = heap.usedBlocks; 388 374 CollectorBlock **blocks = heap.blocks; 389 size_t usedOversizeCells = heap.usedOversizeCells;390 CollectorCell **oversizeCells = heap.oversizeCells;391 375 392 376 const size_t lastCellOffset = sizeof(CollectorCell) * (CELLS_PER_BLOCK - 1); … … 397 381 for (size_t block = 0; block < usedBlocks; block++) { 398 382 size_t offset = x - reinterpret_cast<char *>(blocks[block]); 399 if (offset <= lastCellOffset && offset % sizeof(CollectorCell) == 0) 400 goto gotGoodPointer; 401 } 402 for (size_t i = 0; i != usedOversizeCells; i++) 403 if (x == reinterpret_cast<char *>(oversizeCells[i])) 404 goto gotGoodPointer; 405 continue; 406 407 gotGoodPointer: 408 if (((CollectorCell *)x)->u.freeCell.zeroIfFree != 0) { 409 JSCell *imp = reinterpret_cast<JSCell *>(x); 410 if (!imp->marked()) 411 imp->mark(); 383 if (offset <= lastCellOffset && offset % sizeof(CollectorCell) == 0) { 384 if (((CollectorCell *)x)->u.freeCell.zeroIfFree != 0) { 385 JSCell *imp = reinterpret_cast<JSCell *>(x); 386 if (!imp->marked()) 387 imp->mark(); 388 } 389 break; 390 } 412 391 } 413 392 } … … 702 681 } 703 682 } 704 705 for (size_t cell = 0; cell < heap.usedOversizeCells; cell++) {706 ASSERT(count < mainThreadOnlyObjectCount);707 708 JSCell* imp = reinterpret_cast<JSCell*>(heap.oversizeCells[cell]);709 if (imp->m_collectOnMainThreadOnly) {710 if (!imp->marked())711 imp->mark();712 if (++count == mainThreadOnlyObjectCount)713 return;714 }715 }716 683 } 717 684 … … 851 818 heap.firstBlockWithPossibleSpace = 0; 852 819 853 size_t cell = 0;854 while (cell < heap.usedOversizeCells) {855 JSCell *imp = (JSCell *)heap.oversizeCells[cell];856 857 if (imp->m_marked) {858 imp->m_marked = false;859 cell++;860 } else {861 ASSERT(currentThreadIsMainThread || !imp->m_collectOnMainThreadOnly);862 if (imp->m_collectOnMainThreadOnly)863 --mainThreadOnlyObjectCount;864 imp->~JSCell();865 #if DEBUG_COLLECTOR866 heap.oversizeCells[cell]->u.freeCell.zeroIfFree = 0;867 #else868 fastFree(imp);869 #endif870 871 // swap with the last oversize cell so we compact as we go872 heap.oversizeCells[cell] = heap.oversizeCells[heap.usedOversizeCells - 1];873 874 heap.usedOversizeCells--;875 numLiveObjects--;876 877 if (heap.numOversizeCells > MIN_ARRAY_SIZE && heap.usedOversizeCells < heap.numOversizeCells / LOW_WATER_FACTOR) {878 heap.numOversizeCells = heap.numOversizeCells / GROWTH_FACTOR;879 heap.oversizeCells = (CollectorCell **)fastRealloc(heap.oversizeCells, heap.numOversizeCells * sizeof(CollectorCell *));880 }881 }882 }883 884 820 bool deleted = heap.numLiveObjects != numLiveObjects; 885 821
Note:
See TracChangeset
for help on using the changeset viewer.