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;
}
}
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();
}
Aggregations