Search in sources :

Example 36 with JavaConstant

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

the class StringEqualsConstantTest method testStringEquals.

private void testStringEquals(String s0, String s1) {
    ResolvedJavaMethod method = getResolvedJavaMethod("stringEquals");
    StructuredGraph graph = parseForCompile(method);
    graph.getParameter(0).replaceAndDelete(asConstant(graph, s0));
    graph.getParameter(1).replaceAndDelete(asConstant(graph, s1));
    compile(method, graph);
    FixedNode firstFixed = graph.start().next();
    Assert.assertThat(firstFixed, instanceOf(ReturnNode.class));
    ReturnNode ret = (ReturnNode) firstFixed;
    JavaConstant result = ret.result().asJavaConstant();
    if (result == null) {
        Assert.fail("result not constant: " + ret.result());
    } else {
        int expected = s0.equals(s1) ? 1 : 0;
        Assert.assertEquals("result", expected, result.asInt());
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 37 with JavaConstant

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

the class StringHashConstantTest method test2.

@Test
public void test2() {
    ResolvedJavaMethod method = getResolvedJavaMethod("constantHashCode");
    StructuredGraph graph = parseForCompile(method);
    FixedNode firstFixed = graph.start().next();
    Assert.assertThat(firstFixed, instanceOf(ReturnNode.class));
    ReturnNode ret = (ReturnNode) firstFixed;
    JavaConstant result = ret.result().asJavaConstant();
    if (result == null) {
        Assert.fail("result not constant: " + ret.result());
    } else {
        int expected = A_CONSTANT_STRING.hashCode();
        Assert.assertEquals("result", expected, result.asInt());
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 38 with JavaConstant

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

the class StringHashConstantTest method test1.

@Test
public void test1() {
    ResolvedJavaMethod method = getResolvedJavaMethod("parameterizedHashCode");
    StructuredGraph graph = parseForCompile(method);
    String s = "some string";
    int expected = s.hashCode();
    graph.getParameter(0).replaceAndDelete(asConstant(graph, s));
    compile(method, graph);
    FixedNode firstFixed = graph.start().next();
    Assert.assertThat(firstFixed, instanceOf(ReturnNode.class));
    ReturnNode ret = (ReturnNode) firstFixed;
    JavaConstant result = ret.result().asJavaConstant();
    if (result == null) {
        Assert.fail("result not constant: " + ret.result());
    } else {
        Assert.assertEquals("result", expected, result.asInt());
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 39 with JavaConstant

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

the class SystemArrayCopyTest method parse.

@Override
protected StructuredGraph parse(StructuredGraph.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 (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
            int index = param.index();
            if (args[index] != null) {
                JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[index].getJavaKind(), args[index]);
                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 40 with JavaConstant

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

the class ReflectionSubstitutionType method throwFailedCast.

private static void throwFailedCast(HostedGraphKit graphKit, ResolvedJavaType expectedType, ValueNode actual) {
    ResolvedJavaMethod createFailedCast = graphKit.findMethod(ExceptionHelpers.class, "createFailedCast", true);
    JavaConstant expected = graphKit.getConstantReflection().asJavaClass(expectedType);
    ValueNode expectedNode = graphKit.createConstant(expected, JavaKind.Object);
    ValueNode exception = graphKit.createJavaCallWithExceptionAndUnwind(InvokeKind.Static, createFailedCast, expectedNode, actual);
    graphKit.append(new UnwindNode(exception));
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

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