2011-02-03 Geoffrey Garen <ggaren@apple.com>
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Feb 2011 19:23:42 +0000 (19:23 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Feb 2011 19:23:42 +0000 (19:23 +0000)
        Reviewed by Sam Weinig.

        Start using MarkedBlock instead of CollectorBlock
        https://bugs.webkit.org/show_bug.cgi?id=53693

        SunSpider reports no change.

        * runtime/MarkedBlock.h:
        (JSC::MarkedBlock::blockFor):
        (JSC::MarkedBlock::setMarked):
        (JSC::MarkedBlock::isCellAligned):
        (JSC::MarkedBlock::isPossibleCell): Updated for const-ness.

        * runtime/MarkedSpace.cpp:
        (JSC::MarkedSpace::allocateBlock):
        (JSC::MarkedSpace::containsSlowCase):
        (JSC::MarkedSpace::clearMarkBits): Updated for const-ness.

        * runtime/MarkedSpace.h:
        (JSC::CollectorHeap::collectorBlock):
        (JSC::MarkedSpace::heap):
        (JSC::MarkedSpace::isMarked):
        (JSC::MarkedSpace::testAndSetMarked):
        (JSC::MarkedSpace::setMarked):
        (JSC::MarkedSpace::contains): Switched from CollectorBlock to MarkedBlock,
        and deleted dead CollectorBlock-related code.

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/MarkedBlock.h
Source/JavaScriptCore/runtime/MarkedSpace.cpp
Source/JavaScriptCore/runtime/MarkedSpace.h

index a0dca5acd012ffc868af0a72ffb7cd19b06c4b32..abe53378de8fa4dfb59b94fde0b130795354dabd 100644 (file)
@@ -1,3 +1,32 @@
+2011-02-03  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Start using MarkedBlock instead of CollectorBlock
+        https://bugs.webkit.org/show_bug.cgi?id=53693
+        
+        SunSpider reports no change.
+        
+        * runtime/MarkedBlock.h:
+        (JSC::MarkedBlock::blockFor):
+        (JSC::MarkedBlock::setMarked):
+        (JSC::MarkedBlock::isCellAligned):
+        (JSC::MarkedBlock::isPossibleCell): Updated for const-ness.
+
+        * runtime/MarkedSpace.cpp:
+        (JSC::MarkedSpace::allocateBlock):
+        (JSC::MarkedSpace::containsSlowCase):
+        (JSC::MarkedSpace::clearMarkBits): Updated for const-ness.
+
+        * runtime/MarkedSpace.h:
+        (JSC::CollectorHeap::collectorBlock):
+        (JSC::MarkedSpace::heap):
+        (JSC::MarkedSpace::isMarked):
+        (JSC::MarkedSpace::testAndSetMarked):
+        (JSC::MarkedSpace::setMarked):
+        (JSC::MarkedSpace::contains): Switched from CollectorBlock to MarkedBlock,
+        and deleted dead CollectorBlock-related code.
+
 2011-02-03  Patrick Gansterer  <paroga@webkit.org>
 
         Reviewed by Darin Adler.
index 00311df548a3f0bed2cb03cbb37e6c60cdfb1c92..c92eb4cf0fa43c5d0de79b1ca4fa510f98609b55 100644 (file)
@@ -55,14 +55,14 @@ namespace JSC {
 
     class MarkedBlock {
     public:
-        static bool isCellAligned(void*);
-        static bool isPossibleCell(void*);
-        static MarkedBlock* blockFor(void*);
+        static bool isCellAligned(const void*);
+        static bool isPossibleCell(const void*);
+        static MarkedBlock* blockFor(const void*);
 
         size_t cellNumber(const JSCell*);
         bool isMarked(const JSCell*);
         bool testAndSetMarked(const JSCell*);
-        void setMarked(JSCell* cell);
+        void setMarked(const JSCell*);
 
         FixedArray<CollectorCell, CELLS_PER_BLOCK> cells;
         WTF::Bitmap<CELLS_PER_BLOCK> marked;
@@ -76,7 +76,7 @@ namespace JSC {
         typedef MarkedBlock Block;
     };
 
-    inline MarkedBlock* MarkedBlock::blockFor(void* p)
+    inline MarkedBlock* MarkedBlock::blockFor(const void* p)
     {
         return reinterpret_cast<MarkedBlock*>(reinterpret_cast<uintptr_t>(p) & BLOCK_MASK);
     }
@@ -96,17 +96,17 @@ namespace JSC {
         return marked.testAndSet(cellNumber(cell));
     }
 
-    inline void MarkedBlock::setMarked(JSCell* cell)
+    inline void MarkedBlock::setMarked(const JSCell* cell)
     {
         marked.set(cellNumber(cell));
     }
 
-    inline bool MarkedBlock::isCellAligned(void* p)
+    inline bool MarkedBlock::isCellAligned(const void* p)
     {
         return !((intptr_t)(p) & CELL_MASK);
     }
 
-    inline bool MarkedBlock::isPossibleCell(void* p)
+    inline bool MarkedBlock::isPossibleCell(const void* p)
     {
         return isCellAligned(p) && p;
     }
index 6ff71f9db1b8684afd55df6fdc4b65cd21fda482..5dd93641c1eff3c11fd79c46fb95fa12c3c21d31 100644 (file)
@@ -59,10 +59,10 @@ void MarkedSpace::destroy()
     memset(&m_heap, 0, sizeof(CollectorHeap));
 }
 
-NEVER_INLINE CollectorBlock* MarkedSpace::allocateBlock()
+NEVER_INLINE MarkedBlock* MarkedSpace::allocateBlock()
 {
     PageAllocationAligned allocation = PageAllocationAligned::allocate(BLOCK_SIZE, BLOCK_SIZE, OSAllocator::JSGCHeapPages);
-    CollectorBlock* block = static_cast<CollectorBlock*>(allocation.base());
+    MarkedBlock* block = static_cast<MarkedBlock*>(allocation.base());
     if (!block)
         CRASH();
 
@@ -185,7 +185,7 @@ void MarkedSpace::shrinkBlocks(size_t neededBlocks)
         m_heap.collectorBlock(i)->marked.set(HeapConstants::cellsPerBlock - 1);
 }
 
-bool MarkedSpace::containsSlowCase(void* x)
+bool MarkedSpace::containsSlowCase(const void* x)
 {
     uintptr_t xAsBits = reinterpret_cast<uintptr_t>(x);
     xAsBits &= CELL_ALIGN_MASK;
@@ -195,7 +195,7 @@ bool MarkedSpace::containsSlowCase(void* x)
     if (offset > lastCellOffset)
         return false;
 
-    CollectorBlock* blockAddr = reinterpret_cast<CollectorBlock*>(xAsBits - offset);
+    MarkedBlock* blockAddr = reinterpret_cast<MarkedBlock*>(xAsBits - offset);
     size_t usedBlocks = m_heap.usedBlocks;
     for (size_t block = 0; block < usedBlocks; block++) {
         if (m_heap.collectorBlock(block) != blockAddr)
@@ -224,7 +224,7 @@ void MarkedSpace::clearMarkBits()
         clearMarkBits(m_heap.collectorBlock(i));
 }
 
-void MarkedSpace::clearMarkBits(CollectorBlock* block)
+void MarkedSpace::clearMarkBits(MarkedBlock* block)
 {
     // allocate assumes that the last cell in every block is marked.
     block->marked.clearAll();
index 84e3b09fa216f5d128034b2d7d70961c49249433..a2bdb31e84329ec6d7b4874efbc2690681a89c26 100644 (file)
@@ -23,6 +23,7 @@
 #define MarkedSpace_h
 
 #include "MachineStackMarker.h"
+#include "MarkedBlock.h"
 #include "PageAllocationAligned.h"
 #include <wtf/Bitmap.h>
 #include <wtf/FixedArray.h>
@@ -32,7 +33,6 @@
 
 namespace JSC {
 
-    class CollectorBlock;
     class Heap;
     class JSCell;
     class JSGlobalData;
@@ -40,12 +40,6 @@ namespace JSC {
     class MarkStack;
     class WeakGCHandle;
 
-#if OS(WINCE) || OS(SYMBIAN) || PLATFORM(BREWMP)
-    const size_t BLOCK_SIZE = 64 * 1024; // 64k
-#else
-    const size_t BLOCK_SIZE = 256 * 1024; // 256k
-#endif
-
     struct CollectorHeap {
         size_t nextBlock;
         size_t nextCell;
@@ -54,9 +48,9 @@ namespace JSC {
         size_t numBlocks;
         size_t usedBlocks;
 
-        CollectorBlock* collectorBlock(size_t index) const
+        MarkedBlock* collectorBlock(size_t index) const
         {
-            return static_cast<CollectorBlock*>(blocks[index].base());
+            return static_cast<MarkedBlock*>(blocks[index].base());
         }
     };
 
@@ -67,7 +61,7 @@ namespace JSC {
 
         static bool isMarked(const JSCell*);
         static bool testAndSetMarked(const JSCell*);
-        static void setMarked(JSCell*);
+        static void setMarked(const JSCell*);
 
         MarkedSpace(JSGlobalData*);
         void destroy();
@@ -85,108 +79,50 @@ namespace JSC {
         size_t capacity() const;
         size_t objectCount() const;
 
-        bool contains(void*);
+        bool contains(const void*);
 
         LiveObjectIterator primaryHeapBegin();
         LiveObjectIterator primaryHeapEnd();
 
     private:
-        bool isCellAligned(void*);
-        bool isPossibleCell(void*);
-        bool containsSlowCase(void*);
-
-        static CollectorBlock* cellBlock(const JSCell*);
-        static size_t cellOffset(const JSCell*);
+        bool containsSlowCase(const void*);
 
-        NEVER_INLINE CollectorBlock* allocateBlock();
+        NEVER_INLINE MarkedBlock* allocateBlock();
         NEVER_INLINE void freeBlock(size_t);
         void resizeBlocks();
         void growBlocks(size_t neededBlocks);
         void shrinkBlocks(size_t neededBlocks);
 
-        void clearMarkBits(CollectorBlock*);
+        void clearMarkBits(MarkedBlock*);
         size_t markedCells(size_t startBlock = 0, size_t startCell = 0) const;
 
         CollectorHeap m_heap;
         JSGlobalData* m_globalData;
     };
 
-    // tunable parameters
-    // derived constants
-    const size_t BLOCK_OFFSET_MASK = BLOCK_SIZE - 1;
-    const size_t BLOCK_MASK = ~BLOCK_OFFSET_MASK;
-    const size_t MINIMUM_CELL_SIZE = 64;
-    const size_t CELL_ARRAY_LENGTH = (MINIMUM_CELL_SIZE / sizeof(double)) + (MINIMUM_CELL_SIZE % sizeof(double) != 0 ? sizeof(double) : 0);
-    const size_t CELL_SIZE = CELL_ARRAY_LENGTH * sizeof(double);
-    const size_t SMALL_CELL_SIZE = CELL_SIZE / 2;
-    const size_t CELL_MASK = CELL_SIZE - 1;
-    const size_t CELL_ALIGN_MASK = ~CELL_MASK;
-    const size_t CELLS_PER_BLOCK = (BLOCK_SIZE - sizeof(MarkedSpace*)) * 8 * CELL_SIZE / (8 * CELL_SIZE + 1) / CELL_SIZE; // one bitmap byte can represent 8 cells.
-    
-    struct CollectorCell {
-        FixedArray<double, CELL_ARRAY_LENGTH> memory;
-    };
-
-    class CollectorBlock {
-    public:
-        FixedArray<CollectorCell, CELLS_PER_BLOCK> cells;
-        WTF::Bitmap<CELLS_PER_BLOCK> marked;
-        Heap* heap;
-    };
-
-    struct HeapConstants {
-        static const size_t cellSize = CELL_SIZE;
-        static const size_t cellsPerBlock = CELLS_PER_BLOCK;
-        typedef CollectorCell Cell;
-        typedef CollectorBlock Block;
-    };
-
-    inline CollectorBlock* MarkedSpace::cellBlock(const JSCell* cell)
-    {
-        return reinterpret_cast<CollectorBlock*>(reinterpret_cast<uintptr_t>(cell) & BLOCK_MASK);
-    }
-
-    inline size_t MarkedSpace::cellOffset(const JSCell* cell)
-    {
-        return (reinterpret_cast<uintptr_t>(cell) & BLOCK_OFFSET_MASK) / CELL_SIZE;
-    }
-
     inline Heap* MarkedSpace::heap(JSCell* cell)
     {
-        return cellBlock(cell)->heap;
+        return MarkedBlock::blockFor(cell)->heap;
     }
 
     inline bool MarkedSpace::isMarked(const JSCell* cell)
     {
-        return cellBlock(cell)->marked.get(cellOffset(cell));
+        return MarkedBlock::blockFor(cell)->isMarked(cell);
     }
 
     inline bool MarkedSpace::testAndSetMarked(const JSCell* cell)
     {
-        return cellBlock(cell)->marked.testAndSet(cellOffset(cell));
-    }
-
-    inline void MarkedSpace::setMarked(JSCell* cell)
-    {
-        cellBlock(cell)->marked.set(cellOffset(cell));
-    }
-
-    // Cell size needs to be a power of two for isPossibleCell to be valid.
-    COMPILE_ASSERT(!(sizeof(CollectorCell) % 2), Collector_cell_size_is_power_of_two);
-
-    inline bool MarkedSpace::isCellAligned(void *p)
-    {
-        return !((intptr_t)(p) & CELL_MASK);
+        return MarkedBlock::blockFor(cell)->testAndSetMarked(cell);
     }
 
-    inline bool MarkedSpace::isPossibleCell(void* p)
+    inline void MarkedSpace::setMarked(const JSCell* cell)
     {
-        return isCellAligned(p) && p;
+        MarkedBlock::blockFor(cell)->setMarked(cell);
     }
 
-    inline bool MarkedSpace::contains(void* x)
+    inline bool MarkedSpace::contains(const void* x)
     {
-        if (!isPossibleCell(x))
+        if (!MarkedBlock::isPossibleCell(x))
             return false;
             
         return containsSlowCase(x);