Ignore:
Timestamp:
Dec 11, 2009, 11:20:27 PM (15 years ago)
Author:
[email protected]
Message:

Rolled out my last patch because the bots were crashing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Collector.h

    r52040 r52047  
    2929#include <wtf/Noncopyable.h>
    3030#include <wtf/OwnPtr.h>
    31 #include <wtf/StdLibExtras.h>
    3231#include <wtf/Threading.h>
    3332
     33// This is supremely lame that we require pthreads to build on windows.
    3434#if ENABLE(JSC_MULTIPLE_THREADS)
    3535#include <pthread.h>
     
    5050    enum HeapType { PrimaryHeap, NumberHeap };
    5151
    52     template <HeapType> class LiveObjectIterator;
     52    template <HeapType> class CollectorHeapIterator;
    5353
    5454    struct CollectorHeap {
    55         size_t nextBlock;
    56         size_t nextCell;
    57 
    5855        CollectorBlock** blocks;
    5956        size_t numBlocks;
    6057        size_t usedBlocks;
    61 
     58        size_t firstBlockWithPossibleSpace;
     59
     60        size_t numLiveObjects;
     61        size_t numLiveObjectsAtLastCollect;
    6262        size_t extraCost;
    63        
    64         bool didShrink;
     63#if ENABLE(JSC_ZOMBIES)
     64        size_t numZombies;
     65#endif
    6566
    6667        OperationInProgress operationInProgress;
     
    7071    public:
    7172        class Thread;
     73        typedef CollectorHeapIterator<PrimaryHeap> iterator;
    7274
    7375        void destroy();
     
    7678        void* allocate(size_t);
    7779
     80        bool collect();
    7881        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;
    8384
    8485        void reportExtraMemoryCost(size_t cost);
    8586
    86         size_t objectCount() const;
     87        size_t objectCount();
    8788        struct Statistics {
    8889            size_t size;
     
    114115        static bool isNumber(JSCell*);
    115116       
    116         LiveObjectIterator<PrimaryHeap> primaryHeapBegin();
    117         LiveObjectIterator<PrimaryHeap> primaryHeapEnd();
     117        // Iterators for the object heap.
     118        iterator primaryHeapBegin();
     119        iterator primaryHeapEnd();
    118120
    119121    private:
    120122        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();
    124124        static CollectorBlock* cellBlock(const JSCell*);
    125125        static size_t cellOffset(const JSCell*);
     
    132132        template <HeapType heapType> NEVER_INLINE void freeBlock(size_t);
    133133        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*);
    141135
    142136        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();
    148137        void markProtectedObjects(MarkStack&);
    149138        void markCurrentThreadConservatively(MarkStack&);
     
    201190    const size_t CELL_MASK = CELL_SIZE - 1;
    202191    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);
    205193    const size_t SMALL_CELLS_PER_BLOCK = 2 * CELLS_PER_BLOCK;
    206194    const size_t BITMAP_SIZE = (CELLS_PER_BLOCK + 7) / 8;
    207195    const size_t BITMAP_WORDS = (BITMAP_SIZE + 3) / sizeof(uint32_t);
    208 
     196 
    209197    struct CollectorBitmap {
    210198        uint32_t bits[BITMAP_WORDS];
     
    213201        void clear(size_t n) { bits[n >> 5] &= ~(1 << (n & 0x1F)); }
    214202        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         }
    233203    };
    234204 
    235205    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;
    237213    };
    238214
    239215    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;
    241223    };
    242224
     
    244226    public:
    245227        CollectorCell cells[CELLS_PER_BLOCK];
     228        uint32_t usedCells;
     229        CollectorCell* freeList;
    246230        CollectorBitmap marked;
    247231        Heap* heap;
     
    252236    public:
    253237        SmallCollectorCell cells[SMALL_CELLS_PER_BLOCK];
     238        uint32_t usedCells;
     239        SmallCollectorCell* freeList;
    254240        CollectorBitmap marked;
    255241        Heap* heap;
     
    302288    inline void Heap::reportExtraMemoryCost(size_t cost)
    303289    {
    304         if (cost > minExtraCost)
    305             recordExtraCost(cost);
     290        if (cost > minExtraCostSize)
     291            recordExtraCost(cost / (CELL_SIZE * 2));
    306292    }
    307293
Note: See TracChangeset for help on using the changeset viewer.