Search in sources :

Example 96 with ResolvedJavaMethod

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

the class DeoptimizeOnVolatileReadTest method test2.

@Test
public void test2() {
    ResolvedJavaMethod method = getResolvedJavaMethod("test2Snippet");
    Dummy dummy = new Dummy();
    Result expected = executeExpected(method, null, dummy);
    assertEquals(new Result(0, null), expected);
    dummy.f2 = true;
    InstalledCode code = getCode(method);
    Result actual;
    try {
        actual = new Result(code.executeVarargs(dummy), null);
    } catch (Exception e) {
        actual = new Result(null, e);
    }
    // The code should get deoptimized, and resume execution at the then-branch.
    assertEquals(new Result(1, null), actual);
    assertFalse(code.isValid());
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 97 with ResolvedJavaMethod

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

the class EdgesTest method testMethod.

private void testMethod(Method method, Object receiver, Object... args) {
    try {
        // Invoke the method to ensure it has a type profile
        for (int i = 0; i < 5000; i++) {
            method.invoke(receiver, args);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method);
    StructuredGraph g = parseProfiled(javaMethod, AllowAssumptions.NO);
    HighTierContext context = getDefaultHighTierContext();
    new InliningPhase(new InlineMethodSubstitutionsPolicy(), new CanonicalizerPhase()).apply(g, context);
    new CanonicalizerPhase().apply(g, context);
    Assert.assertTrue(g.getNodes().filter(InstanceOfNode.class).isEmpty());
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InlineMethodSubstitutionsPolicy(org.graalvm.compiler.phases.common.inlining.policy.InlineMethodSubstitutionsPolicy) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 98 with ResolvedJavaMethod

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

the class FloatArraysEqualsTest method testStableArray.

public void testStableArray(String methodName) {
    ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
    Result expected = executeExpected(method, null);
    StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
    for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class).snapshot()) {
        if (getConstantReflection().readArrayLength(constantNode.asJavaConstant()) != null) {
            ConstantNode newConstantNode = ConstantNode.forConstant(constantNode.asJavaConstant(), 1, true, getMetaAccess());
            newConstantNode = graph.unique(newConstantNode);
            constantNode.replaceAndDelete(newConstantNode);
        }
    }
    CompilationResult result = compile(method, graph);
    InstalledCode code = addMethod(graph.getDebug(), method, result);
    Result actual;
    try {
        actual = new Result(code.executeVarargs(), null);
    } catch (Exception e) {
        actual = new Result(null, e);
    }
    assertEquals(expected, actual);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 99 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod 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 100 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod 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)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)331 ValueNode (org.graalvm.compiler.nodes.ValueNode)104 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)89 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)67 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)66 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 Test (org.junit.Test)54 DebugContext (org.graalvm.compiler.debug.DebugContext)35 OptionValues (org.graalvm.compiler.options.OptionValues)32 InstalledCode (jdk.vm.ci.code.InstalledCode)24 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)23 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)22 JavaKind (jdk.vm.ci.meta.JavaKind)21 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)20 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)19 JavaConstant (jdk.vm.ci.meta.JavaConstant)17 LogicNode (org.graalvm.compiler.nodes.LogicNode)17 ArrayList (java.util.ArrayList)16