Search in sources :

Example 31 with InstalledCode

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

the class HotSpotForeignCallLinkageImpl method finalizeAddress.

@Override
public void finalizeAddress(Backend backend) {
    if (address == 0) {
        assert checkStubCondition();
        InstalledCode code = stub.getCode(backend);
        EconomicSet<Register> destroyedRegisters = stub.getDestroyedCallerRegisters();
        if (!destroyedRegisters.isEmpty()) {
            AllocatableValue[] temporaryLocations = new AllocatableValue[destroyedRegisters.size()];
            int i = 0;
            for (Register reg : destroyedRegisters) {
                temporaryLocations[i++] = reg.asValue();
            }
            temporaries = temporaryLocations;
        }
        address = code.getStart();
    }
}
Also used : Register(jdk.vm.ci.code.Register) InstalledCode(jdk.vm.ci.code.InstalledCode) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 32 with InstalledCode

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

the class HotSpotStackIntrospectionTest method test.

private void test(String name) throws InvalidInstalledCodeException {
    ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(getMethod(name));
    Function<Void, Void> f = o -> {
        stackIntrospection.iterateFrames(null, null, 0, frame -> {
            if (frame.getMethod().equals(method)) {
                frame.materializeVirtualObjects(true);
            }
            return null;
        });
        return null;
    };
    InstalledCode code = getCode(method);
    code.executeVarargs(f);
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode) InvalidInstalledCodeException(jdk.vm.ci.code.InvalidInstalledCodeException) GraalTest(org.graalvm.compiler.test.GraalTest) InspectedFrame(jdk.vm.ci.code.stack.InspectedFrame) Assume(org.junit.Assume) Test(org.junit.Test) StackIntrospection(jdk.vm.ci.code.stack.StackIntrospection) HotSpotJVMCIRuntime(jdk.vm.ci.hotspot.HotSpotJVMCIRuntime) Function(java.util.function.Function) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 33 with InstalledCode

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

the class HotSpotUnsafeSubstitutionTest 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 34 with InstalledCode

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

the class GraalCompilerAssumptionsTest method testAssumption.

/**
 * Checks the behavior of class loading on {@link Assumption invalidation}. {@code methodName}
 * is compiled and the resulting graph is checked for {@code expectedAssumption}. The code is
 * installed and optionally {@code classToLoad} is loaded. The class is assumed to be an inner
 * class of the test class and the name of the class to load is constructed relative to that.
 *
 * @param methodName the method to compile
 * @param expectedAssumption expected {@link Assumption} instance to find in graph
 * @param classToLoad an optional class to load to trigger an invalidation check
 * @param willInvalidate true if loading {@code classToLoad} should invalidate the method
 */
protected void testAssumption(String methodName, Assumption expectedAssumption, String classToLoad, boolean willInvalidate) {
    ResolvedJavaMethod javaMethod = getResolvedJavaMethod(methodName);
    StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
    assertTrue(!graph.getAssumptions().isEmpty());
    checkGraph(expectedAssumption, graph);
    CompilationResult compilationResult = compile(javaMethod, graph);
    final InstalledCode installedCode = getBackend().createDefaultInstalledCode(graph.getDebug(), javaMethod, compilationResult);
    assertTrue(installedCode.isValid());
    if (classToLoad != null) {
        String fullName = getClass().getName() + "$" + classToLoad;
        try {
            Class.forName(fullName);
        } catch (ClassNotFoundException e) {
            fail("Can't find class %s", fullName);
        }
        assertTrue(!willInvalidate == installedCode.isValid(), "method should be %s", willInvalidate ? "invalid" : "valid");
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 35 with InstalledCode

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

the class GraalCompilerTest method executeActual.

protected Result executeActual(OptionValues options, ResolvedJavaMethod method, Object receiver, Object... args) {
    before(method);
    Object[] executeArgs = argsWithReceiver(receiver, args);
    checkArgs(method, executeArgs);
    InstalledCode compiledMethod = getCode(method, options);
    try {
        return new Result(compiledMethod.executeVarargs(executeArgs), null);
    } catch (Throwable e) {
        return new Result(null, e);
    } finally {
        after();
    }
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)

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