Title: [215228] trunk/Source
Revision
215228
Author
[email protected]
Date
2017-04-11 07:56:21 -0700 (Tue, 11 Apr 2017)

Log Message

[JSC][GTK] Use RunLoop::Timer in GTK port
https://bugs.webkit.org/show_bug.cgi?id=170723

Reviewed by Carlos Garcia Campos.

Source/_javascript_Core:

This patch makes GTK port use RunLoop::Timer for JSRunLoopTimer.
Only Cocoa-based ports use platform-specific Timer because it
has additional feature that changes RunLoop to the WebThread one.

And we enable Heap timers in all the ports including JSCOnly port.

* heap/EdenGCActivityCallback.cpp:
(JSC::EdenGCActivityCallback::lastGCLength):
* heap/EdenGCActivityCallback.h:
* heap/FullGCActivityCallback.cpp:
(JSC::FullGCActivityCallback::lastGCLength):
* heap/FullGCActivityCallback.h:
* heap/GCActivityCallback.cpp:
(JSC::GCActivityCallback::GCActivityCallback):
(JSC::GCActivityCallback::doWork):
(JSC::GCActivityCallback::scheduleTimer):
(JSC::GCActivityCallback::cancelTimer):
(JSC::GCActivityCallback::nextFireTime):
(JSC::GCActivityCallback::didAllocate):
* heap/GCActivityCallback.h:
* heap/IncrementalSweeper.cpp:
(JSC::IncrementalSweeper::doWork):
(JSC::IncrementalSweeper::doSweep):
* heap/IncrementalSweeper.h:
* heap/StopIfNecessaryTimer.cpp:
(JSC::StopIfNecessaryTimer::scheduleSoon):
* runtime/JSRunLoopTimer.cpp:
(JSC::JSRunLoopTimer::setRunLoop):
(JSC::JSRunLoopTimer::scheduleTimer):
(JSC::JSRunLoopTimer::cancelTimer):
(JSC::JSRunLoopTimer::JSRunLoopTimer):
(JSC::JSRunLoopTimer::~JSRunLoopTimer):
(JSC::JSRunLoopTimer::timerDidFireCallback):
* runtime/JSRunLoopTimer.h:
* runtime/PromiseDeferredTimer.cpp:
(JSC::PromiseDeferredTimer::scheduleWorkSoon):

Source/WTF:

Add secondsUntilFire method. And add setName and setPriority
for GTK RunLoop::Timer.

* wtf/RunLoop.h:
* wtf/cf/RunLoopCF.cpp:
(WTF::RunLoop::TimerBase::secondsUntilFire):
* wtf/generic/RunLoopGeneric.cpp:
(WTF::RunLoop::TimerBase::secondsUntilFire):
* wtf/glib/RunLoopGLib.cpp:
(WTF::RunLoop::TimerBase::setName):
(WTF::RunLoop::TimerBase::secondsUntilFire):
* wtf/win/RunLoopWin.cpp:
(WTF::RunLoop::TimerBase::timerFired):
(WTF::RunLoop::TimerBase::start):
(WTF::RunLoop::TimerBase::isActive):
(WTF::RunLoop::TimerBase::secondsUntilFire):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (215227 => 215228)


--- trunk/Source/_javascript_Core/ChangeLog	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-04-11 14:56:21 UTC (rev 215228)
@@ -1,3 +1,47 @@
+2017-04-11  Yusuke Suzuki  <[email protected]>
+
+        [JSC][GTK] Use RunLoop::Timer in GTK port
+        https://bugs.webkit.org/show_bug.cgi?id=170723
+
+        Reviewed by Carlos Garcia Campos.
+
+        This patch makes GTK port use RunLoop::Timer for JSRunLoopTimer.
+        Only Cocoa-based ports use platform-specific Timer because it
+        has additional feature that changes RunLoop to the WebThread one.
+
+        And we enable Heap timers in all the ports including JSCOnly port.
+
+        * heap/EdenGCActivityCallback.cpp:
+        (JSC::EdenGCActivityCallback::lastGCLength):
+        * heap/EdenGCActivityCallback.h:
+        * heap/FullGCActivityCallback.cpp:
+        (JSC::FullGCActivityCallback::lastGCLength):
+        * heap/FullGCActivityCallback.h:
+        * heap/GCActivityCallback.cpp:
+        (JSC::GCActivityCallback::GCActivityCallback):
+        (JSC::GCActivityCallback::doWork):
+        (JSC::GCActivityCallback::scheduleTimer):
+        (JSC::GCActivityCallback::cancelTimer):
+        (JSC::GCActivityCallback::nextFireTime):
+        (JSC::GCActivityCallback::didAllocate):
+        * heap/GCActivityCallback.h:
+        * heap/IncrementalSweeper.cpp:
+        (JSC::IncrementalSweeper::doWork):
+        (JSC::IncrementalSweeper::doSweep):
+        * heap/IncrementalSweeper.h:
+        * heap/StopIfNecessaryTimer.cpp:
+        (JSC::StopIfNecessaryTimer::scheduleSoon):
+        * runtime/JSRunLoopTimer.cpp:
+        (JSC::JSRunLoopTimer::setRunLoop):
+        (JSC::JSRunLoopTimer::scheduleTimer):
+        (JSC::JSRunLoopTimer::cancelTimer):
+        (JSC::JSRunLoopTimer::JSRunLoopTimer):
+        (JSC::JSRunLoopTimer::~JSRunLoopTimer):
+        (JSC::JSRunLoopTimer::timerDidFireCallback):
+        * runtime/JSRunLoopTimer.h:
+        * runtime/PromiseDeferredTimer.cpp:
+        (JSC::PromiseDeferredTimer::scheduleWorkSoon):
+
 2017-04-11  Guillaume Emont  <[email protected]>
 
         [jsc][mips] Add missing MacroAssembler functions after r214187

Modified: trunk/Source/_javascript_Core/heap/EdenGCActivityCallback.cpp (215227 => 215228)


--- trunk/Source/_javascript_Core/heap/EdenGCActivityCallback.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/heap/EdenGCActivityCallback.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -31,8 +31,6 @@
 
 namespace JSC {
 
-#if USE(CF) || USE(GLIB)
-
 EdenGCActivityCallback::EdenGCActivityCallback(Heap* heap)
     : GCActivityCallback(heap)
 {
@@ -43,9 +41,9 @@
     m_vm->heap.collectAsync(CollectionScope::Eden);
 }
 
-double EdenGCActivityCallback::lastGCLength()
+Seconds EdenGCActivityCallback::lastGCLength()
 {
-    return m_vm->heap.lastEdenGCLength().seconds();
+    return m_vm->heap.lastEdenGCLength();
 }
 
 double EdenGCActivityCallback::deathRate()
@@ -69,32 +67,4 @@
     return std::min((static_cast<double>(bytes) / MB) * Options::percentCPUPerMBForEdenTimer(), Options::collectionTimerMaxPercentCPU());
 }
 
-#else
-
-EdenGCActivityCallback::EdenGCActivityCallback(Heap* heap)
-    : GCActivityCallback(heap->vm())
-{
-}
-
-void EdenGCActivityCallback::doCollection()
-{
-}
-
-double EdenGCActivityCallback::lastGCLength()
-{
-    return 0;
-}
-
-double EdenGCActivityCallback::deathRate()
-{
-    return 0;
-}
-
-double EdenGCActivityCallback::gcTimeSlice(size_t)
-{
-    return 0;
-}
-
-#endif // USE(CF) || USE(GLIB)
-
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/heap/EdenGCActivityCallback.h (215227 => 215228)


--- trunk/Source/_javascript_Core/heap/EdenGCActivityCallback.h	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/heap/EdenGCActivityCallback.h	2017-04-11 14:56:21 UTC (rev 215228)
@@ -36,7 +36,7 @@
     void doCollection() override;
 
 protected:
-    double lastGCLength() override;
+    Seconds lastGCLength() override;
     double gcTimeSlice(size_t bytes) override;
     double deathRate() override;
 };

Modified: trunk/Source/_javascript_Core/heap/FullGCActivityCallback.cpp (215227 => 215228)


--- trunk/Source/_javascript_Core/heap/FullGCActivityCallback.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/heap/FullGCActivityCallback.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -30,8 +30,6 @@
 
 namespace JSC {
 
-#if USE(CF) || USE(GLIB)
-
 #if !PLATFORM(IOS)
 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.
 #endif
@@ -58,9 +56,9 @@
     heap.collectAsync(CollectionScope::Full);
 }
 
-double FullGCActivityCallback::lastGCLength()
+Seconds FullGCActivityCallback::lastGCLength()
 {
-    return m_vm->heap.lastFullGCLength().seconds();
+    return m_vm->heap.lastFullGCLength();
 }
 
 double FullGCActivityCallback::deathRate()
@@ -84,32 +82,4 @@
     return std::min((static_cast<double>(bytes) / MB) * Options::percentCPUPerMBForFullTimer(), Options::collectionTimerMaxPercentCPU());
 }
 
-#else
-
-FullGCActivityCallback::FullGCActivityCallback(Heap* heap)
-    : GCActivityCallback(heap)
-{
-}
-
-void FullGCActivityCallback::doCollection()
-{
-}
-
-double FullGCActivityCallback::lastGCLength()
-{
-    return 0;
-}
-
-double FullGCActivityCallback::deathRate()
-{
-    return 0;
-}
-
-double FullGCActivityCallback::gcTimeSlice(size_t)
-{
-    return 0;
-}
-
-#endif // USE(CF) || USE(GLIB)
-
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/heap/FullGCActivityCallback.h (215227 => 215228)


--- trunk/Source/_javascript_Core/heap/FullGCActivityCallback.h	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/heap/FullGCActivityCallback.h	2017-04-11 14:56:21 UTC (rev 215228)
@@ -39,7 +39,7 @@
     void setDidSyncGCRecently() { m_didSyncGCRecently = true; }
 
 protected:
-    double lastGCLength() override;
+    Seconds lastGCLength() override;
     double gcTimeSlice(size_t bytes) override;
     double deathRate() override;
 

Modified: trunk/Source/_javascript_Core/heap/GCActivityCallback.cpp (215227 => 215228)


--- trunk/Source/_javascript_Core/heap/GCActivityCallback.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/heap/GCActivityCallback.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -34,30 +34,16 @@
 #include "JSObject.h"
 #include "VM.h"
 
-#if USE(GLIB)
-#include <glib.h>
-#endif
-
 namespace JSC {
 
 bool GCActivityCallback::s_shouldCreateGCTimer = true;
 
-#if USE(CF) || USE(GLIB)
-
 const double timerSlop = 2.0; // Fudge factor to avoid performance cost of resetting timer.
 
-#if USE(CF)
 GCActivityCallback::GCActivityCallback(Heap* heap)
     : GCActivityCallback(heap->vm())
 {
 }
-#elif USE(GLIB)
-GCActivityCallback::GCActivityCallback(Heap* heap)
-    : GCActivityCallback(heap->vm())
-{
-    g_source_set_ready_time(m_timer.get(), g_get_monotonic_time() + s_decade * G_USEC_PER_SEC);
-}
-#endif
 
 void GCActivityCallback::doWork()
 {
@@ -67,7 +53,7 @@
     
     JSLockHolder locker(m_vm);
     if (heap->isDeferred()) {
-        scheduleTimer(0);
+        scheduleTimer(0_s);
         return;
     }
 
@@ -75,43 +61,49 @@
 }
 
 #if USE(CF)
-void GCActivityCallback::scheduleTimer(double newDelay)
+void GCActivityCallback::scheduleTimer(Seconds newDelay)
 {
     if (newDelay * timerSlop > m_delay)
         return;
-    double delta = m_delay - newDelay;
+    Seconds delta = m_delay - newDelay;
     m_delay = newDelay;
-    m_nextFireTime = WTF::currentTime() + newDelay;
-    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFRunLoopTimerGetNextFireDate(m_timer.get()) - delta);
+    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFRunLoopTimerGetNextFireDate(m_timer.get()) - delta.seconds());
 }
 
 void GCActivityCallback::cancelTimer()
 {
     m_delay = s_decade;
-    m_nextFireTime = 0;
-    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
+    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade.seconds());
 }
-#elif USE(GLIB)
-void GCActivityCallback::scheduleTimer(double newDelay)
+
+double GCActivityCallback::nextFireTime()
 {
-    ASSERT(newDelay >= 0);
+    return CFRunLoopTimerGetNextFireDate(m_timer.get());
+}
+#else
+void GCActivityCallback::scheduleTimer(Seconds newDelay)
+{
     if (newDelay * timerSlop > m_delay)
         return;
-
-    double delta = m_delay - newDelay;
+    Seconds delta = m_delay - newDelay;
     m_delay = newDelay;
-    m_nextFireTime = WTF::currentTime() + newDelay;
 
-    gint64 readyTime = g_source_get_ready_time(m_timer.get());
-    g_source_set_ready_time(m_timer.get(), readyTime - delta * G_USEC_PER_SEC);
+    Seconds secondsUntilFire = m_timer.secondsUntilFire();
+    m_timer.startOneShot(secondsUntilFire - delta);
 }
 
 void GCActivityCallback::cancelTimer()
 {
     m_delay = s_decade;
-    m_nextFireTime = 0;
-    g_source_set_ready_time(m_timer.get(), g_get_monotonic_time() + s_decade * G_USEC_PER_SEC);
+    m_timer.startOneShot(s_decade);
 }
+
+double GCActivityCallback::nextFireTime()
+{
+    // FIXME: Should return MonotonicTime.
+    // https://bugs.webkit.org/show_bug.cgi?id=170725
+    return (MonotonicTime::now() + m_timer.secondsUntilFire()).secondsSinceEpoch().value();
+}
 #endif
 
 void GCActivityCallback::didAllocate(size_t bytes)
@@ -121,7 +113,7 @@
     if (!bytes)
         bytes = 1;
     double bytesExpectedToReclaim = static_cast<double>(bytes) * deathRate();
-    double newDelay = lastGCLength() / gcTimeSlice(bytesExpectedToReclaim);
+    Seconds newDelay = lastGCLength() / gcTimeSlice(bytesExpectedToReclaim);
     scheduleTimer(newDelay);
 }
 
@@ -135,30 +127,5 @@
     cancelTimer();
 }
 
-#else
-
-GCActivityCallback::GCActivityCallback(Heap* heap)
-    : GCActivityCallback(heap->vm())
-{
 }
 
-void GCActivityCallback::doWork()
-{
-}
-
-void GCActivityCallback::didAllocate(size_t)
-{
-}
-
-void GCActivityCallback::willCollect()
-{
-}
-
-void GCActivityCallback::cancel()
-{
-}
-
-#endif
-
-}
-

Modified: trunk/Source/_javascript_Core/heap/GCActivityCallback.h (215227 => 215228)


--- trunk/Source/_javascript_Core/heap/GCActivityCallback.h	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/heap/GCActivityCallback.h	2017-04-11 14:56:21 UTC (rev 215228)
@@ -60,16 +60,13 @@
 
     static bool s_shouldCreateGCTimer;
 
-#if USE(CF) || USE(GLIB)
-    double nextFireTime() const { return m_nextFireTime; }
-#endif
+    JS_EXPORT_PRIVATE double nextFireTime();
 
 protected:
-    virtual double lastGCLength() = 0;
+    virtual Seconds lastGCLength() = 0;
     virtual double gcTimeSlice(size_t bytes) = 0;
     virtual double deathRate() = 0;
 
-#if USE(CF)
     GCActivityCallback(VM* vm)
         : Base(vm)
         , m_enabled(true)
@@ -76,32 +73,15 @@
         , m_delay(s_decade)
     {
     }
-#elif USE(GLIB)
-    GCActivityCallback(VM* vm)
-        : Base(vm)
-        , m_enabled(true)
-        , m_delay(s_decade)
-    {
-    }
-#else
-    GCActivityCallback(VM* vm)
-        : Base(vm)
-        , m_enabled(true)
-    {
-    }
-#endif
 
     bool m_enabled;
 
-#if USE(CF) || USE(GLIB)
 protected:
     void cancelTimer();
-    void scheduleTimer(double);
+    void scheduleTimer(Seconds);
 
 private:
-    double m_delay;
-    double m_nextFireTime { 0 };
-#endif
+    Seconds m_delay;
 };
 
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/heap/IncrementalSweeper.cpp (215227 => 215228)


--- trunk/Source/_javascript_Core/heap/IncrementalSweeper.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/heap/IncrementalSweeper.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -35,7 +35,7 @@
 
 namespace JSC {
 
-static const double sweepTimeSlice = .01; // seconds
+static const Seconds sweepTimeSlice = 10_ms; // seconds
 static const double sweepTimeTotal = .10;
 static const double sweepTimeMultiplier = 1.0 / sweepTimeTotal;
 
@@ -52,13 +52,13 @@
 
 void IncrementalSweeper::doWork()
 {
-    doSweep(WTF::monotonicallyIncreasingTime());
+    doSweep(MonotonicTime::now());
 }
 
-void IncrementalSweeper::doSweep(double sweepBeginTime)
+void IncrementalSweeper::doSweep(MonotonicTime sweepBeginTime)
 {
     while (sweepNextBlock()) {
-        double elapsedTime = WTF::monotonicallyIncreasingTime() - sweepBeginTime;
+        Seconds elapsedTime = MonotonicTime::now() - sweepBeginTime;
         if (elapsedTime < sweepTimeSlice)
             continue;
 

Modified: trunk/Source/_javascript_Core/heap/IncrementalSweeper.h (215227 => 215228)


--- trunk/Source/_javascript_Core/heap/IncrementalSweeper.h	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/heap/IncrementalSweeper.h	2017-04-11 14:56:21 UTC (rev 215228)
@@ -45,7 +45,7 @@
     JS_EXPORT_PRIVATE void stopSweeping();
 
 private:
-    void doSweep(double startTime);
+    void doSweep(MonotonicTime startTime);
     void scheduleTimer();
     
     MarkedAllocator* m_currentAllocator;

Modified: trunk/Source/_javascript_Core/heap/StopIfNecessaryTimer.cpp (215227 => 215228)


--- trunk/Source/_javascript_Core/heap/StopIfNecessaryTimer.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/heap/StopIfNecessaryTimer.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -48,7 +48,7 @@
         WTF::loadLoadFence();
         return;
     }
-    scheduleTimer(0);
+    scheduleTimer(0_s);
 }
 
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp (215227 => 215228)


--- trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -35,7 +35,7 @@
 #include <wtf/MainThread.h>
 #include <wtf/Threading.h>
 
-#if USE(GLIB)
+#if USE(GLIB_EVENT_LOOP)
 #include <glib.h>
 #include <wtf/glib/RunLoopSourcePriority.h>
 #endif
@@ -42,6 +42,8 @@
 
 namespace JSC {
 
+const Seconds JSRunLoopTimer::s_decade { 60 * 60 * 24 * 365 * 10 };
+
 void JSRunLoopTimer::timerDidFire()
 {
     m_apiLock->lock();
@@ -63,8 +65,6 @@
 
 #if USE(CF)
 
-const CFTimeInterval JSRunLoopTimer::s_decade = 60 * 60 * 24 * 365 * 10;
-
 JSRunLoopTimer::JSRunLoopTimer(VM* vm)
     : m_vm(vm)
     , m_apiLock(&vm->apiLock())
@@ -85,7 +85,7 @@
         m_runLoop = runLoop;
         memset(&m_context, 0, sizeof(CFRunLoopTimerContext));
         m_context.info = this;
-        m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade, s_decade, 0, 0, JSRunLoopTimer::timerDidFireCallback, &m_context));
+        m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade.seconds(), s_decade.seconds(), 0, 0, JSRunLoopTimer::timerDidFireCallback, &m_context));
         CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
     }
 }
@@ -100,86 +100,44 @@
     static_cast<JSRunLoopTimer*>(contextPtr)->timerDidFire();
 }
 
-void JSRunLoopTimer::scheduleTimer(double intervalInSeconds)
+void JSRunLoopTimer::scheduleTimer(Seconds intervalInSeconds)
 {
-    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + intervalInSeconds);
+    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + intervalInSeconds.seconds());
     m_isScheduled = true;
 }
 
 void JSRunLoopTimer::cancelTimer()
 {
-    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
+    CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade.seconds());
     m_isScheduled = false;
 }
 
-#elif USE(GLIB)
+#else
 
-const long JSRunLoopTimer::s_decade = 60 * 60 * 24 * 365 * 10;
-
-static GSourceFuncs JSRunLoopTimerSourceFunctions = {
-    nullptr, // prepare
-    nullptr, // check
-    // dispatch
-    [](GSource*, GSourceFunc callback, gpointer userData) -> gboolean
-    {
-        return callback(userData);
-    },
-    nullptr, // finalize
-    nullptr, // closure_callback
-    nullptr, // closure_marshall
-};
-
 JSRunLoopTimer::JSRunLoopTimer(VM* vm)
     : m_vm(vm)
     , m_apiLock(&vm->apiLock())
-    , m_timer(adoptGRef(g_source_new(&JSRunLoopTimerSourceFunctions, sizeof(GSource))))
+    , m_timer(RunLoop::current(), this, &JSRunLoopTimer::timerDidFireCallback)
 {
-    g_source_set_priority(m_timer.get(), RunLoopSourcePriority::_javascript_Timer);
-    g_source_set_name(m_timer.get(), "[_javascript_Core] JSRunLoopTimer");
-    g_source_set_callback(m_timer.get(), [](gpointer userData) -> gboolean {
-        auto& runLoopTimer = *static_cast<JSRunLoopTimer*>(userData);
-        g_source_set_ready_time(runLoopTimer.m_timer.get(), g_get_monotonic_time() + JSRunLoopTimer::s_decade * G_USEC_PER_SEC);
-        runLoopTimer.timerDidFire();
-        return G_SOURCE_CONTINUE;
-    }, this, nullptr);
-    g_source_attach(m_timer.get(), g_main_context_get_thread_default());
+#if USE(GLIB_EVENT_LOOP)
+    m_timer.setPriority(RunLoopSourcePriority::_javascript_Timer);
+    m_timer.setName("[_javascript_Core] JSRunLoopTimer");
+#endif
+    m_timer.startOneShot(s_decade);
 }
 
 JSRunLoopTimer::~JSRunLoopTimer()
 {
-    g_source_destroy(m_timer.get());
 }
 
-void JSRunLoopTimer::scheduleTimer(double intervalInSeconds)
+void JSRunLoopTimer::timerDidFireCallback()
 {
-    g_source_set_ready_time(m_timer.get(), g_get_monotonic_time() + intervalInSeconds * G_USEC_PER_SEC);
-    m_isScheduled = true;
-}
-
-void JSRunLoopTimer::cancelTimer()
-{
-    g_source_set_ready_time(m_timer.get(), g_get_monotonic_time() + s_decade * G_USEC_PER_SEC);
-    m_isScheduled = false;
-}
-
-#else
-
-const Seconds JSRunLoopTimer::s_decade { 60 * 60 * 24 * 365 * 10 };
-
-JSRunLoopTimer::JSRunLoopTimer(VM* vm)
-    : m_vm(vm)
-    , m_apiLock(&vm->apiLock())
-    , m_timer(RunLoop::current(), this, &JSRunLoopTimer::timerDidFire)
-{
     m_timer.startOneShot(s_decade);
+    timerDidFire();
 }
 
-JSRunLoopTimer::~JSRunLoopTimer()
+void JSRunLoopTimer::scheduleTimer(Seconds intervalInSeconds)
 {
-}
-
-void JSRunLoopTimer::scheduleTimer(double intervalInSeconds)
-{
     m_timer.startOneShot(intervalInSeconds);
     m_isScheduled = true;
 }

Modified: trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h (215227 => 215228)


--- trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h	2017-04-11 14:56:21 UTC (rev 215228)
@@ -36,10 +36,6 @@
 #include <CoreFoundation/CoreFoundation.h>
 #endif
 
-#if USE(GLIB)
-#include <wtf/glib/GRefPtr.h>
-#endif
-
 namespace JSC {
 
 class JSLock;
@@ -50,12 +46,14 @@
     JSRunLoopTimer(VM*);
 #if USE(CF)
     static void timerDidFireCallback(CFRunLoopTimerRef, void*);
+#else
+    void timerDidFireCallback();
 #endif
 
     JS_EXPORT_PRIVATE virtual ~JSRunLoopTimer();
     virtual void doWork() = 0;
 
-    void scheduleTimer(double intervalInSeconds);
+    void scheduleTimer(Seconds intervalInSeconds);
     void cancelTimer();
     bool isScheduled() const { return m_isScheduled; }
 
@@ -66,11 +64,11 @@
 protected:
     VM* m_vm;
 
+    static const Seconds s_decade;
+
     RefPtr<JSLock> m_apiLock;
     bool m_isScheduled { false };
 #if USE(CF)
-    static const CFTimeInterval s_decade;
-
     RetainPtr<CFRunLoopTimerRef> m_timer;
     RetainPtr<CFRunLoopRef> m_runLoop;
 
@@ -77,11 +75,7 @@
     CFRunLoopTimerContext m_context;
 
     Lock m_shutdownMutex;
-#elif USE(GLIB)
-    static const long s_decade;
-    GRefPtr<GSource> m_timer;
 #else
-    static const Seconds s_decade;
     RunLoop::Timer<JSRunLoopTimer> m_timer;
 #endif
     

Modified: trunk/Source/_javascript_Core/runtime/PromiseDeferredTimer.cpp (215227 => 215228)


--- trunk/Source/_javascript_Core/runtime/PromiseDeferredTimer.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/_javascript_Core/runtime/PromiseDeferredTimer.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -134,7 +134,7 @@
     LockHolder locker(m_taskLock);
     m_tasks.append(std::make_tuple(ticket, WTFMove(task)));
     if (!isScheduled() && !m_currentlyRunningTask)
-        scheduleTimer(0);
+        scheduleTimer(0_s);
 }
 
 } // namespace JSC

Modified: trunk/Source/WTF/ChangeLog (215227 => 215228)


--- trunk/Source/WTF/ChangeLog	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/WTF/ChangeLog	2017-04-11 14:56:21 UTC (rev 215228)
@@ -1,5 +1,29 @@
 2017-04-11  Yusuke Suzuki  <[email protected]>
 
+        [JSC][GTK] Use RunLoop::Timer in GTK port
+        https://bugs.webkit.org/show_bug.cgi?id=170723
+
+        Reviewed by Carlos Garcia Campos.
+
+        Add secondsUntilFire method. And add setName and setPriority
+        for GTK RunLoop::Timer.
+
+        * wtf/RunLoop.h:
+        * wtf/cf/RunLoopCF.cpp:
+        (WTF::RunLoop::TimerBase::secondsUntilFire):
+        * wtf/generic/RunLoopGeneric.cpp:
+        (WTF::RunLoop::TimerBase::secondsUntilFire):
+        * wtf/glib/RunLoopGLib.cpp:
+        (WTF::RunLoop::TimerBase::setName):
+        (WTF::RunLoop::TimerBase::secondsUntilFire):
+        * wtf/win/RunLoopWin.cpp:
+        (WTF::RunLoop::TimerBase::timerFired):
+        (WTF::RunLoop::TimerBase::start):
+        (WTF::RunLoop::TimerBase::isActive):
+        (WTF::RunLoop::TimerBase::secondsUntilFire):
+
+2017-04-11  Yusuke Suzuki  <[email protected]>
+
         [JSC] Enable JSRunLoopTimer for JSCOnly and Windows
         https://bugs.webkit.org/show_bug.cgi?id=170655
 

Modified: trunk/Source/WTF/wtf/RunLoop.h (215227 => 215228)


--- trunk/Source/WTF/wtf/RunLoop.h	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/WTF/wtf/RunLoop.h	2017-04-11 14:56:21 UTC (rev 215228)
@@ -93,10 +93,12 @@
 
         WTF_EXPORT_PRIVATE void stop();
         WTF_EXPORT_PRIVATE bool isActive() const;
+        WTF_EXPORT_PRIVATE Seconds secondsUntilFire() const;
 
         virtual void fired() = 0;
 
 #if USE(GLIB_EVENT_LOOP)
+        void setName(const char*);
         void setPriority(int);
 #endif
 
@@ -106,8 +108,11 @@
         Ref<RunLoop> m_runLoop;
 
 #if USE(WINDOWS_EVENT_LOOP)
+        bool isActive(const AbstractLocker&) const;
         static void timerFired(RunLoop*, uint64_t ID);
         uint64_t m_ID;
+        MonotonicTime m_nextFireDate;
+        Seconds m_interval;
         bool m_isRepeating;
 #elif USE(COCOA_EVENT_LOOP)
         static void timerFired(CFRunLoopTimerRef, void*);

Modified: trunk/Source/WTF/wtf/cf/RunLoopCF.cpp (215227 => 215228)


--- trunk/Source/WTF/wtf/cf/RunLoopCF.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/WTF/wtf/cf/RunLoopCF.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -119,4 +119,11 @@
     return m_timer && CFRunLoopTimerIsValid(m_timer.get());
 }
 
+Seconds RunLoop::TimerBase::secondsUntilFire() const
+{
+    if (isActive())
+        return std::max<Seconds>(Seconds { CFRunLoopTimerGetNextFireDate(m_timer.get()) - CFAbsoluteTimeGetCurrent() }, 0_s);
+    return 0_s;
+}
+
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp (215227 => 215228)


--- trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -293,4 +293,12 @@
     return m_scheduledTask;
 }
 
+Seconds RunLoop::TimerBase::secondsUntilFire() const
+{
+    LockHolder locker(m_runLoop->m_loopLock);
+    if (isActive(locker))
+        return std::max<Seconds>(m_scheduledTask->scheduledTimePoint() - MonotonicTime::now(), 0_s);
+    return 0_s;
+}
+
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp (215227 => 215228)


--- trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -176,6 +176,11 @@
     g_source_destroy(m_source.get());
 }
 
+void RunLoop::TimerBase::setName(const char* name)
+{
+    g_source_set_name(m_source.get(), name);
+}
+
 void RunLoop::TimerBase::setPriority(int priority)
 {
     g_source_set_priority(m_source.get(), priority);
@@ -211,4 +216,9 @@
     return g_source_get_ready_time(m_source.get()) != -1;
 }
 
+Seconds RunLoop::TimerBase::secondsUntilFire() const
+{
+    return std::max<Seconds>(Seconds::fromMicroseconds(g_source_get_ready_time(m_source.get()) - g_get_monotonic_time()), 0_s);
+}
+
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/win/RunLoopWin.cpp (215227 => 215228)


--- trunk/Source/WTF/wtf/win/RunLoopWin.cpp	2017-04-11 13:19:21 UTC (rev 215227)
+++ trunk/Source/WTF/wtf/win/RunLoopWin.cpp	2017-04-11 14:56:21 UTC (rev 215228)
@@ -131,7 +131,8 @@
         if (!timer->m_isRepeating) {
             runLoop->m_activeTimers.remove(it);
             ::KillTimer(runLoop->m_runLoopMessageWindow, ID);
-        }
+        } else
+            m_nextFireDate = MonotonicTime::now() + m_interval;
     }
 
     timer->fired();
@@ -160,6 +161,8 @@
     LockHolder locker(m_runLoop->m_activeTimersLock);
     m_isRepeating = repeat;
     m_runLoop->m_activeTimers.set(m_ID, this);
+    m_interval = Seconds(nextFireInterval);
+    m_nextFireDate = MonotonicTime::now() + m_interval;
     ::SetTimer(m_runLoop->m_runLoopMessageWindow, m_ID, nextFireInterval * 1000, 0);
 }
 
@@ -174,10 +177,24 @@
     ::KillTimer(m_runLoop->m_runLoopMessageWindow, m_ID);
 }
 
+bool RunLoop::TimerBase::isActive(const AbstractLocker&) const
+{
+    return m_runLoop->m_activeTimers.contains(m_ID);
+}
+
 bool RunLoop::TimerBase::isActive() const
 {
     LockHolder locker(m_runLoop->m_activeTimersLock);
-    return m_runLoop->m_activeTimers.contains(m_ID);
+    return isActive(locker);
 }
 
+Seconds RunLoop::TimerBase::secondsUntilFire() const
+{
+    LockHolder locker(m_runLoop->m_activeTimersLock);
+    if (isActive(locker))
+        return std::max<Seconds>(m_nextFireDate - MonotonicTime::now(), 0_s);
+    return 0_s;
+}
+
+
 } // namespace WTF
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to