blob: 0d0116f42120c4ff3035b3df22b88dc34748a36e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#include "config.h"
#include "IncrementalSweeper.h"
#include "APIShims.h"
#include "Heap.h"
#include "JSObject.h"
#include "JSString.h"
#include "MarkedBlock.h"
#include "ScopeChain.h"
#include <wtf/HashSet.h>
#include <wtf/WTFThreadData.h>
namespace JSC {
#if USE(CF)
static const CFTimeInterval sweepTimeSlicePerBlock = 0.01;
static const CFTimeInterval sweepTimeMultiplier = 1.0 / sweepTimeSlicePerBlock;
void IncrementalSweeper::doWork()
{
APIEntryShim shim(m_globalData);
doSweep(WTF::monotonicallyIncreasingTime());
}
IncrementalSweeper::IncrementalSweeper(Heap* heap, CFRunLoopRef runLoop)
: HeapTimer(heap->globalData(), runLoop)
, m_currentBlockToSweepIndex(0)
, m_lengthOfLastSweepIncrement(0.0)
{
}
PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap* heap)
{
return adoptPtr(new IncrementalSweeper(heap, CFRunLoopGetCurrent()));
}
void IncrementalSweeper::scheduleTimer()
{
CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + (m_lengthOfLastSweepIncrement * sweepTimeMultiplier));
}
void IncrementalSweeper::cancelTimer()
{
CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
}
void IncrementalSweeper::doSweep(double sweepBeginTime)
{
for (; m_currentBlockToSweepIndex < m_blocksToSweep.size(); m_currentBlockToSweepIndex++) {
MarkedBlock* nextBlock = m_blocksToSweep[m_currentBlockToSweepIndex];
if (!nextBlock->needsSweeping())
continue;
nextBlock->sweep();
m_blocksToSweep[m_currentBlockToSweepIndex++] = 0;
m_lengthOfLastSweepIncrement = WTF::monotonicallyIncreasingTime() - sweepBeginTime;
scheduleTimer();
return;
}
m_blocksToSweep.clear();
cancelTimer();
}
void IncrementalSweeper::startSweeping(const HashSet<MarkedBlock*>& blockSnapshot)
{
WTF::copyToVector(blockSnapshot, m_blocksToSweep);
m_currentBlockToSweepIndex = 0;
scheduleTimer();
}
#else
IncrementalSweeper::IncrementalSweeper(JSGlobalData* globalData)
: HeapTimer(globalData)
{
}
void IncrementalSweeper::doWork()
{
}
PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap* heap)
{
return adoptPtr(new IncrementalSweeper(heap->globalData()));
}
void IncrementalSweeper::startSweeping(const HashSet<MarkedBlock*>&)
{
}
#endif
} // namespace JSC
|