Search in sources :

Example 36 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.

the class DeoptEntryOp method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb) {
    CompilationResult compilation = crb.compilationResult;
    /* Search for the previous added info point. */
    List<Infopoint> infoPoints = compilation.getInfopoints();
    int size = infoPoints.size();
    for (int idx = size - 1; idx >= 0; idx--) {
        Infopoint infopoint = infoPoints.get(idx);
        int entryOffset = CodeInfoEncoder.getEntryOffset(infopoint);
        if (entryOffset >= 0) {
            if (entryOffset == crb.asm.position()) {
                crb.asm.ensureUniquePC();
                break;
            }
        }
    }
    /* Register this location as a deopt infopoint. */
    compilation.addInfopoint(new DeoptEntryInfopoint(crb.asm.position(), state.debugInfo()));
    /* Add NOP so that the next infopoint (e.g., an invoke) gets a unique PC. */
    crb.asm.ensureUniquePC();
}
Also used : DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint) CompilationResult(org.graalvm.compiler.code.CompilationResult) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint)

Example 37 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.

the class SubstrateGraalUtils method doCompile.

/**
 * Actual method compilation.
 *
 * For zone allocation this is where the zone boundary can be placed when the code is only
 * compiled. However using the returned compilation result would result into a zone allocation
 * invariant violation.
 */
private static CompilationResult doCompile(DebugContext initialDebug, RuntimeConfiguration runtimeConfig, Suites suites, LIRSuites lirSuites, final SubstrateMethod method) {
    String methodString = method.format("%H.%n(%p)");
    SubstrateCompilationIdentifier compilationId = new SubstrateCompilationIdentifier();
    return new CompilationWrapper<CompilationResult>(GraalSupport.get().getDebugOutputDirectory(), compilationProblemsPerAction) {

        @SuppressWarnings({ "unchecked", "unused" })
        <E extends Throwable> RuntimeException silenceThrowable(Class<E> type, Throwable ex) throws E {
            throw (E) ex;
        }

        @Override
        protected CompilationResult handleException(Throwable t) {
            throw silenceThrowable(RuntimeException.class, t);
        }

        @Override
        protected CompilationResult performCompilation(DebugContext debug) {
            StructuredGraph graph = GraalSupport.decodeGraph(debug, null, compilationId, method);
            return compileGraph(runtimeConfig, suites, lirSuites, method, graph);
        }

        @Override
        public String toString() {
            return methodString;
        }

        @Override
        protected DebugContext createRetryDebugContext(OptionValues options) {
            return GraalSupport.get().openDebugContext(options, compilationId, method);
        }
    }.run(initialDebug);
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateCompilationIdentifier(com.oracle.svm.core.graal.code.SubstrateCompilationIdentifier) DebugContext(org.graalvm.compiler.debug.DebugContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompilationResult(org.graalvm.compiler.code.CompilationResult) SubstrateCompilationResult(com.oracle.svm.core.graal.code.SubstrateCompilationResult)

Example 38 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.

the class SubstrateGraalUtils method doCompileAndInstall.

/**
 * This method does the actual compilation and installation of the method. Nothing is returned
 * by this call. The code is installed via pinned objects and the address is updated in the
 * {@link InstalledCode} argument.
 *
 * For zone allocation this is where the zone boundary can be placed when the code needs to be
 * compiled and installed.
 */
private static void doCompileAndInstall(DebugContext debug, RuntimeConfiguration runtimeConfig, Suites suites, LIRSuites lirSuites, SubstrateMethod method, SubstrateInstalledCodeImpl installedCode, boolean testTrampolineJumps) {
    CompilationResult compilationResult = doCompile(debug, runtimeConfig, suites, lirSuites, method);
    installMethod(method, compilationResult, installedCode, testTrampolineJumps);
}
Also used : CompilationResult(org.graalvm.compiler.code.CompilationResult) SubstrateCompilationResult(com.oracle.svm.core.graal.code.SubstrateCompilationResult)

Example 39 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.

the class JVMCIInfopointErrorTest method test.

private void test(DebugContext debug, TestSpec spec) {
    ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
    StructuredGraph graph = parseForCompile(method, debug);
    TestNode test = graph.add(new TestNode(spec));
    graph.addAfterFixed(graph.start(), test);
    CompilationResult compResult = compile(method, graph);
    CodeCacheProvider codeCache = getCodeCache();
    HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, method, null, compResult);
    codeCache.addCode(method, compiledCode, null, null);
}
Also used : HotSpotCompiledCode(jdk.vm.ci.hotspot.HotSpotCompiledCode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompilationResult(org.graalvm.compiler.code.CompilationResult) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 40 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult 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)

Aggregations

CompilationResult (org.graalvm.compiler.code.CompilationResult)46 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)20 Test (org.junit.Test)15 DebugContext (org.graalvm.compiler.debug.DebugContext)13 CallingConvention (jdk.vm.ci.code.CallingConvention)12 RegisterConfig (jdk.vm.ci.code.RegisterConfig)12 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)12 Register (jdk.vm.ci.code.Register)11 TargetDescription (jdk.vm.ci.code.TargetDescription)11 AssemblerTest (org.graalvm.compiler.asm.test.AssemblerTest)11 AMD64Assembler (org.graalvm.compiler.asm.amd64.AMD64Assembler)9 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)8 Infopoint (jdk.vm.ci.code.site.Infopoint)8 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)8 OptionValues (org.graalvm.compiler.options.OptionValues)8 InstalledCode (jdk.vm.ci.code.InstalledCode)7 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)6 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)6 CodeCacheProvider (jdk.vm.ci.code.CodeCacheProvider)5 LIRSuites (org.graalvm.compiler.lir.phases.LIRSuites)5