Search in sources :

Example 1 with HotSpotCompiledCode

use of jdk.vm.ci.hotspot.HotSpotCompiledCode in project graal by oracle.

the class HotSpotCompiledCodeBuilder method createCompiledCode.

public static HotSpotCompiledCode createCompiledCode(CodeCacheProvider codeCache, ResolvedJavaMethod method, HotSpotCompilationRequest compRequest, CompilationResult compResult) {
    String name = compResult.getName();
    byte[] targetCode = compResult.getTargetCode();
    int targetCodeSize = compResult.getTargetCodeSize();
    Site[] sites = getSortedSites(codeCache, compResult);
    Assumption[] assumptions = compResult.getAssumptions();
    ResolvedJavaMethod[] methods = compResult.getMethods();
    List<CodeAnnotation> annotations = compResult.getAnnotations();
    Comment[] comments = new Comment[annotations.size()];
    if (!annotations.isEmpty()) {
        for (int i = 0; i < comments.length; i++) {
            CodeAnnotation annotation = annotations.get(i);
            String text;
            if (annotation instanceof CodeComment) {
                CodeComment codeComment = (CodeComment) annotation;
                text = codeComment.value;
            } else if (annotation instanceof JumpTable) {
                JumpTable jumpTable = (JumpTable) annotation;
                text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]";
            } else {
                text = annotation.toString();
            }
            comments[i] = new Comment(annotation.position, text);
        }
    }
    DataSection data = compResult.getDataSection();
    byte[] dataSection = new byte[data.getSectionSize()];
    ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder());
    Builder<DataPatch> patchBuilder = Stream.builder();
    data.buildDataSection(buffer, (position, vmConstant) -> {
        patchBuilder.accept(new DataPatch(position, new ConstantReference(vmConstant)));
    });
    int dataSectionAlignment = data.getSectionAlignment();
    DataPatch[] dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]);
    int totalFrameSize = compResult.getTotalFrameSize();
    StackSlot customStackArea = compResult.getCustomStackArea();
    boolean isImmutablePIC = compResult.isImmutablePIC();
    if (method instanceof HotSpotResolvedJavaMethod) {
        HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method;
        int entryBCI = compResult.getEntryBCI();
        boolean hasUnsafeAccess = compResult.hasUnsafeAccess();
        int id;
        long jvmciEnv;
        if (compRequest != null) {
            id = compRequest.getId();
            jvmciEnv = compRequest.getJvmciEnv();
        } else {
            id = hsMethod.allocateCompileId(entryBCI);
            jvmciEnv = 0L;
        }
        return new HotSpotCompiledNmethod(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC, totalFrameSize, customStackArea, hsMethod, entryBCI, id, jvmciEnv, hasUnsafeAccess);
    } else {
        return new HotSpotCompiledCode(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC, totalFrameSize, customStackArea);
    }
}
Also used : Site(jdk.vm.ci.code.site.Site) CodeAnnotation(org.graalvm.compiler.code.CompilationResult.CodeAnnotation) HotSpotCompiledCode(jdk.vm.ci.hotspot.HotSpotCompiledCode) ConstantReference(jdk.vm.ci.code.site.ConstantReference) JumpTable(org.graalvm.compiler.code.CompilationResult.JumpTable) Assumption(jdk.vm.ci.meta.Assumptions.Assumption) CodeComment(org.graalvm.compiler.code.CompilationResult.CodeComment) Comment(jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) StackSlot(jdk.vm.ci.code.StackSlot) ByteBuffer(java.nio.ByteBuffer) Infopoint(jdk.vm.ci.code.site.Infopoint) CodeComment(org.graalvm.compiler.code.CompilationResult.CodeComment) DataPatch(jdk.vm.ci.code.site.DataPatch) DataSection(org.graalvm.compiler.code.DataSection) HotSpotCompiledNmethod(jdk.vm.ci.hotspot.HotSpotCompiledNmethod) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with HotSpotCompiledCode

use of jdk.vm.ci.hotspot.HotSpotCompiledCode in project graal by oracle.

the class Stub method getCode.

/**
 * Gets the code for this stub, compiling it first if necessary.
 */
@SuppressWarnings("try")
public synchronized InstalledCode getCode(final Backend backend) {
    if (code == null) {
        try (DebugContext debug = openDebugContext(DebugContext.forCurrentThread())) {
            try (DebugContext.Scope d = debug.scope("CompilingStub", providers.getCodeCache(), debugScopeContext())) {
                CodeCacheProvider codeCache = providers.getCodeCache();
                CompilationResult compResult = buildCompilationResult(debug, backend);
                try (DebugContext.Scope s = debug.scope("CodeInstall", compResult);
                    DebugContext.Activation a = debug.activate()) {
                    assert destroyedCallerRegisters != null;
                    // Add a GeneratePIC check here later, we don't want to install
                    // code if we don't have a corresponding VM global symbol.
                    HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, null, null, compResult);
                    code = codeCache.installCode(null, compiledCode, null, null, false);
                } catch (Throwable e) {
                    throw debug.handle(e);
                }
            } catch (Throwable e) {
                throw debug.handle(e);
            }
            assert code != null : "error installing stub " + this;
        }
    }
    return code;
}
Also used : HotSpotCompiledCode(jdk.vm.ci.hotspot.HotSpotCompiledCode) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider)

Example 3 with HotSpotCompiledCode

use of jdk.vm.ci.hotspot.HotSpotCompiledCode in project graal by oracle.

the class JVMCIInfopointErrorTest method test.

private void test(DebugContext debug, TestSpec spec) {
    ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
    StructuredGraph graph = parseForCompile(method, debug);
    TestNode test = graph.add(new TestNode(spec));
    graph.addAfterFixed(graph.start(), test);
    CompilationResult compResult = compile(method, graph);
    CodeCacheProvider codeCache = getCodeCache();
    HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, method, null, compResult);
    codeCache.addCode(method, compiledCode, null, null);
}
Also used : HotSpotCompiledCode(jdk.vm.ci.hotspot.HotSpotCompiledCode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompilationResult(org.graalvm.compiler.code.CompilationResult) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

HotSpotCompiledCode (jdk.vm.ci.hotspot.HotSpotCompiledCode)3 CodeCacheProvider (jdk.vm.ci.code.CodeCacheProvider)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 CompilationResult (org.graalvm.compiler.code.CompilationResult)2 ByteBuffer (java.nio.ByteBuffer)1 StackSlot (jdk.vm.ci.code.StackSlot)1 ConstantReference (jdk.vm.ci.code.site.ConstantReference)1 DataPatch (jdk.vm.ci.code.site.DataPatch)1 Infopoint (jdk.vm.ci.code.site.Infopoint)1 Site (jdk.vm.ci.code.site.Site)1 Comment (jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment)1 HotSpotCompiledNmethod (jdk.vm.ci.hotspot.HotSpotCompiledNmethod)1 HotSpotResolvedJavaMethod (jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod)1 Assumption (jdk.vm.ci.meta.Assumptions.Assumption)1 CodeAnnotation (org.graalvm.compiler.code.CompilationResult.CodeAnnotation)1 CodeComment (org.graalvm.compiler.code.CompilationResult.CodeComment)1 JumpTable (org.graalvm.compiler.code.CompilationResult.JumpTable)1 DataSection (org.graalvm.compiler.code.DataSection)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1