Changeset 77082 in webkit


Ignore:
Timestamp:
Jan 29, 2011 10:23:13 PM (13 years ago)
Author:
ggaren@apple.com
Message:

2011-01-29 Geoffrey Garen <ggaren@apple.com>

Reviewed by Cameron Zwarich.

Simplified Heap iteration
https://bugs.webkit.org/show_bug.cgi?id=53393

  • runtime/CollectorHeapIterator.h: (JSC::CollectorHeapIterator::isValid): (JSC::CollectorHeapIterator::isLive): (JSC::CollectorHeapIterator::advance): Removed "max" argument to advance because it's a constant. (JSC::LiveObjectIterator::LiveObjectIterator): (JSC::LiveObjectIterator::operator++): (JSC::DeadObjectIterator::DeadObjectIterator): (JSC::DeadObjectIterator::operator++): (JSC::ObjectIterator::ObjectIterator): (JSC::ObjectIterator::operator++): Factored out common checks into two helper functions -- isValid() for "Am I past the end?" and isLive() for "Is the cell I'm pointing to live?".
  • runtime/MarkedSpace.cpp: (JSC::MarkedSpace::freeBlock): (JSC::MarkedSpace::sweep): Always sweep from the beginning of the heap to the end, to avoid making sweep subtly reliant on internal Heap state. (JSC::MarkedSpace::primaryHeapBegin): (JSC::MarkedSpace::primaryHeapEnd): Always be explicit about where iteration begins.
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r77081 r77082  
     12011-01-29  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Cameron Zwarich.
     4
     5        Simplified Heap iteration
     6        https://bugs.webkit.org/show_bug.cgi?id=53393
     7
     8        * runtime/CollectorHeapIterator.h:
     9        (JSC::CollectorHeapIterator::isValid):
     10        (JSC::CollectorHeapIterator::isLive):
     11        (JSC::CollectorHeapIterator::advance): Removed "max" argument to
     12        advance because it's a constant.
     13        (JSC::LiveObjectIterator::LiveObjectIterator):
     14        (JSC::LiveObjectIterator::operator++):
     15        (JSC::DeadObjectIterator::DeadObjectIterator):
     16        (JSC::DeadObjectIterator::operator++):
     17        (JSC::ObjectIterator::ObjectIterator):
     18        (JSC::ObjectIterator::operator++): Factored out common checks into
     19        two helper functions -- isValid() for "Am I past the end?" and isLive()
     20        for "Is the cell I'm pointing to live?".
     21
     22        * runtime/MarkedSpace.cpp:
     23        (JSC::MarkedSpace::freeBlock):
     24        (JSC::MarkedSpace::sweep): Always sweep from the beginning of the heap
     25        to the end, to avoid making sweep subtly reliant on internal Heap state.
     26        (JSC::MarkedSpace::primaryHeapBegin):
     27        (JSC::MarkedSpace::primaryHeapEnd): Always be explicit about where
     28        iteration begins.
     29
    1302011-01-29  Geoffrey Garen  <ggaren@apple.com>
    231
  • trunk/Source/JavaScriptCore/runtime/CollectorHeapIterator.h

    r75443 r77082  
    3939    protected:
    4040        CollectorHeapIterator(CollectorHeap&, size_t startBlock, size_t startCell);
    41         void advance(size_t max);
     41        void advance();
     42        bool isValid();
     43        bool isLive();
    4244
    4345        CollectorHeap& m_heap;
     
    7678    }
    7779
     80    inline bool CollectorHeapIterator::isValid()
     81    {
     82        return m_block < m_heap.usedBlocks;
     83    }
     84
     85    inline bool CollectorHeapIterator::isLive()
     86    {
     87        return m_block < m_heap.nextBlock
     88            || (m_block == m_heap.nextBlock && m_cell < m_heap.nextCell)
     89            || (m_block < m_heap.usedBlocks && m_heap.collectorBlock(m_block)->marked.get(m_cell));
     90    }
     91
    7892    inline JSCell* CollectorHeapIterator::operator*() const
    7993    {
     
    8397    // Iterators advance up to the next-to-last -- and not the last -- cell in a
    8498    // block, since the last cell is a dummy sentinel.
    85     inline void CollectorHeapIterator::advance(size_t max)
     99    inline void CollectorHeapIterator::advance()
    86100    {
    87101        ++m_cell;
    88         if (m_cell == max) {
     102        if (m_cell == HeapConstants::cellsPerBlock - 1) {
    89103            m_cell = 0;
    90104            ++m_block;
     
    93107
    94108    inline LiveObjectIterator::LiveObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell)
    95         : CollectorHeapIterator(heap, startBlock, startCell - 1)
     109        : CollectorHeapIterator(heap, startBlock, startCell)
    96110    {
    97         ++(*this);
     111        if (isValid() && !isLive())
     112            ++(*this);
    98113    }
    99114
    100115    inline LiveObjectIterator& LiveObjectIterator::operator++()
    101116    {
    102         advance(HeapConstants::cellsPerBlock - 1);
    103         if (m_block < m_heap.nextBlock || (m_block == m_heap.nextBlock && m_cell < m_heap.nextCell))
    104             return *this;
    105 
    106         while (m_block < m_heap.usedBlocks && !m_heap.collectorBlock(m_block)->marked.get(m_cell))
    107             advance(HeapConstants::cellsPerBlock - 1);
     117        do {
     118            advance();
     119        } while (isValid() && !isLive());
    108120        return *this;
    109121    }
    110122
    111123    inline DeadObjectIterator::DeadObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell)
    112         : CollectorHeapIterator(heap, startBlock, startCell - 1)
     124        : CollectorHeapIterator(heap, startBlock, startCell)
    113125    {
    114         ++(*this);
     126        if (isValid() && isLive())
     127            ++(*this);
    115128    }
    116129
     
    118131    {
    119132        do {
    120             advance(HeapConstants::cellsPerBlock - 1);
    121             ASSERT(m_block > m_heap.nextBlock || (m_block == m_heap.nextBlock && m_cell >= m_heap.nextCell));
    122         } while (m_block < m_heap.usedBlocks && m_heap.collectorBlock(m_block)->marked.get(m_cell));
     133            advance();
     134        } while (isValid() && isLive());
    123135        return *this;
    124136    }
    125137
    126138    inline ObjectIterator::ObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell)
    127         : CollectorHeapIterator(heap, startBlock, startCell - 1)
     139        : CollectorHeapIterator(heap, startBlock, startCell)
    128140    {
    129         ++(*this);
     141        if (isValid())
     142            ++(*this);
    130143    }
    131144
    132145    inline ObjectIterator& ObjectIterator::operator++()
    133146    {
    134         advance(HeapConstants::cellsPerBlock - 1);
     147        advance();
    135148        return *this;
    136149    }
  • trunk/Source/JavaScriptCore/runtime/MarkedSpace.cpp

    r77081 r77082  
    9292NEVER_INLINE void MarkedSpace::freeBlock(size_t block)
    9393{
    94     ObjectIterator it(m_heap, block);
    95     ObjectIterator end(m_heap, block + 1);
     94    ObjectIterator it(m_heap, block, 0);
     95    ObjectIterator end(m_heap, block + 1, 0);
    9696    for ( ; it != end; ++it)
    9797        (*it)->~JSCell();
     
    252252#endif
    253253
    254     DeadObjectIterator it(m_heap, m_heap.nextBlock, m_heap.nextCell);
    255     DeadObjectIterator end(m_heap, m_heap.usedBlocks);
     254    DeadObjectIterator it(m_heap, 0, 0);
     255    DeadObjectIterator end(m_heap, m_heap.usedBlocks, 0);
    256256    for ( ; it != end; ++it) {
    257257        JSCell* cell = *it;
     
    301301LiveObjectIterator MarkedSpace::primaryHeapBegin()
    302302{
    303     return LiveObjectIterator(m_heap, 0);
     303    return LiveObjectIterator(m_heap, 0, 0);
    304304}
    305305
    306306LiveObjectIterator MarkedSpace::primaryHeapEnd()
    307307{
    308     return LiveObjectIterator(m_heap, m_heap.usedBlocks);
     308    return LiveObjectIterator(m_heap, m_heap.usedBlocks, 0);
    309309}
    310310
Note: See TracChangeset for help on using the changeset viewer.