Commit f1b74c88 authored by ggaren@apple.com's avatar ggaren@apple.com

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.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77082 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 13bb8583
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.
2011-01-29 Geoffrey Garen <ggaren@apple.com>
Reviewed by Cameron Zwarich.
......
......@@ -38,7 +38,9 @@ namespace JSC {
protected:
CollectorHeapIterator(CollectorHeap&, size_t startBlock, size_t startCell);
void advance(size_t max);
void advance();
bool isValid();
bool isLive();
CollectorHeap& m_heap;
size_t m_block;
......@@ -75,6 +77,18 @@ namespace JSC {
return m_block != other.m_block || m_cell != other.m_cell;
}
inline bool CollectorHeapIterator::isValid()
{
return m_block < m_heap.usedBlocks;
}
inline bool CollectorHeapIterator::isLive()
{
return m_block < m_heap.nextBlock
|| (m_block == m_heap.nextBlock && m_cell < m_heap.nextCell)
|| (m_block < m_heap.usedBlocks && m_heap.collectorBlock(m_block)->marked.get(m_cell));
}
inline JSCell* CollectorHeapIterator::operator*() const
{
return reinterpret_cast<JSCell*>(&m_heap.collectorBlock(m_block)->cells[m_cell]);
......@@ -82,56 +96,55 @@ namespace JSC {
// Iterators advance up to the next-to-last -- and not the last -- cell in a
// block, since the last cell is a dummy sentinel.
inline void CollectorHeapIterator::advance(size_t max)
inline void CollectorHeapIterator::advance()
{
++m_cell;
if (m_cell == max) {
if (m_cell == HeapConstants::cellsPerBlock - 1) {
m_cell = 0;
++m_block;
}
}
inline LiveObjectIterator::LiveObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell)
: CollectorHeapIterator(heap, startBlock, startCell - 1)
: CollectorHeapIterator(heap, startBlock, startCell)
{
++(*this);
if (isValid() && !isLive())
++(*this);
}
inline LiveObjectIterator& LiveObjectIterator::operator++()
{
advance(HeapConstants::cellsPerBlock - 1);
if (m_block < m_heap.nextBlock || (m_block == m_heap.nextBlock && m_cell < m_heap.nextCell))
return *this;
while (m_block < m_heap.usedBlocks && !m_heap.collectorBlock(m_block)->marked.get(m_cell))
advance(HeapConstants::cellsPerBlock - 1);
do {
advance();
} while (isValid() && !isLive());
return *this;
}
inline DeadObjectIterator::DeadObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell)
: CollectorHeapIterator(heap, startBlock, startCell - 1)
: CollectorHeapIterator(heap, startBlock, startCell)
{
++(*this);
if (isValid() && isLive())
++(*this);
}
inline DeadObjectIterator& DeadObjectIterator::operator++()
{
do {
advance(HeapConstants::cellsPerBlock - 1);
ASSERT(m_block > m_heap.nextBlock || (m_block == m_heap.nextBlock && m_cell >= m_heap.nextCell));
} while (m_block < m_heap.usedBlocks && m_heap.collectorBlock(m_block)->marked.get(m_cell));
advance();
} while (isValid() && isLive());
return *this;
}
inline ObjectIterator::ObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell)
: CollectorHeapIterator(heap, startBlock, startCell - 1)
: CollectorHeapIterator(heap, startBlock, startCell)
{
++(*this);
if (isValid())
++(*this);
}
inline ObjectIterator& ObjectIterator::operator++()
{
advance(HeapConstants::cellsPerBlock - 1);
advance();
return *this;
}
......
......@@ -91,8 +91,8 @@ NEVER_INLINE CollectorBlock* MarkedSpace::allocateBlock()
NEVER_INLINE void MarkedSpace::freeBlock(size_t block)
{
ObjectIterator it(m_heap, block);
ObjectIterator end(m_heap, block + 1);
ObjectIterator it(m_heap, block, 0);
ObjectIterator end(m_heap, block + 1, 0);
for ( ; it != end; ++it)
(*it)->~JSCell();
m_heap.blocks[block].deallocate();
......@@ -251,8 +251,8 @@ void MarkedSpace::sweep()
Structure* dummyMarkableCellStructure = globalData()->dummyMarkableCellStructure.get();
#endif
DeadObjectIterator it(m_heap, m_heap.nextBlock, m_heap.nextCell);
DeadObjectIterator end(m_heap, m_heap.usedBlocks);
DeadObjectIterator it(m_heap, 0, 0);
DeadObjectIterator end(m_heap, m_heap.usedBlocks, 0);
for ( ; it != end; ++it) {
JSCell* cell = *it;
#if ENABLE(JSC_ZOMBIES)
......@@ -300,12 +300,12 @@ void MarkedSpace::reset()
LiveObjectIterator MarkedSpace::primaryHeapBegin()
{
return LiveObjectIterator(m_heap, 0);
return LiveObjectIterator(m_heap, 0, 0);
}
LiveObjectIterator MarkedSpace::primaryHeapEnd()
{
return LiveObjectIterator(m_heap, m_heap.usedBlocks);
return LiveObjectIterator(m_heap, m_heap.usedBlocks, 0);
}
} // namespace JSC
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment