< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/CompilationWrapper.java

Print this page

        

*** 23,33 **** package org.graalvm.compiler.core; import static org.graalvm.compiler.core.CompilationWrapper.ExceptionAction.ExitVM; ! import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationBailoutAction; import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationFailureAction; import static org.graalvm.compiler.core.GraalCompilerOptions.ExitVMOnException; import static org.graalvm.compiler.core.GraalCompilerOptions.MaxCompilationProblemsPerAction; import static org.graalvm.compiler.debug.DebugContext.VERBOSE_LEVEL; import static org.graalvm.compiler.debug.DebugOptions.Dump; --- 23,33 ---- package org.graalvm.compiler.core; import static org.graalvm.compiler.core.CompilationWrapper.ExceptionAction.ExitVM; ! import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationBailoutAsFailure; import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationFailureAction; import static org.graalvm.compiler.core.GraalCompilerOptions.ExitVMOnException; import static org.graalvm.compiler.core.GraalCompilerOptions.MaxCompilationProblemsPerAction; import static org.graalvm.compiler.debug.DebugContext.VERBOSE_LEVEL; import static org.graalvm.compiler.debug.DebugOptions.Dump;
*** 43,60 **** import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.DiagnosticsOutputDirectory; import org.graalvm.compiler.debug.PathUtilities; import org.graalvm.compiler.debug.TTY; - import org.graalvm.compiler.options.EnumOptionKey; import org.graalvm.compiler.options.OptionValues; import jdk.vm.ci.code.BailoutException; /** * Wrapper for a compilation that centralizes what action to take based on ! * {@link GraalCompilerOptions#CompilationBailoutAction} and * {@link GraalCompilerOptions#CompilationFailureAction} when an uncaught exception occurs during * compilation. */ public abstract class CompilationWrapper<T> { --- 43,59 ---- import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.DiagnosticsOutputDirectory; import org.graalvm.compiler.debug.PathUtilities; import org.graalvm.compiler.debug.TTY; import org.graalvm.compiler.options.OptionValues; import jdk.vm.ci.code.BailoutException; /** * Wrapper for a compilation that centralizes what action to take based on ! * {@link GraalCompilerOptions#CompilationBailoutAsFailure} and * {@link GraalCompilerOptions#CompilationFailureAction} when an uncaught exception occurs during * compilation. */ public abstract class CompilationWrapper<T> {
*** 69,86 **** --- 68,88 ---- public enum ExceptionAction { /** * Print nothing to the console. */ Silent, + /** * Print a stack trace to the console. */ Print, + /** * An exception causes the compilation to be retried with extra diagnostics enabled. */ Diagnose, + /** * Same as {@link #Diagnose} except that the VM process is exited after retrying. */ ExitVM;
*** 120,150 **** * @return a value representing the result of a failed compilation (may be {@code null}) */ protected abstract T handleException(Throwable t); /** ! * Gets the action to take based on the value of {@code actionKey} in {@code options}. * ! * Subclasses can override this to choose a different action based on factors such as whether ! * {@code actionKey} has been explicitly set in {@code options} for example. * * @param cause the cause of the bailout or failure */ ! protected ExceptionAction lookupAction(OptionValues options, EnumOptionKey<ExceptionAction> actionKey, Throwable cause) { ! if (actionKey == CompilationFailureAction) { ! if (ExitVMOnException.getValue(options)) { ! assert CompilationFailureAction.getDefaultValue() != ExceptionAction.ExitVM; ! assert ExitVMOnException.getDefaultValue() != true; ! if (CompilationFailureAction.hasBeenSet(options) && CompilationFailureAction.getValue(options) != ExceptionAction.ExitVM) { ! TTY.printf("WARNING: Ignoring %s=%s since %s=true has been explicitly specified.%n", ! CompilationFailureAction.getName(), CompilationFailureAction.getValue(options), ! ExitVMOnException.getName()); ! } ! return ExceptionAction.ExitVM; } } ! return actionKey.getValue(options); } /** * Perform the compilation wrapped by this object. * --- 122,155 ---- * @return a value representing the result of a failed compilation (may be {@code null}) */ protected abstract T handleException(Throwable t); /** ! * Gets the action to take based on the value of ! * {@link GraalCompilerOptions#CompilationBailoutAsFailure}, ! * {@link GraalCompilerOptions#CompilationFailureAction} and ! * {@link GraalCompilerOptions#ExitVMOnException} in {@code options}. * ! * Subclasses can override this to choose a different action. * * @param cause the cause of the bailout or failure */ ! protected ExceptionAction lookupAction(OptionValues options, Throwable cause) { ! if (cause instanceof BailoutException && !CompilationBailoutAsFailure.getValue(options)) { ! return ExceptionAction.Silent; ! } ! if (ExitVMOnException.getValue(options)) { ! assert CompilationFailureAction.getDefaultValue() != ExceptionAction.ExitVM; ! assert ExitVMOnException.getDefaultValue() != true; ! if (CompilationFailureAction.hasBeenSet(options) && CompilationFailureAction.getValue(options) != ExceptionAction.ExitVM) { ! TTY.printf("WARNING: Ignoring %s=%s since %s=true has been explicitly specified.%n", ! CompilationFailureAction.getName(), CompilationFailureAction.getValue(options), ! ExitVMOnException.getName()); } + return ExceptionAction.ExitVM; } ! return CompilationFailureAction.getValue(options); } /** * Perform the compilation wrapped by this object. *
*** 171,221 **** try { return performCompilation(initialDebug); } catch (Throwable cause) { OptionValues initialOptions = initialDebug.getOptions(); - String causeType = "failure"; - EnumOptionKey<ExceptionAction> actionKey; - if (cause instanceof BailoutException) { - actionKey = CompilationBailoutAction; - causeType = "bailout"; - } else { - actionKey = CompilationFailureAction; - causeType = "failure"; - } synchronized (CompilationFailureAction) { // Serialize all compilation failure handling. // This prevents retry compilation storms and interleaving // of compilation exception messages. // It also allows for reliable testing of CompilationWrapper // by avoiding a race whereby retry compilation output from a // forced crash (i.e., use of GraalCompilerOptions.CrashAt) // is truncated. ! ExceptionAction action = lookupAction(initialOptions, actionKey, cause); ! action = adjustAction(initialOptions, actionKey, action); if (action == ExceptionAction.Silent) { return handleException(cause); } if (action == ExceptionAction.Print) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (PrintStream ps = new PrintStream(baos)) { ps.printf("%s: Compilation of %s failed: ", Thread.currentThread(), this); cause.printStackTrace(ps); ! ps.printf("To disable compilation %s notifications, set %s to %s (e.g., -Dgraal.%s=%s).%n", ! causeType, ! actionKey.getName(), ExceptionAction.Silent, ! actionKey.getName(), ExceptionAction.Silent); ! ps.printf("To capture more information for diagnosing or reporting a compilation %s, " + "set %s to %s or %s (e.g., -Dgraal.%s=%s).%n", ! causeType, ! actionKey.getName(), ExceptionAction.Diagnose, ExceptionAction.ExitVM, ! actionKey.getName(), ExceptionAction.Diagnose); } TTY.print(baos.toString()); return handleException(cause); } --- 176,215 ---- try { return performCompilation(initialDebug); } catch (Throwable cause) { OptionValues initialOptions = initialDebug.getOptions(); synchronized (CompilationFailureAction) { // Serialize all compilation failure handling. // This prevents retry compilation storms and interleaving // of compilation exception messages. // It also allows for reliable testing of CompilationWrapper // by avoiding a race whereby retry compilation output from a // forced crash (i.e., use of GraalCompilerOptions.CrashAt) // is truncated. ! ExceptionAction action = lookupAction(initialOptions, cause); ! action = adjustAction(initialOptions, action); if (action == ExceptionAction.Silent) { return handleException(cause); } if (action == ExceptionAction.Print) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (PrintStream ps = new PrintStream(baos)) { ps.printf("%s: Compilation of %s failed: ", Thread.currentThread(), this); cause.printStackTrace(ps); ! ps.printf("To disable compilation failure notifications, set %s to %s (e.g., -Dgraal.%s=%s).%n", ! CompilationFailureAction.getName(), ExceptionAction.Silent, ! CompilationFailureAction.getName(), ExceptionAction.Silent); ! ps.printf("To capture more information for diagnosing or reporting a compilation failure, " + "set %s to %s or %s (e.g., -Dgraal.%s=%s).%n", ! CompilationFailureAction.getName(), ExceptionAction.Diagnose, ExceptionAction.ExitVM, ! CompilationFailureAction.getName(), ExceptionAction.Diagnose); } TTY.print(baos.toString()); return handleException(cause); }
*** 247,265 **** String message; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (PrintStream ps = new PrintStream(baos)) { ps.printf("%s: Compilation of %s failed:%n", Thread.currentThread(), this); cause.printStackTrace(ps); ! ps.printf("To disable compilation %s notifications, set %s to %s (e.g., -Dgraal.%s=%s).%n", ! causeType, ! actionKey.getName(), ExceptionAction.Silent, ! actionKey.getName(), ExceptionAction.Silent); ! ps.printf("To print a message for a compilation %s without retrying the compilation, " + "set %s to %s (e.g., -Dgraal.%s=%s).%n", ! causeType, ! actionKey.getName(), ExceptionAction.Print, ! actionKey.getName(), ExceptionAction.Print); if (dumpPath != null) { ps.println("Retrying compilation of " + this); } else { ps.println("Not retrying compilation of " + this + " as the dump path could not be created."); } --- 241,257 ---- String message; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (PrintStream ps = new PrintStream(baos)) { ps.printf("%s: Compilation of %s failed:%n", Thread.currentThread(), this); cause.printStackTrace(ps); ! ps.printf("To disable compilation failure notifications, set %s to %s (e.g., -Dgraal.%s=%s).%n", ! CompilationFailureAction.getName(), ExceptionAction.Silent, ! CompilationFailureAction.getName(), ExceptionAction.Silent); ! ps.printf("To print a message for a compilation failure without retrying the compilation, " + "set %s to %s (e.g., -Dgraal.%s=%s).%n", ! CompilationFailureAction.getName(), ExceptionAction.Print, ! CompilationFailureAction.getName(), ExceptionAction.Print); if (dumpPath != null) { ps.println("Retrying compilation of " + this); } else { ps.println("Not retrying compilation of " + this + " as the dump path could not be created."); }
*** 318,337 **** /** * Adjusts {@code initialAction} if necessary based on * {@link GraalCompilerOptions#MaxCompilationProblemsPerAction}. */ ! private ExceptionAction adjustAction(OptionValues initialOptions, EnumOptionKey<ExceptionAction> actionKey, ExceptionAction initialAction) { ExceptionAction action = initialAction; int maxProblems = MaxCompilationProblemsPerAction.getValue(initialOptions); if (action != ExceptionAction.ExitVM) { synchronized (problemsHandledPerAction) { while (action != ExceptionAction.Silent) { int problems = problemsHandledPerAction.getOrDefault(action, 0); if (problems >= maxProblems) { if (problems == maxProblems) { ! TTY.printf("Warning: adjusting %s from %s to %s after %s (%d) failed compilations%n", actionKey, action, action.quieter(), MaxCompilationProblemsPerAction, maxProblems); // Ensure that the message above is only printed once problemsHandledPerAction.put(action, problems + 1); } action = action.quieter(); --- 310,329 ---- /** * Adjusts {@code initialAction} if necessary based on * {@link GraalCompilerOptions#MaxCompilationProblemsPerAction}. */ ! private ExceptionAction adjustAction(OptionValues initialOptions, ExceptionAction initialAction) { ExceptionAction action = initialAction; int maxProblems = MaxCompilationProblemsPerAction.getValue(initialOptions); if (action != ExceptionAction.ExitVM) { synchronized (problemsHandledPerAction) { while (action != ExceptionAction.Silent) { int problems = problemsHandledPerAction.getOrDefault(action, 0); if (problems >= maxProblems) { if (problems == maxProblems) { ! TTY.printf("Warning: adjusting %s from %s to %s after %s (%d) failed compilations%n", CompilationFailureAction, action, action.quieter(), MaxCompilationProblemsPerAction, maxProblems); // Ensure that the message above is only printed once problemsHandledPerAction.put(action, problems + 1); } action = action.quieter();
< prev index next >