]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - heap/WeakSet.cpp
JavaScriptCore-1218.tar.gz
[apple/javascriptcore.git] / heap / WeakSet.cpp
index d9c773cefd68047a0c67d1ac5d7f8a081e89d039..e62e66eae348b86e08e36d7482b43d7f125866dd 100644 (file)
@@ -27,6 +27,7 @@
 #include "WeakSet.h"
 
 #include "Heap.h"
+#include "VM.h"
 
 namespace JSC {
 
@@ -35,59 +36,17 @@ WeakSet::~WeakSet()
     WeakBlock* next = 0;
     for (WeakBlock* block = m_blocks.head(); block; block = next) {
         next = block->next();
-        WeakBlock::destroy(block);
+        heap()->blockAllocator().deallocate(WeakBlock::destroy(block));
     }
     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; block = block->next())
         block->sweep();
-    }
-}
-
-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 +63,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 +73,8 @@ WeakBlock::FreeCell* WeakSet::tryFindAllocator()
 
 WeakBlock::FreeCell* WeakSet::addAllocator()
 {
-    WeakBlock* block = WeakBlock::create();
-    m_heap->didAllocate(WeakBlock::blockSize);
+    WeakBlock* block = WeakBlock::create(heap()->blockAllocator().allocate<WeakBlock>());
+    heap()->didAllocate(WeakBlock::blockSize);
     m_blocks.append(block);
     WeakBlock::SweepResult sweepResult = block->takeSweepResult();
     ASSERT(!sweepResult.isNull() && sweepResult.freeList);
@@ -126,7 +84,7 @@ WeakBlock::FreeCell* WeakSet::addAllocator()
 void WeakSet::removeAllocator(WeakBlock* block)
 {
     m_blocks.remove(block);
-    WeakBlock::destroy(block);
+    heap()->blockAllocator().deallocate(WeakBlock::destroy(block));
 }
 
 } // namespace JSC