Search in sources :

Example 26 with InstalledCode

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

the class AMD64HotSpotFrameOmissionTest method testHelper.

private void testHelper(String name, CodeGenerator gen) {
    ResolvedJavaMethod javaMethod = getResolvedJavaMethod(name);
    InstalledCode installedCode = getCode(javaMethod);
    TargetDescription target = getCodeCache().getTarget();
    AMD64Assembler asm = new AMD64Assembler(target);
    gen.generateCode(asm);
    byte[] expectedCode = asm.close(true);
    // Only compare up to expectedCode.length bytes to ignore
    // padding instructions adding during code installation
    byte[] actualCode = Arrays.copyOf(installedCode.getCode(), expectedCode.length);
    Assert.assertArrayEquals(expectedCode, actualCode);
}
Also used : AMD64Assembler(org.graalvm.compiler.asm.amd64.AMD64Assembler) TargetDescription(jdk.vm.ci.code.TargetDescription) InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 27 with InstalledCode

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

the class AssemblerTest method assembleMethod.

@SuppressWarnings("try")
protected InstalledCode assembleMethod(Method m, CodeGenTest test) {
    ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(m);
    OptionValues options = getInitialOptions();
    DebugContext debug = getDebugContext(options);
    try (DebugContext.Scope s = debug.scope("assembleMethod", method, codeCache)) {
        RegisterConfig registerConfig = codeCache.getRegisterConfig();
        CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
        StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
        CallingConvention cc = backend.newLIRGenerationResult(compilationId, null, null, graph, null).getCallingConvention();
        CompilationResult compResult = new CompilationResult(graph.compilationId());
        byte[] targetCode = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc);
        compResult.setTargetCode(targetCode, targetCode.length);
        compResult.setTotalFrameSize(0);
        compResult.close();
        InstalledCode code = backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compResult);
        for (DisassemblerProvider dis : GraalServices.load(DisassemblerProvider.class)) {
            String disasm1 = dis.disassembleCompiledCode(codeCache, compResult);
            Assert.assertTrue(compResult.toString(), disasm1 == null || disasm1.length() > 0);
            String disasm2 = dis.disassembleInstalledCode(codeCache, compResult, code);
            Assert.assertTrue(code.toString(), disasm2 == null || disasm2.length() > 0);
        }
        return code;
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) RegisterConfig(jdk.vm.ci.code.RegisterConfig) CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) OptionValues(org.graalvm.compiler.options.OptionValues) DebugContext(org.graalvm.compiler.debug.DebugContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DisassemblerProvider(org.graalvm.compiler.code.DisassemblerProvider) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 28 with InstalledCode

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

the class TruffleCallBoundaryInstrumentation method recordMark.

@Override
public Mark recordMark(Object id) {
    Mark mark = super.recordMark(id);
    if ((int) id == config.MARKID_VERIFIED_ENTRY) {
        ResolvedJavaType optimizedCallTargetType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.hotspot.HotSpotOptimizedCallTarget");
        int installedCodeOffset = getFieldOffset("installedCode", optimizedCallTargetType);
        int entryPointOffset = getFieldOffset("entryPoint", metaAccess.lookupJavaType(InstalledCode.class));
        injectTailCallCode(installedCodeOffset, entryPointOffset);
    }
    return mark;
}
Also used : Mark(jdk.vm.ci.code.site.Mark) InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 29 with InstalledCode

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

the class DeoptimizeDirectiveTest method testZeroBranchProbability.

@Test
public void testZeroBranchProbability() {
    ResolvedJavaMethod method = getResolvedJavaMethod("zeroBranchProbabilitySnippet");
    Result expected = executeExpected(method, null, true);
    InstalledCode code = getCode(method);
    Result actual;
    try {
        actual = new Result(code.executeVarargs(true), null);
    } catch (Exception e) {
        actual = new Result(null, e);
    }
    assertEquals(expected, actual);
    assertFalse("code should be invalidated", 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 30 with InstalledCode

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

the class DeoptimizeDirectiveTest method testDeoptimizeCheckValid.

private boolean testDeoptimizeCheckValid(ResolvedJavaMethod method) {
    Result expected = executeExpected(method, null);
    InstalledCode code = getCode(method);
    Result actual;
    try {
        actual = new Result(code.executeVarargs(), null);
    } catch (Exception e) {
        actual = new Result(null, e);
    }
    assertEquals(expected, actual);
    return code.isValid();
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode)

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