use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class GraalCompilerTest method compile.
/**
* Compiles a given method.
*
* @param installedCodeOwner the method the compiled code will be associated with when installed
* @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will
* be obtained from {@code installedCodeOwner} via
* {@link #parseForCompile(ResolvedJavaMethod)}.
* @param compilationId
*/
@SuppressWarnings("try")
protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationResult compilationResult, CompilationIdentifier compilationId, OptionValues options) {
StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, compilationId, options) : graph;
lastCompiledGraph = graphToCompile;
DebugContext debug = graphToCompile.getDebug();
try (DebugContext.Scope s = debug.scope("Compile", graphToCompile)) {
assert options != null;
Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default);
return GraalCompiler.compile(request);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.code.CompilationResult 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();
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class DontReuseArgumentSpaceTest method run0.
@Test
public void run0() throws Throwable {
/*
* Exercise the methods once so everything is resolved
*/
callTwice(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
/*
* Create a standalone compile of killArguments. This test assumes that zapping of argument
* space is being performed by the backend.
*/
ResolvedJavaMethod javaMethod = getResolvedJavaMethod("killArguments");
StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
CompilationResult compilationResult = compile(javaMethod, graph);
DebugContext debug = getDebugContext();
getBackend().createDefaultInstalledCode(debug, javaMethod, compilationResult);
test("callTwice", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class InfopointReasonTest method callInfopoints.
@Test
public void callInfopoints() {
final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
final StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
final CompilationResult cr = compileGraph(graph, graph.method(), getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(graph.getOptions()), createLIRSuites(graph.getOptions()), new CompilationResult(graph.compilationId()), CompilationResultBuilderFactory.Default);
for (Infopoint sp : cr.getInfopoints()) {
assertNotNull(sp.reason);
if (sp instanceof Call) {
assertDeepEquals(InfopointReason.CALL, sp.reason);
}
}
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class CFGPrinterObserver method checkMethodScope.
/**
* Looks for the outer most method and its {@link DebugDumpScope#decorator}s in the current
* debug scope and opens a new compilation scope if this pair does not match the current method
* and decorator pair.
*/
private boolean checkMethodScope(DebugContext debug) {
JavaMethod method = null;
CompilationIdentifier compilation = null;
ArrayList<String> decorators = new ArrayList<>();
for (Object o : debug.context()) {
if (o instanceof JavaMethod) {
method = (JavaMethod) o;
decorators.clear();
} else if (o instanceof StructuredGraph) {
StructuredGraph graph = (StructuredGraph) o;
if (graph.method() != null) {
method = graph.method();
decorators.clear();
compilation = graph.compilationId();
}
} else if (o instanceof DebugDumpScope) {
DebugDumpScope debugDumpScope = (DebugDumpScope) o;
if (debugDumpScope.decorator) {
decorators.add(debugDumpScope.name);
}
} else if (o instanceof CompilationResult) {
CompilationResult compilationResult = (CompilationResult) o;
compilation = compilationResult.getCompilationId();
}
}
if (method == null && compilation == null) {
return false;
}
if (compilation != null) {
if (!compilation.equals(curCompilation) || !curDecorators.equals(decorators)) {
cfgPrinter.printCompilation(compilation);
}
} else {
if (!method.equals(curMethod) || !curDecorators.equals(decorators)) {
cfgPrinter.printCompilation(method);
}
}
curCompilation = compilation;
curMethod = method;
curDecorators = decorators;
return true;
}
Aggregations