22 */ |
22 */ |
23 |
23 |
24 |
24 |
25 package org.graalvm.compiler.jtt.jdk; |
25 package org.graalvm.compiler.jtt.jdk; |
26 |
26 |
|
27 import org.graalvm.compiler.api.directives.GraalDirectives; |
|
28 import org.graalvm.compiler.jtt.JTTTest; |
27 import org.junit.Test; |
29 import org.junit.Test; |
28 |
30 |
29 import org.graalvm.compiler.jtt.JTTTest; |
31 /** |
30 |
32 * Checks that the time between 2 successive calls to {@link System#nanoTime()} is less than 30 |
31 /* |
33 * microseconds at least once in 5_000_000 attempts. |
32 */ |
34 */ |
33 public class System_nanoTime02 extends JTTTest { |
35 public class System_nanoTime02 extends JTTTest { |
34 |
36 |
35 public static boolean test() { |
37 public static boolean test() { |
36 long minDelta = Long.MAX_VALUE; |
38 for (int i = 0; i < 5_000_000; i++) { |
37 |
39 long delta = System.nanoTime() - System.nanoTime(); |
38 // the first call to System.nanoTime might take a long time due to call resolution |
40 if (delta < 30_000) { |
39 for (int c = 0; c < 10; c++) { |
41 return true; |
40 long start = System.nanoTime(); |
|
41 long delta = 0; |
|
42 int i; |
|
43 for (i = 0; delta == 0 && i < 50000; i++) { |
|
44 delta = System.nanoTime() - start; |
|
45 // do nothing. |
|
46 } |
|
47 if (delta < minDelta) { |
|
48 minDelta = delta; |
|
49 } |
42 } |
50 } |
43 } |
51 |
44 if (!GraalDirectives.inCompiledCode()) { |
52 // better get at least 30 microsecond resolution. |
45 // We don't care about the result for the interpreter, C1 or C2 |
53 return minDelta > 1 && minDelta < 30000; |
46 return true; |
|
47 } |
|
48 return false; |
54 } |
49 } |
55 |
50 |
56 @Test |
51 @Test |
57 public void run0() throws Throwable { |
52 public void run0() throws Throwable { |
58 runTest("test"); |
53 runTest("test"); |
59 } |
54 } |
60 |
|
61 } |
55 } |