Unreviewed, rolling out r235107.
[WebKit-https.git] / Source / JavaScriptCore / heap / GCActivityCallback.cpp
index 593b20b..007fdd8 100644 (file)
 #include "JSObject.h"
 #include "VM.h"
 
-#if PLATFORM(EFL)
-#include <wtf/MainThread.h>
-#elif 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 PLATFORM(EFL)
-GCActivityCallback::GCActivityCallback(Heap* heap)
-    : GCActivityCallback(heap->vm(), WTF::isMainThread())
-{
-}
-#elif USE(GLIB)
-GCActivityCallback::GCActivityCallback(Heap* heap)
-    : GCActivityCallback(heap->vm())
-{
-}
-#endif
 
 void GCActivityCallback::doWork()
 {
@@ -73,7 +53,7 @@ void GCActivityCallback::doWork()
     
     JSLockHolder locker(m_vm);
     if (heap->isDeferred()) {
-        scheduleTimer(0);
+        scheduleTimer(0_s);
         return;
     }
 
@@ -81,87 +61,57 @@ void GCActivityCallback::doWork()
 }
 
 #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 PLATFORM(EFL)
-void GCActivityCallback::scheduleTimer(double newDelay)
-{
-    if (newDelay * timerSlop > m_delay)
-        return;
 
-    stop();
-    m_delay = newDelay;
-    
-    ASSERT(!m_timer);
-    m_timer = add(newDelay, this);
-}
-
-void GCActivityCallback::cancelTimer()
+MonotonicTime GCActivityCallback::nextFireTime()
 {
-    m_delay = s_hour;
-    stop();
+    return MonotonicTime::now() + Seconds(CFRunLoopTimerGetNextFireDate(m_timer.get()) - CFAbsoluteTimeGetCurrent());
 }
-#elif USE(GLIB)
-void GCActivityCallback::scheduleTimer(double newDelay)
+#else
+void GCActivityCallback::scheduleTimer(Seconds newDelay)
 {
-    ASSERT(newDelay >= 0);
-    if (m_delay != -1 && newDelay * timerSlop > m_delay)
+    if (newDelay * timerSlop > m_delay)
         return;
-
+    Seconds delta = m_delay - newDelay;
     m_delay = newDelay;
-    m_nextFireTime = WTF::currentTime() + newDelay;
-    if (!m_delay) {
-        g_source_set_ready_time(m_timer.get(), 0);
-        return;
-    }
 
-    auto delayDuration = std::chrono::duration<double>(m_delay);
-    auto safeDelayDuration = std::chrono::microseconds::max();
-    if (delayDuration < safeDelayDuration)
-        safeDelayDuration = std::chrono::duration_cast<std::chrono::microseconds>(delayDuration);
-    gint64 currentTime = g_get_monotonic_time();
-    gint64 targetTime = currentTime + std::min<gint64>(G_MAXINT64 - currentTime, safeDelayDuration.count());
-    ASSERT(targetTime >= currentTime);
-    g_source_set_ready_time(m_timer.get(), targetTime);
+    Seconds secondsUntilFire = m_timer.secondsUntilFire();
+    m_timer.startOneShot(std::max<Seconds>(secondsUntilFire - delta, 0_s));
 }
 
 void GCActivityCallback::cancelTimer()
 {
-    m_delay = -1;
-    m_nextFireTime = 0;
-    g_source_set_ready_time(m_timer.get(), -1);
+    m_delay = s_decade;
+    m_timer.startOneShot(s_decade);
 }
-#endif
 
-void GCActivityCallback::didAllocate(size_t bytes)
+MonotonicTime GCActivityCallback::nextFireTime()
 {
-#if PLATFORM(EFL)
-    if (!isEnabled())
-        return;
-
-    ASSERT(WTF::isMainThread());
+    return MonotonicTime::now() + m_timer.secondsUntilFire();
+}
 #endif
 
+void GCActivityCallback::didAllocate(size_t bytes)
+{
     // The first byte allocated in an allocation cycle will report 0 bytes to didAllocate. 
     // We pretend it's one byte so that we don't ignore this allocation entirely.
     if (!bytes)
         bytes = 1;
     double bytesExpectedToReclaim = static_cast<double>(bytes) * deathRate();
-    double newDelay = lastGCLength() / gcTimeSlice(bytesExpectedToReclaim);
+    Seconds newDelay = lastGCLength() / gcTimeSlice(bytesExpectedToReclaim);
     scheduleTimer(newDelay);
 }
 
@@ -175,30 +125,5 @@ void GCActivityCallback::cancel()
     cancelTimer();
 }
 
-#else
-
-GCActivityCallback::GCActivityCallback(Heap* heap)
-    : GCActivityCallback(heap->vm())
-{
-}
-
-void GCActivityCallback::doWork()
-{
-}
-
-void GCActivityCallback::didAllocate(size_t)
-{
-}
-
-void GCActivityCallback::willCollect()
-{
-}
-
-void GCActivityCallback::cancel()
-{
-}
-
-#endif
-
 }