Search in sources :

Example 1 with DataPatch

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

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

the class Stub method checkStubInvariants.

/**
 * Checks the conditions a compilation must satisfy to be installed as a RuntimeStub.
 */
private boolean checkStubInvariants(CompilationResult compResult) {
    assert compResult.getExceptionHandlers().isEmpty() : this;
    // assumptions and there is no point in recording evol_method dependencies
    assert compResult.getAssumptions() == null : "stubs should not use assumptions: " + this;
    for (DataPatch data : compResult.getDataPatches()) {
        if (data.reference instanceof ConstantReference) {
            ConstantReference ref = (ConstantReference) data.reference;
            if (ref.getConstant() instanceof HotSpotMetaspaceConstant) {
                HotSpotMetaspaceConstant c = (HotSpotMetaspaceConstant) ref.getConstant();
                if (c.asResolvedJavaType() != null && c.asResolvedJavaType().getName().equals("[I")) {
                    // embedding the type '[I' is safe, since it is never unloaded
                    continue;
                }
            }
        }
        assert !(data.reference instanceof ConstantReference) : this + " cannot have embedded object or metadata constant: " + data.reference;
    }
    for (Infopoint infopoint : compResult.getInfopoints()) {
        assert infopoint instanceof Call : this + " cannot have non-call infopoint: " + infopoint;
        Call call = (Call) infopoint;
        assert call.target instanceof HotSpotForeignCallLinkage : this + " cannot have non runtime call: " + call.target;
        HotSpotForeignCallLinkage callLinkage = (HotSpotForeignCallLinkage) call.target;
        assert !callLinkage.isCompiledStub() || callLinkage.getDescriptor().equals(UNCOMMON_TRAP_HANDLER) : this + " cannot call compiled stub " + callLinkage;
    }
    return true;
}
Also used : Call(jdk.vm.ci.code.site.Call) ConstantReference(jdk.vm.ci.code.site.ConstantReference) DataPatch(jdk.vm.ci.code.site.DataPatch) HotSpotForeignCallLinkage(org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage) Infopoint(jdk.vm.ci.code.site.Infopoint) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)

Example 3 with DataPatch

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

the class InstalledCodeBuilder method patchData.

private void patchData(AMD64InstructionPatcher patcher) {
    for (DataPatch dataPatch : compilation.getDataPatches()) {
        DataSectionReference ref = (DataSectionReference) dataPatch.reference;
        int pcDisplacement = constantsOffset + ref.getOffset() - dataPatch.pcOffset;
        patcher.findPatchData(dataPatch.pcOffset, pcDisplacement).apply(compiledBytes);
    }
}
Also used : DataPatch(jdk.vm.ci.code.site.DataPatch) DataSectionReference(jdk.vm.ci.code.site.DataSectionReference) Infopoint(jdk.vm.ci.code.site.Infopoint)

Example 4 with DataPatch

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

the class GraalCompiler method emitCode.

@SuppressWarnings("try")
public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods, EconomicSet<ResolvedJavaField> accessedFields, int bytecodeSize, LIRGenerationResult lirGenRes, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) {
    DebugContext debug = lirGenRes.getLIR().getDebug();
    try (DebugCloseable a = EmitCode.start(debug)) {
        FrameMap frameMap = lirGenRes.getFrameMap();
        CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGenRes, frameMap, compilationResult, factory);
        backend.emitCode(crb, lirGenRes.getLIR(), installedCodeOwner);
        if (assumptions != null && !assumptions.isEmpty()) {
            compilationResult.setAssumptions(assumptions.toArray());
        }
        if (rootMethod != null) {
            compilationResult.setMethods(rootMethod, inlinedMethods);
            compilationResult.setFields(accessedFields);
            compilationResult.setBytecodeSize(bytecodeSize);
        }
        crb.finish();
        if (debug.isCountEnabled()) {
            List<DataPatch> ldp = compilationResult.getDataPatches();
            JavaKind[] kindValues = JavaKind.values();
            CounterKey[] dms = new CounterKey[kindValues.length];
            for (int i = 0; i < dms.length; i++) {
                dms[i] = DebugContext.counter("DataPatches-%s", kindValues[i]);
            }
            for (DataPatch dp : ldp) {
                JavaKind kind = JavaKind.Illegal;
                if (dp.reference instanceof ConstantReference) {
                    VMConstant constant = ((ConstantReference) dp.reference).getConstant();
                    if (constant instanceof JavaConstant) {
                        kind = ((JavaConstant) constant).getJavaKind();
                    }
                }
                dms[kind.ordinal()].add(debug, 1);
            }
            DebugContext.counter("CompilationResults").increment(debug);
            DebugContext.counter("CodeBytesEmitted").add(debug, compilationResult.getTargetCodeSize());
            DebugContext.counter("InfopointsEmitted").add(debug, compilationResult.getInfopoints().size());
            DebugContext.counter("DataPatches").add(debug, ldp.size());
            DebugContext.counter("ExceptionHandlersEmitted").add(debug, compilationResult.getExceptionHandlers().size());
        }
        debug.dump(DebugContext.BASIC_LEVEL, compilationResult, "After code generation");
    }
}
Also used : FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) ConstantReference(jdk.vm.ci.code.site.ConstantReference) JavaConstant(jdk.vm.ci.meta.JavaConstant) DebugContext(org.graalvm.compiler.debug.DebugContext) CounterKey(org.graalvm.compiler.debug.CounterKey) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) DataPatch(jdk.vm.ci.code.site.DataPatch) VMConstant(jdk.vm.ci.meta.VMConstant) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 5 with DataPatch

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

the class CompilationResult method recordDataPatch.

/**
 * Records a data patch in the code section. The data patch can refer to something in the
 * {@link DataSectionReference data section} or directly to an {@link ConstantReference inlined
 * constant}.
 *
 * @param codePos the position in the code that needs to be patched
 * @param ref the reference that should be inserted in the code
 */
public void recordDataPatch(int codePos, Reference ref) {
    checkOpen();
    assert codePos >= 0 && ref != null;
    dataPatches.add(new DataPatch(codePos, ref));
}
Also used : DataPatch(jdk.vm.ci.code.site.DataPatch)

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