Refactored WeakBlock to use malloc, clarify behavior
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 May 2012 23:55:27 +0000 (23:55 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 May 2012 23:55:27 +0000 (23:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=87318

Reviewed by Filip Pizlo.

We want to use malloc so we can make these smaller than 4KB,
since an individual MarkedBlock will usually have fewer than
4KB worth of weak pointers.

* heap/Heap.cpp:
(JSC::Heap::markRoots): Renamed visitLiveWeakImpls to visit, since
we no longer need to distinguish from "visitDeadWeakImpls".

Renamed "visitDeadWeakImpls" to "reap" because we're not actually
doing any visiting -- we're just tagging things as dead.

* heap/WeakBlock.cpp:
(JSC::WeakBlock::create):
(JSC::WeakBlock::destroy):
(JSC::WeakBlock::WeakBlock): Malloc!

(JSC::WeakBlock::visit):
(JSC::WeakBlock::reap): Renamed as above.

* heap/WeakBlock.h:
(WeakBlock): Reduced to 3KB, as explained above.

* heap/WeakSet.cpp:
(JSC::WeakSet::visit):
(JSC::WeakSet::reap):
* heap/WeakSet.h:
(WeakSet): Updated for renames, and to match WebKit style.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@118269 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/Heap.cpp
Source/JavaScriptCore/heap/WeakBlock.cpp
Source/JavaScriptCore/heap/WeakBlock.h
Source/JavaScriptCore/heap/WeakSet.cpp
Source/JavaScriptCore/heap/WeakSet.h

index b56f5e1..faea16b 100644 (file)
@@ -1,3 +1,38 @@
+2012-05-23  Geoffrey Garen  <ggaren@apple.com>
+
+        Refactored WeakBlock to use malloc, clarify behavior
+        https://bugs.webkit.org/show_bug.cgi?id=87318
+
+        Reviewed by Filip Pizlo.
+
+        We want to use malloc so we can make these smaller than 4KB,
+        since an individual MarkedBlock will usually have fewer than
+        4KB worth of weak pointers.
+
+        * heap/Heap.cpp:
+        (JSC::Heap::markRoots): Renamed visitLiveWeakImpls to visit, since
+        we no longer need to distinguish from "visitDeadWeakImpls".
+
+        Renamed "visitDeadWeakImpls" to "reap" because we're not actually
+        doing any visiting -- we're just tagging things as dead.
+
+        * heap/WeakBlock.cpp:
+        (JSC::WeakBlock::create):
+        (JSC::WeakBlock::destroy):
+        (JSC::WeakBlock::WeakBlock): Malloc!
+
+        (JSC::WeakBlock::visit):
+        (JSC::WeakBlock::reap): Renamed as above.
+
+        * heap/WeakBlock.h:
+        (WeakBlock): Reduced to 3KB, as explained above.
+
+        * heap/WeakSet.cpp:
+        (JSC::WeakSet::visit):
+        (JSC::WeakSet::reap):
+        * heap/WeakSet.h:
+        (WeakSet): Updated for renames, and to match WebKit style.
+
 2012-05-23  Filip Pizlo  <fpizlo@apple.com>
 
         Use after free in JSC::DFG::ByteCodeParser::processPhiStack
index a43af8a..75272bf 100644 (file)
@@ -561,7 +561,7 @@ void Heap::markRoots(bool fullGC)
     {
         GCPHASE(VisitingLiveWeakHandles);
         while (true) {
-            m_weakSet.visitLiveWeakImpls(heapRootVisitor);
+            m_weakSet.visit(heapRootVisitor);
             harvestWeakReferences();
             if (visitor.isEmpty())
                 break;
@@ -576,8 +576,8 @@ void Heap::markRoots(bool fullGC)
     }
 
     {
-        GCPHASE(VisitingDeadWeakHandles);
-        m_weakSet.visitDeadWeakImpls(heapRootVisitor);
+        GCPHASE(ReapingWeakHandles);
+        m_weakSet.reap();
     }
 
     GCCOUNTER(VisitedValueCount, visitor.visitCount());
index ded1584..685779d 100644 (file)
@@ -36,19 +36,16 @@ namespace JSC {
 
 WeakBlock* WeakBlock::create()
 {
-    PageAllocation allocation = PageAllocation::allocate(blockSize, OSAllocator::JSGCHeapPages);
-    if (!static_cast<bool>(allocation))
-        CRASH();
-    return new (NotNull, allocation.base()) WeakBlock(allocation);
+    void* allocation = fastMalloc(blockSize);
+    return new (NotNull, allocation) WeakBlock;
 }
 
 void WeakBlock::destroy(WeakBlock* block)
 {
-    block->m_allocation.deallocate();
+    fastFree(block);
 }
 
-WeakBlock::WeakBlock(PageAllocation& allocation)
-    : m_allocation(allocation)
+WeakBlock::WeakBlock()
 {
     for (size_t i = 0; i < weakImplCount(); ++i) {
         WeakImpl* weakImpl = &weakImpls()[i];
@@ -90,7 +87,7 @@ void WeakBlock::sweep()
     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 (isEmpty())
@@ -118,9 +115,9 @@ 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 a block is completely empty, a reaping won't have any effect.
     if (isEmpty())
         return;
 
index 471f49b..dc3e89d 100644 (file)
@@ -30,7 +30,6 @@
 #include "WeakHandleOwner.h"
 #include "WeakImpl.h"
 #include <wtf/DoublyLinkedList.h>
-#include <wtf/PageAllocation.h>
 #include <wtf/StdLibExtras.h>
 
 namespace JSC {
@@ -42,7 +41,7 @@ class WeakHandleOwner;
 class WeakBlock : public DoublyLinkedListNode<WeakBlock> {
 public:
     friend class WTF::DoublyLinkedListNode<WeakBlock>;
-    static const size_t blockSize = 4 * KB;
+    static const size_t blockSize = 3 * KB; // 5% of MarkedBlock size
 
     struct FreeCell {
         FreeCell* next;
@@ -64,25 +63,23 @@ public:
     bool isEmpty();
 
     void sweep();
-    const SweepResult& sweepResult();
     SweepResult takeSweepResult();
 
-    void visitLiveWeakImpls(HeapRootVisitor&);
-    void visitDeadWeakImpls(HeapRootVisitor&);
+    void visit(HeapRootVisitor&);
+    void reap();
 
     void lastChanceToFinalize();
 
 private:
     static FreeCell* asFreeCell(WeakImpl*);
 
-    WeakBlock(PageAllocation&);
+    WeakBlock();
     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;
@@ -113,11 +110,6 @@ 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);
index b225517..9bc5d41 100644 (file)
@@ -46,16 +46,16 @@ void WeakSet::lastChanceToFinalize()
         block->lastChanceToFinalize();
 }
 
-void WeakSet::visitLiveWeakImpls(HeapRootVisitor& visitor)
+void WeakSet::visit(HeapRootVisitor& visitor)
 {
     for (WeakBlock* block = m_blocks.head(); block; block = block->next())
-        block->visitLiveWeakImpls(visitor);
+        block->visit(visitor);
 }
 
-void WeakSet::visitDeadWeakImpls(HeapRootVisitor& visitor)
+void WeakSet::reap()
 {
     for (WeakBlock* block = m_blocks.head(); block; block = block->next())
-        block->visitDeadWeakImpls(visitor);
+        block->reap();
 }
 
 void WeakSet::sweep()
index fb0c5df..5dd9f91 100644 (file)
@@ -35,15 +35,15 @@ class WeakImpl;
 
 class WeakSet {
 public:
-    WeakSet(Heap*);
-    void lastChanceToFinalize();
-    ~WeakSet();
-
     static WeakImpl* allocate(JSValue, WeakHandleOwner* = 0, void* context = 0);
     static void deallocate(WeakImpl*);
 
-    void visitLiveWeakImpls(HeapRootVisitor&);
-    void visitDeadWeakImpls(HeapRootVisitor&);
+    WeakSet(Heap*);
+    ~WeakSet();
+    void lastChanceToFinalize();
+
+    void visit(HeapRootVisitor&);
+    void reap();
 
     void sweep();
     void resetAllocator();