+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.
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;
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);
}
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;
}
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();
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;
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)
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();
#define MarkedSpace_h
#include "MachineStackMarker.h"
+#include "MarkedBlock.h"
#include "PageAllocationAligned.h"
#include <wtf/Bitmap.h>
#include <wtf/FixedArray.h>
namespace JSC {
- class CollectorBlock;
class Heap;
class JSCell;
class JSGlobalData;
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;
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());
}
};
static bool isMarked(const JSCell*);
static bool testAndSetMarked(const JSCell*);
- static void setMarked(JSCell*);
+ static void setMarked(const JSCell*);
MarkedSpace(JSGlobalData*);
void destroy();
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);