summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/heap/IncrementalSweeper.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-06-01 10:36:58 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-06-01 10:36:58 +0200
commitb1e9e47fa11f608ae16bc07f97a2acf95bf80272 (patch)
treec88c45e80c9c44506e7cdf9a3bb39ebf82a8cd5b /Source/JavaScriptCore/heap/IncrementalSweeper.cpp
parentbe01689f43cf6882cf670d33df49ead1f570c53a (diff)
downloadqtwebkit-b1e9e47fa11f608ae16bc07f97a2acf95bf80272.tar.gz
Imported WebKit commit 499c84c99aa98e9870fa7eaa57db476c6d160d46 (http://svn.webkit.org/repository/webkit/trunk@119200)
Weekly update :). Particularly relevant changes for Qt are the use of the WebCore image decoders and direct usage of libpng/libjpeg if available in the system.
Diffstat (limited to 'Source/JavaScriptCore/heap/IncrementalSweeper.cpp')
-rw-r--r--Source/JavaScriptCore/heap/IncrementalSweeper.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/heap/IncrementalSweeper.cpp b/Source/JavaScriptCore/heap/IncrementalSweeper.cpp
new file mode 100644
index 000000000..08a9f6c73
--- /dev/null
+++ b/Source/JavaScriptCore/heap/IncrementalSweeper.cpp
@@ -0,0 +1,107 @@
+#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 decade = 60 * 60 * 24 * 365 * 10;
+static const CFTimeInterval sweepTimeSlicePerBlock = 0.01;
+static const CFTimeInterval sweepTimeMultiplier = 1.0 / sweepTimeSlicePerBlock;
+
+void IncrementalSweeper::timerDidFire(CFRunLoopTimerRef, void* info)
+{
+ Heap* heap = static_cast<Heap*>(info);
+ APIEntryShim shim(heap->globalData());
+ heap->sweeper()->doSweep(WTF::monotonicallyIncreasingTime());
+}
+
+IncrementalSweeper::IncrementalSweeper(Heap* heap, CFRunLoopRef runLoop)
+ : m_heap(heap)
+ , m_currentBlockToSweepIndex(0)
+ , m_lengthOfLastSweepIncrement(0.0)
+{
+ memset(&m_context, 0, sizeof(CFRunLoopTimerContext));
+ m_context.info = m_heap;
+ m_runLoop = runLoop;
+ m_timer.adoptCF(CFRunLoopTimerCreate(0, CFAbsoluteTimeGetCurrent(), decade, 0, 0, &timerDidFire, &m_context));
+ CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
+}
+
+IncrementalSweeper::~IncrementalSweeper()
+{
+ CFRunLoopRemoveTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
+ CFRunLoopTimerInvalidate(m_timer.get());
+}
+
+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() + 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()
+{
+}
+
+IncrementalSweeper::~IncrementalSweeper()
+{
+}
+
+PassOwnPtr<IncrementalSweeper> IncrementalSweeper::create(Heap*)
+{
+ return adoptPtr(new IncrementalSweeper());
+}
+
+void IncrementalSweeper::startSweeping(const HashSet<MarkedBlock*>&)
+{
+}
+
+#endif
+
+} // namespace JSC