Skip to content

Commit

Permalink
[GR-58710] Compilation alarm test: check for scaled periods.
Browse files Browse the repository at this point in the history
PullRequest: graal/18970
  • Loading branch information
davleopo committed Oct 7, 2024
2 parents ecc7c2d + 858050f commit 5559305
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ protected void run(StructuredGraph graph, LowTierContext context) {

@Test
public void testTimeOutRetryToString() {
// 1D will be multiplied by 2 since we are running with assertions
OptionValues opt = new OptionValues(getInitialOptions(), CompilationAlarm.Options.CompilationExpirationPeriod, 1D);
final double secondsToWait = 1D;
OptionValues opt = new OptionValues(getInitialOptions(), CompilationAlarm.Options.CompilationExpirationPeriod, secondsToWait);
try {
test(opt, "foo", 10000);
} catch (Throwable t) {
if (!t.getMessage().contains("Compilation exceeded 2.000 seconds")) {
if (!t.getMessage().contains("Compilation exceeded")) {
throw new AssertionError("Unexpected exception: " + t, t);
}
StructuredGraph g = lastCompiledGraph;
Expand All @@ -103,7 +103,9 @@ public void testTimeOutRetryToString() {
duration += c;
index++;
}
assert Integer.parseInt(duration) >= 2000 - IMPRECISION_DELTA : String.format("Must at least wait for 2000ms but waited %s error was %s", duration, message);
final double scaledSecondsToWait = CompilationAlarm.scaleExpirationPeriod(secondsToWait, opt);
assert Integer.parseInt(duration) >= (scaledSecondsToWait * 1000) -
IMPRECISION_DELTA : String.format("Must at least wait for 2000ms but waited %s error was %s", duration, message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,24 @@ private CompilationAlarm(double period) {
public void reset(OptionValues options) {
double optionPeriod = Options.CompilationExpirationPeriod.getValue(options);
if (optionPeriod > 0) {
if (Assertions.assertionsEnabled()) {
optionPeriod *= 2;
}
if (Assertions.detailedAssertionsEnabled(options)) {
optionPeriod *= 2;
}
reset(optionPeriod);
reset(scaleExpirationPeriod(optionPeriod, options));
}
}

/**
* Scale the compilation alarm expiration period to account for different system properties. The
* period has a default value or can be set by users. Global context flags like assertions can
* slow down compilation significantly and we want to avoid false positives of the alarm.
*/
public static double scaleExpirationPeriod(double period, OptionValues options) {
double p = period;
if (Assertions.assertionsEnabled()) {
p *= 2;
}
if (Assertions.detailedAssertionsEnabled(options)) {
p *= 2;
}
return p;
}

/**
Expand Down

0 comments on commit 5559305

Please sign in to comment.