]>
git.saurik.com Git - apple/javascriptcore.git/blob - heap/MarkedAllocator.h
8b3620f08858ad1e62b3453b87523f12ba44ae07
1 #ifndef MarkedAllocator_h
2 #define MarkedAllocator_h
4 #include "MarkedBlock.h"
5 #include <wtf/DoublyLinkedList.h>
11 class LLIntOffsetsExtractor
;
17 class MarkedAllocator
{
19 friend class DFG::SpeculativeJIT
;
25 size_t cellSize() { return m_cellSize
; }
26 bool cellsNeedDestruction() { return m_cellsNeedDestruction
; }
28 Heap
* heap() { return m_heap
; }
30 template<typename Functor
> void forEachBlock(Functor
&);
32 void addBlock(MarkedBlock
*);
33 void removeBlock(MarkedBlock
*);
34 void init(Heap
*, MarkedSpace
*, size_t cellSize
, bool cellsNeedDestruction
);
36 bool isPagedOut(double deadline
);
39 friend class LLIntOffsetsExtractor
;
41 JS_EXPORT_PRIVATE
void* allocateSlowCase();
43 void* tryAllocateHelper();
44 MarkedBlock
* allocateBlock();
46 MarkedBlock::FreeList m_freeList
;
47 MarkedBlock
* m_currentBlock
;
48 DoublyLinkedList
<HeapBlock
> m_blockList
;
50 bool m_cellsNeedDestruction
;
52 MarkedSpace
* m_markedSpace
;
55 inline MarkedAllocator::MarkedAllocator()
58 , m_cellsNeedDestruction(true)
64 inline void MarkedAllocator::init(Heap
* heap
, MarkedSpace
* markedSpace
, size_t cellSize
, bool cellsNeedDestruction
)
67 m_markedSpace
= markedSpace
;
68 m_cellSize
= cellSize
;
69 m_cellsNeedDestruction
= cellsNeedDestruction
;
72 inline void* MarkedAllocator::allocate()
74 MarkedBlock::FreeCell
* head
= m_freeList
.head
;
75 // This is a light-weight fast path to cover the most common case.
77 return allocateSlowCase();
79 m_freeList
.head
= head
->next
;
83 inline void MarkedAllocator::reset()
85 m_currentBlock
= static_cast<MarkedBlock
*>(m_blockList
.head());
88 inline void MarkedAllocator::zapFreeList()
90 if (!m_currentBlock
) {
91 ASSERT(!m_freeList
.head
);
95 m_currentBlock
->zapFreeList(m_freeList
);
96 m_freeList
= MarkedBlock::FreeList();
99 template <typename Functor
> inline void MarkedAllocator::forEachBlock(Functor
& functor
)
102 for (HeapBlock
* block
= m_blockList
.head(); block
; block
= next
) {
103 next
= block
->next();
104 functor(static_cast<MarkedBlock
*>(block
));