1 #ifndef MarkedAllocator_h
2 #define MarkedAllocator_h
4 #include "MarkedBlock.h"
5 #include <wtf/DoublyLinkedList.h>
11 class LLIntOffsetsExtractor
;
17 class MarkedAllocator
{
18 friend class LLIntOffsetsExtractor
;
21 static ptrdiff_t offsetOfFreeListHead();
25 void canonicalizeCellLivenessData();
26 size_t cellSize() { return m_cellSize
; }
27 MarkedBlock::DestructorType
destructorType() { return m_destructorType
; }
28 void* allocate(size_t);
29 Heap
* heap() { return m_heap
; }
31 template<typename Functor
> void forEachBlock(Functor
&);
33 void addBlock(MarkedBlock
*);
34 void removeBlock(MarkedBlock
*);
35 void init(Heap
*, MarkedSpace
*, size_t cellSize
, MarkedBlock::DestructorType
);
37 bool isPagedOut(double deadline
);
40 JS_EXPORT_PRIVATE
void* allocateSlowCase(size_t);
41 void* tryAllocate(size_t);
42 void* tryAllocateHelper(size_t);
43 MarkedBlock
* allocateBlock(size_t);
45 MarkedBlock::FreeList m_freeList
;
46 MarkedBlock
* m_currentBlock
;
47 MarkedBlock
* m_blocksToSweep
;
48 DoublyLinkedList
<MarkedBlock
> m_blockList
;
50 MarkedBlock::DestructorType m_destructorType
;
52 MarkedSpace
* m_markedSpace
;
55 inline ptrdiff_t MarkedAllocator::offsetOfFreeListHead()
57 return OBJECT_OFFSETOF(MarkedAllocator
, m_freeList
) + OBJECT_OFFSETOF(MarkedBlock::FreeList
, head
);
60 inline MarkedAllocator::MarkedAllocator()
64 , m_destructorType(MarkedBlock::None
)
70 inline void MarkedAllocator::init(Heap
* heap
, MarkedSpace
* markedSpace
, size_t cellSize
, MarkedBlock::DestructorType destructorType
)
73 m_markedSpace
= markedSpace
;
74 m_cellSize
= cellSize
;
75 m_destructorType
= destructorType
;
78 inline void* MarkedAllocator::allocate(size_t bytes
)
80 MarkedBlock::FreeCell
* head
= m_freeList
.head
;
81 if (UNLIKELY(!head
)) {
82 void* result
= allocateSlowCase(bytes
);
84 memset(result
, 0xCD, bytes
);
89 m_freeList
.head
= head
->next
;
91 memset(head
, 0xCD, bytes
);
96 inline void MarkedAllocator::reset()
99 m_freeList
= MarkedBlock::FreeList();
100 m_blocksToSweep
= m_blockList
.head();
103 inline void MarkedAllocator::canonicalizeCellLivenessData()
105 if (!m_currentBlock
) {
106 ASSERT(!m_freeList
.head
);
110 m_currentBlock
->canonicalizeCellLivenessData(m_freeList
);
112 m_freeList
= MarkedBlock::FreeList();
115 template <typename Functor
> inline void MarkedAllocator::forEachBlock(Functor
& functor
)
118 for (MarkedBlock
* block
= m_blockList
.head(); block
; block
= next
) {
119 next
= block
->next();