Search in sources :

Example 91 with ResolvedJavaMethod

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

the class PEGraphDecoderTest method test.

@Test
@SuppressWarnings("try")
public void test() {
    ResolvedJavaMethod testMethod = getResolvedJavaMethod(PEGraphDecoderTest.class, "doTest", Object.class);
    StructuredGraph targetGraph = null;
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope scope = debug.scope("GraphPETest", testMethod)) {
        GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true);
        registerPlugins(graphBuilderConfig.getPlugins().getInvocationPlugins());
        targetGraph = new StructuredGraph.Builder(getInitialOptions(), debug, AllowAssumptions.YES).method(testMethod).build();
        CachingPEGraphDecoder decoder = new CachingPEGraphDecoder(getTarget().arch, targetGraph, getProviders(), graphBuilderConfig, OptimisticOptimizations.NONE, AllowAssumptions.YES, null, null, new InlineInvokePlugin[] { new InlineAll() }, null, null, null, null);
        decoder.decode(testMethod, false);
        debug.dump(DebugContext.BASIC_LEVEL, targetGraph, "Target Graph");
        targetGraph.verify();
        PhaseContext context = new PhaseContext(getProviders());
        new CanonicalizerPhase().apply(targetGraph, context);
        targetGraph.verify();
    } catch (Throwable ex) {
        if (targetGraph != null) {
            debug.dump(DebugContext.BASIC_LEVEL, targetGraph, ex.toString());
        }
        debug.handle(ex);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) CachingPEGraphDecoder(org.graalvm.compiler.replacements.CachingPEGraphDecoder) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Example 92 with ResolvedJavaMethod

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

the class ReplacementsParseTest method testRootCompileStringize.

@Test
public void testRootCompileStringize() {
    ResolvedJavaMethod method = getResolvedJavaMethod(TestObject.class, "stringize");
    test(method, null, "a string");
    test(method, null, Boolean.TRUE);
    test(method, null, THROW_EXCEPTION_MARKER);
}
Also used : ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test)

Example 93 with ResolvedJavaMethod

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

the class StandardMethodSubstitutionsTest method testSubstitution.

public void testSubstitution(String testMethodName, Class<?> intrinsicClass, Class<?> holder, String methodName, boolean optional, Object... args) {
    ResolvedJavaMethod realJavaMethod = getResolvedJavaMethod(holder, methodName);
    ResolvedJavaMethod testJavaMethod = getResolvedJavaMethod(testMethodName);
    StructuredGraph graph = testGraph(testMethodName);
    // Check to see if the resulting graph contains the expected node
    StructuredGraph replacement = getReplacements().getSubstitution(realJavaMethod, -1, false, null);
    if (replacement == null && !optional) {
        assertInGraph(graph, intrinsicClass);
    }
    for (Object l : args) {
        // Force compilation
        InstalledCode code = getCode(testJavaMethod);
        assert optional || code != null;
        // Verify that the original method and the substitution produce the same value
        Object expected = invokeSafe(realJavaMethod, null, l);
        assertDeepEquals(expected, invokeSafe(testJavaMethod, null, l));
        // Verify that the generated code and the original produce the same value
        assertDeepEquals(expected, executeVarargsSafe(code, l));
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 94 with ResolvedJavaMethod

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

the class MethodSubstitutionTest method testSubstitution.

protected void testSubstitution(String testMethodName, Class<?> intrinsicClass, Class<?> holder, String methodName, Class<?>[] parameterTypes, boolean optional, Object[] args1, Object[] args2) {
    ResolvedJavaMethod realMethod = getResolvedJavaMethod(holder, methodName, parameterTypes);
    ResolvedJavaMethod testMethod = getResolvedJavaMethod(testMethodName);
    StructuredGraph graph = testGraph(testMethodName);
    // Check to see if the resulting graph contains the expected node
    StructuredGraph replacement = getReplacements().getSubstitution(realMethod, -1, false, null);
    if (replacement == null && !optional) {
        assertInGraph(graph, intrinsicClass);
    }
    // Force compilation
    InstalledCode code = getCode(testMethod);
    assert optional || code != null;
    for (int i = 0; i < args1.length; i++) {
        Object arg1 = args1[i];
        Object arg2 = args2[i];
        Object expected = invokeSafe(realMethod, null, arg1, arg2);
        // Verify that the original method and the substitution produce the same value
        assertDeepEquals(expected, invokeSafe(testMethod, null, arg1, arg2));
        // Verify that the generated code and the original produce the same value
        assertDeepEquals(expected, executeVarargsSafe(code, arg1, arg2));
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 95 with ResolvedJavaMethod

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

the class DeoptimizeOnExceptionTest method test3.

@Test
public void test3() {
    Assume.assumeTrue("Only works on jdk8 right now", Java8OrEarlier);
    ResolvedJavaMethod method = getResolvedJavaMethod("test3Snippet");
    for (int i = 0; i < 2; i++) {
        Result actual;
        boolean expectedCompiledCode = (method.getProfilingInfo().getDeoptimizationCount(DeoptimizationReason.NotCompiledExceptionHandler) != 0);
        InstalledCode code = getCode(method, null, false, true, new OptionValues(getInitialOptions(), HighTier.Options.Inline, false));
        assertTrue(code.isValid());
        try {
            actual = new Result(code.executeVarargs(false), null);
        } catch (Exception e) {
            actual = new Result(null, e);
        }
        assertTrue(i > 0 == expectedCompiledCode, "expect compiled code to stay around after the first iteration");
        assertEquals(new Result(expectedCompiledCode, null), actual);
        assertTrue(expectedCompiledCode == code.isValid());
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) InstalledCode(jdk.vm.ci.code.InstalledCode) 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