Search in sources :

Example 11 with DebugDumpScope

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

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);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase)

Example 13 with DebugDumpScope

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);
    }
}
Also used : DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DebugContext(org.graalvm.compiler.debug.DebugContext) PiNode(org.graalvm.compiler.nodes.PiNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with DebugDumpScope

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);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DefaultLoopPolicies(org.graalvm.compiler.loop.DefaultLoopPolicies) LoopUnswitchingPhase(org.graalvm.compiler.loop.phases.LoopUnswitchingPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 15 with DebugDumpScope

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);
    }
}
Also used : NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) Node(org.graalvm.compiler.graph.Node) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameState(org.graalvm.compiler.nodes.FrameState) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase)

Aggregations

DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)18 DebugContext (org.graalvm.compiler.debug.DebugContext)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)16 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)10 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)6 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)6 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)5 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 CompilationResult (org.graalvm.compiler.code.CompilationResult)3 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)3 Node (org.graalvm.compiler.graph.Node)3 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)3 JavaMethod (jdk.vm.ci.meta.JavaMethod)2 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)2 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)2 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)2 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)2