]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 A |
1 | #ifndef MarkedAllocator_h |
2 | #define MarkedAllocator_h | |
3 | ||
4 | #include "MarkedBlock.h" | |
5 | #include <wtf/DoublyLinkedList.h> | |
6 | ||
7 | namespace JSC { | |
8 | ||
9 | class Heap; | |
10 | class MarkedSpace; | |
11 | class LLIntOffsetsExtractor; | |
12 | ||
13 | namespace DFG { | |
14 | class SpeculativeJIT; | |
15 | } | |
16 | ||
17 | class MarkedAllocator { | |
93a37866 | 18 | friend class LLIntOffsetsExtractor; |
6fe7ccc8 A |
19 | |
20 | public: | |
93a37866 A |
21 | static ptrdiff_t offsetOfFreeListHead(); |
22 | ||
6fe7ccc8 | 23 | MarkedAllocator(); |
81345200 | 24 | void lastChanceToFinalize(); |
6fe7ccc8 | 25 | void reset(); |
81345200 A |
26 | void stopAllocating(); |
27 | void resumeAllocating(); | |
6fe7ccc8 | 28 | size_t cellSize() { return m_cellSize; } |
93a37866 A |
29 | MarkedBlock::DestructorType destructorType() { return m_destructorType; } |
30 | void* allocate(size_t); | |
6fe7ccc8 | 31 | Heap* heap() { return m_heap; } |
81345200 A |
32 | MarkedBlock* takeLastActiveBlock() |
33 | { | |
34 | MarkedBlock* block = m_lastActiveBlock; | |
35 | m_lastActiveBlock = 0; | |
36 | return block; | |
37 | } | |
6fe7ccc8 A |
38 | |
39 | template<typename Functor> void forEachBlock(Functor&); | |
40 | ||
41 | void addBlock(MarkedBlock*); | |
42 | void removeBlock(MarkedBlock*); | |
93a37866 | 43 | void init(Heap*, MarkedSpace*, size_t cellSize, MarkedBlock::DestructorType); |
6fe7ccc8 A |
44 | |
45 | bool isPagedOut(double deadline); | |
46 | ||
47 | private: | |
93a37866 A |
48 | JS_EXPORT_PRIVATE void* allocateSlowCase(size_t); |
49 | void* tryAllocate(size_t); | |
50 | void* tryAllocateHelper(size_t); | |
81345200 | 51 | void* tryPopFreeList(size_t); |
93a37866 | 52 | MarkedBlock* allocateBlock(size_t); |
81345200 | 53 | ALWAYS_INLINE void doTestCollectionsIfNeeded(); |
6fe7ccc8 A |
54 | |
55 | MarkedBlock::FreeList m_freeList; | |
56 | MarkedBlock* m_currentBlock; | |
81345200 A |
57 | MarkedBlock* m_lastActiveBlock; |
58 | MarkedBlock* m_nextBlockToSweep; | |
93a37866 | 59 | DoublyLinkedList<MarkedBlock> m_blockList; |
81345200 | 60 | DoublyLinkedList<MarkedBlock> m_retiredBlocks; |
6fe7ccc8 | 61 | size_t m_cellSize; |
93a37866 | 62 | MarkedBlock::DestructorType m_destructorType; |
6fe7ccc8 A |
63 | Heap* m_heap; |
64 | MarkedSpace* m_markedSpace; | |
65 | }; | |
66 | ||
93a37866 A |
67 | inline ptrdiff_t MarkedAllocator::offsetOfFreeListHead() |
68 | { | |
69 | return OBJECT_OFFSETOF(MarkedAllocator, m_freeList) + OBJECT_OFFSETOF(MarkedBlock::FreeList, head); | |
70 | } | |
71 | ||
6fe7ccc8 A |
72 | inline MarkedAllocator::MarkedAllocator() |
73 | : m_currentBlock(0) | |
81345200 A |
74 | , m_lastActiveBlock(0) |
75 | , m_nextBlockToSweep(0) | |
6fe7ccc8 | 76 | , m_cellSize(0) |
93a37866 | 77 | , m_destructorType(MarkedBlock::None) |
6fe7ccc8 A |
78 | , m_heap(0) |
79 | , m_markedSpace(0) | |
80 | { | |
81 | } | |
82 | ||
93a37866 | 83 | inline void MarkedAllocator::init(Heap* heap, MarkedSpace* markedSpace, size_t cellSize, MarkedBlock::DestructorType destructorType) |
6fe7ccc8 A |
84 | { |
85 | m_heap = heap; | |
86 | m_markedSpace = markedSpace; | |
87 | m_cellSize = cellSize; | |
93a37866 | 88 | m_destructorType = destructorType; |
6fe7ccc8 A |
89 | } |
90 | ||
93a37866 | 91 | inline void* MarkedAllocator::allocate(size_t bytes) |
6fe7ccc8 A |
92 | { |
93 | MarkedBlock::FreeCell* head = m_freeList.head; | |
93a37866 A |
94 | if (UNLIKELY(!head)) { |
95 | void* result = allocateSlowCase(bytes); | |
96 | #ifndef NDEBUG | |
97 | memset(result, 0xCD, bytes); | |
98 | #endif | |
99 | return result; | |
100 | } | |
6fe7ccc8 A |
101 | |
102 | m_freeList.head = head->next; | |
93a37866 A |
103 | #ifndef NDEBUG |
104 | memset(head, 0xCD, bytes); | |
105 | #endif | |
6fe7ccc8 A |
106 | return head; |
107 | } | |
108 | ||
81345200 | 109 | inline void MarkedAllocator::stopAllocating() |
6fe7ccc8 | 110 | { |
81345200 | 111 | ASSERT(!m_lastActiveBlock); |
6fe7ccc8 A |
112 | if (!m_currentBlock) { |
113 | ASSERT(!m_freeList.head); | |
114 | return; | |
115 | } | |
116 | ||
81345200 A |
117 | m_currentBlock->stopAllocating(m_freeList); |
118 | m_lastActiveBlock = m_currentBlock; | |
93a37866 | 119 | m_currentBlock = 0; |
6fe7ccc8 A |
120 | m_freeList = MarkedBlock::FreeList(); |
121 | } | |
122 | ||
81345200 A |
123 | inline void MarkedAllocator::resumeAllocating() |
124 | { | |
125 | if (!m_lastActiveBlock) | |
126 | return; | |
127 | ||
128 | m_freeList = m_lastActiveBlock->resumeAllocating(); | |
129 | m_currentBlock = m_lastActiveBlock; | |
130 | m_lastActiveBlock = 0; | |
131 | } | |
132 | ||
6fe7ccc8 A |
133 | template <typename Functor> inline void MarkedAllocator::forEachBlock(Functor& functor) |
134 | { | |
93a37866 A |
135 | MarkedBlock* next; |
136 | for (MarkedBlock* block = m_blockList.head(); block; block = next) { | |
6fe7ccc8 | 137 | next = block->next(); |
93a37866 | 138 | functor(block); |
6fe7ccc8 | 139 | } |
81345200 A |
140 | |
141 | for (MarkedBlock* block = m_retiredBlocks.head(); block; block = next) { | |
142 | next = block->next(); | |
143 | functor(block); | |
144 | } | |
6fe7ccc8 | 145 | } |
81345200 | 146 | |
6fe7ccc8 A |
147 | } // namespace JSC |
148 | ||
149 | #endif |