Changeset 10641 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Sep 27, 2005, 7:25:58 PM (20 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r10634 r10641 49 49 50 50 // tunable parameters 51 const int MINIMUM_CELL_SIZE = 56;52 const int BLOCK_SIZE = (8 * 4096);53 const int SPARE_EMPTY_BLOCKS = 2;54 const int MIN_ARRAY_SIZE = 14;55 const int GROWTH_FACTOR = 2;56 const int LOW_WATER_FACTOR = 4;57 const int ALLOCATIONS_PER_COLLECTION = 1000;51 const size_t MINIMUM_CELL_SIZE = 56; 52 const size_t BLOCK_SIZE = (8 * 4096); 53 const size_t SPARE_EMPTY_BLOCKS = 2; 54 const size_t MIN_ARRAY_SIZE = 14; 55 const size_t GROWTH_FACTOR = 2; 56 const size_t LOW_WATER_FACTOR = 4; 57 const size_t ALLOCATIONS_PER_COLLECTION = 1000; 58 58 59 59 // derived constants 60 const int CELL_ARRAY_LENGTH = (MINIMUM_CELL_SIZE / sizeof(double)) + (MINIMUM_CELL_SIZE % sizeof(double) != 0 ? sizeof(double) : 0);61 const int CELL_SIZE = CELL_ARRAY_LENGTH * sizeof(double);62 const int CELLS_PER_BLOCK = ((BLOCK_SIZE * 8 - sizeof(int32_t) * 8 - sizeof(void *) * 8) / (CELL_SIZE * 8));60 const size_t CELL_ARRAY_LENGTH = (MINIMUM_CELL_SIZE / sizeof(double)) + (MINIMUM_CELL_SIZE % sizeof(double) != 0 ? sizeof(double) : 0); 61 const size_t CELL_SIZE = CELL_ARRAY_LENGTH * sizeof(double); 62 const size_t CELLS_PER_BLOCK = ((BLOCK_SIZE * 8 - sizeof(uint32_t) * 8 - sizeof(void *) * 8) / (CELL_SIZE * 8)); 63 63 64 64 … … 77 77 struct CollectorBlock { 78 78 CollectorCell cells[CELLS_PER_BLOCK]; 79 int32_t usedCells;79 uint32_t usedCells; 80 80 CollectorCell *freeList; 81 81 }; … … 83 83 struct CollectorHeap { 84 84 CollectorBlock **blocks; 85 int numBlocks;86 int usedBlocks;87 int firstBlockWithPossibleSpace;85 size_t numBlocks; 86 size_t usedBlocks; 87 size_t firstBlockWithPossibleSpace; 88 88 89 89 CollectorCell **oversizeCells; 90 int numOversizeCells;91 int usedOversizeCells;92 93 int numLiveObjects;94 int numLiveObjectsAtLastCollect;90 size_t numOversizeCells; 91 size_t usedOversizeCells; 92 93 size_t numLiveObjects; 94 size_t numLiveObjectsAtLastCollect; 95 95 }; 96 96 … … 104 104 105 105 // collect if needed 106 int numLiveObjects = heap.numLiveObjects;106 size_t numLiveObjects = heap.numLiveObjects; 107 107 if (numLiveObjects - heap.numLiveObjectsAtLastCollect >= ALLOCATIONS_PER_COLLECTION) { 108 108 collect(); … … 110 110 } 111 111 112 if (s > static_cast<size_t>(CELL_SIZE)) {112 if (s > CELL_SIZE) { 113 113 // oversize allocator 114 114 115 int usedOversizeCells = heap.usedOversizeCells;116 int numOversizeCells = heap.numOversizeCells;115 size_t usedOversizeCells = heap.usedOversizeCells; 116 size_t numOversizeCells = heap.numOversizeCells; 117 117 118 118 if (usedOversizeCells == numOversizeCells) { … … 132 132 // slab allocator 133 133 134 int usedBlocks = heap.usedBlocks;135 136 int i = heap.firstBlockWithPossibleSpace;134 size_t usedBlocks = heap.usedBlocks; 135 136 size_t i = heap.firstBlockWithPossibleSpace; 137 137 CollectorBlock *targetBlock; 138 int targetBlockUsedCells;138 size_t targetBlockUsedCells; 139 139 if (i != usedBlocks) { 140 140 targetBlock = heap.blocks[i]; … … 153 153 // didn't find one, need to allocate a new block 154 154 155 int numBlocks = heap.numBlocks;155 size_t numBlocks = heap.numBlocks; 156 156 if (usedBlocks == numBlocks) { 157 157 numBlocks = max(MIN_ARRAY_SIZE, numBlocks * GROWTH_FACTOR); … … 234 234 #endif 235 235 236 #define IS_POINTER_ALIGNED(p) (((int )(p) & (sizeof(char *) - 1)) == 0)236 #define IS_POINTER_ALIGNED(p) (((intptr_t)(p) & (sizeof(char *) - 1)) == 0) 237 237 238 238 // cells are 8-byte aligned 239 #define IS_CELL_ALIGNED(p) (((int )(p) & 7) == 0)239 #define IS_CELL_ALIGNED(p) (((intptr_t)(p) & 7) == 0) 240 240 241 241 void Collector::markStackObjectsConservatively(void *start, void *end) … … 254 254 char **e = (char **)end; 255 255 256 int usedBlocks = heap.usedBlocks;256 size_t usedBlocks = heap.usedBlocks; 257 257 CollectorBlock **blocks = heap.blocks; 258 int usedOversizeCells = heap.usedOversizeCells;258 size_t usedOversizeCells = heap.usedOversizeCells; 259 259 CollectorCell **oversizeCells = heap.oversizeCells; 260 260 … … 264 264 char *x = *p++; 265 265 if (IS_CELL_ALIGNED(x) && x) { 266 for ( int block = 0; block < usedBlocks; block++) {266 for (size_t block = 0; block < usedBlocks; block++) { 267 267 size_t offset = x - reinterpret_cast<char *>(blocks[block]); 268 268 if (offset <= lastCellOffset && offset % sizeof(CollectorCell) == 0) 269 269 goto gotGoodPointer; 270 270 } 271 for ( int i = 0; i != usedOversizeCells; i++)271 for (size_t i = 0; i != usedOversizeCells; i++) 272 272 if (x == reinterpret_cast<char *>(oversizeCells[i])) 273 273 goto gotGoodPointer; … … 397 397 // SWEEP: delete everything with a zero refcount (garbage) and unmark everything else 398 398 399 int emptyBlocks = 0;400 int numLiveObjects = heap.numLiveObjects;401 402 for ( int block = 0; block < heap.usedBlocks; block++) {399 size_t emptyBlocks = 0; 400 size_t numLiveObjects = heap.numLiveObjects; 401 402 for (size_t block = 0; block < heap.usedBlocks; block++) { 403 403 CollectorBlock *curBlock = heap.blocks[block]; 404 404 405 int usedCells = curBlock->usedCells;405 size_t usedCells = curBlock->usedCells; 406 406 CollectorCell *freeList = curBlock->freeList; 407 407 408 408 if (usedCells == CELLS_PER_BLOCK) { 409 409 // special case with a block where all cells are used -- testing indicates this happens often 410 for ( int i = 0; i < CELLS_PER_BLOCK; i++) {410 for (size_t i = 0; i < CELLS_PER_BLOCK; i++) { 411 411 CollectorCell *cell = curBlock->cells + i; 412 412 AllocatedValueImp *imp = reinterpret_cast<AllocatedValueImp *>(cell); … … 425 425 } 426 426 } else { 427 int minimumCellsToProcess = usedCells;428 for ( int i = 0; i < minimumCellsToProcess; i++) {427 size_t minimumCellsToProcess = usedCells; 428 for (size_t i = 0; i < minimumCellsToProcess; i++) { 429 429 CollectorCell *cell = curBlock->cells + i; 430 430 if (cell->u.freeCell.zeroIfFree == 0) { … … 473 473 heap.firstBlockWithPossibleSpace = 0; 474 474 475 int cell = 0;475 size_t cell = 0; 476 476 while (cell < heap.usedOversizeCells) { 477 477 AllocatedValueImp *imp = (AllocatedValueImp *)heap.oversizeCells[cell]; … … 511 511 } 512 512 513 int Collector::size()513 size_t Collector::size() 514 514 { 515 515 return heap.numLiveObjects; … … 522 522 #endif 523 523 524 int Collector::numInterpreters()525 { 526 int count = 0;524 size_t Collector::numInterpreters() 525 { 526 size_t count = 0; 527 527 if (InterpreterImp::s_hook) { 528 528 InterpreterImp *scr = InterpreterImp::s_hook; … … 535 535 } 536 536 537 int Collector::numGCNotAllowedObjects()537 size_t Collector::numGCNotAllowedObjects() 538 538 { 539 539 return 0; 540 540 } 541 541 542 int Collector::numReferencedObjects()543 { 544 int count = 0;545 546 int size = ProtectedValues::_tableSize;542 size_t Collector::numReferencedObjects() 543 { 544 size_t count = 0; 545 546 size_t size = ProtectedValues::_tableSize; 547 547 ProtectedValues::KeyValue *table = ProtectedValues::_table; 548 for ( int i = 0; i < size; i++) {548 for (size_t i = 0; i < size; i++) { 549 549 AllocatedValueImp *val = table[i].key; 550 550 if (val) { -
trunk/JavaScriptCore/kjs/collector.h
r9768 r10641 54 54 */ 55 55 static bool collect(); 56 static int size();56 static size_t size(); 57 57 static bool outOfMemory() { return memoryFull; } 58 58 … … 64 64 #endif 65 65 66 static int numInterpreters();67 static int numGCNotAllowedObjects();68 static int numReferencedObjects();66 static size_t numInterpreters(); 67 static size_t numGCNotAllowedObjects(); 68 static size_t numReferencedObjects(); 69 69 #if APPLE_CHANGES 70 70 static const void *rootObjectClasses(); // actually returns CFSetRef
Note:
See TracChangeset
for help on using the changeset viewer.