diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/debug/test/CompilationAlarmPhaseTimesTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/debug/test/CompilationAlarmPhaseTimesTest.java index 33520be83e50..a91aefc89fee 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/debug/test/CompilationAlarmPhaseTimesTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/debug/test/CompilationAlarmPhaseTimesTest.java @@ -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; @@ -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); } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/util/CompilationAlarm.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/util/CompilationAlarm.java index 65c910e7a5db..6113ef96eb60 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/util/CompilationAlarm.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/util/CompilationAlarm.java @@ -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; } /**