]>
git.saurik.com Git - apple/javascriptcore.git/blob - heap/HeapTimer.cpp
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "HeapTimer.h"
29 #include "GCActivityCallback.h"
30 #include "IncrementalSweeper.h"
33 #include "JSCInlines.h"
34 #include <wtf/MainThread.h>
35 #include <wtf/Threading.h>
45 const CFTimeInterval
HeapTimer::s_decade
= 60 * 60 * 24 * 365 * 10;
47 static const void* retainAPILock(const void* info
)
49 static_cast<JSLock
*>(const_cast<void*>(info
))->ref();
53 static void releaseAPILock(const void* info
)
55 static_cast<JSLock
*>(const_cast<void*>(info
))->deref();
58 HeapTimer::HeapTimer(VM
* vm
, CFRunLoopRef runLoop
)
62 memset(&m_context
, 0, sizeof(CFRunLoopTimerContext
));
63 m_context
.info
= &vm
->apiLock();
64 m_context
.retain
= retainAPILock
;
65 m_context
.release
= releaseAPILock
;
66 m_timer
= adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault
, s_decade
, s_decade
, 0, 0, HeapTimer::timerDidFire
, &m_context
));
67 CFRunLoopAddTimer(m_runLoop
.get(), m_timer
.get(), kCFRunLoopCommonModes
);
70 HeapTimer::~HeapTimer()
72 CFRunLoopRemoveTimer(m_runLoop
.get(), m_timer
.get(), kCFRunLoopCommonModes
);
73 CFRunLoopTimerInvalidate(m_timer
.get());
76 void HeapTimer::timerDidFire(CFRunLoopTimerRef timer
, void* context
)
78 JSLock
* apiLock
= static_cast<JSLock
*>(context
);
81 VM
* vm
= apiLock
->vm();
82 // The VM has been destroyed, so we should just give up.
88 HeapTimer
* heapTimer
= 0;
89 if (vm
->heap
.fullActivityCallback() && vm
->heap
.fullActivityCallback()->m_timer
.get() == timer
)
90 heapTimer
= vm
->heap
.fullActivityCallback();
91 else if (vm
->heap
.edenActivityCallback() && vm
->heap
.edenActivityCallback()->m_timer
.get() == timer
)
92 heapTimer
= vm
->heap
.edenActivityCallback();
93 else if (vm
->heap
.sweeper()->m_timer
.get() == timer
)
94 heapTimer
= vm
->heap
.sweeper();
96 RELEASE_ASSERT_NOT_REACHED();
99 JSLockHolder
locker(vm
);
108 HeapTimer::HeapTimer(VM
* vm
)
114 HeapTimer::~HeapTimer()
119 Ecore_Timer
* HeapTimer::add(double delay
, void* agent
)
121 return ecore_timer_add(delay
, reinterpret_cast<Ecore_Task_Cb
>(timerEvent
), agent
);
124 void HeapTimer::stop()
129 ecore_timer_del(m_timer
);
133 bool HeapTimer::timerEvent(void* info
)
135 HeapTimer
* agent
= static_cast<HeapTimer
*>(info
);
137 JSLockHolder
locker(agent
->m_vm
);
141 return ECORE_CALLBACK_CANCEL
;
144 HeapTimer::HeapTimer(VM
* vm
)
149 HeapTimer::~HeapTimer()
153 void HeapTimer::invalidate()