Search in sources :

Example 1 with CompiledCode

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

the class Backend method createInstalledCode.

/**
 * Installs code based on a given compilation result.
 *
 * @param method the method compiled to produce {@code compiledCode} or {@code null} if the
 *            input to {@code compResult} was not a {@link ResolvedJavaMethod}
 * @param compilationRequest the compilation request or {@code null}
 * @param compilationResult the code to be installed
 * @param predefinedInstalledCode a pre-allocated {@link InstalledCode} object to use as a
 *            reference to the installed code. If {@code null}, a new {@link InstalledCode}
 *            object will be created.
 * @param speculationLog the speculation log to be used
 * @param isDefault specifies if the installed code should be made the default implementation of
 *            {@code compRequest.getMethod()}. The default implementation for a method is the
 *            code executed for standard calls to the method. This argument is ignored if
 *            {@code compRequest == null}.
 * @param context a custom debug context to use for the code installation
 * @return a reference to the compiled and ready-to-run installed code
 * @throws BailoutException if the code installation failed
 */
@SuppressWarnings("try")
public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult, SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault, Object[] context) {
    Object[] debugContext = context != null ? context : new Object[] { getProviders().getCodeCache(), method, compilationResult };
    CodeInstallationTask[] tasks;
    synchronized (this) {
        tasks = new CodeInstallationTask[codeInstallationTaskFactories.size()];
        for (int i = 0; i < codeInstallationTaskFactories.size(); i++) {
            tasks[i] = codeInstallationTaskFactories.get(i).create();
        }
    }
    try (DebugContext.Scope s2 = debug.scope("CodeInstall", debugContext);
        DebugContext.Activation a = debug.activate()) {
        InstalledCode installedCode;
        try {
            preCodeInstallationTasks(tasks, compilationResult, predefinedInstalledCode);
            CompiledCode compiledCode = createCompiledCode(method, compilationRequest, compilationResult);
            installedCode = getProviders().getCodeCache().installCode(method, compiledCode, predefinedInstalledCode, speculationLog, isDefault);
            assert predefinedInstalledCode == null || installedCode == predefinedInstalledCode;
        } catch (Throwable t) {
            failCodeInstallationTasks(tasks, t);
            throw t;
        }
        postCodeInstallationTasks(tasks, installedCode);
        return installedCode;
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode) CompiledCode(jdk.vm.ci.code.CompiledCode) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 2 with CompiledCode

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

the class HotSpotTruffleCompilerImpl method installTruffleCallBoundaryMethods.

/**
 * @see #compileTruffleCallBoundaryMethod
 */
@Override
@SuppressWarnings("try")
public void installTruffleCallBoundaryMethods() {
    HotSpotTruffleCompilerRuntime runtime = (HotSpotTruffleCompilerRuntime) TruffleCompilerRuntime.getRuntime();
    for (ResolvedJavaMethod method : runtime.getTruffleCallBoundaryMethods()) {
        HotSpotCompilationIdentifier compilationId = (HotSpotCompilationIdentifier) backend.getCompilationIdentifier(method);
        OptionValues options = getOptions();
        try (DebugContext debug = DebugStubsAndSnippets.getValue(options) ? hotspotGraalRuntime.openDebugContext(options, compilationId, method, getDebugHandlerFactories()) : DebugContext.DISABLED;
            Activation a = debug.activate();
            DebugContext.Scope d = debug.scope("InstallingTruffleStub")) {
            CompilationResult compResult = compileTruffleCallBoundaryMethod(method, compilationId, debug);
            CodeCacheProvider codeCache = providers.getCodeCache();
            try (DebugContext.Scope s = debug.scope("CodeInstall", codeCache, method, compResult)) {
                CompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, method, compilationId.getRequest(), compResult);
                codeCache.setDefaultCode(method, compiledCode);
            } catch (Throwable e) {
                throw debug.handle(e);
            }
        }
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) HotSpotCompilationIdentifier(org.graalvm.compiler.hotspot.HotSpotCompilationIdentifier) Activation(org.graalvm.compiler.debug.DebugContext.Activation) CompiledCode(jdk.vm.ci.code.CompiledCode) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) HotSpotCodeCacheProvider(jdk.vm.ci.hotspot.HotSpotCodeCacheProvider) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) HotSpotTruffleCompilerRuntime(org.graalvm.compiler.truffle.common.hotspot.HotSpotTruffleCompilerRuntime) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

CompiledCode (jdk.vm.ci.code.CompiledCode)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 CodeCacheProvider (jdk.vm.ci.code.CodeCacheProvider)1 InstalledCode (jdk.vm.ci.code.InstalledCode)1 HotSpotCodeCacheProvider (jdk.vm.ci.hotspot.HotSpotCodeCacheProvider)1 HotSpotResolvedJavaMethod (jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 CompilationResult (org.graalvm.compiler.code.CompilationResult)1 Activation (org.graalvm.compiler.debug.DebugContext.Activation)1 HotSpotCompilationIdentifier (org.graalvm.compiler.hotspot.HotSpotCompilationIdentifier)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 HotSpotTruffleCompilerRuntime (org.graalvm.compiler.truffle.common.hotspot.HotSpotTruffleCompilerRuntime)1