X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/heap/WeakBlock.cpp?ds=sidebyside diff --git a/heap/WeakBlock.cpp b/heap/WeakBlock.cpp index 7ba778b..7c7d86c 100644 --- a/heap/WeakBlock.cpp +++ b/heap/WeakBlock.cpp @@ -29,26 +29,25 @@ #include "Heap.h" #include "HeapRootVisitor.h" #include "JSObject.h" -#include "ScopeChain.h" +#include "JSCInlines.h" #include "Structure.h" namespace JSC { -WeakBlock* WeakBlock::create() +WeakBlock* WeakBlock::create(MarkedBlock& markedBlock) { - PageAllocation allocation = PageAllocation::allocate(blockSize, OSAllocator::JSGCHeapPages); - if (!static_cast(allocation)) - CRASH(); - return new (NotNull, allocation.base()) WeakBlock(allocation); + return new (NotNull, fastMalloc(blockSize)) WeakBlock(markedBlock); } void WeakBlock::destroy(WeakBlock* block) { - block->m_allocation.deallocate(); + block->~WeakBlock(); + fastFree(block); } -WeakBlock::WeakBlock(PageAllocation& allocation) - : m_allocation(allocation) +WeakBlock::WeakBlock(MarkedBlock& markedBlock) + : DoublyLinkedListNode() + , m_markedBlock(&markedBlock) { for (size_t i = 0; i < weakImplCount(); ++i) { WeakImpl* weakImpl = &weakImpls()[i]; @@ -56,10 +55,10 @@ WeakBlock::WeakBlock(PageAllocation& allocation) addToFreeList(&m_sweepResult.freeList, weakImpl); } - ASSERT(!m_sweepResult.isNull() && m_sweepResult.blockIsFree); + ASSERT(isEmpty()); } -void WeakBlock::finalizeAll() +void WeakBlock::lastChanceToFinalize() { for (size_t i = 0; i < weakImplCount(); ++i) { WeakImpl* weakImpl = &weakImpls()[i]; @@ -72,7 +71,8 @@ void WeakBlock::finalizeAll() void WeakBlock::sweep() { - if (!m_sweepResult.isNull()) + // If a block is completely empty, a sweep won't have any effect. + if (isEmpty()) return; SweepResult sweepResult; @@ -82,18 +82,27 @@ void WeakBlock::sweep() finalize(weakImpl); if (weakImpl->state() == WeakImpl::Deallocated) addToFreeList(&sweepResult.freeList, weakImpl); - else + else { sweepResult.blockIsFree = false; + if (weakImpl->state() == WeakImpl::Live) + sweepResult.blockIsLogicallyEmpty = false; + } } m_sweepResult = sweepResult; ASSERT(!m_sweepResult.isNull()); } -void WeakBlock::visitLiveWeakImpls(HeapRootVisitor& heapRootVisitor) +void WeakBlock::visit(HeapRootVisitor& heapRootVisitor) { // If a block is completely empty, a visit won't have any effect. - if (!m_sweepResult.isNull() && m_sweepResult.blockIsFree) + if (isEmpty()) + return; + + // If this WeakBlock doesn't belong to a MarkedBlock, we won't even be here. + ASSERT(m_markedBlock); + + if (m_markedBlock->isAllocated()) return; SlotVisitor& visitor = heapRootVisitor.visitor(); @@ -104,7 +113,7 @@ void WeakBlock::visitLiveWeakImpls(HeapRootVisitor& heapRootVisitor) continue; const JSValue& jsValue = weakImpl->jsValue(); - if (Heap::isMarked(jsValue.asCell())) + if (m_markedBlock->isMarkedOrNewlyAllocated(jsValue.asCell())) continue; WeakHandleOwner* weakHandleOwner = weakImpl->weakHandleOwner(); @@ -118,10 +127,16 @@ void WeakBlock::visitLiveWeakImpls(HeapRootVisitor& heapRootVisitor) } } -void WeakBlock::visitDeadWeakImpls(HeapRootVisitor&) +void WeakBlock::reap() { - // If a block is completely empty, a visit won't have any effect. - if (!m_sweepResult.isNull() && m_sweepResult.blockIsFree) + // If a block is completely empty, a reaping won't have any effect. + if (isEmpty()) + return; + + // If this WeakBlock doesn't belong to a MarkedBlock, we won't even be here. + ASSERT(m_markedBlock); + + if (m_markedBlock->isAllocated()) return; for (size_t i = 0; i < weakImplCount(); ++i) { @@ -129,7 +144,7 @@ void WeakBlock::visitDeadWeakImpls(HeapRootVisitor&) if (weakImpl->state() > WeakImpl::Dead) continue; - if (Heap::isMarked(weakImpl->jsValue().asCell())) { + if (m_markedBlock->isMarkedOrNewlyAllocated(weakImpl->jsValue().asCell())) { ASSERT(weakImpl->state() == WeakImpl::Live); continue; }