Search in sources :

Example 16 with CompilationResult

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

the class InvokeGraal method compileAndInstallMethod.

/**
 * The simplest way to compile a method, using the default behavior for everything.
 */
@SuppressWarnings("try")
protected InstalledCode compileAndInstallMethod(ResolvedJavaMethod method) {
    /* Create a unique compilation identifier, visible in IGV. */
    CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
    OptionValues options = getInitialOptions();
    DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
    try (DebugContext.Scope s = debug.scope("compileAndInstallMethod", new DebugDumpScope(String.valueOf(compilationId), true))) {
        /*
             * The graph that is compiled. We leave it empty (no nodes added yet). This means that
             * it will be filled according to the graphBuilderSuite defined below. We also specify
             * that we want the compilation to make optimistic assumptions about runtime state such
             * as the loaded class hierarchy.
             */
        StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).compilationId(compilationId).build();
        /*
             * The phases used to build the graph. Usually this is just the GraphBuilderPhase. If
             * the graph already contains nodes, it is ignored.
             */
        PhaseSuite<HighTierContext> graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite();
        /*
             * The optimization phases that are applied to the graph. This is the main configuration
             * point for Graal. Add or remove phases to customize your compilation.
             */
        Suites suites = backend.getSuites().getDefaultSuites(options);
        /*
             * The low-level phases that are applied to the low-level representation.
             */
        LIRSuites lirSuites = backend.getSuites().getDefaultLIRSuites(options);
        /*
             * We want Graal to perform all speculative optimistic optimizations, using the
             * profiling information that comes with the method (collected by the interpreter) for
             * speculation.
             */
        OptimisticOptimizations optimisticOpts = OptimisticOptimizations.ALL;
        ProfilingInfo profilingInfo = graph.getProfilingInfo(method);
        /* The default class and configuration for compilation results. */
        CompilationResult compilationResult = new CompilationResult(graph.compilationId());
        CompilationResultBuilderFactory factory = CompilationResultBuilderFactory.Default;
        /* Invoke the whole Graal compilation pipeline. */
        GraalCompiler.compileGraph(graph, method, providers, backend, graphBuilderSuite, optimisticOpts, profilingInfo, suites, lirSuites, compilationResult, factory);
        /*
             * Install the compilation result into the VM, i.e., copy the byte[] array that contains
             * the machine code into an actual executable memory location.
             */
        return backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compilationResult);
    } catch (Throwable ex) {
        throw debug.handle(ex);
    }
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) OptionValues(org.graalvm.compiler.options.OptionValues) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) DebugContext(org.graalvm.compiler.debug.DebugContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) OptimisticOptimizations(org.graalvm.compiler.phases.OptimisticOptimizations) CompilationResultBuilderFactory(org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 17 with CompilationResult

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

the class FloatArraysEqualsTest method testStableArray.

public void testStableArray(String methodName) {
    ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
    Result expected = executeExpected(method, null);
    StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
    for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class).snapshot()) {
        if (getConstantReflection().readArrayLength(constantNode.asJavaConstant()) != null) {
            ConstantNode newConstantNode = ConstantNode.forConstant(constantNode.asJavaConstant(), 1, true, getMetaAccess());
            newConstantNode = graph.unique(newConstantNode);
            constantNode.replaceAndDelete(newConstantNode);
        }
    }
    CompilationResult result = compile(method, graph);
    InstalledCode code = addMethod(graph.getDebug(), method, result);
    Result actual;
    try {
        actual = new Result(code.executeVarargs(), null);
    } catch (Exception e) {
        actual = new Result(null, e);
    }
    assertEquals(expected, actual);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 18 with CompilationResult

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

the class GraalCompilerTest method compile.

/**
 * Compiles a given method.
 *
 * @param installedCodeOwner the method the compiled code will be associated with when installed
 * @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will
 *            be obtained from {@code installedCodeOwner} via
 *            {@link #parseForCompile(ResolvedJavaMethod)}.
 */
protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) {
    OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
    CompilationIdentifier compilationId = getOrCreateCompilationId(installedCodeOwner, graph);
    return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) OptionValues(org.graalvm.compiler.options.OptionValues) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 19 with CompilationResult

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

the class NativeImageCodeCache method layoutMethods.

@SuppressWarnings("try")
public void layoutMethods(DebugContext debug) {
    try (Indent indent = debug.logAndIndent("layout methods")) {
        // Assign a location to all methods.
        assert codeCacheSize == 0;
        HostedMethod firstMethod = null;
        for (Entry<HostedMethod, CompilationResult> entry : compilations.entrySet()) {
            HostedMethod method = entry.getKey();
            if (firstMethod == null) {
                firstMethod = method;
            }
            CompilationResult compilation = entry.getValue();
            compilationsByStart.put(codeCacheSize, compilation);
            method.setCodeAddressOffset(codeCacheSize);
            codeCacheSize = ObjectLayout.roundUp(codeCacheSize + compilation.getTargetCodeSize(), CODE_ALIGNMENT);
        }
        // Build run-time metadata.
        FrameInfoCustomization frameInfoCustomization = new FrameInfoCustomization();
        CodeInfoEncoder codeInfoEncoder = new CodeInfoEncoder(frameInfoCustomization, null);
        for (Entry<HostedMethod, CompilationResult> entry : compilations.entrySet()) {
            final HostedMethod method = entry.getKey();
            final CompilationResult compilation = entry.getValue();
            codeInfoEncoder.addMethod(method, compilation, method.getCodeAddressOffset());
        }
        if (NativeImageOptions.PrintMethodHistogram.getValue()) {
            System.out.println("encoded deopt entry points                 ; " + frameInfoCustomization.numDeoptEntryPoints);
            System.out.println("encoded during call entry points           ; " + frameInfoCustomization.numDuringCallEntryPoints);
        }
        ImageCodeInfo imageCodeInfo = CodeInfoTable.getImageCodeCache();
        codeInfoEncoder.encodeAll();
        codeInfoEncoder.install(imageCodeInfo);
        imageCodeInfo.setData(MethodPointer.factory(firstMethod), WordFactory.unsigned(codeCacheSize));
        if (CodeInfoEncoder.Options.CodeInfoEncoderCounters.getValue()) {
            for (Counter counter : ImageSingletons.lookup(CodeInfoEncoder.Counters.class).group.getCounters()) {
                System.out.println(counter.getName() + " ; " + counter.getValue());
            }
        }
        if (Options.VerifyDeoptimizationEntryPoints.getValue()) {
            /*
                 * Missing deoptimization entry points lead to hard-to-debug transient failures, so
                 * we want the verification on all the time and not just when assertions are on.
                 */
            verifyDeoptEntries(imageCodeInfo);
        }
        assert verifyMethods(codeInfoEncoder);
    }
}
Also used : Indent(org.graalvm.compiler.debug.Indent) CodeInfoEncoder(com.oracle.svm.core.code.CodeInfoEncoder) Counter(com.oracle.svm.core.util.Counter) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CompilationResult(org.graalvm.compiler.code.CompilationResult) ImageCodeInfo(com.oracle.svm.core.code.ImageCodeInfo)

Example 20 with CompilationResult

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

the class NativeImageCodeCache method layoutConstants.

public void layoutConstants() {
    for (CompilationResult compilation : compilations.values()) {
        for (DataSection.Data data : compilation.getDataSection()) {
            if (data instanceof SubstrateDataBuilder.ObjectData) {
                JavaConstant constant = ((SubstrateDataBuilder.ObjectData) data).getConstant();
                constantReasons.put(constant, compilation.getName());
            }
        }
        dataSection.addAll(compilation.getDataSection());
    }
    dataSection.close();
}
Also used : DataSection(org.graalvm.compiler.code.DataSection) JavaConstant(jdk.vm.ci.meta.JavaConstant) CompilationResult(org.graalvm.compiler.code.CompilationResult)

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