]>
git.saurik.com Git - apple/javascriptcore.git/blob - heap/MarkedAllocator.cpp
2 #include "MarkedAllocator.h"
4 #include "GCActivityCallback.h"
6 #include "JSGlobalData.h"
7 #include <wtf/CurrentTime.h>
11 bool MarkedAllocator::isPagedOut(double deadline
)
13 unsigned itersSinceLastTimeCheck
= 0;
14 HeapBlock
* block
= m_blockList
.head();
16 block
= block
->next();
17 ++itersSinceLastTimeCheck
;
18 if (itersSinceLastTimeCheck
>= Heap::s_timeCheckResolution
) {
19 double currentTime
= WTF::monotonicallyIncreasingTime();
20 if (currentTime
> deadline
)
22 itersSinceLastTimeCheck
= 0;
29 inline void* MarkedAllocator::tryAllocateHelper()
31 if (!m_freeList
.head
) {
32 for (MarkedBlock
*& block
= m_currentBlock
; block
; block
= static_cast<MarkedBlock
*>(block
->next())) {
33 m_freeList
= block
->sweep(MarkedBlock::SweepToFreeList
);
36 block
->didConsumeFreeList();
43 MarkedBlock::FreeCell
* head
= m_freeList
.head
;
44 m_freeList
.head
= head
->next
;
49 inline void* MarkedAllocator::tryAllocate()
51 ASSERT(!m_heap
->isBusy());
52 m_heap
->m_operationInProgress
= Allocation
;
53 void* result
= tryAllocateHelper();
54 m_heap
->m_operationInProgress
= NoOperation
;
58 void* MarkedAllocator::allocateSlowCase()
60 ASSERT(m_heap
->globalData()->apiLock().currentThreadIsHoldingLock());
61 #if COLLECT_ON_EVERY_ALLOCATION
62 m_heap
->collectAllGarbage();
63 ASSERT(m_heap
->m_operationInProgress
== NoOperation
);
66 ASSERT(!m_freeList
.head
);
67 m_heap
->didAllocate(m_freeList
.bytes
);
69 void* result
= tryAllocate();
71 if (LIKELY(result
!= 0))
74 if (m_heap
->shouldCollect()) {
75 m_heap
->collect(Heap::DoNotSweep
);
77 result
= tryAllocate();
82 ASSERT(!m_heap
->shouldCollect());
84 MarkedBlock
* block
= allocateBlock();
88 result
= tryAllocate();
93 MarkedBlock
* MarkedAllocator::allocateBlock()
95 MarkedBlock
* block
= static_cast<MarkedBlock
*>(m_heap
->blockAllocator().allocate());
97 block
= MarkedBlock::recycle(block
, m_heap
, m_cellSize
, m_cellsNeedDestruction
);
99 block
= MarkedBlock::create(m_heap
, m_cellSize
, m_cellsNeedDestruction
);
101 m_markedSpace
->didAddBlock(block
);
106 void MarkedAllocator::addBlock(MarkedBlock
* block
)
108 ASSERT(!m_currentBlock
);
109 ASSERT(!m_freeList
.head
);
111 m_blockList
.append(block
);
112 m_currentBlock
= block
;
113 m_freeList
= block
->sweep(MarkedBlock::SweepToFreeList
);
116 void MarkedAllocator::removeBlock(MarkedBlock
* block
)
118 if (m_currentBlock
== block
)
120 m_blockList
.remove(block
);