Title: [215241] trunk
Revision
215241
Author
[email protected]
Date
2017-04-11 11:25:42 -0700 (Tue, 11 Apr 2017)

Log Message

[WebCore][JSC] ResourceUsageData.{timeOfNextEdenCollection,timeOfNextFullCollection} should be MonotonicTime
https://bugs.webkit.org/show_bug.cgi?id=170725

Reviewed by Sam Weinig.

Source/_javascript_Core:

This patch makes GCActivityCallback return MonotonicTime instead of raw double value.

* heap/GCActivityCallback.cpp:
(JSC::GCActivityCallback::nextFireTime):
* heap/GCActivityCallback.h:

Source/WebCore:

Use MonotonicTime instead of raw doubles.
Currently, large part of data structures and helper functions are the same in
ResourceUsageOverlayCocoa.mm and ResourceUsageOverlayLinux.cpp. This should be
unified in a separate patch.

* page/ResourceUsageData.h:
* page/cocoa/ResourceUsageOverlayCocoa.mm:
(WebCore::gcTimerString):
(WebCore::ResourceUsageOverlay::platformDraw):
* page/linux/ResourceUsageOverlayLinux.cpp:
(WebCore::gcTimerString):

Source/WTF:

Make MonotonicTime more constexpr friendly mainly to annotate MonotonicTime::nan() as constexpr.

* wtf/MonotonicTime.h:
(WTF::MonotonicTime::MonotonicTime):
(WTF::MonotonicTime::fromRawSeconds):
(WTF::MonotonicTime::infinity):
(WTF::MonotonicTime::nan):
(WTF::MonotonicTime::secondsSinceEpoch):
(WTF::MonotonicTime::operator bool):
(WTF::MonotonicTime::operator+):
(WTF::MonotonicTime::operator-):
(WTF::MonotonicTime::operator==):
(WTF::MonotonicTime::operator!=):
(WTF::MonotonicTime::operator<):
(WTF::MonotonicTime::operator>):
(WTF::MonotonicTime::operator<=):
(WTF::MonotonicTime::operator>=):

Tools:

* TestWebKitAPI/Tests/WTF/Time.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (215240 => 215241)


--- trunk/Source/_javascript_Core/ChangeLog	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-04-11 18:25:42 UTC (rev 215241)
@@ -1,3 +1,16 @@
+2017-04-11  Yusuke Suzuki  <[email protected]>
+
+        [WebCore][JSC] ResourceUsageData.{timeOfNextEdenCollection,timeOfNextFullCollection} should be MonotonicTime
+        https://bugs.webkit.org/show_bug.cgi?id=170725
+
+        Reviewed by Sam Weinig.
+
+        This patch makes GCActivityCallback return MonotonicTime instead of raw double value.
+
+        * heap/GCActivityCallback.cpp:
+        (JSC::GCActivityCallback::nextFireTime):
+        * heap/GCActivityCallback.h:
+
 2017-04-11  Guillaume Emont  <[email protected]>
 
         [jsc] Add missing MacroAssemblerMIPS::or32() implementation

Modified: trunk/Source/_javascript_Core/heap/GCActivityCallback.cpp (215240 => 215241)


--- trunk/Source/_javascript_Core/heap/GCActivityCallback.cpp	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Source/_javascript_Core/heap/GCActivityCallback.cpp	2017-04-11 18:25:42 UTC (rev 215241)
@@ -76,9 +76,9 @@
     CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade.seconds());
 }
 
-double GCActivityCallback::nextFireTime()
+MonotonicTime GCActivityCallback::nextFireTime()
 {
-    return CFRunLoopTimerGetNextFireDate(m_timer.get());
+    return MonotonicTime::now() + (CFRunLoopTimerGetNextFireDate(m_timer.get()) - CFAbsoluteTimeGetCurrent());
 }
 #else
 void GCActivityCallback::scheduleTimer(Seconds newDelay)
@@ -98,11 +98,9 @@
     m_timer.startOneShot(s_decade);
 }
 
-double GCActivityCallback::nextFireTime()
+MonotonicTime GCActivityCallback::nextFireTime()
 {
-    // FIXME: Should return MonotonicTime.
-    // https://bugs.webkit.org/show_bug.cgi?id=170725
-    return (MonotonicTime::now() + m_timer.secondsUntilFire()).secondsSinceEpoch().value();
+    return MonotonicTime::now() + m_timer.secondsUntilFire();
 }
 #endif
 

Modified: trunk/Source/_javascript_Core/heap/GCActivityCallback.h (215240 => 215241)


--- trunk/Source/_javascript_Core/heap/GCActivityCallback.h	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Source/_javascript_Core/heap/GCActivityCallback.h	2017-04-11 18:25:42 UTC (rev 215241)
@@ -60,7 +60,7 @@
 
     static bool s_shouldCreateGCTimer;
 
-    double nextFireTime();
+    MonotonicTime nextFireTime();
 
 protected:
     virtual Seconds lastGCLength() = 0;

Modified: trunk/Source/WTF/ChangeLog (215240 => 215241)


--- trunk/Source/WTF/ChangeLog	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Source/WTF/ChangeLog	2017-04-11 18:25:42 UTC (rev 215241)
@@ -1,5 +1,30 @@
 2017-04-11  Yusuke Suzuki  <[email protected]>
 
+        [WebCore][JSC] ResourceUsageData.{timeOfNextEdenCollection,timeOfNextFullCollection} should be MonotonicTime
+        https://bugs.webkit.org/show_bug.cgi?id=170725
+
+        Reviewed by Sam Weinig.
+
+        Make MonotonicTime more constexpr friendly mainly to annotate MonotonicTime::nan() as constexpr.
+
+        * wtf/MonotonicTime.h:
+        (WTF::MonotonicTime::MonotonicTime):
+        (WTF::MonotonicTime::fromRawSeconds):
+        (WTF::MonotonicTime::infinity):
+        (WTF::MonotonicTime::nan):
+        (WTF::MonotonicTime::secondsSinceEpoch):
+        (WTF::MonotonicTime::operator bool):
+        (WTF::MonotonicTime::operator+):
+        (WTF::MonotonicTime::operator-):
+        (WTF::MonotonicTime::operator==):
+        (WTF::MonotonicTime::operator!=):
+        (WTF::MonotonicTime::operator<):
+        (WTF::MonotonicTime::operator>):
+        (WTF::MonotonicTime::operator<=):
+        (WTF::MonotonicTime::operator>=):
+
+2017-04-11  Yusuke Suzuki  <[email protected]>
+
         Unreviewed, build fix for Windows port after r215228
         https://bugs.webkit.org/show_bug.cgi?id=170723
 

Modified: trunk/Source/WTF/wtf/MonotonicTime.h (215240 => 215241)


--- trunk/Source/WTF/wtf/MonotonicTime.h	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Source/WTF/wtf/MonotonicTime.h	2017-04-11 18:25:42 UTC (rev 215241)
@@ -46,35 +46,34 @@
     static const ClockType clockType = ClockType::Monotonic;
     
     // This is the epoch. So, x.secondsSinceEpoch() should be the same as x - MonotonicTime().
-    MonotonicTime() { }
+    constexpr MonotonicTime() { }
     
     // Call this if you know for sure that the double represents time according to
     // WTF::monotonicallyIncreasingTime(). It must be in seconds and it must be from the same time
     // source.
-    static MonotonicTime fromRawSeconds(double value)
+    static constexpr MonotonicTime fromRawSeconds(double value)
     {
-        MonotonicTime result;
-        result.m_value = value;
-        return result;
+        return MonotonicTime(value);
     }
     
     WTF_EXPORT_PRIVATE static MonotonicTime now();
     
-    static MonotonicTime infinity() { return fromRawSeconds(std::numeric_limits<double>::infinity()); }
+    static constexpr MonotonicTime infinity() { return fromRawSeconds(std::numeric_limits<double>::infinity()); }
+    static constexpr MonotonicTime nan() { return fromRawSeconds(std::numeric_limits<double>::quiet_NaN()); }
 
-    Seconds secondsSinceEpoch() const { return Seconds(m_value); }
+    constexpr Seconds secondsSinceEpoch() const { return Seconds(m_value); }
     
     MonotonicTime approximateMonotonicTime() const { return *this; }
     WTF_EXPORT_PRIVATE WallTime approximateWallTime() const;
     
-    explicit operator bool() const { return !!m_value; }
+    explicit constexpr operator bool() const { return !!m_value; }
     
-    MonotonicTime operator+(Seconds other) const
+    constexpr MonotonicTime operator+(Seconds other) const
     {
         return fromRawSeconds(m_value + other.value());
     }
     
-    MonotonicTime operator-(Seconds other) const
+    constexpr MonotonicTime operator-(Seconds other) const
     {
         return fromRawSeconds(m_value - other.value());
     }
@@ -86,7 +85,7 @@
     
     // Time is a scalar and scalars can be negated as this could arise from algebraic
     // transformations. So, we allow it.
-    MonotonicTime operator-() const
+    constexpr MonotonicTime operator-() const
     {
         return fromRawSeconds(-m_value);
     }
@@ -101,37 +100,37 @@
         return *this = *this - other;
     }
     
-    Seconds operator-(MonotonicTime other) const
+    constexpr Seconds operator-(MonotonicTime other) const
     {
         return Seconds(m_value - other.m_value);
     }
     
-    bool operator==(MonotonicTime other) const
+    constexpr bool operator==(MonotonicTime other) const
     {
         return m_value == other.m_value;
     }
     
-    bool operator!=(MonotonicTime other) const
+    constexpr bool operator!=(MonotonicTime other) const
     {
         return m_value != other.m_value;
     }
     
-    bool operator<(MonotonicTime other) const
+    constexpr bool operator<(MonotonicTime other) const
     {
         return m_value < other.m_value;
     }
     
-    bool operator>(MonotonicTime other) const
+    constexpr bool operator>(MonotonicTime other) const
     {
         return m_value > other.m_value;
     }
     
-    bool operator<=(MonotonicTime other) const
+    constexpr bool operator<=(MonotonicTime other) const
     {
         return m_value <= other.m_value;
     }
     
-    bool operator>=(MonotonicTime other) const
+    constexpr bool operator>=(MonotonicTime other) const
     {
         return m_value >= other.m_value;
     }
@@ -139,6 +138,11 @@
     WTF_EXPORT_PRIVATE void dump(PrintStream&) const;
 
 private:
+    constexpr MonotonicTime(double rawValue)
+        : m_value(rawValue)
+    {
+    }
+
     double m_value { 0 };
 };
 

Modified: trunk/Source/WebCore/ChangeLog (215240 => 215241)


--- trunk/Source/WebCore/ChangeLog	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Source/WebCore/ChangeLog	2017-04-11 18:25:42 UTC (rev 215241)
@@ -1,3 +1,22 @@
+2017-04-11  Yusuke Suzuki  <[email protected]>
+
+        [WebCore][JSC] ResourceUsageData.{timeOfNextEdenCollection,timeOfNextFullCollection} should be MonotonicTime
+        https://bugs.webkit.org/show_bug.cgi?id=170725
+
+        Reviewed by Sam Weinig.
+
+        Use MonotonicTime instead of raw doubles.
+        Currently, large part of data structures and helper functions are the same in
+        ResourceUsageOverlayCocoa.mm and ResourceUsageOverlayLinux.cpp. This should be
+        unified in a separate patch.
+
+        * page/ResourceUsageData.h:
+        * page/cocoa/ResourceUsageOverlayCocoa.mm:
+        (WebCore::gcTimerString):
+        (WebCore::ResourceUsageOverlay::platformDraw):
+        * page/linux/ResourceUsageOverlayLinux.cpp:
+        (WebCore::gcTimerString):
+
 2017-04-11  Youenn Fablet  <[email protected]>
 
         Activate WebRTC data channel tests for WK1

Modified: trunk/Source/WebCore/page/ResourceUsageData.h (215240 => 215241)


--- trunk/Source/WebCore/page/ResourceUsageData.h	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Source/WebCore/page/ResourceUsageData.h	2017-04-11 18:25:42 UTC (rev 215241)
@@ -28,6 +28,7 @@
 #if ENABLE(RESOURCE_USAGE)
 
 #include <array>
+#include <wtf/MonotonicTime.h>
 
 namespace WebCore {
 
@@ -68,8 +69,8 @@
     size_t totalDirtySize { 0 };
     size_t totalExternalSize { 0 };
     std::array<MemoryCategoryInfo, MemoryCategory::NumberOfCategories> categories;
-    double timeOfNextEdenCollection { 0 };
-    double timeOfNextFullCollection { 0 };
+    MonotonicTime timeOfNextEdenCollection { MonotonicTime::nan() };
+    MonotonicTime timeOfNextFullCollection { MonotonicTime::nan() };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm (215240 => 215241)


--- trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm	2017-04-11 18:25:42 UTC (rev 215241)
@@ -154,8 +154,8 @@
     RingBuffer<size_t> totalExternalSize;
     RingBuffer<size_t> gcHeapSize;
     std::array<HistoricMemoryCategoryInfo, MemoryCategory::NumberOfCategories> categories;
-    double timeOfNextEdenCollection { 0 };
-    double timeOfNextFullCollection { 0 };
+    MonotonicTime timeOfNextEdenCollection { MonotonicTime::nan() };
+    MonotonicTime timeOfNextFullCollection { MonotonicTime::nan() };
 };
 
 HistoricResourceUsageData::HistoricResourceUsageData()
@@ -433,11 +433,11 @@
     return String::format("%lu", number);
 }
 
-static String gcTimerString(double timerFireDate, double now)
+static String gcTimerString(MonotonicTime timerFireDate, MonotonicTime now)
 {
-    if (!timerFireDate)
+    if (std::isnan(timerFireDate))
         return ASCIILiteral("[not scheduled]");
-    return String::format("%g", timerFireDate - now);
+    return String::format("%g", (timerFireDate - now).seconds());
 }
 
 void ResourceUsageOverlay::platformDraw(CGContextRef context)
@@ -478,7 +478,7 @@
     }
     y -= 5;
 
-    double now = WTF::currentTime();
+    MonotonicTime now = MonotonicTime::now();
     showText(context, 10, y + 10, colorForLabels, String::format("    Eden GC: %s", gcTimerString(data.timeOfNextEdenCollection, now).ascii().data()));
     showText(context, 10, y + 20, colorForLabels, String::format("    Full GC: %s", gcTimerString(data.timeOfNextFullCollection, now).ascii().data()));
 

Modified: trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp (215240 => 215241)


--- trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp	2017-04-11 18:25:42 UTC (rev 215241)
@@ -59,11 +59,11 @@
     return String::format("%lu", number);
 }
 
-static String gcTimerString(double timerFireDate, double now)
+static String gcTimerString(MonotonicTime timerFireDate, MonotonicTime now)
 {
-    if (!timerFireDate)
+    if (std::isnan(timerFireDate))
         return ASCIILiteral("[not scheduled]");
-    return String::format("%g", timerFireDate - now);
+    return String::format("%g", (timerFireDate - now).seconds());
 }
 
 static const float gFontSize = 14;
@@ -112,7 +112,7 @@
         context.drawText(m_textFont, TextRun(string), position);
         position.move(0, gFontSize + 2);
 
-        double now = WTF::currentTime();
+        MonotonicTime now = MonotonicTime::now();
         string = "Eden GC: " + gcTimerString(gData.timeOfNextEdenCollection, now);
         context.drawText(m_textFont, TextRun(string), position);
         position.move(0, gFontSize + 2);

Modified: trunk/Tools/ChangeLog (215240 => 215241)


--- trunk/Tools/ChangeLog	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Tools/ChangeLog	2017-04-11 18:25:42 UTC (rev 215241)
@@ -1,3 +1,13 @@
+2017-04-11  Yusuke Suzuki  <[email protected]>
+
+        [WebCore][JSC] ResourceUsageData.{timeOfNextEdenCollection,timeOfNextFullCollection} should be MonotonicTime
+        https://bugs.webkit.org/show_bug.cgi?id=170725
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/Tests/WTF/Time.cpp:
+        (TestWebKitAPI::TEST):
+
 2017-04-10  Alex Christensen  <[email protected]>
 
         Revert r215217

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Time.cpp (215240 => 215241)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/Time.cpp	2017-04-11 17:34:01 UTC (rev 215240)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Time.cpp	2017-04-11 18:25:42 UTC (rev 215241)
@@ -353,5 +353,37 @@
     EXPECT_TRUE(negativeInfinity.nanosecondsAs<uint64_t>() == 0);
 }
 
+// Test MonotonicTime constexpr features. If they are not calculated in constexpr,
+// they invokes global constructors and becomes compile errors.
+static const MonotonicTime NaN = MonotonicTime::nan();
+static const MonotonicTime Infinity = MonotonicTime::infinity();
+static const MonotonicTime Zero = MonotonicTime::fromRawSeconds(0);
+static const MonotonicTime _One_ = Zero + Seconds(1);
+static const MonotonicTime NegativeOne = Zero - Seconds(1);
+static const bool ZeroIsFalse = !!Zero;
+static const bool Equal = Zero == Zero;
+static const bool NotEqual = Zero != One;
+static const bool LessThan = Zero < One;
+static const bool GreaterThan = One > Zero;
+static const bool LessThanOrEqual = Zero <= Zero;
+static const bool GreaterThanOrEqual = Zero >= Zero;
+
+TEST(WTF_Time, constexprMonotonicTime)
+{
+    EXPECT_TRUE(std::isnan(NaN));
+    EXPECT_TRUE(std::isinf(Infinity));
+    EXPECT_TRUE(Zero.secondsSinceEpoch().value() == 0.0);
+    EXPECT_TRUE(One.secondsSinceEpoch().value() == 1.0);
+    EXPECT_TRUE(NegativeOne.secondsSinceEpoch().value() == -1.0);
+    EXPECT_FALSE(ZeroIsFalse);
+    EXPECT_TRUE(Equal);
+    EXPECT_TRUE(NotEqual);
+    EXPECT_TRUE(LessThan);
+    EXPECT_TRUE(GreaterThan);
+    EXPECT_TRUE(LessThanOrEqual);
+    EXPECT_TRUE(GreaterThanOrEqual);
+}
+
+
 } // namespace TestWebKitAPI
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to