Search in sources :

Example 1 with CompilationPrinter

use of org.graalvm.compiler.core.CompilationPrinter in project graal by oracle.

the class TruffleCompilerImpl method compileAST.

/**
 * Compiles a Truffle AST. If compilation succeeds, the AST will have compiled code associated
 * with it that can be executed instead of interpreting the AST.
 *
 * @param compilable representation of the AST to be compiled
 * @param inliningPlan
 * @param compilationId identifier to be used for the compilation
 * @param cancellable an object polled during the compilation process to
 *            {@linkplain CancellationBailoutException abort} early if the thread owning the
 *            cancellable requests it
 * @param listener
 */
@SuppressWarnings("try")
public void compileAST(DebugContext debug, final CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, CompilationIdentifier compilationId, Cancellable cancellable, TruffleCompilerListener listener) {
    final CompilationPrinter printer = CompilationPrinter.begin(TruffleCompilerOptions.getOptions(), compilationId, new TruffleDebugJavaMethod(compilable), INVOCATION_ENTRY_BCI);
    StructuredGraph graph = null;
    try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(TruffleCompilerOptions.getOptions())) {
        PhaseSuite<HighTierContext> graphBuilderSuite = createGraphBuilderSuite();
        // Failed speculations must be collected before any compilation or
        // partial evaluation is performed.
        SpeculationLog speculationLog = compilable.getSpeculationLog();
        if (speculationLog != null) {
            speculationLog.collectFailedSpeculations();
        }
        try (DebugCloseable a = PartialEvaluationTime.start(debug);
            DebugCloseable c = PartialEvaluationMemUse.start(debug)) {
            graph = partialEvaluator.createGraph(debug, compilable, inliningPlan, AllowAssumptions.YES, compilationId, speculationLog, cancellable);
        }
        // Check if the task has been cancelled
        if (cancellable != null && cancellable.isCancelled()) {
            return;
        }
        if (listener != null) {
            listener.onTruffleTierFinished(compilable, inliningPlan, new GraphInfoImpl(graph));
        }
        CompilationResult compilationResult = compilePEGraph(graph, compilable.toString(), graphBuilderSuite, compilable, asCompilationRequest(compilationId), listener);
        if (listener != null) {
            listener.onSuccess(compilable, inliningPlan, new GraphInfoImpl(graph), new CompilationResultInfoImpl(compilationResult));
        }
        // Partial evaluation and installation are included in
        // compilation time and memory usage reported by printer
        printer.finish(compilationResult);
    } catch (Throwable t) {
        // graph is null
        if (listener != null) {
            BailoutException bailout = t instanceof BailoutException ? (BailoutException) t : null;
            boolean permanentBailout = bailout != null ? bailout.isPermanent() : false;
            listener.onFailure(compilable, t.toString(), bailout != null, permanentBailout);
        }
        throw t;
    }
}
Also used : CompilationAlarm(org.graalvm.compiler.core.common.util.CompilationAlarm) TruffleDebugJavaMethod(org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod) CancellationBailoutException(org.graalvm.compiler.core.common.CancellationBailoutException) BailoutException(jdk.vm.ci.code.BailoutException) RetryableBailoutException(org.graalvm.compiler.core.common.RetryableBailoutException) SpeculationLog(jdk.vm.ci.meta.SpeculationLog) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompilationPrinter(org.graalvm.compiler.core.CompilationPrinter) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 2 with CompilationPrinter

use of org.graalvm.compiler.core.CompilationPrinter 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)

Aggregations

BailoutException (jdk.vm.ci.code.BailoutException)2 CompilationResult (org.graalvm.compiler.code.CompilationResult)2 CompilationPrinter (org.graalvm.compiler.core.CompilationPrinter)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 InstalledCode (jdk.vm.ci.code.InstalledCode)1 SpeculationLog (jdk.vm.ci.meta.SpeculationLog)1 CancellationBailoutException (org.graalvm.compiler.core.common.CancellationBailoutException)1 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)1 RetryableBailoutException (org.graalvm.compiler.core.common.RetryableBailoutException)1 CompilationAlarm (org.graalvm.compiler.core.common.util.CompilationAlarm)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)1 GraalError (org.graalvm.compiler.debug.GraalError)1 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)1 TruffleDebugJavaMethod (org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod)1