Search in sources :

Example 1 with ImageCodeInfo

use of com.oracle.svm.core.code.ImageCodeInfo 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)

Aggregations

CodeInfoEncoder (com.oracle.svm.core.code.CodeInfoEncoder)1 ImageCodeInfo (com.oracle.svm.core.code.ImageCodeInfo)1 Counter (com.oracle.svm.core.util.Counter)1 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)1 CompilationResult (org.graalvm.compiler.code.CompilationResult)1 Indent (org.graalvm.compiler.debug.Indent)1