use of com.oracle.truffle.api.OptimizationFailedException in project graal by oracle.
the class OptimizedCallTarget method onCompilationFailed.
@Override
public final void onCompilationFailed(Supplier<String> serializedException, boolean silent, boolean bailout, boolean permanentBailout, boolean graphTooBig) {
if (graphTooBig) {
if (computeBlockCompilations()) {
// retry compilation
return;
}
}
ExceptionAction action;
if (bailout && !permanentBailout) {
/*
* Non-permanent bailouts are expected cases. A non-permanent bailout would be for
* example class redefinition during code installation. As opposed to permanent
* bailouts, non-permanent bailouts will trigger recompilation and are not considered a
* failure state.
*/
action = ExceptionAction.Silent;
} else {
compilationFailed = true;
action = silent ? ExceptionAction.Silent : engine.compilationFailureAction;
}
if (action == ExceptionAction.Throw) {
final InternalError error = new InternalError(serializedException.get());
throw new OptimizationFailedException(error, this);
}
if (action.ordinal() >= ExceptionAction.Print.ordinal()) {
GraalTruffleRuntime rt = runtime();
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("AST", getNonTrivialNodeCount());
rt.logEvent(this, 0, "opt fail", toString(), properties, serializedException.get());
if (action == ExceptionAction.ExitVM) {
String reason;
if (getOptionValue(PolyglotCompilerOptions.CompilationFailureAction) == ExceptionAction.ExitVM) {
reason = "engine.CompilationFailureAction=ExitVM";
} else if (getOptionValue(PolyglotCompilerOptions.CompilationExceptionsAreFatal)) {
reason = "engine.CompilationExceptionsAreFatal=true";
} else {
reason = "engine.PerformanceWarningsAreFatal=true";
}
log(String.format("Exiting VM due to %s", reason));
System.exit(-1);
}
}
}
use of com.oracle.truffle.api.OptimizationFailedException in project graal by oracle.
the class GraalTruffleRuntime method compileImpl.
@SuppressWarnings("try")
private void compileImpl(TruffleDebugContext initialDebug, OptimizedCallTarget callTarget, TruffleCompilationTask task) {
boolean compilationStarted = false;
try {
TruffleCompiler compiler = getTruffleCompiler(callTarget);
try (TruffleCompilation compilation = compiler.openCompilation(callTarget)) {
final Map<String, Object> optionsMap = getOptionsForCompiler(callTarget);
TruffleDebugContext debug = initialDebug;
if (debug == null) {
debug = compiler.openDebugContext(optionsMap, compilation);
}
listeners.onCompilationStarted(callTarget, task);
compilationStarted = true;
try {
compiler.doCompile(debug, compilation, optionsMap, task, listeners.isEmpty() ? null : listeners);
} finally {
if (initialDebug == null) {
debug.close();
}
}
TruffleInlining inlining = (TruffleInlining) task.inliningData();
truffleDump(callTarget, compiler, compilation, optionsMap, inlining);
inlining.dequeueTargets();
}
} catch (OptimizationFailedException e) {
// Listeners already notified
throw e;
} catch (RuntimeException | Error e) {
notifyCompilationFailure(callTarget, e, compilationStarted, task.tier());
throw e;
} catch (Throwable e) {
notifyCompilationFailure(callTarget, e, compilationStarted, task.tier());
throw new InternalError(e);
}
}
use of com.oracle.truffle.api.OptimizationFailedException in project graal by oracle.
the class ExceptionActionTest method executeInSubProcess.
private void executeInSubProcess(BiConsumer<String, String> verifier, Supplier<RootNode> rootNodeFactory, String[] additionalVmOptions, String... contextOptions) throws IOException, InterruptedException {
Path log = SubprocessTestUtils.isSubprocess() ? null : File.createTempFile("compiler", ".log").toPath();
SubprocessUtil.Subprocess subprocess = null;
boolean success = false;
try {
String[] useVMOptions = Arrays.copyOf(additionalVmOptions, additionalVmOptions.length + 2);
useVMOptions[useVMOptions.length - 2] = String.format("-D%s=%s", LOG_FILE_PROPERTY, log);
// Prevent graal graph dumping for ExceptionAction#Diagnose
useVMOptions[useVMOptions.length - 1] = "-Dgraal.Dump=Truffle:0";
subprocess = SubprocessTestUtils.executeInSubprocess(ExceptionActionTest.class, () -> {
setupContext(contextOptions);
OptimizedCallTarget target = (OptimizedCallTarget) rootNodeFactory.get().getCallTarget();
try {
target.call();
} catch (RuntimeException e) {
OptimizationFailedException optFailedException = isOptimizationFailed(e);
if (optFailedException != null) {
TruffleCompilerRuntime.getRuntime().log(target, optFailedException.getClass().getName());
}
}
}, false, useVMOptions);
success = true;
} finally {
if (log != null) {
if (success) {
String logContent = String.join("\n", Files.readAllLines(log));
String output = String.join("\n", subprocess.output);
verifier.accept(logContent, output);
}
Files.deleteIfExists(log);
}
}
}
Aggregations