Search in sources :

Example 11 with BailoutException

use of jdk.vm.ci.code.BailoutException in project graal by oracle.

the class GraalCompilerTest method getCode.

/**
 * Gets installed code for a given method and graph, compiling it first if necessary.
 *
 * @param installedCodeOwner the method the compiled code will be associated with when installed
 * @param graph the graph to be compiled. If null, a graph will be obtained from
 *            {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}.
 * @param forceCompile specifies whether to ignore any previous code cached for the (method,
 *            key) pair
 * @param installAsDefault specifies whether to install as the default implementation
 * @param options the options that will be used in {@link #parseForCompile(ResolvedJavaMethod)}
 */
@SuppressWarnings("try")
protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
    boolean useCache = !forceCompile && getArgumentToBind() == null;
    if (useCache && graph == null) {
        InstalledCode cached = cache.get(installedCodeOwner);
        if (cached != null) {
            if (cached.isValid()) {
                return cached;
            }
        }
    }
    // loop for retrying compilation
    for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
        final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
        InstalledCode installedCode = null;
        StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
        DebugContext debug = graphToCompile.getDebug();
        try (AllocSpy spy = AllocSpy.open(installedCodeOwner);
            DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
            CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
            CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(graphToCompile.compilationId()), id, options);
            printer.finish(compResult);
            try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
                DebugContext.Activation a = debug.activate()) {
                try {
                    if (installAsDefault) {
                        installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
                    } else {
                        installedCode = addMethod(debug, installedCodeOwner, compResult);
                    }
                    if (installedCode == null) {
                        throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
                    }
                } catch (BailoutException e) {
                    if (retry < BAILOUT_RETRY_LIMIT && graph == null && !e.isPermanent()) {
                        // retry (if there is no predefined graph)
                        TTY.println(String.format("Restart compilation %s (%s) due to a non-permanent bailout!", installedCodeOwner, id));
                        continue;
                    }
                    throw e;
                }
            } catch (Throwable e) {
                throw debug.handle(e);
            }
        } catch (Throwable e) {
            throw debug.handle(e);
        }
        if (useCache) {
            cache.put(installedCodeOwner, installedCode);
        }
        return installedCode;
    }
    throw GraalError.shouldNotReachHere();
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DebugContext(org.graalvm.compiler.debug.DebugContext) BailoutException(jdk.vm.ci.code.BailoutException) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) CompilationPrinter(org.graalvm.compiler.core.CompilationPrinter) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 12 with BailoutException

use of jdk.vm.ci.code.BailoutException in project graal by oracle.

the class DebugConfigImpl method interceptException.

@Override
public RuntimeException interceptException(DebugContext debug, Throwable e) {
    if (e instanceof BailoutException && !DebugOptions.InterceptBailout.getValue(options)) {
        return null;
    }
    OptionValues interceptOptions = new OptionValues(options, DebugOptions.Count, null, DebugOptions.Time, null, DebugOptions.TrackMemUse, null, DebugOptions.Verify, null, DebugOptions.Dump, ":" + BASIC_LEVEL, DebugOptions.Log, ":" + BASIC_LEVEL);
    DebugConfigImpl config = new DebugConfigImpl(interceptOptions, output, dumpHandlers, verifyHandlers);
    ScopeImpl scope = debug.currentScope;
    scope.updateFlags(config);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        debug.log("Exception raised in scope %s: %s", debug.getCurrentScopeName(), baos);
        Map<Object, Object> firstSeen = new IdentityHashMap<>();
        for (Object o : debug.context()) {
            // Only dump a context object once.
            if (!firstSeen.containsKey(o)) {
                firstSeen.put(o, o);
                if (DebugOptions.DumpOnError.getValue(options) || DebugOptions.Dump.getValue(options) != null) {
                    debug.dump(DebugContext.BASIC_LEVEL, o, "Exception: %s", e);
                }
                debug.log("Context obj %s", o);
            }
        }
    } finally {
        scope.updateFlags(this);
    }
    return null;
}
Also used : BailoutException(jdk.vm.ci.code.BailoutException) PrintStream(java.io.PrintStream) OptionValues(org.graalvm.compiler.options.OptionValues) IdentityHashMap(java.util.IdentityHashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

BailoutException (jdk.vm.ci.code.BailoutException)12 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)5 CancellationBailoutException (org.graalvm.compiler.core.common.CancellationBailoutException)3 RetryableBailoutException (org.graalvm.compiler.core.common.RetryableBailoutException)3 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)3 DebugContext (org.graalvm.compiler.debug.DebugContext)3 OptionValues (org.graalvm.compiler.options.OptionValues)3 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 CompilationResult (org.graalvm.compiler.code.CompilationResult)2 CompilationPrinter (org.graalvm.compiler.core.CompilationPrinter)2 PermanentBailoutException (org.graalvm.compiler.core.common.PermanentBailoutException)2 GraalError (org.graalvm.compiler.debug.GraalError)2 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)2 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)2 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)2 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)2 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1