X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..81345200c95645a1b0d2635520f96ad55dfde63f:/heap/WeakBlock.h?ds=sidebyside diff --git a/heap/WeakBlock.h b/heap/WeakBlock.h index 9e546ea..b6b631e 100644 --- a/heap/WeakBlock.h +++ b/heap/WeakBlock.h @@ -30,19 +30,19 @@ #include "WeakHandleOwner.h" #include "WeakImpl.h" #include -#include #include namespace JSC { +class DeadBlock; class HeapRootVisitor; class JSValue; class WeakHandleOwner; -class WeakBlock : public DoublyLinkedListNode { +class WeakBlock : public HeapBlock { public: friend class WTF::DoublyLinkedListNode; - static const size_t blockSize = 4 * KB; + static const size_t blockSize = 4 * KB; // 5% of MarkedBlock size struct FreeCell { FreeCell* next; @@ -56,33 +56,30 @@ public: FreeCell* freeList; }; - static WeakBlock* create(); - static void destroy(WeakBlock*); + static WeakBlock* create(DeadBlock*); static WeakImpl* asWeakImpl(FreeCell*); + bool isEmpty(); + void sweep(); - const SweepResult& sweepResult(); SweepResult takeSweepResult(); - void visitLiveWeakImpls(HeapRootVisitor&); - void visitDeadWeakImpls(HeapRootVisitor&); + void visit(HeapRootVisitor&); + void reap(); - void finalizeAll(); + void lastChanceToFinalize(); private: static FreeCell* asFreeCell(WeakImpl*); - WeakBlock(PageAllocation&); + WeakBlock(Region*); WeakImpl* firstWeakImpl(); void finalize(WeakImpl*); WeakImpl* weakImpls(); size_t weakImplCount(); void addToFreeList(FreeCell**, WeakImpl*); - PageAllocation m_allocation; - WeakBlock* m_prev; - WeakBlock* m_next; SweepResult m_sweepResult; }; @@ -100,7 +97,7 @@ inline bool WeakBlock::SweepResult::isNull() const inline WeakImpl* WeakBlock::asWeakImpl(FreeCell* freeCell) { - return reinterpret_cast(freeCell); + return reinterpret_cast_ptr(freeCell); } inline WeakBlock::SweepResult WeakBlock::takeSweepResult() @@ -111,29 +108,14 @@ inline WeakBlock::SweepResult WeakBlock::takeSweepResult() return tmp; } -inline const WeakBlock::SweepResult& WeakBlock::sweepResult() -{ - return m_sweepResult; -} - inline WeakBlock::FreeCell* WeakBlock::asFreeCell(WeakImpl* weakImpl) { - return reinterpret_cast(weakImpl); -} - -inline void WeakBlock::finalize(WeakImpl* weakImpl) -{ - ASSERT(weakImpl->state() == WeakImpl::Dead); - weakImpl->setState(WeakImpl::Finalized); - WeakHandleOwner* weakHandleOwner = weakImpl->weakHandleOwner(); - if (!weakHandleOwner) - return; - weakHandleOwner->finalize(Handle::wrapSlot(&const_cast(weakImpl->jsValue())), weakImpl->context()); + return reinterpret_cast_ptr(weakImpl); } inline WeakImpl* WeakBlock::weakImpls() { - return reinterpret_cast(this) + ((sizeof(WeakBlock) + sizeof(WeakImpl) - 1) / sizeof(WeakImpl)); + return reinterpret_cast_ptr(this) + ((sizeof(WeakBlock) + sizeof(WeakImpl) - 1) / sizeof(WeakImpl)); } inline size_t WeakBlock::weakImplCount() @@ -151,6 +133,11 @@ inline void WeakBlock::addToFreeList(FreeCell** freeList, WeakImpl* weakImpl) *freeList = freeCell; } +inline bool WeakBlock::isEmpty() +{ + return !m_sweepResult.isNull() && m_sweepResult.blockIsFree; +} + } // namespace JSC #endif // WeakBlock_h