Search in sources :

Example 51 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class GraalCompilerTest method bindArguments.

protected void bindArguments(StructuredGraph graph, Object[] argsToBind) {
    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 (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
        JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[param.index()].getJavaKind(), args[param.index()]);
        ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
        param.replaceAtUsages(replacement);
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 52 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class ConditionTest method testMeet.

@Test
public void testMeet() {
    Random rand = new Random(13);
    for (Condition c1 : Condition.values()) {
        for (Condition c2 : Condition.values()) {
            Condition meet = c1.meet(c2);
            assertEquals(meet, c2.meet(c1));
            if (meet != null) {
                for (int i = 0; i < 1000; i++) {
                    JavaConstant a = JavaConstant.forInt(rand.nextInt());
                    JavaConstant b = JavaConstant.forInt(i < 100 ? a.asInt() : rand.nextInt());
                    boolean result1 = c1.foldCondition(a, b, null, false);
                    boolean result2 = c2.foldCondition(a, b, null, false);
                    boolean resultMeet = meet.foldCondition(a, b, null, false);
                    if (result1 || result2) {
                        assertTrue(resultMeet);
                    } else {
                        assertFalse(resultMeet);
                    }
                }
            }
        }
    }
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) Random(java.util.Random) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 53 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class NegateNodeCanonicalizationTest method testLong.

@Test
public void testLong() {
    long[] a = new long[] { Long.MIN_VALUE, Long.MIN_VALUE + 1, -1, 0, 1, Long.MAX_VALUE - 1, Long.MAX_VALUE };
    for (long i : a) {
        ConstantNode node = ConstantNode.forLong(i, graph);
        JavaConstant expected = JavaConstant.forLong(-i);
        assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 54 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class NegateNodeCanonicalizationTest method testByte.

@Test
public void testByte() {
    byte[] a = new byte[] { Byte.MIN_VALUE, Byte.MIN_VALUE + 1, -1, 0, 1, Byte.MAX_VALUE - 1, Byte.MAX_VALUE };
    for (byte i : a) {
        ConstantNode node = ConstantNode.forByte(i, graph);
        JavaConstant expected = JavaConstant.forInt(-i);
        assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 55 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class DynamicDeoptimizeNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (actionAndReason.isConstant() && speculation.isConstant()) {
        JavaConstant constant = actionAndReason.asJavaConstant();
        JavaConstant speculationConstant = speculation.asJavaConstant();
        DeoptimizeNode newDeopt = new DeoptimizeNode(tool.getMetaAccess().decodeDeoptAction(constant), tool.getMetaAccess().decodeDeoptReason(constant), tool.getMetaAccess().decodeDebugId(constant), speculationConstant, stateBefore());
        return newDeopt;
    }
    return this;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5