Search in sources :

Example 1 with ConstantReference

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

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

the class CompilationResultBuilder method recordInlineDataInCodeWithNote.

public void recordInlineDataInCodeWithNote(Constant data, Object note) {
    assert data != null;
    int pos = asm.position();
    debug.log("Inline data in code: pos = %d, data = %s, note = %s", pos, data, note);
    if (data instanceof VMConstant) {
        compilationResult.recordDataPatchWithNote(pos, new ConstantReference((VMConstant) data), note);
    }
}
Also used : ConstantReference(jdk.vm.ci.code.site.ConstantReference) VMConstant(jdk.vm.ci.meta.VMConstant)

Example 3 with ConstantReference

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

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

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

the class CompilationResultBuilder method recordInlineDataInCode.

public void recordInlineDataInCode(Constant data) {
    assert data != null;
    int pos = asm.position();
    debug.log("Inline data in code: pos = %d, data = %s", pos, data);
    if (data instanceof VMConstant) {
        compilationResult.recordDataPatch(pos, new ConstantReference((VMConstant) data));
    }
}
Also used : ConstantReference(jdk.vm.ci.code.site.ConstantReference) VMConstant(jdk.vm.ci.meta.VMConstant)

Aggregations

ConstantReference (jdk.vm.ci.code.site.ConstantReference)5 DataPatch (jdk.vm.ci.code.site.DataPatch)3 VMConstant (jdk.vm.ci.meta.VMConstant)3 Infopoint (jdk.vm.ci.code.site.Infopoint)2 ByteBuffer (java.nio.ByteBuffer)1 StackSlot (jdk.vm.ci.code.StackSlot)1 Call (jdk.vm.ci.code.site.Call)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 HotSpotMetaspaceConstant (jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)1 HotSpotResolvedJavaMethod (jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod)1 Assumption (jdk.vm.ci.meta.Assumptions.Assumption)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 JavaKind (jdk.vm.ci.meta.JavaKind)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