Search in sources :

Example 21 with CompilationResult

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

the class GraalCompilerState method prepareRequest.

/**
 * Copies the {@link #originalGraph original graph} and prepares the {@link #request}.
 *
 * The {@link Suites} can be changed by overriding {@link #createSuites}. {@link LIRSuites} can
 * be changed by overriding {@link #createLIRSuites}.
 */
protected final void prepareRequest() {
    assert originalGraph != null : "call initialzeMethod first";
    CompilationIdentifier compilationId = backend.getCompilationIdentifier(originalGraph.method());
    graph = originalGraph.copyWithIdentifier(compilationId, originalGraph.getDebug());
    assert !graph.isFrozen();
    ResolvedJavaMethod installedCodeOwner = graph.method();
    request = new Request<>(graph, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(getOptions()), createLIRSuites(getOptions()), new CompilationResult(graph.compilationId()), CompilationResultBuilderFactory.Default);
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 22 with CompilationResult

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

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

the class TruffleCompilationResultBuilderFactory method createBuilder.

@Override
public CompilationResultBuilder createBuilder(CodeCacheProvider codeCache, ForeignCallsProvider foreignCalls, FrameMap frameMap, Assembler asm, DataBuilder dataBuilder, FrameContext frameContext, OptionValues options, DebugContext debug, CompilationResult compilationResult) {
    return new CompilationResultBuilder(codeCache, foreignCalls, frameMap, asm, dataBuilder, frameContext, options, debug, compilationResult) {

        @Override
        protected void closeCompilationResult() {
            CompilationResult result = this.compilationResult;
            result.setMethods(graph.method(), graph.getMethods());
            result.setBytecodeSize(graph.getBytecodeSize());
            Set<Assumption> newAssumptions = new HashSet<>();
            for (Assumption assumption : graph.getAssumptions()) {
                TruffleCompilationResultBuilderFactory.processAssumption(newAssumptions, assumption, validAssumptions);
            }
            if (result.getAssumptions() != null) {
                for (Assumption assumption : result.getAssumptions()) {
                    TruffleCompilationResultBuilderFactory.processAssumption(newAssumptions, assumption, validAssumptions);
                }
            }
            result.setAssumptions(newAssumptions.toArray(new Assumption[newAssumptions.size()]));
            super.closeCompilationResult();
        }
    };
}
Also used : CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) CompilationResult(org.graalvm.compiler.code.CompilationResult) TruffleAssumption(org.graalvm.compiler.truffle.compiler.nodes.TruffleAssumption) Assumption(jdk.vm.ci.meta.Assumptions.Assumption) HashSet(java.util.HashSet)

Example 24 with CompilationResult

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

the class TruffleCompilerImpl method compileAST.

/**
 * Compiles a Truffle AST. If compilation succeeds, the AST will have compiled code associated
 * with it that can be executed instead of interpreting the AST.
 *
 * @param compilable representation of the AST to be compiled
 * @param inliningPlan
 * @param compilationId identifier to be used for the compilation
 * @param cancellable an object polled during the compilation process to
 *            {@linkplain CancellationBailoutException abort} early if the thread owning the
 *            cancellable requests it
 * @param listener
 */
@SuppressWarnings("try")
public void compileAST(DebugContext debug, final CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, CompilationIdentifier compilationId, Cancellable cancellable, TruffleCompilerListener listener) {
    final CompilationPrinter printer = CompilationPrinter.begin(TruffleCompilerOptions.getOptions(), compilationId, new TruffleDebugJavaMethod(compilable), INVOCATION_ENTRY_BCI);
    StructuredGraph graph = null;
    try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(TruffleCompilerOptions.getOptions())) {
        PhaseSuite<HighTierContext> graphBuilderSuite = createGraphBuilderSuite();
        // Failed speculations must be collected before any compilation or
        // partial evaluation is performed.
        SpeculationLog speculationLog = compilable.getSpeculationLog();
        if (speculationLog != null) {
            speculationLog.collectFailedSpeculations();
        }
        try (DebugCloseable a = PartialEvaluationTime.start(debug);
            DebugCloseable c = PartialEvaluationMemUse.start(debug)) {
            graph = partialEvaluator.createGraph(debug, compilable, inliningPlan, AllowAssumptions.YES, compilationId, speculationLog, cancellable);
        }
        // Check if the task has been cancelled
        if (cancellable != null && cancellable.isCancelled()) {
            return;
        }
        if (listener != null) {
            listener.onTruffleTierFinished(compilable, inliningPlan, new GraphInfoImpl(graph));
        }
        CompilationResult compilationResult = compilePEGraph(graph, compilable.toString(), graphBuilderSuite, compilable, asCompilationRequest(compilationId), listener);
        if (listener != null) {
            listener.onSuccess(compilable, inliningPlan, new GraphInfoImpl(graph), new CompilationResultInfoImpl(compilationResult));
        }
        // Partial evaluation and installation are included in
        // compilation time and memory usage reported by printer
        printer.finish(compilationResult);
    } catch (Throwable t) {
        // graph is null
        if (listener != null) {
            BailoutException bailout = t instanceof BailoutException ? (BailoutException) t : null;
            boolean permanentBailout = bailout != null ? bailout.isPermanent() : false;
            listener.onFailure(compilable, t.toString(), bailout != null, permanentBailout);
        }
        throw t;
    }
}
Also used : CompilationAlarm(org.graalvm.compiler.core.common.util.CompilationAlarm) TruffleDebugJavaMethod(org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod) CancellationBailoutException(org.graalvm.compiler.core.common.CancellationBailoutException) BailoutException(jdk.vm.ci.code.BailoutException) RetryableBailoutException(org.graalvm.compiler.core.common.RetryableBailoutException) SpeculationLog(jdk.vm.ci.meta.SpeculationLog) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompilationPrinter(org.graalvm.compiler.core.CompilationPrinter) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 25 with CompilationResult

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

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