Changeset 123931 in webkit


Ignore:
Timestamp:
Jul 27, 2012 3:59:14 PM (12 years ago)
Author:
mhahnenberg@apple.com
Message:

Split functionality of MarkedAllocator::m_currentBlock
https://bugs.webkit.org/show_bug.cgi?id=92550

Reviewed by Filip Pizlo.

MarkedAllocator::m_currentBlock serves two purposes right now; it indicates the block that is currently
being used for allocation and the beginning of the list of blocks that need to be swept. We should split
these two functionalities into two separate fields.

  • heap/MarkedAllocator.cpp:

(JSC::MarkedAllocator::tryAllocateHelper): Use m_blocksToSweep instead of m_currentBlock as the
initializer/reference of the loop. Only change m_currentBlock when we know what the result will be.
(JSC::MarkedAllocator::addBlock): When we add a new block we know that both m_blocksToSweep and
m_currentBlock are null. In order to preserve the invariant that m_currentBlock <= m_blocksToSweep,
we assign both of them to point to the new block.
(JSC::MarkedAllocator::removeBlock): We need a separate check to see if the block we're removing is
m_blocksToSweep and if so, advance it to the next block in the list.

  • heap/MarkedAllocator.h:

(MarkedAllocator): Initialize m_blocksToSweep.
(JSC::MarkedAllocator::MarkedAllocator):
(JSC::MarkedAllocator::reset): We set m_blocksToSweep to be the head of our list. This function is called
at the end of a collection, so all of the blocks in our allocator need to be swept. We need to sweep a
block before we can start allocating, so m_currentBlock is set to null. We also set the freeList to
the empty FreeList to emphasize the fact that we can't start allocating until we do some sweeping.

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r123905 r123931  
     12012-07-27  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Split functionality of MarkedAllocator::m_currentBlock
     4        https://bugs.webkit.org/show_bug.cgi?id=92550
     5
     6        Reviewed by Filip Pizlo.
     7
     8        MarkedAllocator::m_currentBlock serves two purposes right now; it indicates the block that is currently
     9        being used for allocation and the beginning of the list of blocks that need to be swept. We should split
     10        these two functionalities into two separate fields.
     11
     12        * heap/MarkedAllocator.cpp:
     13        (JSC::MarkedAllocator::tryAllocateHelper): Use m_blocksToSweep instead of m_currentBlock as the
     14        initializer/reference of the loop. Only change m_currentBlock when we know what the result will be.
     15        (JSC::MarkedAllocator::addBlock): When we add a new block we know that both m_blocksToSweep and
     16        m_currentBlock are null. In order to preserve the invariant that m_currentBlock <= m_blocksToSweep,
     17        we assign both of them to point to the new block.
     18        (JSC::MarkedAllocator::removeBlock): We need a separate check to see if the block we're removing is
     19        m_blocksToSweep and if so, advance it to the next block in the list.
     20        * heap/MarkedAllocator.h:
     21        (MarkedAllocator): Initialize m_blocksToSweep.
     22        (JSC::MarkedAllocator::MarkedAllocator):
     23        (JSC::MarkedAllocator::reset): We set m_blocksToSweep to be the head of our list. This function is called
     24        at the end of a collection, so all of the blocks in our allocator need to be swept. We need to sweep a
     25        block before we can start allocating, so m_currentBlock is set to null. We also set the freeList to
     26        the empty FreeList to emphasize the fact that we can't start allocating until we do some sweeping.
     27
    1282012-07-27  Mark Hahnenberg  <mhahnenberg@apple.com>
    229
  • trunk/Source/JavaScriptCore/heap/MarkedAllocator.cpp

    r123813 r123931  
    3030{
    3131    if (!m_freeList.head) {
    32         for (MarkedBlock*& block = m_currentBlock; block; block = static_cast<MarkedBlock*>(block->next())) {
     32        for (MarkedBlock*& block = m_blocksToSweep; block; block = static_cast<MarkedBlock*>(block->next())) {
    3333            m_freeList = block->sweep(MarkedBlock::SweepToFreeList);
    34             if (m_freeList.head)
     34            if (m_freeList.head) {
     35                m_currentBlock = block;
    3536                break;
     37            }
    3638            block->didConsumeFreeList();
    3739        }
    3840       
    39         if (!m_freeList.head)
     41        if (!m_freeList.head) {
     42            m_currentBlock = 0;
    4043            return 0;
     44        }
    4145    }
    4246   
     
    101105{
    102106    ASSERT(!m_currentBlock);
     107    ASSERT(!m_blocksToSweep);
    103108    ASSERT(!m_freeList.head);
    104109   
    105110    m_blockList.append(block);
    106     m_currentBlock = block;
     111    m_blocksToSweep = m_currentBlock = block;
    107112    m_freeList = block->sweep(MarkedBlock::SweepToFreeList);
    108113}
     
    114119        m_freeList = MarkedBlock::FreeList();
    115120    }
     121    if (m_blocksToSweep == block)
     122        m_blocksToSweep = static_cast<MarkedBlock*>(m_blocksToSweep->next());
    116123    m_blockList.remove(block);
    117124}
  • trunk/Source/JavaScriptCore/heap/MarkedAllocator.h

    r123813 r123931  
    4747    MarkedBlock::FreeList m_freeList;
    4848    MarkedBlock* m_currentBlock;
     49    MarkedBlock* m_blocksToSweep;
    4950    DoublyLinkedList<HeapBlock> m_blockList;
    5051    size_t m_cellSize;
     
    5758inline MarkedAllocator::MarkedAllocator()
    5859    : m_currentBlock(0)
     60    , m_blocksToSweep(0)
    5961    , m_cellSize(0)
    6062    , m_cellsNeedDestruction(true)
     
    8789inline void MarkedAllocator::reset()
    8890{
    89     m_currentBlock = static_cast<MarkedBlock*>(m_blockList.head());
     91    m_currentBlock = 0;
     92    m_freeList = MarkedBlock::FreeList();
     93    m_blocksToSweep = static_cast<MarkedBlock*>(m_blockList.head());
    9094}
    9195
Note: See TracChangeset for help on using the changeset viewer.