summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore
diff options
context:
space:
mode:
authorSergio Ahumada <sergio.ahumada@digia.com>2013-03-22 15:31:08 +0100
committerSergio Ahumada <sergio.ahumada@digia.com>2013-03-22 15:31:08 +0100
commite8a56c51780cd3e3a0043c4f6a8849d4c2d87dd6 (patch)
tree85dc5ef1ce13d7e197c3bb3fd6f845ab7da93449 /Source/JavaScriptCore
parent68753e64d1d606d7627fae83e05863d110226c15 (diff)
parent99783e2c7e917224da401ddbd33354c131b3a377 (diff)
downloadqtwebkit-e8a56c51780cd3e3a0043c4f6a8849d4c2d87dd6.tar.gz
Merge branch 'dev' into stable
This starts Qt 5.1 release cycle Conflicts: Source/sync.profile Change-Id: I570f2804b9e5baf6d2b5573d1030887866077124
Diffstat (limited to 'Source/JavaScriptCore')
-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
-rw-r--r--Source/JavaScriptCore/runtime/GCActivityCallback.cpp29
-rw-r--r--Source/JavaScriptCore/runtime/GCActivityCallback.h8
6 files changed, 126 insertions, 10 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..66d28f228 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) && !USE(CF)
+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
diff --git a/Source/JavaScriptCore/runtime/GCActivityCallback.cpp b/Source/JavaScriptCore/runtime/GCActivityCallback.cpp
index 74cbdbaef..0c07b5e02 100644
--- a/Source/JavaScriptCore/runtime/GCActivityCallback.cpp
+++ b/Source/JavaScriptCore/runtime/GCActivityCallback.cpp
@@ -40,14 +40,15 @@
namespace JSC {
-#if USE(CF)
+#if USE(CF) || PLATFORM(QT)
const double gcTimeSlicePerMB = 0.01; // Percentage of CPU time we will spend to reclaim 1 MB
const double maxGCTimeSlice = 0.05; // The maximum amount of CPU time we want to use for opportunistic timer-triggered collections.
const double timerSlop = 2.0; // Fudge factor to avoid performance cost of resetting timer.
const double pagingTimeOut = 0.1; // Time in seconds to allow opportunistic timer to iterate over all blocks to see if the Heap is paged out.
-const CFTimeInterval hour = 60 * 60;
+const double hour = 60 * 60;
+#if USE(CF)
DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
: GCActivityCallback(heap->globalData(), CFRunLoopGetCurrent())
, m_delay(s_decade)
@@ -59,6 +60,13 @@ DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap, CFRunLoopRef ru
, m_delay(s_decade)
{
}
+#elif PLATFORM(QT)
+DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
+ : GCActivityCallback(heap->globalData())
+ , m_delay(hour)
+{
+}
+#endif
void DefaultGCActivityCallback::doWork()
{
@@ -78,6 +86,7 @@ void DefaultGCActivityCallback::doWork()
heap->collect(Heap::DoNotSweep);
}
+#if USE(CF)
void DefaultGCActivityCallback::scheduleTimer(double newDelay)
{
if (newDelay * timerSlop > m_delay)
@@ -92,6 +101,22 @@ void DefaultGCActivityCallback::cancelTimer()
m_delay = s_decade;
CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
}
+#elif PLATFORM(QT)
+
+void DefaultGCActivityCallback::scheduleTimer(double newDelay)
+{
+ if (newDelay * timerSlop > m_delay)
+ return;
+ m_delay = newDelay;
+ m_timer.start(newDelay * 1000, this);
+}
+
+void DefaultGCActivityCallback::cancelTimer()
+{
+ m_delay = hour;
+ m_timer.stop();
+}
+#endif
void DefaultGCActivityCallback::didAllocate(size_t bytes)
{
diff --git a/Source/JavaScriptCore/runtime/GCActivityCallback.h b/Source/JavaScriptCore/runtime/GCActivityCallback.h
index c112a7120..3522e6c8e 100644
--- a/Source/JavaScriptCore/runtime/GCActivityCallback.h
+++ b/Source/JavaScriptCore/runtime/GCActivityCallback.h
@@ -57,7 +57,7 @@ protected:
, m_enabled(true)
{
}
-# else
+#else
GCActivityCallback(JSGlobalData* globalData)
: HeapTimer(globalData)
, m_enabled(true)
@@ -83,10 +83,12 @@ public:
#if USE(CF)
protected:
DefaultGCActivityCallback(Heap*, CFRunLoopRef);
-
+#endif
+#if USE(CF) || PLATFORM(QT)
+protected:
void cancelTimer();
void scheduleTimer(double);
-
+
private:
double m_delay;
#endif