Search in sources :

Example 11 with CompilationIdentifier

use of org.graalvm.compiler.core.common.CompilationIdentifier 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 12 with CompilationIdentifier

use of org.graalvm.compiler.core.common.CompilationIdentifier in project graal by oracle.

the class GraalTruffleRuntime method doCompile.

@SuppressWarnings("try")
protected void doCompile(OptionValues options, OptimizedCallTarget callTarget, Cancellable task) {
    listeners.onCompilationStarted(callTarget);
    TruffleCompiler compiler = getTruffleCompiler();
    TruffleInlining inlining = new TruffleInlining(callTarget, new DefaultInliningPolicy());
    CompilationIdentifier compilationId = compiler.getCompilationIdentifier(callTarget);
    try (DebugContext debug = compilationId != null ? compiler.openDebugContext(options, compilationId, callTarget) : null) {
        try (Scope s = debug != null ? debug.scope("Truffle", new TruffleDebugJavaMethod(callTarget)) : null) {
            maybeDumpTruffleTree(debug, options, callTarget, inlining);
            compiler.doCompile(debug, compilationId, options, callTarget, inlining, task, listeners.isEmpty() ? null : listeners);
        } catch (RuntimeException | Error e) {
            throw e;
        } catch (Throwable e) {
            throw new InternalError(e);
        }
    }
    dequeueInlinedCallSites(inlining, callTarget);
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) Scope(org.graalvm.compiler.debug.DebugContext.Scope) TruffleDebugJavaMethod(org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod) GraalError(org.graalvm.compiler.debug.GraalError) ServiceConfigurationError(java.util.ServiceConfigurationError) TruffleCompiler(org.graalvm.compiler.truffle.common.TruffleCompiler) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 13 with CompilationIdentifier

use of org.graalvm.compiler.core.common.CompilationIdentifier in project graal by oracle.

the class HotSpotGraalCompilerTest method compileAndInstallSubstitution.

protected InstalledCode compileAndInstallSubstitution(Class<?> c, String methodName) {
    ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(getMethod(c, methodName));
    HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) JVMCI.getRuntime().getCompiler();
    HotSpotGraalRuntimeProvider rt = (HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class);
    HotSpotProviders providers = rt.getHostBackend().getProviders();
    CompilationIdentifier compilationId = runtime().getHostBackend().getCompilationIdentifier(method);
    OptionValues options = getInitialOptions();
    StructuredGraph graph = compiler.getIntrinsicGraph(method, providers, compilationId, options, getDebugContext(options));
    if (graph != null) {
        return getCode(method, graph, true, true, graph.getOptions());
    }
    return null;
}
Also used : HotSpotGraalCompiler(org.graalvm.compiler.hotspot.HotSpotGraalCompiler) CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) OptionValues(org.graalvm.compiler.options.OptionValues) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) HotSpotGraalRuntimeProvider(org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider) HotSpotProviders(org.graalvm.compiler.hotspot.meta.HotSpotProviders) HotSpotGraalRuntimeProvider(org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 14 with CompilationIdentifier

use of org.graalvm.compiler.core.common.CompilationIdentifier in project graal by oracle.

the class GraalCompilerTest method getCode.

/**
 * Gets installed code for a given method and graph, compiling it first if necessary.
 *
 * @param installedCodeOwner the method the compiled code will be associated with when installed
 * @param graph the graph to be compiled. If null, a graph will be obtained from
 *            {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}.
 * @param forceCompile specifies whether to ignore any previous code cached for the (method,
 *            key) pair
 * @param installAsDefault specifies whether to install as the default implementation
 * @param options the options that will be used in {@link #parseForCompile(ResolvedJavaMethod)}
 */
@SuppressWarnings("try")
protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
    boolean useCache = !forceCompile && getArgumentToBind() == null;
    if (useCache && graph == null) {
        InstalledCode cached = cache.get(installedCodeOwner);
        if (cached != null) {
            if (cached.isValid()) {
                return cached;
            }
        }
    }
    // loop for retrying compilation
    for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
        final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
        InstalledCode installedCode = null;
        StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
        DebugContext debug = graphToCompile.getDebug();
        try (AllocSpy spy = AllocSpy.open(installedCodeOwner);
            DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
            CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
            CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(graphToCompile.compilationId()), id, options);
            printer.finish(compResult);
            try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
                DebugContext.Activation a = debug.activate()) {
                try {
                    if (installAsDefault) {
                        installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
                    } else {
                        installedCode = addMethod(debug, installedCodeOwner, compResult);
                    }
                    if (installedCode == null) {
                        throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
                    }
                } catch (BailoutException e) {
                    if (retry < BAILOUT_RETRY_LIMIT && graph == null && !e.isPermanent()) {
                        // retry (if there is no predefined graph)
                        TTY.println(String.format("Restart compilation %s (%s) due to a non-permanent bailout!", installedCodeOwner, id));
                        continue;
                    }
                    throw e;
                }
            } catch (Throwable e) {
                throw debug.handle(e);
            }
        } catch (Throwable e) {
            throw debug.handle(e);
        }
        if (useCache) {
            cache.put(installedCodeOwner, installedCode);
        }
        return installedCode;
    }
    throw GraalError.shouldNotReachHere();
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DebugContext(org.graalvm.compiler.debug.DebugContext) BailoutException(jdk.vm.ci.code.BailoutException) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) CompilationPrinter(org.graalvm.compiler.core.CompilationPrinter) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 15 with CompilationIdentifier

use of org.graalvm.compiler.core.common.CompilationIdentifier in project graal by oracle.

the class LoopPartialUnrollTest method buildGraph.

@SuppressWarnings("try")
public StructuredGraph buildGraph(String name, boolean partialUnroll) {
    CompilationIdentifier id = new CompilationIdentifier() {

        @Override
        public String toString(Verbosity verbosity) {
            return name;
        }
    };
    ResolvedJavaMethod method = getResolvedJavaMethod(name);
    OptionValues options = new OptionValues(getInitialOptions(), DefaultLoopPolicies.Options.UnrollMaxIterations, 2);
    StructuredGraph graph = parse(builder(method, StructuredGraph.AllowAssumptions.YES, id, options), getEagerGraphBuilderSuite());
    try (DebugContext.Scope buildScope = graph.getDebug().scope(name, method, graph)) {
        MidTierContext context = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, null);
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
        canonicalizer.apply(graph, context);
        new RemoveValueProxyPhase().apply(graph);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        new FloatingReadPhase().apply(graph);
        new DeadCodeEliminationPhase().apply(graph);
        new ConditionalEliminationPhase(true).apply(graph, context);
        ComputeLoopFrequenciesClosure.compute(graph);
        new GuardLoweringPhase().apply(graph, context);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
        new FrameStateAssignmentPhase().apply(graph);
        new DeoptimizationGroupingPhase().apply(graph, context);
        canonicalizer.apply(graph, context);
        new ConditionalEliminationPhase(true).apply(graph, context);
        if (partialUnroll) {
            LoopsData dataCounted = new LoopsData(graph);
            dataCounted.detectedCountedLoops();
            for (LoopEx loop : dataCounted.countedLoops()) {
                LoopFragmentInside newSegment = loop.inside().duplicate();
                newSegment.insertWithinAfter(loop, false);
            }
            canonicalizer.apply(graph, getDefaultMidTierContext());
        }
        new DeadCodeEliminationPhase().apply(graph);
        canonicalizer.apply(graph, context);
        graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "before compare");
        return graph;
    } catch (Throwable e) {
        throw getDebugContext().handle(e);
    }
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) LoopsData(org.graalvm.compiler.loop.LoopsData) OptionValues(org.graalvm.compiler.options.OptionValues) LoopFragmentInside(org.graalvm.compiler.loop.LoopFragmentInside) RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoopEx(org.graalvm.compiler.loop.LoopEx) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DeoptimizationGroupingPhase(org.graalvm.compiler.phases.common.DeoptimizationGroupingPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)16 DebugContext (org.graalvm.compiler.debug.DebugContext)10 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)10 CompilationResult (org.graalvm.compiler.code.CompilationResult)7 OptionValues (org.graalvm.compiler.options.OptionValues)7 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)6 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)4 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)3 InstalledCode (jdk.vm.ci.code.InstalledCode)2 Scope (org.graalvm.compiler.debug.DebugContext.Scope)2 GraalError (org.graalvm.compiler.debug.GraalError)2 LIRSuites (org.graalvm.compiler.lir.phases.LIRSuites)2 RemoveValueProxyPhase (org.graalvm.compiler.phases.common.RemoveValueProxyPhase)2 Suites (org.graalvm.compiler.phases.tiers.Suites)2 TruffleOptionsOverrideScope (org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope)2 RootNode (com.oracle.truffle.api.nodes.RootNode)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 ServiceConfigurationError (java.util.ServiceConfigurationError)1 BailoutException (jdk.vm.ci.code.BailoutException)1