Skip to content

Commit ab89a68

Browse files
committed
improve systemic compilation failure mechanism
1 parent 0de434d commit ab89a68

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/CompilationWrapper.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import java.io.IOException;
3939
import java.io.OutputStream;
4040
import java.io.PrintStream;
41+
import java.io.PrintWriter;
42+
import java.io.StringWriter;
4143
import java.util.Formatter;
4244
import java.util.Map;
4345
import java.util.concurrent.TimeUnit;
@@ -436,6 +438,9 @@ private void maybeExitVM(ExceptionAction action) {
436438
private static final long COMPILATION_FAILURE_DETECTION_PERIOD_NS = TimeUnit.SECONDS.toNanos(2);
437439
private static final int MIN_COMPILATIONS_FOR_FAILURE_DETECTION = 25;
438440

441+
// Ensures the system compilation failure warning is printed once per VM process.
442+
private static final GlobalAtomicLong SYSTEMIC_COMPILATION_FAILURE_WARNED = new GlobalAtomicLong("SYSTEMIC_COMPILATION_FAILURE_WARNED", 0L);
443+
439444
/**
440445
* Gets the start of the current compilation period, initializing it to {@code initialValue} if
441446
* this is the first period.
@@ -487,17 +492,23 @@ private static boolean detectCompilationFailureRateTooHigh(OptionValues options,
487492
// Wait for period to expire or some minimum amount of compilations
488493
// before detecting systemic failure.
489494
if (rate > maxRate && (periodExpired || total > MIN_COMPILATIONS_FOR_FAILURE_DETECTION)) {
490-
Formatter msg = new Formatter();
491-
String option = GraalCompilerOptions.SystemicCompilationFailureRate.getName();
492-
msg.format("Warning: Systemic Graal compilation failure detected: %d of %d (%d%%) of compilations failed during last %d ms [max rate set by %s is %d%%]. ",
493-
failed, total, rate, TimeUnit.NANOSECONDS.toMillis(periodNS), option, maxRateValue);
494-
msg.format("To mitigate systemic compilation failure detection, set %s to a higher value. ", option);
495-
msg.format("To disable systemic compilation failure detection, set %s to 0. ", option);
496-
msg.format("To get more information on compilation failures, set %s to Print or Diagnose. ", GraalCompilerOptions.CompilationFailureAction.getName());
497-
TTY.println(msg.toString());
498-
if (maxRateValue < 0) {
499-
// A negative value means the VM should be exited
500-
return true;
495+
if (SYSTEMIC_COMPILATION_FAILURE_WARNED.compareAndSet(0L, 1L)) {
496+
Formatter msg = new Formatter();
497+
String option = GraalCompilerOptions.SystemicCompilationFailureRate.getName();
498+
msg.format("Warning: Systemic Graal compilation failure detected: %d of %d (%d%%) of compilations failed during last %d ms [max rate set by %s is %d%%]. ",
499+
failed, total, rate, TimeUnit.NANOSECONDS.toMillis(periodNS), option, maxRateValue);
500+
msg.format("To mitigate systemic compilation failure detection, set %s to a higher value. ", option);
501+
msg.format("To disable systemic compilation failure detection, set %s to 0. ", option);
502+
msg.format("To get more information on compilation failures, set %s to Print or Diagnose. ", GraalCompilerOptions.CompilationFailureAction.getName());
503+
StringWriter sw = new StringWriter();
504+
cause.printStackTrace(new PrintWriter(sw));
505+
msg.format("Current failure: %s", sw.toString().replace("\n", "\\n").replace("\t", "\\t"));
506+
TTY.println(msg.toString());
507+
508+
if (maxRateValue < 0) {
509+
// A negative value means the VM should be exited
510+
return true;
511+
}
501512
}
502513
periodExpired = true;
503514
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/GraalCompilerOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Emit a heap dump after each phase matching the given phase filter(s).
7878
"CompilationFailureAction before changing to a less verbose action. " +
7979
"This does not apply to the ExitVM action..", type = OptionType.User)
8080
public static final OptionKey<Integer> MaxCompilationProblemsPerAction = new OptionKey<>(2);
81-
@Option(help = "Specifies the compilation failure rate that indicates a systemic compilation problem (and a resulting warning). " +
81+
@Option(help = "Specifies the compilation failure rate that indicates a systemic compilation problem. " +
8282
"The value is made absolute and clamped to produce P, a value between 0 and 100. " +
8383
"Systemic failure is detected if the percentage of failing compilations in a sliding time window >= P. " +
8484
"A negative value will cause the VM to exit after issuing the warning. Set to 0 to disable systemic compilation problem detection.", type = OptionType.User)

0 commit comments

Comments
 (0)