Skip to content

8365919: Replace currentTimeMillis with nanoTime in Stresser.java #26879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions test/hotspot/jtreg/vmTestbase/nsk/share/test/Stresser.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ public class Stresser implements ExecutionController {
private String name;
private long maxIterations;
private long iterations;

// In milliseconds
private long startTime;
private long finishTime;
private long currentTime;

private PrintStream defaultOutput = System.out;

/*
Expand Down Expand Up @@ -179,15 +181,15 @@ public void printStressInfo(PrintStream out) {
*/
public void printExecutionInfo(PrintStream out) {
println(out, "Completed iterations: " + iterations);
println(out, "Execution time: " + (currentTime - startTime) + " seconds");
println(out, "Execution time: " + (currentTime - startTime)/1000.0 + " seconds");
if (!finished) {
println(out, "Execution is not finished yet");
} else if (forceFinish) {
println(out, "Execution was forced to finish");
} else if (maxIterations != 0 && iterations >= maxIterations) {
println(out, "Execution finished because number of iterations was exceeded: " + iterations + " >= " + maxIterations);
} else if (finishTime != 0 && currentTime >= finishTime) {
println(out, "Execution finished because time was exceeded: " + (currentTime - startTime) + " >= " + (finishTime - startTime));
} else if (options.getTime() != 0 && (currentTime - startTime) >= options.getTime() * 1000) {
println(out, "Execution finished because time was exceeded: " + (currentTime - startTime) + " >= " + options.getTime() * 1000);
}
}

Expand All @@ -209,12 +211,7 @@ public void start(long stdIterations) {
maxIterations = stdIterations * options.getIterationsFactor();
iterations = 0;
long stressTime = options.getTime();
startTime = System.currentTimeMillis();
if (stressTime == 0) {
finishTime = 0;
} else {
finishTime = startTime + stressTime * 1000;
}
startTime = System.nanoTime()/1000000;
finished = false;
forceFinish = false;
if (options.isDebugEnabled()) {
Expand All @@ -232,7 +229,7 @@ public void start(long stdIterations) {
* finally {} block.
*/
public void finish() {
currentTime = System.currentTimeMillis();
currentTime = System.nanoTime()/1000000;
finished = true;
if (options.isDebugEnabled()) {
printExecutionInfo(defaultOutput);
Expand All @@ -255,10 +252,12 @@ public void forceFinish() {
*/
public boolean iteration() {
++iterations;
boolean result = continueExecution();
// Call print at the end to show the most up-to-date info.
if (options.isDebugDetailed()) {
printExecutionInfo(defaultOutput);
}
return continueExecution();
return result;
}

/**
Expand All @@ -267,14 +266,14 @@ public boolean iteration() {
* @return true if execution needs to continue
*/
public boolean continueExecution() {
currentTime = System.currentTimeMillis();
currentTime = System.nanoTime()/1000000;
if (startTime == 0) {
throw new TestBug("Stresser is not started.");
}
return !forceFinish
&& !finished
&& (maxIterations == 0 || iterations < maxIterations)
&& (finishTime == 0 || currentTime < finishTime);
&& (options.getTime() == 0 || (currentTime - startTime) < options.getTime() * 1000);
}

/**
Expand Down Expand Up @@ -309,7 +308,7 @@ public long getIterationsLeft() {
* @return time
*/
public long getExecutionTime() {
return System.currentTimeMillis() - startTime;
return System.nanoTime()/1000000 - startTime;
}

/**
Expand All @@ -318,11 +317,12 @@ public long getExecutionTime() {
* @return time
*/
public long getTimeLeft() {
long current = System.currentTimeMillis();
if (current >= finishTime) {
long elapsedTime = System.nanoTime()/1000000 - startTime;
long stressTime = options.getTime() * 1000;
if (elapsedTime >= stressTime) {
return 0;
} else {
return finishTime - current;
return stressTime - elapsedTime;
}
}

Expand Down