]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - heap/WeakBlock.h
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / heap / WeakBlock.h
index 9e546ea32ecb3f2e1be1d54255cb55b741d5528e..b6b631e27b100049ee5a9b18a13350e086264c75 100644 (file)
 #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;
@@ -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<WeakImpl*>(freeCell);
+    return reinterpret_cast_ptr<WeakImpl*>(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<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()
@@ -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