Search in sources :

Example 16 with InstalledCode

use of jdk.vm.ci.code.InstalledCode in project graal by oracle.

the class UnsafeSubstitutionsTest method testSubstitution.

public void testSubstitution(String testMethodName, Class<?> holder, String methodName, Class<?>[] parameterTypes, Object receiver, Object[] args1, Object[] args2) {
    ResolvedJavaMethod testMethod = getResolvedJavaMethod(testMethodName);
    ResolvedJavaMethod originalMethod = getResolvedJavaMethod(holder, methodName, parameterTypes);
    // Force compilation
    InstalledCode code = getCode(testMethod);
    assert code != null;
    // Verify that the original method and the substitution produce the same value
    Object expected = invokeSafe(originalMethod, receiver, args1);
    Object actual = invokeSafe(testMethod, null, args2);
    assertDeepEquals(expected, actual);
    // Verify that the generated code and the original produce the same value
    expected = invokeSafe(originalMethod, receiver, args1);
    actual = executeVarargsSafe(code, args2);
    assertDeepEquals(expected, actual);
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 17 with InstalledCode

use of jdk.vm.ci.code.InstalledCode 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 18 with InstalledCode

use of jdk.vm.ci.code.InstalledCode 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 19 with InstalledCode

use of jdk.vm.ci.code.InstalledCode 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)

Example 20 with InstalledCode

use of jdk.vm.ci.code.InstalledCode 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)

Aggregations

InstalledCode (jdk.vm.ci.code.InstalledCode)40 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)25 Test (org.junit.Test)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)13 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)10 CompilationResult (org.graalvm.compiler.code.CompilationResult)8 InvalidInstalledCodeException (jdk.vm.ci.code.InvalidInstalledCodeException)6 DebugContext (org.graalvm.compiler.debug.DebugContext)5 OptionValues (org.graalvm.compiler.options.OptionValues)4 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)3 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)2 GraalError (org.graalvm.compiler.debug.GraalError)2 ScheduleResult (org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 ByteBuffer (java.nio.ByteBuffer)1