mozilla-tests.yaml/js1_5/Array/regress-101964.js is frequently failing on JSC EWS bots.
https://bugs.webkit.org/show_bug.cgi?id=200789
<rdar://problem/54361916>

Reviewed by Keith Miller.

JSTests:

The prevailing theory is that this test is being pre-empted and not getting the
CPU time it needs to complete.  As a result, the wall clock time period for
running the test exceeds the expected time.  This patch tests this theory by
changing the time measurement to use CPU time instead.

* mozilla/js1_5/Array/regress-101964.js:

Source/JavaScriptCore:

* tools/JSDollarVM.cpp:
(JSC::functionCurrentCPUTime):
(JSC::JSDollarVM::finishCreation):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@253008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JSTests/ChangeLog b/JSTests/ChangeLog
index db78483..6c63af8 100644
--- a/JSTests/ChangeLog
+++ b/JSTests/ChangeLog
@@ -1,3 +1,18 @@
+2019-12-02  Mark Lam  <mark.lam@apple.com>
+
+        mozilla-tests.yaml/js1_5/Array/regress-101964.js is frequently failing on JSC EWS bots.
+        https://bugs.webkit.org/show_bug.cgi?id=200789
+        <rdar://problem/54361916>
+
+        Reviewed by Keith Miller.
+
+        The prevailing theory is that this test is being pre-empted and not getting the
+        CPU time it needs to complete.  As a result, the wall clock time period for
+        running the test exceeds the expected time.  This patch tests this theory by
+        changing the time measurement to use CPU time instead.
+
+        * mozilla/js1_5/Array/regress-101964.js:
+
 2019-12-01  Caio Lima  <ticaiolima@gmail.com>
 
         [JSC][MIPS] CallFrame is being clobbered on InternalFunction execution
diff --git a/JSTests/mozilla/js1_5/Array/regress-101964.js b/JSTests/mozilla/js1_5/Array/regress-101964.js
index 6542e34..1d7c54e 100644
--- a/JSTests/mozilla/js1_5/Array/regress-101964.js
+++ b/JSTests/mozilla/js1_5/Array/regress-101964.js
@@ -46,7 +46,7 @@
 
 status = inSection(1);
 var arr = Array(BIG);
-var start = new Date();
+var start = $vm.currentCPUTime();
 arr.length = LITTLE;
 actual = elapsedTime(start);
 expect = FAST;
@@ -62,7 +62,7 @@
 
 function elapsedTime(startTime)
 {
-  return new Date() - startTime;
+  return $vm.currentCPUTime() - startTime;
 }
 
 
diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog
index b07b033..3c540a7 100644
--- a/Source/JavaScriptCore/ChangeLog
+++ b/Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,15 @@
+2019-12-02  Mark Lam  <mark.lam@apple.com>
+
+        mozilla-tests.yaml/js1_5/Array/regress-101964.js is frequently failing on JSC EWS bots.
+        https://bugs.webkit.org/show_bug.cgi?id=200789
+        <rdar://problem/54361916>
+
+        Reviewed by Keith Miller.
+
+        * tools/JSDollarVM.cpp:
+        (JSC::functionCurrentCPUTime):
+        (JSC::JSDollarVM::finishCreation):
+
 2019-12-02  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] Put JSGenerator, JSAsyncGenerator, and JSPromise in IsoSubspace
diff --git a/Source/JavaScriptCore/tools/JSDollarVM.cpp b/Source/JavaScriptCore/tools/JSDollarVM.cpp
index 407f653..70a1a6e 100644
--- a/Source/JavaScriptCore/tools/JSDollarVM.cpp
+++ b/Source/JavaScriptCore/tools/JSDollarVM.cpp
@@ -53,6 +53,7 @@
 #include "VMInspector.h"
 #include "WasmCapabilities.h"
 #include <wtf/Atomics.h>
+#include <wtf/CPUTime.h>
 #include <wtf/DataLog.h>
 #include <wtf/ProcessID.h>
 #include <wtf/StringPrintStream.h>
@@ -2675,6 +2676,12 @@
     return JSValue::encode(jsNumber(static_cast<int32_t>(delta)));
 }
 
+static EncodedJSValue JSC_HOST_CALL functionCurrentCPUTime(JSGlobalObject*, CallFrame*)
+{
+    DollarVMAssertScope assertScope;
+    return JSValue::encode(jsNumber(CPUTime::forCurrentThread().value()));
+}
+
 static EncodedJSValue JSC_HOST_CALL functionTotalGCTime(JSGlobalObject* globalObject, CallFrame*)
 {
     DollarVMAssertScope assertScope;
@@ -2832,6 +2839,7 @@
 
     addFunction(vm, "deltaBetweenButterflies", functionDeltaBetweenButterflies, 2);
     
+    addFunction(vm, "currentCPUTime", functionCurrentCPUTime, 0);
     addFunction(vm, "totalGCTime", functionTotalGCTime, 0);
 
     addFunction(vm, "parseCount", functionParseCount, 0);