Search in sources :

Example 31 with ConstantNode

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

the class AheadOfTimeCompilationTest method testBoxedBooleanAOT.

@Test
public void testBoxedBooleanAOT() {
    StructuredGraph result = compile("getBoxedBoolean", true);
    assertDeepEquals(0, result.getNodes().filter(FloatingReadNode.class).count());
    assertDeepEquals(0, result.getNodes(PiNode.TYPE).count());
    assertDeepEquals(1, getConstantNodes(result).count());
    ConstantNode constant = getConstantNodes(result).first();
    assertDeepEquals(JavaKind.Object, constant.getStackKind());
    JavaConstant c = constant.asJavaConstant();
    Assert.assertEquals(getSnippetReflection().asObject(Boolean.class, c), Boolean.TRUE);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 32 with ConstantNode

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

the class AheadOfTimeCompilationTest method testClassObjectAOT.

@Test
public void testClassObjectAOT() {
    StructuredGraph result = compile("getClassObject", true);
    NodeIterable<ConstantNode> filter = getConstantNodes(result);
    assertDeepEquals(1, filter.count());
    HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) getMetaAccess().lookupJavaType(AheadOfTimeCompilationTest.class);
    assertDeepEquals(type.klass(), filter.first().asConstant());
    int expected = runtime().getVMConfig().classMirrorIsHandle ? 2 : 1;
    assertDeepEquals(expected, result.getNodes().filter(ReadNode.class).count());
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) Test(org.junit.Test)

Example 33 with ConstantNode

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

the class AheadOfTimeCompilationTest method testClassObject.

@Test
public void testClassObject() {
    StructuredGraph result = compile("getClassObject", false);
    NodeIterable<ConstantNode> filter = getConstantNodes(result);
    assertDeepEquals(1, filter.count());
    JavaConstant c = filter.first().asJavaConstant();
    Assert.assertEquals(getSnippetReflection().asObject(Class.class, c), AheadOfTimeCompilationTest.class);
    assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count());
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 34 with ConstantNode

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

the class InstalledCodeExecuteHelperTest method parse.

@Override
protected StructuredGraph parse(Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
    StructuredGraph graph = super.parse(builder, graphBuilderSuite);
    if (argsToBind != null) {
        ResolvedJavaMethod m = graph.method();
        Object receiver = isStatic(m.getModifiers()) ? null : this;
        Object[] args = argsWithReceiver(receiver, argsToBind);
        JavaType[] parameterTypes = m.toParameterTypes();
        assert parameterTypes.length == args.length;
        for (int i = 0; i < argsToBind.length; i++) {
            ParameterNode param = graph.getParameter(i);
            JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[i].getJavaKind(), argsToBind[i]);
            ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
            param.replaceAtUsages(replacement);
        }
    }
    return graph;
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 35 with ConstantNode

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

the class BinaryGraphPrinter method nodeProperties.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void nodeProperties(GraphInfo info, Node node, Map<String, Object> props) {
    node.getDebugProperties((Map) props);
    Graph graph = info.graph;
    ControlFlowGraph cfg = info.cfg;
    NodeMap<Block> nodeToBlocks = info.nodeToBlocks;
    if (cfg != null && DebugOptions.PrintGraphProbabilities.getValue(graph.getOptions()) && node instanceof FixedNode) {
        try {
            props.put("probability", cfg.blockFor(node).probability());
        } catch (Throwable t) {
            props.put("probability", 0.0);
            props.put("probability-exception", t);
        }
    }
    try {
        props.put("NodeCost-Size", node.estimatedNodeSize());
        props.put("NodeCost-Cycles", node.estimatedNodeCycles());
    } catch (Throwable t) {
        props.put("node-cost-exception", t.getMessage());
    }
    if (nodeToBlocks != null) {
        Object block = getBlockForNode(node, nodeToBlocks);
        if (block != null) {
            props.put("node-to-block", block);
        }
    }
    if (node instanceof ControlSinkNode) {
        props.put("category", "controlSink");
    } else if (node instanceof ControlSplitNode) {
        props.put("category", "controlSplit");
    } else if (node instanceof AbstractMergeNode) {
        props.put("category", "merge");
    } else if (node instanceof AbstractBeginNode) {
        props.put("category", "begin");
    } else if (node instanceof AbstractEndNode) {
        props.put("category", "end");
    } else if (node instanceof FixedNode) {
        props.put("category", "fixed");
    } else if (node instanceof VirtualState) {
        props.put("category", "state");
    } else if (node instanceof PhiNode) {
        props.put("category", "phi");
    } else if (node instanceof ProxyNode) {
        props.put("category", "proxy");
    } else {
        if (node instanceof ConstantNode) {
            ConstantNode cn = (ConstantNode) node;
            updateStringPropertiesForConstant((Map) props, cn);
        }
        props.put("category", "floating");
    }
    if (getSnippetReflectionProvider() != null) {
        for (Map.Entry<String, Object> prop : props.entrySet()) {
            if (prop.getValue() instanceof JavaConstantFormattable) {
                props.put(prop.getKey(), ((JavaConstantFormattable) prop.getValue()).format(this));
            }
        }
    }
}
Also used : ProxyNode(org.graalvm.compiler.nodes.ProxyNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) VirtualState(org.graalvm.compiler.nodes.VirtualState) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) Graph(org.graalvm.compiler.graph.Graph) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CachedGraph(org.graalvm.compiler.graph.CachedGraph) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) Block(org.graalvm.compiler.nodes.cfg.Block) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) Map(java.util.Map) NodeMap(org.graalvm.compiler.graph.NodeMap) BlockMap(org.graalvm.compiler.core.common.cfg.BlockMap) JavaConstantFormattable(org.graalvm.compiler.nodes.util.JavaConstantFormattable)

Aggregations

ConstantNode (org.graalvm.compiler.nodes.ConstantNode)100 ValueNode (org.graalvm.compiler.nodes.ValueNode)46 JavaConstant (jdk.vm.ci.meta.JavaConstant)32 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)28 Stamp (org.graalvm.compiler.core.common.type.Stamp)23 Test (org.junit.Test)15 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)14 Node (org.graalvm.compiler.graph.Node)14 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)13 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)13 PhiNode (org.graalvm.compiler.nodes.PhiNode)12 LogicNode (org.graalvm.compiler.nodes.LogicNode)11 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)10 ArrayList (java.util.ArrayList)9 JavaKind (jdk.vm.ci.meta.JavaKind)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 Constant (jdk.vm.ci.meta.Constant)8 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)8 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)7