Changeset 20722 in webkit


Ignore:
Timestamp:
Apr 5, 2007 9:35:43 AM (17 years ago)
Author:
mjs
Message:

Not reviewed, experimental change.


  • remove the concept of oversize objects, now that there aren't any (for now only enforced with an assert).

This change is a .66% speedup on JS iBench for 32-bit platforms, probably much more
for 64-bit since it finally gives a reasonable cell size, but I did not test that.


  • kjs/collector.cpp: (KJS::): Use different cell size for 32-bit and 64-bit, now that there is no oversize allocation. (KJS::Collector::allocate): Remove oversize allocator. (KJS::Collector::markStackObjectsConservatively): Don't check oversize objects. (KJS::Collector::markMainThreadOnlyObjects): Ditto. (KJS::Collector::collect): Ditto.
Location:
branches/js-collector-tweaks/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/js-collector-tweaks/JavaScriptCore/ChangeLog

    r20699 r20722  
     12007-04-05  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Not reviewed, experimental change.
     4       
     5        - remove the concept of oversize objects, now that there aren't any (for now
     6        only enforced with an assert).
     7
     8        This change is a .66% speedup on JS iBench for 32-bit platforms, probably much more
     9        for 64-bit since it finally gives a reasonable cell size, but I did not test that.
     10       
     11        * kjs/collector.cpp:
     12        (KJS::): Use different cell size for 32-bit and 64-bit, now that there is no
     13        oversize allocation.
     14        (KJS::Collector::allocate): Remove oversize allocator.
     15        (KJS::Collector::markStackObjectsConservatively): Don't check oversize objects.
     16        (KJS::Collector::markMainThreadOnlyObjects): Ditto.
     17        (KJS::Collector::collect): Ditto.
     18
    1192007-04-03  Kevin McCullough  <kmccullough@apple.com>
    220
  • branches/js-collector-tweaks/JavaScriptCore/kjs/collector.cpp

    r20353 r20722  
    5959namespace KJS {
    6060
     61
     62
    6163// tunable parameters
    62 const size_t MINIMUM_CELL_SIZE = 48;
     64
     65template<bool is32Bit, bool is64Bit> struct CellSize;
     66template<> struct CellSize<true, false> { static const size_t m_value = 48; }; // 32-bit
     67template<> struct CellSize<false, true> { static const size_t m_value = 80; }; // 64-bit
     68
    6369const size_t BLOCK_SIZE = (8 * 4096);
    6470const size_t SPARE_EMPTY_BLOCKS = 2;
     
    6975
    7076// derived constants
    71 const size_t CELL_ARRAY_LENGTH = (MINIMUM_CELL_SIZE / sizeof(double)) + (MINIMUM_CELL_SIZE % sizeof(double) != 0 ? sizeof(double) : 0);
     77const size_t MINIMUM_CELL_SIZE = CellSize<sizeof(void*) == sizeof(uint32_t), sizeof(void*) == sizeof(uint64_t)>::m_value;
     78const size_t CELL_ARRAY_LENGTH = (MINIMUM_CELL_SIZE / sizeof(double)) + (MINIMUM_CELL_SIZE % sizeof(double) != 0 ? 1 : 0);
    7279const 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 
     80const size_t CELLS_PER_BLOCK = ((BLOCK_SIZE * 8 - sizeof(uint32_t) * 8 - sizeof(void*) * 8) / (CELL_SIZE * 8));
    7581
    7682
     
    98104  size_t firstBlockWithPossibleSpace;
    99105 
    100   CollectorCell **oversizeCells;
    101   size_t numOversizeCells;
    102   size_t usedOversizeCells;
    103 
    104106  size_t numLiveObjects;
    105107  size_t numLiveObjectsAtLastCollect;
    106108};
    107109
    108 static CollectorHeap heap = {NULL, 0, 0, 0, NULL, 0, 0, 0, 0};
     110static CollectorHeap heap = {NULL, 0, 0, 0, 0, 0};
    109111
    110112size_t Collector::mainThreadOnlyObjectCount = 0;
     
    137139  ASSERT(JSLock::lockCount() > 0);
    138140  ASSERT(JSLock::currentThreadIsHoldingLock());
     141  ASSERT(s <= CELL_SIZE);
    139142
    140143  // collect if needed
     
    151154  GCLock lock;
    152155#endif
    153  
    154   if (s > CELL_SIZE) {
    155     // oversize allocator
    156     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   }
    172156 
    173157  // slab allocator
     
    385369  size_t usedBlocks = heap.usedBlocks;
    386370  CollectorBlock **blocks = heap.blocks;
    387   size_t usedOversizeCells = heap.usedOversizeCells;
    388   CollectorCell **oversizeCells = heap.oversizeCells;
    389371
    390372  const size_t lastCellOffset = sizeof(CollectorCell) * (CELLS_PER_BLOCK - 1);
     
    395377      for (size_t block = 0; block < usedBlocks; block++) {
    396378        size_t offset = x - reinterpret_cast<char *>(blocks[block]);
    397         if (offset <= lastCellOffset && offset % sizeof(CollectorCell) == 0)
    398           goto gotGoodPointer;
    399       }
    400       for (size_t i = 0; i != usedOversizeCells; i++)
    401         if (x == reinterpret_cast<char *>(oversizeCells[i]))
    402           goto gotGoodPointer;
    403       continue;
    404 
    405 gotGoodPointer:
    406       if (((CollectorCell *)x)->u.freeCell.zeroIfFree != 0) {
    407         JSCell *imp = reinterpret_cast<JSCell *>(x);
    408         if (!imp->marked())
    409           imp->mark();
     379        if (offset <= lastCellOffset && offset % sizeof(CollectorCell) == 0) {
     380          if (((CollectorCell *)x)->u.freeCell.zeroIfFree != 0) {
     381            JSCell *imp = reinterpret_cast<JSCell *>(x);
     382            if (!imp->marked())
     383              imp->mark();
     384          }
     385          break;
     386        }
    410387      }
    411388    }
     
    695672        }
    696673    }
    697 
    698     for (size_t cell = 0; cell < heap.usedOversizeCells; cell++) {
    699         ASSERT(count < mainThreadOnlyObjectCount);
    700 
    701         JSCell* imp = reinterpret_cast<JSCell*>(heap.oversizeCells[cell]);
    702         if (imp->m_collectOnMainThreadOnly) {
    703             if (!imp->marked())
    704                 imp->mark();
    705             if (++count == mainThreadOnlyObjectCount)
    706                 return;
    707         }
    708     }
    709674}
    710675
     
    842807    heap.firstBlockWithPossibleSpace = 0;
    843808 
    844   size_t cell = 0;
    845   while (cell < heap.usedOversizeCells) {
    846     JSCell *imp = (JSCell *)heap.oversizeCells[cell];
    847    
    848     if (imp->m_marked) {
    849       imp->m_marked = false;
    850       cell++;
    851     } else {
    852       ASSERT(currentThreadIsMainThread || !imp->m_collectOnMainThreadOnly);
    853       if (imp->m_collectOnMainThreadOnly)
    854         --mainThreadOnlyObjectCount;
    855       imp->~JSCell();
    856 #if DEBUG_COLLECTOR
    857       heap.oversizeCells[cell]->u.freeCell.zeroIfFree = 0;
    858 #else
    859       fastFree(imp);
    860 #endif
    861 
    862       // swap with the last oversize cell so we compact as we go
    863       heap.oversizeCells[cell] = heap.oversizeCells[heap.usedOversizeCells - 1];
    864 
    865       heap.usedOversizeCells--;
    866       numLiveObjects--;
    867 
    868       if (heap.numOversizeCells > MIN_ARRAY_SIZE && heap.usedOversizeCells < heap.numOversizeCells / LOW_WATER_FACTOR) {
    869         heap.numOversizeCells = heap.numOversizeCells / GROWTH_FACTOR;
    870         heap.oversizeCells = (CollectorCell **)fastRealloc(heap.oversizeCells, heap.numOversizeCells * sizeof(CollectorCell *));
    871       }
    872     }
    873   }
    874  
    875809  bool deleted = heap.numLiveObjects != numLiveObjects;
    876810
Note: See TracChangeset for help on using the changeset viewer.