Search in sources :

Example 1 with Site

use of jdk.vm.ci.code.site.Site 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 Site

use of jdk.vm.ci.code.site.Site in project graal by oracle.

the class HotSpotCompiledCodeBuilder method getSortedSites.

/**
 * HotSpot expects sites to be presented in ascending order of PC (see
 * {@code DebugInformationRecorder::add_new_pc_offset}). In addition, it expects
 * {@link Infopoint} PCs to be unique.
 */
private static Site[] getSortedSites(CodeCacheProvider codeCache, CompilationResult target) {
    List<Site> sites = new ArrayList<>(target.getExceptionHandlers().size() + target.getInfopoints().size() + target.getDataPatches().size() + target.getMarks().size() + target.getSourceMappings().size());
    sites.addAll(target.getExceptionHandlers());
    sites.addAll(target.getInfopoints());
    sites.addAll(target.getDataPatches());
    sites.addAll(target.getMarks());
    if (codeCache.shouldDebugNonSafepoints()) {
        /*
             * Translate the source mapping into appropriate info points. In HotSpot only one
             * position can really be represented and recording the end PC seems to give the best
             * results and corresponds with what C1 and C2 do. HotSpot doesn't like to see these
             * unless -XX:+DebugNonSafepoints is enabled, so don't emit them in that case.
             */
        List<Site> sourcePositionSites = new ArrayList<>();
        for (SourceMapping source : target.getSourceMappings()) {
            NodeSourcePosition sourcePosition = source.getSourcePosition();
            if (sourcePosition.isPlaceholder() || sourcePosition.isSubstitution()) {
                // HotSpot doesn't understand any of the special positions so just drop them.
                continue;
            }
            assert sourcePosition.verify();
            sourcePosition = sourcePosition.trim();
            /*
                 * Don't add BYTECODE_POSITION info points that would potentially create conflicts.
                 * Under certain conditions the site's pc is not the pc that gets recorded by
                 * HotSpot (see @code {CodeInstaller::site_Call}). So, avoid adding any source
                 * positions that can potentially map to the same pc. To do that make sure that the
                 * source mapping doesn't contain a pc of any important Site.
                 */
            if (sourcePosition != null && !anyMatch(sites, s -> source.contains(s.pcOffset))) {
                sourcePositionSites.add(new Infopoint(source.getEndOffset(), new DebugInfo(sourcePosition), InfopointReason.BYTECODE_POSITION));
            }
        }
        sites.addAll(sourcePositionSites);
    }
    SiteComparator c = new SiteComparator();
    Collections.sort(sites, c);
    if (c.sawCollidingInfopoints) {
        Infopoint lastInfopoint = null;
        List<Site> copy = new ArrayList<>(sites.size());
        for (Site site : sites) {
            if (site instanceof Infopoint) {
                Infopoint info = (Infopoint) site;
                if (lastInfopoint == null || lastInfopoint.pcOffset != info.pcOffset) {
                    lastInfopoint = info;
                    copy.add(info);
                } else {
                    // Omit this colliding infopoint
                    assert lastInfopoint.reason.compareTo(info.reason) <= 0;
                }
            } else {
                copy.add(site);
            }
        }
        sites = copy;
    }
    return sites.toArray(new Site[sites.size()]);
}
Also used : Site(jdk.vm.ci.code.site.Site) ArrayList(java.util.ArrayList) Infopoint(jdk.vm.ci.code.site.Infopoint) SourceMapping(org.graalvm.compiler.code.SourceMapping) DebugInfo(jdk.vm.ci.code.DebugInfo) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Aggregations

Infopoint (jdk.vm.ci.code.site.Infopoint)2 Site (jdk.vm.ci.code.site.Site)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 DebugInfo (jdk.vm.ci.code.DebugInfo)1 StackSlot (jdk.vm.ci.code.StackSlot)1 ConstantReference (jdk.vm.ci.code.site.ConstantReference)1 DataPatch (jdk.vm.ci.code.site.DataPatch)1 HotSpotCompiledCode (jdk.vm.ci.hotspot.HotSpotCompiledCode)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 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)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 SourceMapping (org.graalvm.compiler.code.SourceMapping)1 NodeSourcePosition (org.graalvm.compiler.graph.NodeSourcePosition)1