Search in sources :

Example 6 with DataPatch

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

the class HexCodeFileDisassemblerProvider method disassemble.

private static String disassemble(CodeCacheProvider codeCache, CompilationResult compResult, InstalledCode installedCode) {
    TargetDescription target = codeCache.getTarget();
    RegisterConfig regConfig = codeCache.getRegisterConfig();
    byte[] code = installedCode == null ? Arrays.copyOf(compResult.getTargetCode(), compResult.getTargetCodeSize()) : installedCode.getCode();
    if (code == null) {
        // Method was deoptimized/invalidated
        return "";
    }
    long start = installedCode == null ? 0L : installedCode.getStart();
    HexCodeFile hcf = new HexCodeFile(code, start, target.arch.getName(), target.wordSize * 8);
    if (compResult != null) {
        HexCodeFile.addAnnotations(hcf, compResult.getAnnotations());
        addExceptionHandlersComment(compResult, hcf);
        Register fp = regConfig.getFrameRegister();
        RefMapFormatter slotFormatter = new DefaultRefMapFormatter(target.wordSize, fp, 0);
        for (Infopoint infopoint : compResult.getInfopoints()) {
            if (infopoint instanceof Call) {
                Call call = (Call) infopoint;
                if (call.debugInfo != null) {
                    hcf.addComment(call.pcOffset + call.size, CodeUtil.append(new StringBuilder(100), call.debugInfo, slotFormatter).toString());
                }
                addOperandComment(hcf, call.pcOffset, "{" + codeCache.getTargetName(call) + "}");
            } else {
                if (infopoint.debugInfo != null) {
                    hcf.addComment(infopoint.pcOffset, CodeUtil.append(new StringBuilder(100), infopoint.debugInfo, slotFormatter).toString());
                }
                addOperandComment(hcf, infopoint.pcOffset, "{infopoint: " + infopoint.reason + "}");
            }
        }
        for (DataPatch site : compResult.getDataPatches()) {
            hcf.addOperandComment(site.pcOffset, "{" + site.reference.toString() + "}");
        }
        for (Mark mark : compResult.getMarks()) {
            hcf.addComment(mark.pcOffset, codeCache.getMarkName(mark));
        }
    }
    String hcfEmbeddedString = hcf.toEmbeddedString();
    return HexCodeFileDisTool.tryDisassemble(hcfEmbeddedString);
}
Also used : DefaultRefMapFormatter(jdk.vm.ci.code.CodeUtil.DefaultRefMapFormatter) RefMapFormatter(jdk.vm.ci.code.CodeUtil.RefMapFormatter) RegisterConfig(jdk.vm.ci.code.RegisterConfig) Call(jdk.vm.ci.code.site.Call) TargetDescription(jdk.vm.ci.code.TargetDescription) Mark(jdk.vm.ci.code.site.Mark) Infopoint(jdk.vm.ci.code.site.Infopoint) DataPatch(jdk.vm.ci.code.site.DataPatch) Register(jdk.vm.ci.code.Register) DefaultRefMapFormatter(jdk.vm.ci.code.CodeUtil.DefaultRefMapFormatter)

Example 7 with DataPatch

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

the class NativeImageCodeCache method patchMethods.

/**
 * Patch references from code to other code and constant data. Generate relocation information
 * in the process. More patching can be done, and correspondingly fewer relocation records
 * generated, if the caller passes a non-null rodataDisplacementFromText.
 *
 * @param relocs a relocation map
 */
public void patchMethods(RelocatableBuffer relocs) {
    // in each compilation result...
    for (Entry<HostedMethod, CompilationResult> entry : compilations.entrySet()) {
        HostedMethod method = entry.getKey();
        CompilationResult compilation = entry.getValue();
        // the codecache-relative offset of the compilation
        int compStart = method.getCodeAddressOffset();
        AMD64InstructionPatcher patcher = new AMD64InstructionPatcher(compilation);
        // ... patch direct call sites.
        for (Infopoint infopoint : compilation.getInfopoints()) {
            if (infopoint instanceof Call && ((Call) infopoint).direct) {
                Call call = (Call) infopoint;
                // NOTE that for the moment, we don't make static calls to external
                // (e.g. native) functions. So every static call site has a target
                // which is also in the code cache (a.k.a. a section-local call).
                // This will change, and we will have to case-split here... but not yet.
                int callTargetStart = ((HostedMethod) call.target).getCodeAddressOffset();
                // Patch a PC-relative call.
                // This code handles the case of section-local calls only.
                int pcDisplacement = callTargetStart - (compStart + call.pcOffset);
                patcher.findPatchData(call.pcOffset, pcDisplacement).apply(compilation.getTargetCode());
            }
        }
        // ... and patch references to constant data
        for (DataPatch dataPatch : compilation.getDataPatches()) {
            /*
                 * Constants are allocated offsets in a separate space, which can be emitted as
                 * read-only (.rodata) section.
                 */
            AMD64InstructionPatcher.PatchData patchData = patcher.findPatchData(dataPatch.pcOffset, 0);
            /*
                 * The relocation site is some offset into the instruction, which is some offset
                 * into the method, which is some offset into the text section (a.k.a. code cache).
                 * The offset we get out of the RelocationSiteInfo accounts for the first two, since
                 * we pass it the whole method. We add the method start to get the section-relative
                 * offset.
                 */
            long siteOffset = compStart + patchData.operandPosition;
            /*
                 * Do we have an addend? Yes; it's constStart. BUT x86/x86-64 PC-relative references
                 * are relative to the *next* instruction. So, if the next instruction starts n
                 * bytes from the relocation site, we want to subtract n bytes from our addend.
                 */
            long addend = (patchData.nextInstructionPosition - patchData.operandPosition);
            relocs.addPCRelativeRelocationWithAddend((int) siteOffset, patchData.operandSize, addend, dataPatch.reference);
        }
    }
}
Also used : Call(jdk.vm.ci.code.site.Call) DataPatch(jdk.vm.ci.code.site.DataPatch) AMD64InstructionPatcher(com.oracle.svm.core.graal.code.amd64.AMD64InstructionPatcher) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) Infopoint(jdk.vm.ci.code.site.Infopoint) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) CompilationResult(org.graalvm.compiler.code.CompilationResult) Infopoint(jdk.vm.ci.code.site.Infopoint) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint)

Aggregations

DataPatch (jdk.vm.ci.code.site.DataPatch)7 Infopoint (jdk.vm.ci.code.site.Infopoint)5 Call (jdk.vm.ci.code.site.Call)3 ConstantReference (jdk.vm.ci.code.site.ConstantReference)3 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)1 AMD64InstructionPatcher (com.oracle.svm.core.graal.code.amd64.AMD64InstructionPatcher)1 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)1 ByteBuffer (java.nio.ByteBuffer)1 DefaultRefMapFormatter (jdk.vm.ci.code.CodeUtil.DefaultRefMapFormatter)1 RefMapFormatter (jdk.vm.ci.code.CodeUtil.RefMapFormatter)1 Register (jdk.vm.ci.code.Register)1 RegisterConfig (jdk.vm.ci.code.RegisterConfig)1 StackSlot (jdk.vm.ci.code.StackSlot)1 TargetDescription (jdk.vm.ci.code.TargetDescription)1 DataSectionReference (jdk.vm.ci.code.site.DataSectionReference)1 Mark (jdk.vm.ci.code.site.Mark)1 Site (jdk.vm.ci.code.site.Site)1 HotSpotCompiledCode (jdk.vm.ci.hotspot.HotSpotCompiledCode)1 Comment (jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment)1 HotSpotCompiledNmethod (jdk.vm.ci.hotspot.HotSpotCompiledNmethod)1