X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..HEAD:/heap/WeakSet.cpp diff --git a/heap/WeakSet.cpp b/heap/WeakSet.cpp index d9c773c..1eed8c3 100644 --- a/heap/WeakSet.cpp +++ b/heap/WeakSet.cpp @@ -27,6 +27,8 @@ #include "WeakSet.h" #include "Heap.h" +#include "JSCInlines.h" +#include "VM.h" namespace JSC { @@ -40,54 +42,23 @@ WeakSet::~WeakSet() m_blocks.clear(); } -void WeakSet::finalizeAll() -{ - for (WeakBlock* block = m_blocks.head(); block; block = block->next()) - block->finalizeAll(); -} - -void WeakSet::visitLiveWeakImpls(HeapRootVisitor& visitor) -{ - for (WeakBlock* block = m_blocks.head(); block; block = block->next()) - block->visitLiveWeakImpls(visitor); -} - -void WeakSet::visitDeadWeakImpls(HeapRootVisitor& visitor) -{ - for (WeakBlock* block = m_blocks.head(); block; block = block->next()) - block->visitDeadWeakImpls(visitor); -} - void WeakSet::sweep() { - WeakBlock* next; - for (WeakBlock* block = m_blocks.head(); block; block = next) { - next = block->next(); - - // If a block is completely empty, a new sweep won't have any effect. - if (!block->sweepResult().isNull() && block->sweepResult().blockIsFree) - continue; - - block->takeSweepResult(); // Force a new sweep by discarding the last sweep. + for (WeakBlock* block = m_blocks.head(); block;) { + WeakBlock* nextBlock = block->next(); block->sweep(); + if (block->isLogicallyEmptyButNotFree()) { + // If this WeakBlock is logically empty, but still has Weaks pointing into it, + // we can't destroy it just yet. Detach it from the WeakSet and hand ownership + // to the Heap so we don't pin down the entire 64kB MarkedBlock. + m_blocks.remove(block); + heap()->addLogicallyEmptyWeakBlock(block); + block->disconnectMarkedBlock(); + } + block = nextBlock; } -} - -void WeakSet::shrink() -{ - WeakBlock* next; - for (WeakBlock* block = m_blocks.head(); block; block = next) { - next = block->next(); - if (!block->sweepResult().isNull() && block->sweepResult().blockIsFree) - removeAllocator(block); - } -} - -void WeakSet::resetAllocator() -{ - m_allocator = 0; - m_nextAllocator = m_blocks.head(); + resetAllocator(); } WeakBlock::FreeCell* WeakSet::findAllocator() @@ -104,7 +75,6 @@ WeakBlock::FreeCell* WeakSet::tryFindAllocator() WeakBlock* block = m_nextAllocator; m_nextAllocator = m_nextAllocator->next(); - block->sweep(); WeakBlock::SweepResult sweepResult = block->takeSweepResult(); if (sweepResult.freeList) return sweepResult.freeList; @@ -115,8 +85,8 @@ WeakBlock::FreeCell* WeakSet::tryFindAllocator() WeakBlock::FreeCell* WeakSet::addAllocator() { - WeakBlock* block = WeakBlock::create(); - m_heap->didAllocate(WeakBlock::blockSize); + WeakBlock* block = WeakBlock::create(m_markedBlock); + heap()->didAllocate(WeakBlock::blockSize); m_blocks.append(block); WeakBlock::SweepResult sweepResult = block->takeSweepResult(); ASSERT(!sweepResult.isNull() && sweepResult.freeList);