Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,6 +40,7 @@ public class Automatic {
public static final int MINUTES_TO_WAIT = Integer.getInteger("jdk.test.lib.jittester", 3);

private static Pair<IRNode, IRNode> generateIRTree(String name) {
ProductionLimiter.resetTimer();
SymbolTable.removeAll();
TypeList.removeAll();

Expand Down Expand Up @@ -117,34 +118,41 @@ public static void main(String[] args) {
List<TestsGenerator> generators = getTestGenerators();
do {
double start = System.currentTimeMillis();
System.out.print("[" + LocalTime.now() + "] |");
String name = "Test_" + counter;
Pair<IRNode, IRNode> irTree = generateIRTree(name);
System.out.printf(" %8d |", counter);
long maxWaitTime = TimeUnit.MINUTES.toMillis(MINUTES_TO_WAIT);
double generationTime = System.currentTimeMillis() - start;
System.out.printf(" %8.0f |", generationTime);
start = System.currentTimeMillis();
Thread generatorThread = new Thread(() -> {
for (TestsGenerator generator : generators) {
try {
System.out.print("[" + LocalTime.now() + "] |");
String name = "Test_" + counter;
Pair<IRNode, IRNode> irTree = generateIRTree(name);
System.out.printf(" %8d |", counter);
long maxWaitTime = TimeUnit.MINUTES.toMillis(MINUTES_TO_WAIT);
double generationTime = System.currentTimeMillis() - start;
System.out.printf(" %8.0f |", generationTime);
start = System.currentTimeMillis();
Thread generatorThread = new Thread(() -> {
for (TestsGenerator generator : generators) {
generator.accept(irTree.first, irTree.second);
}
});
generatorThread.start();
try {
generatorThread.join(maxWaitTime);
} catch (InterruptedException ie) {
throw new Error("Test generation interrupted: " + ie, ie);
}
});
generatorThread.start();
try {
generatorThread.join(maxWaitTime);
} catch (InterruptedException ie) {
throw new Error("Test generation interrupted: " + ie, ie);
}
if (generatorThread.isAlive()) {
// maxTime reached, so, proceed to next test generation
generatorThread.interrupt();
} else {
double runningTime = System.currentTimeMillis() - start;
System.out.printf(" %8.0f |%n", runningTime);
if (runningTime < maxWaitTime) {
++counter;
if (generatorThread.isAlive()) {
// maxTime reached, so, proceed to next test generation
generatorThread.interrupt();
} else {
double runningTime = System.currentTimeMillis() - start;
System.out.printf(" %8.0f |%n", runningTime);
if (runningTime < maxWaitTime) {
++counter;
}
}
} catch (RuntimeException ignored) {
// Generation failures happen due to nature of fuzzing test generators,
// such errors are ignored.
System.out.println("Test_" + counter + " ignored, generation failed due to " +
ignored.getMessage());
}
} while (counter < ProductionParams.numberOfTests.value());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,11 +22,17 @@
*/

package jdk.test.lib.jittester;

import java.time.Duration;
import java.time.Instant;

// an utility class to limit steps in the production of an expression
public class ProductionLimiter {

private static Integer limit = -1;

private static Instant limitInstant;

public static void setUnlimited() {
limit = -1;
}
Expand All @@ -44,5 +50,23 @@ public static void limitProduction() throws ProductionFailedException {
if (limit != -1 && limit <= 0) {
throw new ProductionFailedException();
}

if (Instant.now().isAfter(limitInstant)) {
long paramsLimitSeconds = ProductionParams.productionLimitSeconds.value();
Duration elapsed = Duration.between(limitInstant.minusSeconds(paramsLimitSeconds), Instant.now());
String elapsedStr = String.format("%d:%02d:%02d",
elapsed.toHoursPart(), elapsed.toMinutesPart(), elapsed.toSecondsPart());

Duration timeLimit = Duration.ofSeconds(paramsLimitSeconds);
String timeLimitStr = String.format("%d:%02d:%02d",
timeLimit.toHoursPart(), timeLimit.toMinutesPart(), timeLimit.toSecondsPart());

throw new RuntimeException(String.format("A test generation took %s while limit is %s",
elapsedStr, timeLimitStr));
}
}

public static void resetTimer() {
limitInstant = Instant.now().plusSeconds(ProductionParams.productionLimitSeconds.value());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class ProductionParams {

public static Option<Integer> productionLimit = null;
public static Option<Integer> productionLimitSeconds = null;
public static Option<Integer> dataMemberLimit = null;
public static Option<Integer> statementLimit = null;
public static Option<Integer> testStatementLimit = null;
Expand Down Expand Up @@ -81,6 +82,7 @@ public class ProductionParams {

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