Title: [226295] trunk/Source
Revision
226295
Author
[email protected]
Date
2017-12-26 16:33:11 -0800 (Tue, 26 Dec 2017)

Log Message

[JSC] Remove std::chrono completely
https://bugs.webkit.org/show_bug.cgi?id=181165

Reviewed by Konstantin Tokarev.

Source/_javascript_Core:

This patch removes std::chrono use completely from JSC.

* API/JSContextRef.cpp:
(JSContextGroupSetExecutionTimeLimit):
* API/tests/ExecutionTimeLimitTest.cpp:
(currentCPUTimeAsJSFunctionCallback):
(testExecutionTimeLimit):
* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::CodeBlock):
(JSC::timeToLive):
* bytecode/CodeBlock.h:
(JSC::CodeBlock::timeSinceCreation):
* runtime/SamplingProfiler.cpp:
(JSC::SamplingProfiler::SamplingProfiler):
(JSC::SamplingProfiler::timerLoop):
(JSC::SamplingProfiler::takeSample):
(JSC::SamplingProfiler::reportTopFunctions):
(JSC::SamplingProfiler::reportTopBytecodes):
* runtime/SamplingProfiler.h:
(JSC::SamplingProfiler::setTimingInterval):
* runtime/VM.cpp:
(JSC::VM::VM):
* runtime/Watchdog.cpp:
(JSC::Watchdog::Watchdog):
(JSC::Watchdog::setTimeLimit):
(JSC::Watchdog::shouldTerminate):
(JSC::Watchdog::startTimer):
(JSC::currentWallClockTime): Deleted.
* runtime/Watchdog.h:

Source/WTF:

WTF::currentCPUTime now returns WTF::Seconds.
We also add the implementaiton for Linux and FreeBSD.

* wtf/CurrentTime.cpp:
(WTF::currentCPUTime):
* wtf/CurrentTime.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSContextRef.cpp (226294 => 226295)


--- trunk/Source/_javascript_Core/API/JSContextRef.cpp	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/API/JSContextRef.cpp	2017-12-27 00:33:11 UTC (rev 226295)
@@ -99,9 +99,9 @@
     Watchdog& watchdog = vm.ensureWatchdog();
     if (callback) {
         void* callbackPtr = reinterpret_cast<void*>(callback);
-        watchdog.setTimeLimit(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(limit)), internalScriptTimeoutCallback, callbackPtr, callbackData);
+        watchdog.setTimeLimit(Seconds { limit }, internalScriptTimeoutCallback, callbackPtr, callbackData);
     } else
-        watchdog.setTimeLimit(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(limit)));
+        watchdog.setTimeLimit(Seconds { limit });
 }
 
 void JSContextGroupClearExecutionTimeLimit(JSContextGroupRef group)

Modified: trunk/Source/_javascript_Core/API/tests/ExecutionTimeLimitTest.cpp (226294 => 226295)


--- trunk/Source/_javascript_Core/API/tests/ExecutionTimeLimitTest.cpp	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/API/tests/ExecutionTimeLimitTest.cpp	2017-12-27 00:33:11 UTC (rev 226295)
@@ -31,7 +31,6 @@
 #include "_javascript_.h"
 #include "Options.h"
 
-#include <chrono>
 #include <wtf/Atomics.h>
 #include <wtf/Condition.h>
 #include <wtf/CurrentTime.h>
@@ -43,7 +42,6 @@
 #include <dispatch/dispatch.h>
 #endif
 
-using namespace std::chrono;
 using JSC::Options;
 
 static JSGlobalContextRef context = nullptr;
@@ -57,7 +55,7 @@
     UNUSED_PARAM(exception);
     
     ASSERT(JSContextGetGlobalContext(ctx) == context);
-    return JSValueMakeNumber(ctx, currentCPUTime().count() / 1000000.);
+    return JSValueMakeNumber(ctx, currentCPUTime().seconds());
 }
 
 bool shouldTerminateCallbackWasCalled = false;
@@ -97,7 +95,7 @@
 
 struct TierOptions {
     const char* tier;
-    unsigned timeLimitAdjustmentMillis;
+    Seconds timeLimitAdjustment;
     const char* optionsStr;
 };
 
@@ -120,10 +118,10 @@
 int testExecutionTimeLimit()
 {
     static const TierOptions tierOptionsList[] = {
-        { "LLINT",    0,   "--useConcurrentJIT=false --useLLInt=true --useJIT=false" },
-        { "Baseline", 0,   "--useConcurrentJIT=false --useLLInt=true --useJIT=true --useDFGJIT=false" },
-        { "DFG",      200,   "--useConcurrentJIT=false --useLLInt=true --useJIT=true --useDFGJIT=true --useFTLJIT=false" },
-        { "FTL",      500, "--useConcurrentJIT=false --useLLInt=true --useJIT=true --useDFGJIT=true --useFTLJIT=true" },
+        { "LLINT",    0_ms,   "--useConcurrentJIT=false --useLLInt=true --useJIT=false" },
+        { "Baseline", 0_ms,   "--useConcurrentJIT=false --useLLInt=true --useJIT=true --useDFGJIT=false" },
+        { "DFG",      200_ms,   "--useConcurrentJIT=false --useLLInt=true --useJIT=true --useDFGJIT=true --useFTLJIT=false" },
+        { "FTL",      500_ms, "--useConcurrentJIT=false --useLLInt=true --useJIT=true --useDFGJIT=true --useFTLJIT=true" },
     };
     
     bool failed = false;
@@ -137,8 +135,8 @@
 
         Options::setOptions(tierOptions.optionsStr);
         
-        unsigned tierAdjustmentMillis = tierOptions.timeLimitAdjustmentMillis;
-        double timeLimit;
+        Seconds tierAdjustment = tierOptions.timeLimitAdjustment;
+        Seconds timeLimit;
 
         context = JSGlobalContextCreateInGroup(nullptr, nullptr);
 
@@ -154,10 +152,10 @@
         JSStringRelease(currentCPUTimeStr);
 
         /* Test script on another thread: */
-        timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
-        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, shouldTerminateCallback, 0);
+        timeLimit = 100_ms + tierAdjustment;
+        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit.seconds(), shouldTerminateCallback, 0);
         {
-            unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
+            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
 
             JSStringRef script = JSStringCreateWithUTF8CString("function foo() { while (true) { } } foo();");
             exception = nullptr;
@@ -167,7 +165,7 @@
                 JSEvaluateScript(context, script, nullptr, nullptr, 1, exn);
             });
 
-            sleep(Seconds(timeAfterWatchdogShouldHaveFired / 1000.0));
+            sleep(timeAfterWatchdogShouldHaveFired);
 
             if (shouldTerminateCallbackWasCalled)
                 printf("PASS: %s script timed out as expected.\n", tierOptions.tier);
@@ -186,14 +184,14 @@
         }
 
         /* Test script timeout: */
-        timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
-        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, shouldTerminateCallback, 0);
+        timeLimit = 100_ms + tierAdjustment;
+        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit.seconds(), shouldTerminateCallback, 0);
         {
-            unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
+            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
 
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
+            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -203,10 +201,10 @@
             JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
             auto endTime = currentCPUTime();
 
-            if (((endTime - startTime) < milliseconds(timeAfterWatchdogShouldHaveFired)) && shouldTerminateCallbackWasCalled)
+            if (((endTime - startTime) < timeAfterWatchdogShouldHaveFired) && shouldTerminateCallbackWasCalled)
                 printf("PASS: %s script timed out as expected.\n", tierOptions.tier);
             else {
-                if ((endTime - startTime) >= milliseconds(timeAfterWatchdogShouldHaveFired))
+                if ((endTime - startTime) >= timeAfterWatchdogShouldHaveFired)
                     printf("FAIL: %s script did not time out as expected.\n", tierOptions.tier);
                 if (!shouldTerminateCallbackWasCalled)
                     printf("FAIL: %s script timeout callback was not called.\n", tierOptions.tier);
@@ -222,10 +220,10 @@
         }
 
         /* Test script timeout with tail calls: */
-        timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
-        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, shouldTerminateCallback, 0);
+        timeLimit = 100_ms + tierAdjustment;
+        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit.seconds(), shouldTerminateCallback, 0);
         {
-            unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
+            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
 
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("var startTime = currentCPUTime();"
@@ -233,7 +231,7 @@
                                      "'use strict';"
                                      "if (i % 1000 === 0) {"
                                         "if (currentCPUTime() - startTime >");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
+            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral("       ) { return; }");
             scriptBuilder.appendLiteral("    }");
             scriptBuilder.appendLiteral("    return recurse(i + 1); }");
@@ -246,10 +244,10 @@
             JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
             auto endTime = currentCPUTime();
 
-            if (((endTime - startTime) < milliseconds(timeAfterWatchdogShouldHaveFired)) && shouldTerminateCallbackWasCalled)
+            if (((endTime - startTime) < timeAfterWatchdogShouldHaveFired) && shouldTerminateCallbackWasCalled)
                 printf("PASS: %s script with infinite tail calls timed out as expected .\n", tierOptions.tier);
             else {
-                if ((endTime - startTime) >= milliseconds(timeAfterWatchdogShouldHaveFired))
+                if ((endTime - startTime) >= timeAfterWatchdogShouldHaveFired)
                     printf("FAIL: %s script with infinite tail calls did not time out as expected.\n", tierOptions.tier);
                 if (!shouldTerminateCallbackWasCalled)
                     printf("FAIL: %s script with infinite tail calls' timeout callback was not called.\n", tierOptions.tier);
@@ -265,14 +263,14 @@
         }
 
         /* Test the script timeout's TerminatedExecutionException should NOT be catchable: */
-        timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
-        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, shouldTerminateCallback, 0);
+        timeLimit = 100_ms + tierAdjustment;
+        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit.seconds(), shouldTerminateCallback, 0);
         {
-            unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
+            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
             
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); try { while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
+            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } catch(e) { } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -283,8 +281,8 @@
             JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
             auto endTime = currentCPUTime();
             
-            if (((endTime - startTime) >= milliseconds(timeAfterWatchdogShouldHaveFired)) || !shouldTerminateCallbackWasCalled) {
-                if (!((endTime - startTime) < milliseconds(timeAfterWatchdogShouldHaveFired)))
+            if (((endTime - startTime) >= timeAfterWatchdogShouldHaveFired) || !shouldTerminateCallbackWasCalled) {
+                if (!((endTime - startTime) < timeAfterWatchdogShouldHaveFired))
                     printf("FAIL: %s script did not time out as expected.\n", tierOptions.tier);
                 if (!shouldTerminateCallbackWasCalled)
                     printf("FAIL: %s script timeout callback was not called.\n", tierOptions.tier);
@@ -302,14 +300,14 @@
         }
         
         /* Test script timeout with no callback: */
-        timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
-        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, 0, 0);
+        timeLimit = 100_ms + tierAdjustment;
+        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit.seconds(), 0, 0);
         {
-            unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
+            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
             
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
+            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } foo();");
             
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -320,10 +318,10 @@
             JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
             auto endTime = currentCPUTime();
             
-            if (((endTime - startTime) < milliseconds(timeAfterWatchdogShouldHaveFired)) && !shouldTerminateCallbackWasCalled)
+            if (((endTime - startTime) < timeAfterWatchdogShouldHaveFired) && !shouldTerminateCallbackWasCalled)
                 printf("PASS: %s script timed out as expected when no callback is specified.\n", tierOptions.tier);
             else {
-                if ((endTime - startTime) >= milliseconds(timeAfterWatchdogShouldHaveFired))
+                if ((endTime - startTime) >= timeAfterWatchdogShouldHaveFired)
                     printf("FAIL: %s script did not time out as expected when no callback is specified.\n", tierOptions.tier);
                 else
                     printf("FAIL: %s script called stale callback function.\n", tierOptions.tier);
@@ -339,14 +337,14 @@
         }
         
         /* Test script timeout cancellation: */
-        timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
-        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, cancelTerminateCallback, 0);
+        timeLimit = 100_ms + tierAdjustment;
+        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit.seconds(), cancelTerminateCallback, 0);
         {
-            unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
+            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
             
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
+            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -357,10 +355,10 @@
             JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
             auto endTime = currentCPUTime();
             
-            if (((endTime - startTime) >= milliseconds(timeAfterWatchdogShouldHaveFired)) && cancelTerminateCallbackWasCalled && !exception)
+            if (((endTime - startTime) >= timeAfterWatchdogShouldHaveFired) && cancelTerminateCallbackWasCalled && !exception)
                 printf("PASS: %s script timeout was cancelled as expected.\n", tierOptions.tier);
             else {
-                if (((endTime - startTime) < milliseconds(timeAfterWatchdogShouldHaveFired)) || exception)
+                if (((endTime - startTime) < timeAfterWatchdogShouldHaveFired) || exception)
                     printf("FAIL: %s script timeout was not cancelled.\n", tierOptions.tier);
                 if (!cancelTerminateCallbackWasCalled)
                     printf("FAIL: %s script timeout callback was not called.\n", tierOptions.tier);
@@ -374,16 +372,16 @@
         }
         
         /* Test script timeout extension: */
-        timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
-        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, extendTerminateCallback, 0);
+        timeLimit = 100_ms + tierAdjustment;
+        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit.seconds(), extendTerminateCallback, 0);
         {
-            unsigned timeBeforeExtendedDeadline = 250 + tierAdjustmentMillis;
-            unsigned timeAfterExtendedDeadline = 600 + tierAdjustmentMillis;
-            unsigned maxBusyLoopTime = 750 + tierAdjustmentMillis;
+            Seconds timeBeforeExtendedDeadline = 250_ms + tierAdjustment;
+            Seconds timeAfterExtendedDeadline = 600_ms + tierAdjustment;
+            Seconds maxBusyLoopTime = 750_ms + tierAdjustment;
 
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(maxBusyLoopTime / 1000.0); // in seconds.
+            scriptBuilder.appendNumber(maxBusyLoopTime.seconds()); // in seconds.
             scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -395,12 +393,12 @@
             auto endTime = currentCPUTime();
             auto deltaTime = endTime - startTime;
             
-            if ((deltaTime >= milliseconds(timeBeforeExtendedDeadline)) && (deltaTime < milliseconds(timeAfterExtendedDeadline)) && (extendTerminateCallbackCalled == 2) && exception)
+            if ((deltaTime >= timeBeforeExtendedDeadline) && (deltaTime < timeAfterExtendedDeadline) && (extendTerminateCallbackCalled == 2) && exception)
                 printf("PASS: %s script timeout was extended as expected.\n", tierOptions.tier);
             else {
-                if (deltaTime < milliseconds(timeBeforeExtendedDeadline))
+                if (deltaTime < timeBeforeExtendedDeadline)
                     printf("FAIL: %s script timeout was not extended as expected.\n", tierOptions.tier);
-                else if (deltaTime >= milliseconds(timeAfterExtendedDeadline))
+                else if (deltaTime >= timeAfterExtendedDeadline)
                     printf("FAIL: %s script did not timeout.\n", tierOptions.tier);
                 
                 if (extendTerminateCallbackCalled < 1)
@@ -417,14 +415,14 @@
 
 #if HAVE(MACH_EXCEPTIONS)
         /* Test script timeout from dispatch queue: */
-        timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
-        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, dispatchTermitateCallback, 0);
+        timeLimit = 100_ms + tierAdjustment;
+        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit.seconds(), dispatchTermitateCallback, 0);
         {
-            unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
+            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
 
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
+            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -443,11 +441,11 @@
             bool didSynchronize = false;
             bool& didSynchronizeRef = didSynchronize;
 
-            std::chrono::microseconds startTime;
-            std::chrono::microseconds endTime;
+            Seconds startTime;
+            Seconds endTime;
 
-            std::chrono::microseconds& startTimeRef = startTime;
-            std::chrono::microseconds& endTimeRef = endTime;
+            Seconds& startTimeRef = startTime;
+            Seconds& endTimeRef = endTime;
 
             dispatch_group_t group = dispatch_group_create();
             dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
@@ -462,10 +460,10 @@
             auto locker = holdLock(syncLock);
             synchronize.wait(syncLock, [&] { return didSynchronize; });
 
-            if (((endTime - startTime) < milliseconds(timeAfterWatchdogShouldHaveFired)) && dispatchTerminateCallbackCalled)
+            if (((endTime - startTime) < timeAfterWatchdogShouldHaveFired) && dispatchTerminateCallbackCalled)
                 printf("PASS: %s script on dispatch queue timed out as expected.\n", tierOptions.tier);
             else {
-                if ((endTime - startTime) >= milliseconds(timeAfterWatchdogShouldHaveFired))
+                if ((endTime - startTime) >= timeAfterWatchdogShouldHaveFired)
                     printf("FAIL: %s script on dispatch queue did not time out as expected.\n", tierOptions.tier);
                 if (!shouldTerminateCallbackWasCalled)
                     printf("FAIL: %s script on dispatch queue timeout callback was not called.\n", tierOptions.tier);

Modified: trunk/Source/_javascript_Core/ChangeLog (226294 => 226295)


--- trunk/Source/_javascript_Core/ChangeLog	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-12-27 00:33:11 UTC (rev 226295)
@@ -1,3 +1,40 @@
+2017-12-26  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Remove std::chrono completely
+        https://bugs.webkit.org/show_bug.cgi?id=181165
+
+        Reviewed by Konstantin Tokarev.
+
+        This patch removes std::chrono use completely from JSC.
+
+        * API/JSContextRef.cpp:
+        (JSContextGroupSetExecutionTimeLimit):
+        * API/tests/ExecutionTimeLimitTest.cpp:
+        (currentCPUTimeAsJSFunctionCallback):
+        (testExecutionTimeLimit):
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::CodeBlock):
+        (JSC::timeToLive):
+        * bytecode/CodeBlock.h:
+        (JSC::CodeBlock::timeSinceCreation):
+        * runtime/SamplingProfiler.cpp:
+        (JSC::SamplingProfiler::SamplingProfiler):
+        (JSC::SamplingProfiler::timerLoop):
+        (JSC::SamplingProfiler::takeSample):
+        (JSC::SamplingProfiler::reportTopFunctions):
+        (JSC::SamplingProfiler::reportTopBytecodes):
+        * runtime/SamplingProfiler.h:
+        (JSC::SamplingProfiler::setTimingInterval):
+        * runtime/VM.cpp:
+        (JSC::VM::VM):
+        * runtime/Watchdog.cpp:
+        (JSC::Watchdog::Watchdog):
+        (JSC::Watchdog::setTimeLimit):
+        (JSC::Watchdog::shouldTerminate):
+        (JSC::Watchdog::startTimer):
+        (JSC::currentWallClockTime): Deleted.
+        * runtime/Watchdog.h:
+
 2017-12-26  Zan Dobersek  <[email protected]>
 
         REGRESSION(r226269): 60 JSC test failures on ARMv7

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp (226294 => 226295)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2017-12-27 00:33:11 UTC (rev 226295)
@@ -328,7 +328,7 @@
     , m_osrExitCounter(0)
     , m_optimizationDelayCounter(0)
     , m_reoptimizationRetryCounter(0)
-    , m_creationTime(std::chrono::steady_clock::now())
+    , m_creationTime(MonotonicTime::now())
 {
     m_visitWeaklyHasBeenCalled = false;
 
@@ -386,7 +386,7 @@
     , m_osrExitCounter(0)
     , m_optimizationDelayCounter(0)
     , m_reoptimizationRetryCounter(0)
-    , m_creationTime(std::chrono::steady_clock::now())
+    , m_creationTime(MonotonicTime::now())
 {
     m_visitWeaklyHasBeenCalled = false;
 
@@ -1089,36 +1089,36 @@
     return !Heap::isMarked(this);
 }
 
-static std::chrono::milliseconds timeToLive(JITCode::JITType jitType)
+static Seconds timeToLive(JITCode::JITType jitType)
 {
     if (UNLIKELY(Options::useEagerCodeBlockJettisonTiming())) {
         switch (jitType) {
         case JITCode::InterpreterThunk:
-            return std::chrono::milliseconds(10);
+            return 10_ms;
         case JITCode::BaselineJIT:
-            return std::chrono::milliseconds(10 + 20);
+            return 30_ms;
         case JITCode::DFGJIT:
-            return std::chrono::milliseconds(40);
+            return 40_ms;
         case JITCode::FTLJIT:
-            return std::chrono::milliseconds(120);
+            return 120_ms;
         default:
-            return std::chrono::milliseconds::max();
+            return Seconds::infinity();
         }
     }
 
     switch (jitType) {
     case JITCode::InterpreterThunk:
-        return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(5));
+        return 5_s;
     case JITCode::BaselineJIT:
         // Effectively 10 additional seconds, since BaselineJIT and
         // InterpreterThunk share a CodeBlock.
-        return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(5 + 10));
+        return 15_s;
     case JITCode::DFGJIT:
-        return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(20));
+        return 20_s;
     case JITCode::FTLJIT:
-        return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(60));
+        return 60_s;
     default:
-        return std::chrono::milliseconds::max();
+        return Seconds::infinity();
     }
 }
 

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.h (226294 => 226295)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2017-12-27 00:33:11 UTC (rev 226295)
@@ -939,10 +939,9 @@
     void stronglyVisitWeakReferences(const ConcurrentJSLocker&, SlotVisitor&);
     void visitOSRExitTargets(const ConcurrentJSLocker&, SlotVisitor&);
 
-    std::chrono::milliseconds timeSinceCreation()
+    Seconds timeSinceCreation()
     {
-        return std::chrono::duration_cast<std::chrono::milliseconds>(
-            std::chrono::steady_clock::now() - m_creationTime);
+        return MonotonicTime::now() - m_creationTime;
     }
 
     void createRareDataIfNecessary()
@@ -1027,7 +1026,7 @@
     uint16_t m_optimizationDelayCounter;
     uint16_t m_reoptimizationRetryCounter;
 
-    std::chrono::steady_clock::time_point m_creationTime;
+    MonotonicTime m_creationTime;
 
     std::unique_ptr<RareData> m_rareData;
 

Modified: trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp (226294 => 226295)


--- trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp	2017-12-27 00:33:11 UTC (rev 226295)
@@ -278,7 +278,7 @@
     : m_vm(vm)
     , m_weakRandom()
     , m_stopwatch(WTFMove(stopwatch))
-    , m_timingInterval(std::chrono::microseconds(Options::sampleInterval()))
+    , m_timingInterval(Seconds::fromMicroseconds(Options::sampleInterval()))
     , m_isPaused(false)
     , m_isShutDown(false)
 {
@@ -310,7 +310,7 @@
 void SamplingProfiler::timerLoop()
 {
     while (true) {
-        std::chrono::microseconds stackTraceProcessingTime = std::chrono::microseconds(0);
+        Seconds stackTraceProcessingTime = 0_s;
         {
             LockHolder locker(m_lock);
             if (UNLIKELY(m_isShutDown))
@@ -327,12 +327,12 @@
         // with some system process such as a scheduled context switch.
         // http://plv.colorado.edu/papers/mytkowicz-pldi10.pdf
         double randomSignedNumber = (m_weakRandom.get() * 2.0) - 1.0; // A random number between [-1, 1).
-        std::chrono::microseconds randomFluctuation = std::chrono::microseconds(static_cast<int64_t>(randomSignedNumber * static_cast<double>(m_timingInterval.count()) * 0.20l));
-        std::this_thread::sleep_for(m_timingInterval - std::min(m_timingInterval, stackTraceProcessingTime) + randomFluctuation);
+        Seconds randomFluctuation = m_timingInterval * 0.2 * randomSignedNumber;
+        WTF::sleep(m_timingInterval - std::min(m_timingInterval, stackTraceProcessingTime) + randomFluctuation);
     }
 }
 
-void SamplingProfiler::takeSample(const AbstractLocker&, std::chrono::microseconds& stackTraceProcessingTime)
+void SamplingProfiler::takeSample(const AbstractLocker&, Seconds& stackTraceProcessingTime)
 {
     ASSERT(m_lock.isLocked());
     if (m_vm.entryScope) {
@@ -392,7 +392,7 @@
 
             m_jscExecutionThread->resume();
 
-            auto startTime = std::chrono::steady_clock::now();
+            auto startTime = MonotonicTime::now();
             // We can now use data structures that malloc, and do other interesting things, again.
 
             // FIXME: It'd be interesting to take data about the program's state when
@@ -413,8 +413,8 @@
                     m_currentFrames.grow(m_currentFrames.size() * 1.25);
             }
 
-            auto endTime = std::chrono::steady_clock::now();
-            stackTraceProcessingTime = std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime);
+            auto endTime = MonotonicTime::now();
+            stackTraceProcessingTime = endTime - startTime;
         }
     }
 }
@@ -980,7 +980,7 @@
     };
 
     if (Options::samplingProfilerTopFunctionsCount()) {
-        out.print("\n\nSampling rate: ", m_timingInterval.count(), " microseconds\n");
+        out.print("\n\nSampling rate: ", m_timingInterval.microseconds(), " microseconds\n");
         out.print("Top functions as <numSamples  'functionName:sourceID'>\n");
         for (size_t i = 0; i < Options::samplingProfilerTopFunctionsCount(); i++) {
             auto pair = takeMax();
@@ -1053,7 +1053,7 @@
     };
 
     if (Options::samplingProfilerTopBytecodesCount()) {
-        out.print("\n\nSampling rate: ", m_timingInterval.count(), " microseconds\n");
+        out.print("\n\nSampling rate: ", m_timingInterval.microseconds(), " microseconds\n");
         out.print("Hottest bytecodes as <numSamples   'functionName#hash:JITType:bytecodeIndex'>\n");
         for (size_t i = 0; i < Options::samplingProfilerTopBytecodesCount(); i++) {
             auto pair = takeMax();

Modified: trunk/Source/_javascript_Core/runtime/SamplingProfiler.h (226294 => 226295)


--- trunk/Source/_javascript_Core/runtime/SamplingProfiler.h	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/runtime/SamplingProfiler.h	2017-12-27 00:33:11 UTC (rev 226295)
@@ -162,7 +162,7 @@
     void shutdown();
     void visit(SlotVisitor&);
     Lock& getLock() { return m_lock; }
-    void setTimingInterval(std::chrono::microseconds interval) { m_timingInterval = interval; }
+    void setTimingInterval(Seconds interval) { m_timingInterval = interval; }
     JS_EXPORT_PRIVATE void start();
     void start(const AbstractLocker&);
     Vector<StackTrace> releaseStackTraces(const AbstractLocker&);
@@ -185,7 +185,7 @@
 private:
     void createThreadIfNecessary(const AbstractLocker&);
     void timerLoop();
-    void takeSample(const AbstractLocker&, std::chrono::microseconds& stackTraceProcessingTime);
+    void takeSample(const AbstractLocker&, Seconds& stackTraceProcessingTime);
 
     VM& m_vm;
     WeakRandom m_weakRandom;
@@ -192,7 +192,7 @@
     RefPtr<Stopwatch> m_stopwatch;
     Vector<StackTrace> m_stackTraces;
     Vector<UnprocessedStackTrace> m_unprocessedStackTraces;
-    std::chrono::microseconds m_timingInterval;
+    Seconds m_timingInterval;
     double m_lastTime;
     Lock m_lock;
     RefPtr<Thread> m_thread;

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (226294 => 226295)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2017-12-27 00:33:11 UTC (rev 226295)
@@ -418,9 +418,8 @@
         setShouldBuildPCToCodeOriginMapping();
 
     if (Options::watchdog()) {
-        std::chrono::milliseconds timeoutMillis(Options::watchdog());
         Watchdog& watchdog = ensureWatchdog();
-        watchdog.setTimeLimit(timeoutMillis);
+        watchdog.setTimeLimit(Seconds::fromMilliseconds(Options::watchdog()));
     }
 
     // Make sure that any stubs that the JIT is going to use are initialized in non-compilation threads.

Modified: trunk/Source/_javascript_Core/runtime/Watchdog.cpp (226294 => 226295)


--- trunk/Source/_javascript_Core/runtime/Watchdog.cpp	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/runtime/Watchdog.cpp	2017-12-27 00:33:11 UTC (rev 226295)
@@ -32,19 +32,13 @@
 
 namespace JSC {
 
-const std::chrono::microseconds Watchdog::noTimeLimit = std::chrono::microseconds::max();
+const Seconds Watchdog::noTimeLimit { Seconds::infinity() };
 
-static std::chrono::microseconds currentWallClockTime()
-{
-    auto steadyTimeSinceEpoch = std::chrono::steady_clock::now().time_since_epoch();
-    return std::chrono::duration_cast<std::chrono::microseconds>(steadyTimeSinceEpoch);
-}
-
 Watchdog::Watchdog(VM* vm)
     : m_vm(vm)
     , m_timeLimit(noTimeLimit)
     , m_cpuDeadline(noTimeLimit)
-    , m_wallClockDeadline(noTimeLimit)
+    , m_deadline(MonotonicTime::infinity())
     , m_callback(0)
     , m_callbackData1(0)
     , m_callbackData2(0)
@@ -52,7 +46,7 @@
 {
 }
 
-void Watchdog::setTimeLimit(std::chrono::microseconds limit,
+void Watchdog::setTimeLimit(Seconds limit,
     ShouldTerminateCallback callback, void* data1, void* data2)
 {
     ASSERT(m_vm->currentThreadIsHoldingAPILock());
@@ -69,12 +63,12 @@
 bool Watchdog::shouldTerminate(ExecState* exec)
 {
     ASSERT(m_vm->currentThreadIsHoldingAPILock());
-    if (currentWallClockTime() < m_wallClockDeadline)
+    if (MonotonicTime::now() < m_deadline)
         return false; // Just a stale timer firing. Nothing to do.
 
-    // Set m_wallClockDeadline to noTimeLimit here so that we can reject all future
+    // Set m_deadline to MonotonicTime::infinity() here so that we can reject all future
     // spurious wakes.
-    m_wallClockDeadline = noTimeLimit;
+    m_deadline = MonotonicTime::infinity();
 
     auto cpuTime = currentCPUTime();
     if (cpuTime < m_cpuDeadline) {
@@ -130,7 +124,7 @@
     m_hasEnteredVM = false;
 }
 
-void Watchdog::startTimer(std::chrono::microseconds timeLimit)
+void Watchdog::startTimer(Seconds timeLimit)
 {
     ASSERT(m_hasEnteredVM);
     ASSERT(m_vm->currentThreadIsHoldingAPILock());
@@ -138,15 +132,14 @@
     ASSERT(timeLimit <= m_timeLimit);
 
     m_cpuDeadline = currentCPUTime() + timeLimit;
-    auto wallClockTime = currentWallClockTime();
-    auto wallClockDeadline = wallClockTime + timeLimit;
+    auto now = MonotonicTime::now();
+    auto deadline = now + timeLimit;
 
-    if ((wallClockTime < m_wallClockDeadline)
-        && (m_wallClockDeadline <= wallClockDeadline))
+    if ((now < m_deadline) && (m_deadline <= deadline))
         return; // Wait for the current active timer to expire before starting a new one.
 
     // Else, the current active timer won't fire soon enough. So, start a new timer.
-    m_wallClockDeadline = wallClockDeadline;
+    m_deadline = deadline;
 
     // We need to ensure that the Watchdog outlives the timer.
     // For the same reason, the timer may also outlive the VM that the Watchdog operates on.
@@ -153,7 +146,7 @@
     // So, we always need to null check m_vm before using it. The VM will notify the Watchdog
     // via willDestroyVM() before it goes away.
     RefPtr<Watchdog> protectedThis = this;
-    m_timerQueue->dispatchAfter(Seconds::fromMicroseconds(timeLimit.count()), [this, protectedThis] {
+    m_timerQueue->dispatchAfter(timeLimit, [this, protectedThis] {
         LockHolder locker(m_lock);
         if (m_vm)
             m_vm->notifyNeedWatchdogCheck();

Modified: trunk/Source/_javascript_Core/runtime/Watchdog.h (226294 => 226295)


--- trunk/Source/_javascript_Core/runtime/Watchdog.h	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/_javascript_Core/runtime/Watchdog.h	2017-12-27 00:33:11 UTC (rev 226295)
@@ -44,7 +44,7 @@
     void willDestroyVM(VM*);
 
     typedef bool (*ShouldTerminateCallback)(ExecState*, void* data1, void* data2);
-    void setTimeLimit(std::chrono::microseconds limit, ShouldTerminateCallback = 0, void* data1 = 0, void* data2 = 0);
+    void setTimeLimit(Seconds limit, ShouldTerminateCallback = 0, void* data1 = 0, void* data2 = 0);
 
     bool shouldTerminate(ExecState*);
 
@@ -52,19 +52,19 @@
     void enteredVM();
     void exitedVM();
 
-    static const std::chrono::microseconds noTimeLimit;
+    static const Seconds noTimeLimit;
 
 private:
-    void startTimer(std::chrono::microseconds timeLimit);
+    void startTimer(Seconds timeLimit);
     void stopTimer();
 
     Lock m_lock; // Guards access to m_vm.
     VM* m_vm;
 
-    std::chrono::microseconds m_timeLimit;
+    Seconds m_timeLimit;
 
-    std::chrono::microseconds m_cpuDeadline;
-    std::chrono::microseconds m_wallClockDeadline;
+    Seconds m_cpuDeadline;
+    MonotonicTime m_deadline;
 
     bool m_hasEnteredVM { false };
 

Modified: trunk/Source/WTF/ChangeLog (226294 => 226295)


--- trunk/Source/WTF/ChangeLog	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/WTF/ChangeLog	2017-12-27 00:33:11 UTC (rev 226295)
@@ -1,3 +1,17 @@
+2017-12-26  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Remove std::chrono completely
+        https://bugs.webkit.org/show_bug.cgi?id=181165
+
+        Reviewed by Konstantin Tokarev.
+
+        WTF::currentCPUTime now returns WTF::Seconds.
+        We also add the implementaiton for Linux and FreeBSD.
+
+        * wtf/CurrentTime.cpp:
+        (WTF::currentCPUTime):
+        * wtf/CurrentTime.h:
+
 2017-12-22  Wenson Hsieh  <[email protected]>
 
         Unreviewed, try to fix the Sierra build after r226277.

Modified: trunk/Source/WTF/wtf/CurrentTime.cpp (226294 => 226295)


--- trunk/Source/WTF/wtf/CurrentTime.cpp	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/WTF/wtf/CurrentTime.cpp	2017-12-27 00:33:11 UTC (rev 226295)
@@ -33,6 +33,7 @@
 
 #include "config.h"
 #include "CurrentTime.h"
+#include "MonotonicTime.h"
 
 #include "Condition.h"
 #include "Lock.h"
@@ -280,7 +281,7 @@
 
 #endif
 
-std::chrono::microseconds currentCPUTime()
+Seconds currentCPUTime()
 {
 #if OS(DARWIN)
     mach_msg_type_number_t infoCount = THREAD_BASIC_INFO_COUNT;
@@ -291,7 +292,7 @@
     thread_info(threadPort, THREAD_BASIC_INFO, reinterpret_cast<thread_info_t>(&info), &infoCount);
     mach_port_deallocate(mach_task_self(), threadPort);
 
-    return std::chrono::seconds(info.user_time.seconds + info.system_time.seconds) + std::chrono::microseconds(info.user_time.microseconds + info.system_time.microseconds);
+    return Seconds(info.user_time.seconds + info.system_time.seconds) + Seconds::fromMicroseconds(info.user_time.microseconds + info.system_time.microseconds);
 #elif OS(WINDOWS)
     union {
         FILETIME fileTime;
@@ -304,12 +305,16 @@
     
     GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, &kernelTime.fileTime, &userTime.fileTime);
 
-    return std::chrono::microseconds((userTime.fileTimeAsLong + kernelTime.fileTimeAsLong) / 10);
+    return Seconds::fromMicroseconds((userTime.fileTimeAsLong + kernelTime.fileTimeAsLong) / 10);
+#elif OS(LINUX) || OS(FREEBSD) || OS(OPENBSD) || OS(NETBSD)
+    struct timespec ts { };
+    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
+    return Seconds(ts.tv_sec) + Seconds::fromNanoseconds(ts.tv_nsec);
 #else
     // FIXME: We should return the time the current thread has spent executing.
 
-    static auto firstTime = std::chrono::steady_clock::now();
-    return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - firstTime);
+    static MonotonicTime firstTime = MonotonicTime::now();
+    return MonotonicTime::now() - firstTime;
 #endif
 }
 

Modified: trunk/Source/WTF/wtf/CurrentTime.h (226294 => 226295)


--- trunk/Source/WTF/wtf/CurrentTime.h	2017-12-26 18:54:38 UTC (rev 226294)
+++ trunk/Source/WTF/wtf/CurrentTime.h	2017-12-27 00:33:11 UTC (rev 226295)
@@ -32,8 +32,8 @@
 #ifndef CurrentTime_h
 #define CurrentTime_h
 
-#include <chrono>
 #include <time.h>
+#include <wtf/Seconds.h>
 
 namespace WTF {
 
@@ -64,7 +64,7 @@
 // Returns the current CPU time of the current thread.
 // Precision varies depending on platform but is usually as good or better
 // than a millisecond.
-WTF_EXPORT_PRIVATE std::chrono::microseconds currentCPUTime();
+WTF_EXPORT_PRIVATE Seconds currentCPUTime();
 
 WTF_EXPORT_PRIVATE void sleep(double);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to