Commit 03c4f9dd authored by ggaren@apple.com's avatar ggaren@apple.com
Browse files

2011-02-10 Geoffrey Garen <ggaren@apple.com>

        Reviewed by Oliver Hunt.

        A little more encapsulation for MarkedBlock: Moved allocate() and sweep() into MarkedBlock
        https://bugs.webkit.org/show_bug.cgi?id=54253
        
        SunSpider reports no change.

        * runtime/CollectorHeapIterator.h: Removed DeadObjectIterator, since it
        is now unused.

        * runtime/Heap.cpp:
        (JSC::Heap::reset): Moved the call to shrink() here, since it seems a
        little more clear for MarkedSpace's client to tell it explicitly when to
        shrink.

        * runtime/JSCell.h:
        (JSC::JSCell::MarkedBlock::allocate): Split out from MarkedSpace::allocate.

        * runtime/MarkedBlock.cpp:
        (JSC::MarkedBlock::sweep): Split out from MarkedSpace::sweep, and
        converted to more directly iterate a MarkedBlock based on knowing its
        internal structure.

        * runtime/MarkedBlock.h:
        * runtime/MarkedSpace.cpp:
        (JSC::MarkedSpace::allocate):
        (JSC::MarkedSpace::sweep):
        * runtime/MarkedSpace.h: Split out the code mentioned above.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@78284 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 494c0680
2011-02-10 Geoffrey Garen <ggaren@apple.com>
Reviewed by Oliver Hunt.
A little more encapsulation for MarkedBlock: Moved allocate() and sweep() into MarkedBlock
https://bugs.webkit.org/show_bug.cgi?id=54253
SunSpider reports no change.
* runtime/CollectorHeapIterator.h: Removed DeadObjectIterator, since it
is now unused.
* runtime/Heap.cpp:
(JSC::Heap::reset): Moved the call to shrink() here, since it seems a
little more clear for MarkedSpace's client to tell it explicitly when to
shrink.
* runtime/JSCell.h:
(JSC::JSCell::MarkedBlock::allocate): Split out from MarkedSpace::allocate.
* runtime/MarkedBlock.cpp:
(JSC::MarkedBlock::sweep): Split out from MarkedSpace::sweep, and
converted to more directly iterate a MarkedBlock based on knowing its
internal structure.
* runtime/MarkedBlock.h:
* runtime/MarkedSpace.cpp:
(JSC::MarkedSpace::allocate):
(JSC::MarkedSpace::sweep):
* runtime/MarkedSpace.h: Split out the code mentioned above.
2011-02-10 Patrick Gansterer <paroga@webkit.org>
 
Reviewed by Andreas Kling.
......
......@@ -53,12 +53,6 @@ namespace JSC {
LiveObjectIterator& operator++();
};
class DeadObjectIterator : public CollectorHeapIterator {
public:
DeadObjectIterator(CollectorHeap&, size_t startBlock, size_t startCell = 0);
DeadObjectIterator& operator++();
};
inline CollectorHeapIterator::CollectorHeapIterator(CollectorHeap& heap, size_t startBlock, size_t startCell)
: m_heap(heap)
, m_block(startBlock)
......@@ -112,21 +106,6 @@ namespace JSC {
return *this;
}
inline DeadObjectIterator::DeadObjectIterator(CollectorHeap& heap, size_t startBlock, size_t startCell)
: CollectorHeapIterator(heap, startBlock, startCell)
{
if (isValid() && isLive())
++(*this);
}
inline DeadObjectIterator& DeadObjectIterator::operator++()
{
do {
advance();
} while (isValid() && isLive());
return *this;
}
} // namespace JSC
#endif // CollectorHeapIterator_h
......@@ -383,8 +383,10 @@ void Heap::reset(SweepToggle sweepToggle)
m_markedSpace.reset();
m_extraCost = 0;
if (sweepToggle == DoSweep)
if (sweepToggle == DoSweep) {
m_markedSpace.sweep();
m_markedSpace.shrink();
}
size_t usedCellCount = m_markedSpace.markedCells();
size_t proportionalBytes = static_cast<size_t>(usedCellCount * 1.5 * HeapConstants::cellSize);
......
......@@ -401,6 +401,22 @@ namespace JSC {
return isCell() && asCell() && asCell()->isZombie();
}
#endif
inline void* MarkedBlock::allocate(size_t& nextCell)
{
do {
ASSERT(nextCell < HeapConstants::cellsPerBlock);
if (!marked.testAndSet(nextCell)) { // Always false for the last cell in the block
JSCell* cell = reinterpret_cast<JSCell*>(&cells[nextCell++]);
cell->~JSCell();
return cell;
}
nextCell = marked.nextPossiblyUnset(nextCell);
} while (nextCell != HeapConstants::cellsPerBlock);
return 0;
}
} // namespace JSC
#endif // JSCell_h
......@@ -56,4 +56,29 @@ MarkedBlock::MarkedBlock(const PageAllocationAligned& allocation, JSGlobalData*
new (&cells[i]) JSCell(dummyMarkableCellStructure);
}
void MarkedBlock::sweep()
{
#if !ENABLE(JSC_ZOMBIES)
Structure* dummyMarkableCellStructure = m_heap->globalData()->dummyMarkableCellStructure.get();
#endif
for (size_t i = 0; i < HeapConstants::cellsPerBlock; ++i) {
if (marked.get(i))
continue;
JSCell* cell = reinterpret_cast<JSCell*>(&cells[i]);
#if ENABLE(JSC_ZOMBIES)
if (!cell->isZombie()) {
const ClassInfo* info = cell->classInfo();
cell->~JSCell();
new (cell) JSZombie(info, JSZombie::leakedZombieStructure());
marked.set(i);
}
#else
cell->~JSCell();
new (cell) JSCell(dummyMarkableCellStructure);
#endif
}
}
} // namespace JSC
......@@ -64,6 +64,9 @@ namespace JSC {
static MarkedBlock* blockFor(const void*);
Heap* heap() const;
void* allocate(size_t& nextCell);
void sweep();
size_t cellNumber(const void*);
bool isMarked(const void*);
......
......@@ -68,29 +68,15 @@ void* MarkedSpace::allocate(size_t)
do {
ASSERT(m_heap.nextBlock < m_heap.blocks.size());
MarkedBlock* block = m_heap.collectorBlock(m_heap.nextBlock);
do {
ASSERT(m_heap.nextCell < HeapConstants::cellsPerBlock);
if (!block->marked.testAndSet(m_heap.nextCell)) { // Always false for the last cell in the block
CollectorCell* cell = &block->cells[m_heap.nextCell];
JSCell* imp = reinterpret_cast<JSCell*>(cell);
imp->~JSCell();
++m_heap.nextCell;
return cell;
}
m_heap.nextCell = block->marked.nextPossiblyUnset(m_heap.nextCell);
} while (m_heap.nextCell != HeapConstants::cellsPerBlock);
if (void* result = block->allocate(m_heap.nextCell))
return result;
m_heap.nextCell = 0;
m_waterMark += BLOCK_SIZE;
} while (++m_heap.nextBlock != m_heap.blocks.size());
if (m_waterMark < m_highWaterMark) {
MarkedBlock* block = allocateBlock();
ASSERT(!block->marked.get(m_heap.nextCell));
block->marked.set(m_heap.nextCell);
return &block->cells[m_heap.nextCell++];
}
if (m_waterMark < m_highWaterMark)
return allocateBlock()->allocate(m_heap.nextCell);
return 0;
}
......@@ -144,29 +130,8 @@ size_t MarkedSpace::markedCells(size_t startBlock, size_t startCell) const
void MarkedSpace::sweep()
{
#if !ENABLE(JSC_ZOMBIES)
Structure* dummyMarkableCellStructure = globalData()->dummyMarkableCellStructure.get();
#endif
DeadObjectIterator it(m_heap, 0, 0);
DeadObjectIterator end(m_heap, m_heap.blocks.size(), 0);
for ( ; it != end; ++it) {
JSCell* cell = *it;
#if ENABLE(JSC_ZOMBIES)
if (!cell->isZombie()) {
const ClassInfo* info = cell->classInfo();
cell->~JSCell();
new (cell) JSZombie(info, JSZombie::leakedZombieStructure());
Heap::markCell(cell);
}
#else
cell->~JSCell();
// Callers of sweep assume it's safe to mark any cell in the heap.
new (cell) JSCell(dummyMarkableCellStructure);
#endif
}
shrink();
for (size_t i = 0; i < m_heap.blocks.size(); ++i)
m_heap.collectorBlock(i)->sweep();
}
size_t MarkedSpace::objectCount() const
......
......@@ -80,6 +80,7 @@ namespace JSC {
void markRoots();
void reset();
void sweep();
void shrink();
size_t markedCells(size_t startBlock = 0, size_t startCell = 0) const;
size_t size() const;
......@@ -94,7 +95,6 @@ namespace JSC {
private:
NEVER_INLINE MarkedBlock* allocateBlock();
NEVER_INLINE void freeBlock(size_t);
void shrink();
void clearMarkBits(MarkedBlock*);
......
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