Commit ce85b93f authored by mhahnenberg@apple.com's avatar mhahnenberg@apple.com

Build fix

Unreviewed build fix

Forgot to add a couple files.

* heap/MarkedAllocator.cpp: Added.
(JSC):
(JSC::MarkedAllocator::tryAllocateHelper):
(JSC::MarkedAllocator::tryAllocate):
(JSC::MarkedAllocator::allocateSlowCase):
(JSC::MarkedAllocator::allocateBlock):
(JSC::MarkedAllocator::addBlock):
(JSC::MarkedAllocator::removeBlock):
* heap/MarkedAllocator.h: Added.
(JSC):
(DFG):
(MarkedAllocator):
(JSC::MarkedAllocator::cellSize):
(JSC::MarkedAllocator::heap):
(JSC::MarkedAllocator::setHeap):
(JSC::MarkedAllocator::setCellSize):
(JSC::MarkedAllocator::setMarkedSpace):
(JSC::MarkedAllocator::MarkedAllocator):
(JSC::MarkedAllocator::allocate):
(JSC::MarkedAllocator::reset):
(JSC::MarkedAllocator::zapFreeList):
(JSC::MarkedAllocator::forEachBlock):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106677 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3c1e101e
2012-02-03 Mark Hahnenberg <mhahnenberg@apple.com>
Build fix
Unreviewed build fix
Forgot to add a couple files.
* heap/MarkedAllocator.cpp: Added.
(JSC):
(JSC::MarkedAllocator::tryAllocateHelper):
(JSC::MarkedAllocator::tryAllocate):
(JSC::MarkedAllocator::allocateSlowCase):
(JSC::MarkedAllocator::allocateBlock):
(JSC::MarkedAllocator::addBlock):
(JSC::MarkedAllocator::removeBlock):
* heap/MarkedAllocator.h: Added.
(JSC):
(DFG):
(MarkedAllocator):
(JSC::MarkedAllocator::cellSize):
(JSC::MarkedAllocator::heap):
(JSC::MarkedAllocator::setHeap):
(JSC::MarkedAllocator::setCellSize):
(JSC::MarkedAllocator::setMarkedSpace):
(JSC::MarkedAllocator::MarkedAllocator):
(JSC::MarkedAllocator::allocate):
(JSC::MarkedAllocator::reset):
(JSC::MarkedAllocator::zapFreeList):
(JSC::MarkedAllocator::forEachBlock):
2012-02-03 Mark Hahnenberg <mhahnenberg@apple.com>
Refactor MarkedBlock::SizeClass into a separate class
#include "config.h"
#include "MarkedAllocator.h"
#include "Heap.h"
namespace JSC {
inline void* MarkedAllocator::tryAllocateHelper()
{
MarkedBlock::FreeCell* firstFreeCell = m_firstFreeCell;
if (!firstFreeCell) {
for (MarkedBlock*& block = m_currentBlock; block; block = static_cast<MarkedBlock*>(block->next())) {
firstFreeCell = block->sweep(MarkedBlock::SweepToFreeList);
if (firstFreeCell)
break;
m_markedSpace->didConsumeFreeList(block);
block->didConsumeFreeList();
}
if (!firstFreeCell)
return 0;
}
ASSERT(firstFreeCell);
m_firstFreeCell = firstFreeCell->next;
return firstFreeCell;
}
inline void* MarkedAllocator::tryAllocate()
{
m_heap->m_operationInProgress = Allocation;
void* result = tryAllocateHelper();
m_heap->m_operationInProgress = NoOperation;
return result;
}
void* MarkedAllocator::allocateSlowCase()
{
#if COLLECT_ON_EVERY_ALLOCATION
m_heap->collectAllGarbage();
ASSERT(m_heap->m_operationInProgress == NoOperation);
#endif
void* result = tryAllocate();
if (LIKELY(result != 0))
return result;
AllocationEffort allocationEffort;
if ((
#if ENABLE(GGC)
nurseryWaterMark() < m_heap->m_minBytesPerCycle
#else
m_heap->waterMark() < m_heap->highWaterMark()
#endif
) || !m_heap->m_isSafeToCollect)
allocationEffort = AllocationMustSucceed;
else
allocationEffort = AllocationCanFail;
MarkedBlock* block = allocateBlock(allocationEffort);
if (block) {
addBlock(block);
void* result = tryAllocate();
ASSERT(result);
return result;
}
m_heap->collect(Heap::DoNotSweep);
result = tryAllocate();
if (result)
return result;
ASSERT(m_heap->waterMark() < m_heap->highWaterMark());
addBlock(allocateBlock(AllocationMustSucceed));
result = tryAllocate();
ASSERT(result);
return result;
}
MarkedBlock* MarkedAllocator::allocateBlock(AllocationEffort allocationEffort)
{
MarkedBlock* block;
{
MutexLocker locker(m_heap->m_freeBlockLock);
if (m_heap->m_numberOfFreeBlocks) {
block = static_cast<MarkedBlock*>(m_heap->m_freeBlocks.removeHead());
ASSERT(block);
m_heap->m_numberOfFreeBlocks--;
} else
block = 0;
}
if (block)
block = MarkedBlock::recycle(block, m_heap, m_cellSize);
else if (allocationEffort == AllocationCanFail)
return 0;
else
block = MarkedBlock::create(m_heap, m_cellSize);
m_markedSpace->didAddBlock(block);
return block;
}
void MarkedAllocator::addBlock(MarkedBlock* block)
{
ASSERT(!m_currentBlock);
ASSERT(!m_firstFreeCell);
m_blockList.append(block);
m_currentBlock = block;
m_firstFreeCell = block->sweep(MarkedBlock::SweepToFreeList);
}
void MarkedAllocator::removeBlock(MarkedBlock* block)
{
if (m_currentBlock == block)
m_currentBlock = 0;
m_blockList.remove(block);
}
} // namespace JSC
#ifndef MarkedAllocator_h
#define MarkedAllocator_h
#include "MarkedBlock.h"
#include <wtf/DoublyLinkedList.h>
namespace JSC {
class Heap;
class MarkedSpace;
namespace DFG {
class SpeculativeJIT;
}
class MarkedAllocator {
friend class JIT;
friend class DFG::SpeculativeJIT;
public:
MarkedAllocator();
void reset();
void zapFreeList();
size_t cellSize() { return m_cellSize; }
void* allocate();
Heap* heap() { return m_heap; }
template<typename Functor> void forEachBlock(Functor&);
void addBlock(MarkedBlock*);
void removeBlock(MarkedBlock*);
void setHeap(Heap* heap) { m_heap = heap; }
void setCellSize(size_t cellSize) { m_cellSize = cellSize; }
void setMarkedSpace(MarkedSpace* space) { m_markedSpace = space; }
private:
JS_EXPORT_PRIVATE void* allocateSlowCase();
void* tryAllocate();
void* tryAllocateHelper();
MarkedBlock* allocateBlock(AllocationEffort);
MarkedBlock::FreeCell* m_firstFreeCell;
MarkedBlock* m_currentBlock;
DoublyLinkedList<HeapBlock> m_blockList;
size_t m_cellSize;
Heap* m_heap;
MarkedSpace* m_markedSpace;
};
inline MarkedAllocator::MarkedAllocator()
: m_firstFreeCell(0)
, m_currentBlock(0)
, m_cellSize(0)
, m_heap(0)
, m_markedSpace(0)
{
}
inline void* MarkedAllocator::allocate()
{
MarkedBlock::FreeCell* firstFreeCell = m_firstFreeCell;
// This is a light-weight fast path to cover the most common case.
if (UNLIKELY(!firstFreeCell))
return allocateSlowCase();
m_firstFreeCell = firstFreeCell->next;
return firstFreeCell;
}
inline void MarkedAllocator::reset()
{
m_currentBlock = static_cast<MarkedBlock*>(m_blockList.head());
}
inline void MarkedAllocator::zapFreeList()
{
if (!m_currentBlock) {
ASSERT(!m_firstFreeCell);
return;
}
m_currentBlock->zapFreeList(m_firstFreeCell);
m_firstFreeCell = 0;
}
template <typename Functor> inline void MarkedAllocator::forEachBlock(Functor& functor)
{
HeapBlock* next;
for (HeapBlock* block = m_blockList.head(); block; block = next) {
next = block->next();
functor(static_cast<MarkedBlock*>(block));
}
}
} // namespace JSC
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment