summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/heap
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/heap')
-rw-r--r--Source/JavaScriptCore/heap/HeapTimer.cpp71
-rw-r--r--Source/JavaScriptCore/heap/HeapTimer.h17
-rw-r--r--Source/JavaScriptCore/heap/IncrementalSweeper.cpp9
-rw-r--r--Source/JavaScriptCore/heap/IncrementalSweeper.h2
4 files changed, 94 insertions, 5 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)
{
diff --git a/Source/JavaScriptCore/heap/HeapTimer.h b/Source/JavaScriptCore/heap/HeapTimer.h
index 88715098a..e0fcda672 100644
--- a/Source/JavaScriptCore/heap/HeapTimer.h
+++ b/Source/JavaScriptCore/heap/HeapTimer.h
@@ -33,13 +33,22 @@
#include <CoreFoundation/CoreFoundation.h>
#elif PLATFORM(BLACKBERRY)
#include <BlackBerryPlatformTimer.h>
+#elif PLATFORM(QT)
+#include <QBasicTimer>
+#include <QMutex>
+#include <QObject>
+#include <QThread>
#endif
namespace JSC {
class JSGlobalData;
-
+
+#if PLATFORM(QT)
+class HeapTimer : public QObject {
+#else
class HeapTimer {
+#endif
public:
#if USE(CF)
HeapTimer(JSGlobalData*, CFRunLoopRef);
@@ -69,6 +78,12 @@ protected:
void timerDidFire();
BlackBerry::Platform::Timer<HeapTimer> m_timer;
+#elif PLATFORM(QT)
+ void timerEvent(QTimerEvent*);
+ void customEvent(QEvent*);
+ QBasicTimer m_timer;
+ QThread* m_newThread;
+ QMutex m_mutex;
#endif
private:
diff --git a/Source/JavaScriptCore/heap/IncrementalSweeper.cpp b/Source/JavaScriptCore/heap/IncrementalSweeper.cpp
index 4aec4dd51..41bc7f5e4 100644
--- a/Source/JavaScriptCore/heap/IncrementalSweeper.cpp
+++ b/Source/JavaScriptCore/heap/IncrementalSweeper.cpp
@@ -37,7 +37,7 @@
namespace JSC {
-#if USE(CF) || PLATFORM(BLACKBERRY)
+#if USE(CF) || PLATFORM(BLACKBERRY) || PLATFORM(QT)
static const double sweepTimeSlice = .01; // seconds
static const double sweepTimeTotal = .10;
@@ -67,11 +67,12 @@ void IncrementalSweeper::cancelTimer()
CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
}
-#elif PLATFORM(BLACKBERRY)
+#elif PLATFORM(BLACKBERRY) || PLATFORM(QT)
IncrementalSweeper::IncrementalSweeper(Heap* heap)
: HeapTimer(heap->globalData())
, m_currentBlockToSweepIndex(0)
+ , m_blocksToSweep(heap->m_blockSnapshot)
{
}
@@ -82,7 +83,11 @@ IncrementalSweeper* IncrementalSweeper::create(Heap* heap)
void IncrementalSweeper::scheduleTimer()
{
+#if PLATFORM(QT)
+ m_timer.start(sweepTimeSlice * sweepTimeMultiplier * 1000, this);
+#else
m_timer.start(sweepTimeSlice * sweepTimeMultiplier);
+#endif
}
void IncrementalSweeper::cancelTimer()
diff --git a/Source/JavaScriptCore/heap/IncrementalSweeper.h b/Source/JavaScriptCore/heap/IncrementalSweeper.h
index 5b9267bc7..7b0ae99ab 100644
--- a/Source/JavaScriptCore/heap/IncrementalSweeper.h
+++ b/Source/JavaScriptCore/heap/IncrementalSweeper.h
@@ -46,7 +46,7 @@ public:
void willFinishSweeping();
private:
-#if USE(CF) || PLATFORM(BLACKBERRY)
+#if USE(CF) || PLATFORM(BLACKBERRY) || PLATFORM(QT)
#if USE(CF)
IncrementalSweeper(Heap*, CFRunLoopRef);
#else