Search in sources :

Example 1 with OptimizationFailedException

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);
        }
    }
}
Also used : ExceptionAction(org.graalvm.compiler.truffle.options.PolyglotCompilerOptions.ExceptionAction) OptimizationFailedException(com.oracle.truffle.api.OptimizationFailedException) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with OptimizationFailedException

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);
    }
}
Also used : TruffleCompilation(org.graalvm.compiler.truffle.common.TruffleCompilation) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) ServiceConfigurationError(java.util.ServiceConfigurationError) TruffleCompiler(org.graalvm.compiler.truffle.common.TruffleCompiler) OptimizationFailedException(com.oracle.truffle.api.OptimizationFailedException)

Example 3 with OptimizationFailedException

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);
        }
    }
}
Also used : Path(java.nio.file.Path) OptimizationFailedException(com.oracle.truffle.api.OptimizationFailedException) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) SubprocessUtil(org.graalvm.compiler.test.SubprocessUtil)

Aggregations

OptimizationFailedException (com.oracle.truffle.api.OptimizationFailedException)3 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 ServiceConfigurationError (java.util.ServiceConfigurationError)1 SubprocessUtil (org.graalvm.compiler.test.SubprocessUtil)1 TruffleCompilation (org.graalvm.compiler.truffle.common.TruffleCompilation)1 TruffleCompiler (org.graalvm.compiler.truffle.common.TruffleCompiler)1 TruffleDebugContext (org.graalvm.compiler.truffle.common.TruffleDebugContext)1 ExceptionAction (org.graalvm.compiler.truffle.options.PolyglotCompilerOptions.ExceptionAction)1 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)1