Changeset 141089 in webkit


Ignore:
Timestamp:
Jan 29, 2013 2:51:39 AM (11 years ago)
Author:
allan.jensen@digia.com
Message:

[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):

Location:
trunk/Source/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r141069 r141089  
     12013-01-29  Allan Sandfeld Jensen  <allan.jensen@digia.com>
     2
     3        [Qt] Implement IncrementalSweeper and HeapTimer
     4        https://bugs.webkit.org/show_bug.cgi?id=103996
     5
     6        Reviewed by Simon Hausmann.
     7
     8        Implements the incremental sweeping garbage collection for the Qt platform.
     9
     10        * heap/HeapTimer.cpp:
     11        (JSC::HeapTimer::HeapTimer):
     12        (JSC::HeapTimer::~HeapTimer):
     13        (JSC::HeapTimer::timerEvent):
     14        (JSC::HeapTimer::synchronize):
     15        (JSC::HeapTimer::invalidate):
     16        (JSC::HeapTimer::didStartVMShutdown):
     17        * heap/HeapTimer.h:
     18        (HeapTimer):
     19        * heap/IncrementalSweeper.cpp:
     20        (JSC::IncrementalSweeper::IncrementalSweeper):
     21        (JSC::IncrementalSweeper::scheduleTimer):
     22        * heap/IncrementalSweeper.h:
     23        (IncrementalSweeper):
     24
    1252013-01-28  Filip Pizlo  <fpizlo@apple.com>
    226
  • trunk/Source/JavaScriptCore/heap/HeapTimer.cpp

    r127202 r141089  
    3434#include <wtf/Threading.h>
    3535
     36#if PLATFORM(QT)
     37#include <QCoreApplication>
     38#include <QMutexLocker>
     39#include <QThread>
     40#include <QTimerEvent>
     41#endif
     42
    3643namespace JSC {
    3744
     
    133140}
    134141
     142#elif PLATFORM(QT)
     143
     144HeapTimer::HeapTimer(JSGlobalData* globalData)
     145    : m_globalData(globalData)
     146    , m_newThread(0)
     147    , m_mutex(QMutex::NonRecursive)
     148{
     149    // The HeapTimer might be created before the runLoop is started,
     150    // but we need to ensure the thread has an eventDispatcher already.
     151    QEventLoop fakeLoop(this);
     152}
     153
     154HeapTimer::~HeapTimer()
     155{
     156}
     157
     158void HeapTimer::timerEvent(QTimerEvent*)
     159{
     160    QMutexLocker lock(&m_mutex);
     161    if (m_newThread) {
     162        // We need to wait with processing until we are on the right thread.
     163        return;
     164    }
     165
     166    APIEntryShim shim(m_globalData, APIEntryShimWithoutLock::DontRefGlobalData);
     167    doWork();
     168}
     169
     170void HeapTimer::customEvent(QEvent*)
     171{
     172    ASSERT(m_newThread);
     173    QMutexLocker lock(&m_mutex);
     174    moveToThread(m_newThread);
     175    m_newThread = 0;
     176}
     177
     178void HeapTimer::synchronize()
     179{
     180    if (thread() != QThread::currentThread()) {
     181        // We can only move from the objects own thread to another, so we fire an
     182        // event into the owning thread to trigger the move.
     183        // This must be processed before any timerEvents so giving it high priority.
     184        QMutexLocker lock(&m_mutex);
     185        m_newThread = QThread::currentThread();
     186        QCoreApplication::postEvent(this, new QEvent(QEvent::User), Qt::HighEventPriority);
     187    }
     188}
     189
     190void HeapTimer::invalidate()
     191{
     192    QMutexLocker lock(&m_mutex);
     193    m_timer.stop();
     194}
     195
     196void HeapTimer::didStartVMShutdown()
     197{
     198    invalidate();
     199    if (thread() == QThread::currentThread())
     200        delete this;
     201    else
     202        deleteLater();
     203}
     204
    135205#else
    136 
    137206HeapTimer::HeapTimer(JSGlobalData* globalData)
    138207    : m_globalData(globalData)
  • trunk/Source/JavaScriptCore/heap/HeapTimer.h

    r122624 r141089  
    3434#elif PLATFORM(BLACKBERRY)
    3535#include <BlackBerryPlatformTimer.h>
     36#elif PLATFORM(QT)
     37#include <QBasicTimer>
     38#include <QMutex>
     39#include <QObject>
     40#include <QThread>
    3641#endif
    3742
     
    3944
    4045class JSGlobalData;
    41    
     46
     47#if PLATFORM(QT)
     48class HeapTimer : public QObject {
     49#else
    4250class HeapTimer {
     51#endif
    4352public:
    4453#if USE(CF)
     
    7079
    7180    BlackBerry::Platform::Timer<HeapTimer> m_timer;
     81#elif PLATFORM(QT)
     82    void timerEvent(QTimerEvent*);
     83    void customEvent(QEvent*);
     84    QBasicTimer m_timer;
     85    QThread* m_newThread;
     86    QMutex m_mutex;
    7287#endif
    7388   
  • trunk/Source/JavaScriptCore/heap/IncrementalSweeper.cpp

    r131213 r141089  
    3838namespace JSC {
    3939
    40 #if USE(CF) || PLATFORM(BLACKBERRY)
     40#if USE(CF) || PLATFORM(BLACKBERRY) || PLATFORM(QT)
    4141
    4242static const double sweepTimeSlice = .01; // seconds
     
    6868}
    6969
    70 #elif PLATFORM(BLACKBERRY)
     70#elif PLATFORM(BLACKBERRY) || PLATFORM(QT)
    7171   
    7272IncrementalSweeper::IncrementalSweeper(Heap* heap)
    7373    : HeapTimer(heap->globalData())
    7474    , m_currentBlockToSweepIndex(0)
     75    , m_blocksToSweep(heap->m_blockSnapshot)
    7576{
    7677}
     
    8384void IncrementalSweeper::scheduleTimer()
    8485{
     86#if PLATFORM(QT)
     87    m_timer.start(sweepTimeSlice * sweepTimeMultiplier * 1000, this);
     88#else
    8589    m_timer.start(sweepTimeSlice * sweepTimeMultiplier);
     90#endif
    8691}
    8792
  • trunk/Source/JavaScriptCore/heap/IncrementalSweeper.h

    r131213 r141089  
    4747
    4848private:
    49 #if USE(CF) || PLATFORM(BLACKBERRY)
     49#if USE(CF) || PLATFORM(BLACKBERRY) || PLATFORM(QT)
    5050#if USE(CF)
    5151    IncrementalSweeper(Heap*, CFRunLoopRef);
Note: See TracChangeset for help on using the changeset viewer.