#include "WeakHandleOwner.h"
#include "WeakImpl.h"
#include <wtf/DoublyLinkedList.h>
-#include <wtf/PageAllocation.h>
#include <wtf/StdLibExtras.h>
namespace JSC {
+class DeadBlock;
class HeapRootVisitor;
class JSValue;
class WeakHandleOwner;
-class WeakBlock : public DoublyLinkedListNode<WeakBlock> {
+class WeakBlock : public HeapBlock<WeakBlock> {
public:
friend class WTF::DoublyLinkedListNode<WeakBlock>;
- static const size_t blockSize = 4 * KB;
+ static const size_t blockSize = 4 * KB; // 5% of MarkedBlock size
struct FreeCell {
FreeCell* next;
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;
};
inline WeakImpl* WeakBlock::asWeakImpl(FreeCell* freeCell)
{
- return reinterpret_cast<WeakImpl*>(freeCell);
+ return reinterpret_cast_ptr<WeakImpl*>(freeCell);
}
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<FreeCell*>(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<Unknown>::wrapSlot(&const_cast<JSValue&>(weakImpl->jsValue())), weakImpl->context());
+ return reinterpret_cast_ptr<FreeCell*>(weakImpl);
}
inline WeakImpl* WeakBlock::weakImpls()
{
- return reinterpret_cast<WeakImpl*>(this) + ((sizeof(WeakBlock) + sizeof(WeakImpl) - 1) / sizeof(WeakImpl));
+ return reinterpret_cast_ptr<WeakImpl*>(this) + ((sizeof(WeakBlock) + sizeof(WeakImpl) - 1) / sizeof(WeakImpl));
}
inline size_t WeakBlock::weakImplCount()
*freeList = freeCell;
}
+inline bool WeakBlock::isEmpty()
+{
+ return !m_sweepResult.isNull() && m_sweepResult.blockIsFree;
+}
+
} // namespace JSC
#endif // WeakBlock_h