Search in sources :

Example 21 with InstalledCode

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

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

the class StringSubstitutionsTest method testSubstitution.

public void testSubstitution(String testMethodName, Class<?> intrinsicClass, Class<?> holder, String methodName, boolean optional, Object[] args1, Object[] args2) {
    ResolvedJavaMethod realMethod = getResolvedJavaMethod(holder, methodName);
    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, 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 23 with InstalledCode

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

the class TestSHASubstitutions method testWithInstalledIntrinsic.

void testWithInstalledIntrinsic(String className, String methodName, String testSnippetName, Object... args) {
    Class<?> c;
    try {
        c = Class.forName(className);
    } catch (ClassNotFoundException e) {
        // may have been installed
        return;
    }
    InstalledCode code = null;
    try {
        ResolvedJavaMethod method = getResolvedJavaMethod(testSnippetName);
        Object receiver = method.isStatic() ? null : this;
        Result expect = executeExpected(method, receiver, args);
        code = compileAndInstallSubstitution(c, methodName);
        assertTrue("Failed to install " + methodName, code != null);
        testAgainstExpected(method, expect, receiver, args);
    } catch (AssumptionViolatedException e) {
    // Suppress so that subsequent calls to this method within the
    // same Junit @Test annotated method can proceed.
    }
    if (code != null) {
        code.invalidate();
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 24 with InstalledCode

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

the class ExplicitExceptionTest method getCode.

@Override
protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
    InstalledCode installedCode = super.getCode(method, graph, forceCompile, installAsDefault, options);
    Assume.assumeTrue(exceptionWasSeen(method));
    assertDeepEquals(expectedForeignCallCount, lastCompiledGraph.getNodes().filter(ForeignCallNode.class).count());
    return installedCode;
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode)

Example 25 with InstalledCode

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

the class ArrayCopyIntrinsificationTest method getCode.

@Override
protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph g, boolean forceCompile, boolean installAsDefault, OptionValues options) {
    StructuredGraph graph = g == null ? parseForCompile(method) : g;
    int nodeCount = graph.getNodeCount();
    InstalledCode result = super.getCode(method, graph, forceCompile, installAsDefault, options);
    boolean graphWasProcessed = nodeCount != graph.getNodeCount();
    if (graphWasProcessed) {
        if (mustIntrinsify) {
            for (Node node : graph.getNodes()) {
                if (node instanceof Invoke) {
                    Invoke invoke = (Invoke) node;
                    Assert.assertTrue(invoke.callTarget() instanceof DirectCallTargetNode);
                    LoweredCallTargetNode directCall = (LoweredCallTargetNode) invoke.callTarget();
                    JavaMethod callee = directCall.targetMethod();
                    if (callee.getDeclaringClass().equals(getMetaAccess().lookupJavaType(System.class)) && callee.getName().equals("arraycopy")) {
                    // A partial snippet (e.g., ArrayCopySnippets.checkcastArraycopy) may
                    // call the original arraycopy method
                    } else {
                        Assert.assertTrue(callee.toString(), callee.getName().equals("<init>"));
                        Assert.assertTrue(getMetaAccess().lookupJavaType(ArrayIndexOutOfBoundsException.class).equals(callee.getDeclaringClass()) || getMetaAccess().lookupJavaType(NullPointerException.class).equals(callee.getDeclaringClass()));
                    }
                }
            }
        } else {
            boolean found = false;
            for (Node node : graph.getNodes()) {
                if (node instanceof Invoke) {
                    Invoke invoke = (Invoke) node;
                    LoweredCallTargetNode directCall = (LoweredCallTargetNode) invoke.callTarget();
                    JavaMethod callee = directCall.targetMethod();
                    if (callee.getDeclaringClass().equals(getMetaAccess().lookupJavaType(System.class)) && callee.getName().equals("arraycopy")) {
                        found = true;
                    } else {
                        fail("found invoke to some method other than arraycopy: " + callee);
                    }
                }
            }
            Assert.assertTrue("did not find invoke to arraycopy", found);
        }
    }
    return result;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) Node(org.graalvm.compiler.graph.Node) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) InstalledCode(jdk.vm.ci.code.InstalledCode) JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) Invoke(org.graalvm.compiler.nodes.Invoke)

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