Skip to content

Commit 105c486

Browse files
author
Satyen Subramaniam
committed
8303089: [jittester] Add time limit to IRTree generation
Backport-of: 4d33fbd582d0a3c38180385bdef7225426273806
1 parent 3a21a27 commit 105c486

File tree

3 files changed

+61
-27
lines changed

3 files changed

+61
-27
lines changed

test/hotspot/jtreg/testlibrary/jittester/src/jdk/test/lib/jittester/Automatic.java

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,6 +40,7 @@ public class Automatic {
4040
public static final int MINUTES_TO_WAIT = Integer.getInteger("jdk.test.lib.jittester", 3);
4141

4242
private static Pair<IRNode, IRNode> generateIRTree(String name) {
43+
ProductionLimiter.resetTimer();
4344
SymbolTable.removeAll();
4445
TypeList.removeAll();
4546

@@ -117,34 +118,41 @@ public static void main(String[] args) {
117118
List<TestsGenerator> generators = getTestGenerators();
118119
do {
119120
double start = System.currentTimeMillis();
120-
System.out.print("[" + LocalTime.now() + "] |");
121-
String name = "Test_" + counter;
122-
Pair<IRNode, IRNode> irTree = generateIRTree(name);
123-
System.out.printf(" %8d |", counter);
124-
long maxWaitTime = TimeUnit.MINUTES.toMillis(MINUTES_TO_WAIT);
125-
double generationTime = System.currentTimeMillis() - start;
126-
System.out.printf(" %8.0f |", generationTime);
127-
start = System.currentTimeMillis();
128-
Thread generatorThread = new Thread(() -> {
129-
for (TestsGenerator generator : generators) {
121+
try {
122+
System.out.print("[" + LocalTime.now() + "] |");
123+
String name = "Test_" + counter;
124+
Pair<IRNode, IRNode> irTree = generateIRTree(name);
125+
System.out.printf(" %8d |", counter);
126+
long maxWaitTime = TimeUnit.MINUTES.toMillis(MINUTES_TO_WAIT);
127+
double generationTime = System.currentTimeMillis() - start;
128+
System.out.printf(" %8.0f |", generationTime);
129+
start = System.currentTimeMillis();
130+
Thread generatorThread = new Thread(() -> {
131+
for (TestsGenerator generator : generators) {
130132
generator.accept(irTree.first, irTree.second);
133+
}
134+
});
135+
generatorThread.start();
136+
try {
137+
generatorThread.join(maxWaitTime);
138+
} catch (InterruptedException ie) {
139+
throw new Error("Test generation interrupted: " + ie, ie);
131140
}
132-
});
133-
generatorThread.start();
134-
try {
135-
generatorThread.join(maxWaitTime);
136-
} catch (InterruptedException ie) {
137-
throw new Error("Test generation interrupted: " + ie, ie);
138-
}
139-
if (generatorThread.isAlive()) {
140-
// maxTime reached, so, proceed to next test generation
141-
generatorThread.interrupt();
142-
} else {
143-
double runningTime = System.currentTimeMillis() - start;
144-
System.out.printf(" %8.0f |%n", runningTime);
145-
if (runningTime < maxWaitTime) {
146-
++counter;
141+
if (generatorThread.isAlive()) {
142+
// maxTime reached, so, proceed to next test generation
143+
generatorThread.interrupt();
144+
} else {
145+
double runningTime = System.currentTimeMillis() - start;
146+
System.out.printf(" %8.0f |%n", runningTime);
147+
if (runningTime < maxWaitTime) {
148+
++counter;
149+
}
147150
}
151+
} catch (RuntimeException ignored) {
152+
// Generation failures happen due to nature of fuzzing test generators,
153+
// such errors are ignored.
154+
System.out.println("Test_" + counter + " ignored, generation failed due to " +
155+
ignored.getMessage());
148156
}
149157
} while (counter < ProductionParams.numberOfTests.value());
150158
}

test/hotspot/jtreg/testlibrary/jittester/src/jdk/test/lib/jittester/ProductionLimiter.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,11 +22,17 @@
2222
*/
2323

2424
package jdk.test.lib.jittester;
25+
26+
import java.time.Duration;
27+
import java.time.Instant;
28+
2529
// an utility class to limit steps in the production of an expression
2630
public class ProductionLimiter {
2731

2832
private static Integer limit = -1;
2933

34+
private static Instant limitInstant;
35+
3036
public static void setUnlimited() {
3137
limit = -1;
3238
}
@@ -44,5 +50,23 @@ public static void limitProduction() throws ProductionFailedException {
4450
if (limit != -1 && limit <= 0) {
4551
throw new ProductionFailedException();
4652
}
53+
54+
if (Instant.now().isAfter(limitInstant)) {
55+
long paramsLimitSeconds = ProductionParams.productionLimitSeconds.value();
56+
Duration elapsed = Duration.between(limitInstant.minusSeconds(paramsLimitSeconds), Instant.now());
57+
String elapsedStr = String.format("%d:%02d:%02d",
58+
elapsed.toHoursPart(), elapsed.toMinutesPart(), elapsed.toSecondsPart());
59+
60+
Duration timeLimit = Duration.ofSeconds(paramsLimitSeconds);
61+
String timeLimitStr = String.format("%d:%02d:%02d",
62+
timeLimit.toHoursPart(), timeLimit.toMinutesPart(), timeLimit.toSecondsPart());
63+
64+
throw new RuntimeException(String.format("A test generation took %s while limit is %s",
65+
elapsedStr, timeLimitStr));
66+
}
67+
}
68+
69+
public static void resetTimer() {
70+
limitInstant = Instant.now().plusSeconds(ProductionParams.productionLimitSeconds.value());
4771
}
4872
}

test/hotspot/jtreg/testlibrary/jittester/src/jdk/test/lib/jittester/ProductionParams.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
public class ProductionParams {
3030

3131
public static Option<Integer> productionLimit = null;
32+
public static Option<Integer> productionLimitSeconds = null;
3233
public static Option<Integer> dataMemberLimit = null;
3334
public static Option<Integer> statementLimit = null;
3435
public static Option<Integer> testStatementLimit = null;
@@ -81,6 +82,7 @@ public class ProductionParams {
8182

8283
public static void register(OptionResolver optionResolver) {
8384
productionLimit = optionResolver.addIntegerOption('l', "production-limit", 100, "Limit on steps in the production of an expression");
85+
productionLimitSeconds = optionResolver.addIntegerOption("production-limit-seconds", 600, "Limit the time a test generation may take");
8486
dataMemberLimit = optionResolver.addIntegerOption('v', "data-member-limit", 10, "Upper limit on data members");
8587
statementLimit = optionResolver.addIntegerOption('s', "statement-limit", 30, "Upper limit on statements in function");
8688
testStatementLimit = optionResolver.addIntegerOption('e', "test-statement-limit", 300, "Upper limit on statements in test() function");

0 commit comments

Comments
 (0)