summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/heap/HeapTimer.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2013-03-14 14:10:22 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-18 17:25:46 +0100
commit597984021ca00fd98a0dfe2effd742c6e7bd4190 (patch)
treeb18e79f91719f072f339b7b5b068b9004aa7d3d7 /Source/JavaScriptCore/heap/HeapTimer.cpp
parent3774b52275c59d74571b0e1f87950dcfc257d408 (diff)
downloadqtwebkit-597984021ca00fd98a0dfe2effd742c6e7bd4190.tar.gz
[Qt] Implement IncrementalSweeper and HeapTimer
https://bugs.webkit.org/show_bug.cgi?id=103996 Reviewed by Simon Hausmann. Implements the incremental sweeping garbage collection for the Qt platform. * heap/HeapTimer.cpp: (JSC::HeapTimer::HeapTimer): (JSC::HeapTimer::~HeapTimer): (JSC::HeapTimer::timerEvent): (JSC::HeapTimer::synchronize): (JSC::HeapTimer::invalidate): (JSC::HeapTimer::didStartVMShutdown): * heap/HeapTimer.h: (HeapTimer): * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::IncrementalSweeper): (JSC::IncrementalSweeper::scheduleTimer): * heap/IncrementalSweeper.h: (IncrementalSweeper): Change-Id: I47b874c050e08519cf5e3ed5a98a98ac8785971f git-svn-id: http://svn.webkit.org/repository/webkit/trunk@141089 268f45cc-cd09-0410-ab3c-d52691b4dbfc Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'Source/JavaScriptCore/heap/HeapTimer.cpp')
-rw-r--r--Source/JavaScriptCore/heap/HeapTimer.cpp71
1 files changed, 70 insertions, 1 deletions
diff --git a/Source/JavaScriptCore/heap/HeapTimer.cpp b/Source/JavaScriptCore/heap/HeapTimer.cpp
index 214f86757..d69ee9607 100644
--- a/Source/JavaScriptCore/heap/HeapTimer.cpp
+++ b/Source/JavaScriptCore/heap/HeapTimer.cpp
@@ -33,6 +33,13 @@
#include <wtf/MainThread.h>
#include <wtf/Threading.h>
+#if PLATFORM(QT)
+#include <QCoreApplication>
+#include <QMutexLocker>
+#include <QThread>
+#include <QTimerEvent>
+#endif
+
namespace JSC {
#if USE(CF)
@@ -132,8 +139,70 @@ void HeapTimer::didStartVMShutdown()
delete this;
}
-#else
+#elif PLATFORM(QT)
+
+HeapTimer::HeapTimer(JSGlobalData* globalData)
+ : m_globalData(globalData)
+ , m_newThread(0)
+ , m_mutex(QMutex::NonRecursive)
+{
+ // The HeapTimer might be created before the runLoop is started,
+ // but we need to ensure the thread has an eventDispatcher already.
+ QEventLoop fakeLoop(this);
+}
+
+HeapTimer::~HeapTimer()
+{
+}
+
+void HeapTimer::timerEvent(QTimerEvent*)
+{
+ QMutexLocker lock(&m_mutex);
+ if (m_newThread) {
+ // We need to wait with processing until we are on the right thread.
+ return;
+ }
+
+ APIEntryShim shim(m_globalData, APIEntryShimWithoutLock::DontRefGlobalData);
+ doWork();
+}
+void HeapTimer::customEvent(QEvent*)
+{
+ ASSERT(m_newThread);
+ QMutexLocker lock(&m_mutex);
+ moveToThread(m_newThread);
+ m_newThread = 0;
+}
+
+void HeapTimer::synchronize()
+{
+ if (thread() != QThread::currentThread()) {
+ // We can only move from the objects own thread to another, so we fire an
+ // event into the owning thread to trigger the move.
+ // This must be processed before any timerEvents so giving it high priority.
+ QMutexLocker lock(&m_mutex);
+ m_newThread = QThread::currentThread();
+ QCoreApplication::postEvent(this, new QEvent(QEvent::User), Qt::HighEventPriority);
+ }
+}
+
+void HeapTimer::invalidate()
+{
+ QMutexLocker lock(&m_mutex);
+ m_timer.stop();
+}
+
+void HeapTimer::didStartVMShutdown()
+{
+ invalidate();
+ if (thread() == QThread::currentThread())
+ delete this;
+ else
+ deleteLater();
+}
+
+#else
HeapTimer::HeapTimer(JSGlobalData* globalData)
: m_globalData(globalData)
{