Search in sources :

Example 6 with NewArrayNode

use of org.graalvm.compiler.nodes.java.NewArrayNode in project graal by oracle.

the class PartialEscapeAnalysisTest method testPartialEscapeAnalysis.

@SafeVarargs
protected final void testPartialEscapeAnalysis(String snippet, double expectedProbability, int expectedCount, Class<? extends Node>... invalidNodeClasses) {
    prepareGraph(snippet, false);
    for (AbstractMergeNode merge : graph.getNodes(AbstractMergeNode.TYPE)) {
        merge.setStateAfter(null);
    }
    new DeadCodeEliminationPhase().apply(graph);
    new CanonicalizerPhase().apply(graph, context);
    try {
        Assert.assertTrue("partial escape analysis should have removed all NewInstanceNode allocations", graph.getNodes().filter(NewInstanceNode.class).isEmpty());
        Assert.assertTrue("partial escape analysis should have removed all NewArrayNode allocations", graph.getNodes().filter(NewArrayNode.class).isEmpty());
        ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
        double probabilitySum = 0;
        int materializeCount = 0;
        for (CommitAllocationNode materialize : graph.getNodes().filter(CommitAllocationNode.class)) {
            probabilitySum += cfg.blockFor(materialize).probability() * materialize.getVirtualObjects().size();
            materializeCount += materialize.getVirtualObjects().size();
        }
        Assert.assertEquals("unexpected number of MaterializeObjectNodes", expectedCount, materializeCount);
        Assert.assertEquals("unexpected probability of MaterializeObjectNodes", expectedProbability, probabilitySum, 0.01);
        for (Node node : graph.getNodes()) {
            for (Class<? extends Node> clazz : invalidNodeClasses) {
                Assert.assertFalse("instance of invalid class: " + clazz.getSimpleName(), clazz.isInstance(node) && node.usages().isNotEmpty());
            }
        }
    } catch (AssertionError e) {
        TypeSystemTest.outputGraph(graph, snippet + ": " + e.getMessage());
        throw e;
    }
}
Also used : ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode)

Example 7 with NewArrayNode

use of org.graalvm.compiler.nodes.java.NewArrayNode in project graal by oracle.

the class UnusedArray method test.

public void test(String method) {
    StructuredGraph graph = parseEager(method, StructuredGraph.AllowAssumptions.YES);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    NodeIterable<NewArrayNode> newArrayNodes = graph.getNodes().filter(NewArrayNode.class);
    assertThat(newArrayNodes, isEmpty());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Aggregations

NewArrayNode (org.graalvm.compiler.nodes.java.NewArrayNode)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 Node (org.graalvm.compiler.graph.Node)4 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)4 NewInstanceNode (org.graalvm.compiler.nodes.java.NewInstanceNode)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)3 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)3 StoreIndexedNode (org.graalvm.compiler.nodes.java.StoreIndexedNode)3 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)2 FixedNode (org.graalvm.compiler.nodes.FixedNode)2 IfNode (org.graalvm.compiler.nodes.IfNode)2 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 ForeignCallNode (org.graalvm.compiler.nodes.extended.ForeignCallNode)2 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)2 LoadIndexedNode (org.graalvm.compiler.nodes.java.LoadIndexedNode)2