use of org.graalvm.compiler.debug.DebugDumpScope 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.debug.DebugDumpScope in project graal by oracle.
the class DegeneratedLoopsTest method test.
@SuppressWarnings("try")
private void test(final String snippet) {
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope("DegeneratedLoopsTest", new DebugDumpScope(snippet))) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
HighTierContext context = getDefaultHighTierContext();
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
new CanonicalizerPhase().apply(graph, context);
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
debug.dump(DebugContext.BASIC_LEVEL, referenceGraph, "ReferenceGraph");
assertEquals(referenceGraph, graph);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.debug.DebugDumpScope in project graal by oracle.
the class PushNodesThroughPiTest method test1.
@Ignore
@Test
@SuppressWarnings("try")
public void test1() {
final String snippet = "test1Snippet";
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope("PushThroughPi", new DebugDumpScope(snippet))) {
StructuredGraph graph = compileTestSnippet(snippet);
for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) {
OffsetAddressNode address = (OffsetAddressNode) rn.getAddress();
long disp = address.getOffset().asJavaConstant().asLong();
ResolvedJavaType receiverType = StampTool.typeOrNull(address.getBase());
ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(disp, rn.getStackKind());
assert field != null : "Node " + rn + " tries to access a field which doesn't exists for this type";
if (field.getName().equals("x")) {
Assert.assertTrue(address.getBase() instanceof ParameterNode);
} else {
Assert.assertTrue(address.getBase().toString(), address.getBase() instanceof PiNode);
}
}
Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.debug.DebugDumpScope in project graal by oracle.
the class LoopUnswitchTest method test.
@SuppressWarnings("try")
private void test(String snippet, String referenceSnippet) {
DebugContext debug = getDebugContext();
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
final StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
new LoopUnswitchingPhase(new DefaultLoopPolicies()).apply(graph);
// Framestates create comparison problems
graph.clearAllStateAfter();
referenceGraph.clearAllStateAfter();
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
try (DebugContext.Scope s = debug.scope("Test", new DebugDumpScope("Test:" + snippet))) {
assertEquals(referenceGraph, graph);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.debug.DebugDumpScope in project graal by oracle.
the class PoorMansEATest method test.
@SuppressWarnings("try")
private void test(final String snippet) {
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope("PoorMansEATest", new DebugDumpScope(snippet))) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
HighTierContext highTierContext = getDefaultHighTierContext();
new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext);
PhaseContext context = new PhaseContext(getProviders());
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
// remove framestates in order to trigger the simplification.
cleanup: for (FrameState fs : graph.getNodes(FrameState.TYPE).snapshot()) {
for (Node input : fs.inputs()) {
if (input instanceof NewInstanceNode) {
fs.replaceAtUsages(null);
fs.safeDelete();
continue cleanup;
}
}
}
new CanonicalizerPhase().apply(graph, context);
} catch (Throwable e) {
throw debug.handle(e);
}
}
Aggregations