1
1
/*
2
- * Copyright (c) 2017, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2017, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* Copyright (c) 2017 SAP SE and/or its affiliates. All rights reserved.
4
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
5
*
@@ -62,12 +62,12 @@ public Node(int load) {
62
62
}
63
63
}
64
64
65
- public static void warmUp (long warmupEndTime , int size , long seed ) {
65
+ public static void warmUp (long warmupEndTimeNanos , int size , long seed ) {
66
66
Random r = new Random (seed );
67
67
// First let the GC assume most of our objects will die.
68
68
Node [] roots = new Node [size ];
69
69
70
- while (System .currentTimeMillis () < warmupEndTime ) {
70
+ while (System .nanoTime () - warmupEndTimeNanos < 0 ) {
71
71
int index = (int ) (r .nextDouble () * roots .length );
72
72
roots [index ] = new Node (1 );
73
73
}
@@ -78,7 +78,7 @@ public static void warmUp(long warmupEndTime, int size, long seed) {
78
78
}
79
79
}
80
80
81
- public static void runTest (long endTime , int size , double alive , long seed ) {
81
+ public static void runTest (long endTimeNanos , int size , double alive , long seed ) {
82
82
Random r = new Random (seed );
83
83
final int length = 10000 ;
84
84
int [] array1 = new int [length ];
@@ -91,7 +91,7 @@ public static void runTest(long endTime, int size, double alive, long seed) {
91
91
int index = 0 ;
92
92
roots [0 ] = new Node (0 );
93
93
94
- while (!hadError && (System .currentTimeMillis () < endTime )) {
94
+ while (!hadError && (System .nanoTime () - endTimeNanos < 0 )) {
95
95
int test_val1 = TestCriticalArray0 (array1 );
96
96
97
97
if (r .nextDouble () > alive ) {
@@ -136,15 +136,15 @@ public static void main(String[] args) throws Exception {
136
136
int warmupThreads = Integer .parseInt (args [0 ]);
137
137
System .out .println ("# Warmup Threads = " + warmupThreads );
138
138
139
- int warmupDuration = Integer .parseInt (args [1 ]);
140
- System .out .println ("WarmUp Duration = " + warmupDuration );
139
+ long warmupDurationNanos = 1_000_000L * Integer .parseInt (args [1 ]);
140
+ System .out .println ("WarmUp Duration Millis = " + args [ 1 ] );
141
141
int warmupIterations = Integer .parseInt (args [2 ]);
142
142
System .out .println ("# Warmup Iterations = " + warmupIterations );
143
143
144
144
int mainThreads = Integer .parseInt (args [3 ]);
145
145
System .out .println ("# Main Threads = " + mainThreads );
146
- int mainDuration = Integer .parseInt (args [4 ]);
147
- System .out .println ("Main Duration = " + mainDuration );
146
+ long mainDurationNanos = 1_000_000L * Integer .parseInt (args [4 ]);
147
+ System .out .println ("Main Duration Millis = " + args [ 4 ] );
148
148
int mainIterations = Integer .parseInt (args [5 ]);
149
149
System .out .println ("# Main Iterations = " + mainIterations );
150
150
@@ -154,12 +154,12 @@ public static void main(String[] args) throws Exception {
154
154
Thread threads [] = new Thread [Math .max (warmupThreads , mainThreads )];
155
155
156
156
System .out .println ("Start warm-up threads!" );
157
- long warmupStartTime = System .currentTimeMillis ();
157
+ long warmupStartTimeNanos = System .nanoTime ();
158
158
for (int i = 0 ; i < warmupThreads ; i ++) {
159
159
long seed = rng .nextLong ();
160
160
threads [i ] = new Thread () {
161
161
public void run () {
162
- warmUp (warmupStartTime + warmupDuration , warmupIterations , seed );
162
+ warmUp (warmupStartTimeNanos + warmupDurationNanos , warmupIterations , seed );
163
163
};
164
164
};
165
165
threads [i ].start ();
@@ -170,12 +170,12 @@ public void run() {
170
170
System .gc ();
171
171
System .out .println ("Keep alive a lot" );
172
172
173
- long startTime = System .currentTimeMillis ();
173
+ long startTimeNanos = System .nanoTime ();
174
174
for (int i = 0 ; i < mainThreads ; i ++) {
175
175
long seed = rng .nextLong ();
176
176
threads [i ] = new Thread () {
177
177
public void run () {
178
- runTest (startTime + mainDuration , mainIterations , liveFrac , seed );
178
+ runTest (startTimeNanos + mainDurationNanos , mainIterations , liveFrac , seed );
179
179
};
180
180
};
181
181
threads [i ].start ();
0 commit comments