Search in sources :

Example 1 with VMConstant

use of jdk.vm.ci.meta.VMConstant in project graal by oracle.

the class HotSpotDataBuilder method createDataItem.

@Override
public Data createDataItem(Constant constant) {
    if (JavaConstant.isNull(constant)) {
        boolean compressed = COMPRESSED_NULL.equals(constant);
        int size = compressed ? 4 : target.wordSize;
        return ZeroData.create(size, size);
    } else if (constant instanceof VMConstant) {
        VMConstant vmConstant = (VMConstant) constant;
        if (!(constant instanceof HotSpotConstant)) {
            throw new GraalError(String.valueOf(constant));
        }
        HotSpotConstant c = (HotSpotConstant) vmConstant;
        int size = c.isCompressed() ? 4 : target.wordSize;
        return new Data(size, size) {

            @Override
            protected void emit(ByteBuffer buffer, Patches patches) {
                int position = buffer.position();
                if (getSize() == Integer.BYTES) {
                    buffer.putInt(0xDEADDEAD);
                } else {
                    buffer.putLong(0xDEADDEADDEADDEADL);
                }
                patches.registerPatch(position, vmConstant);
            }
        };
    } else if (constant instanceof SerializableConstant) {
        SerializableConstant s = (SerializableConstant) constant;
        return new SerializableData(s);
    } else {
        throw new GraalError(String.valueOf(constant));
    }
}
Also used : HotSpotConstant(jdk.vm.ci.hotspot.HotSpotConstant) GraalError(org.graalvm.compiler.debug.GraalError) VMConstant(jdk.vm.ci.meta.VMConstant) SerializableData(org.graalvm.compiler.code.DataSection.SerializableData) ZeroData(org.graalvm.compiler.code.DataSection.ZeroData) Data(org.graalvm.compiler.code.DataSection.Data) ByteBuffer(java.nio.ByteBuffer) SerializableData(org.graalvm.compiler.code.DataSection.SerializableData) Patches(org.graalvm.compiler.code.DataSection.Patches) SerializableConstant(jdk.vm.ci.meta.SerializableConstant)

Example 2 with VMConstant

use of jdk.vm.ci.meta.VMConstant in project graal by oracle.

the class AMD64ArithmeticLIRGenerator method emitStoreConst.

protected void emitStoreConst(AMD64Kind kind, AMD64AddressValue address, ConstantValue value, LIRFrameState state) {
    Constant c = value.getConstant();
    if (JavaConstant.isNull(c)) {
        assert kind == AMD64Kind.DWORD || kind == AMD64Kind.QWORD;
        OperandSize size = kind == AMD64Kind.DWORD ? DWORD : QWORD;
        getLIRGen().append(new AMD64BinaryConsumer.MemoryConstOp(AMD64MIOp.MOV, size, address, 0, state));
        return;
    } else if (c instanceof VMConstant) {
        // only 32-bit constants can be patched
        if (kind == AMD64Kind.DWORD) {
            if (getLIRGen().target().inlineObjects || !(c instanceof JavaConstant)) {
                // if c is a JavaConstant, it's an oop, otherwise it's a metaspace constant
                assert !(c instanceof JavaConstant) || ((JavaConstant) c).getJavaKind() == JavaKind.Object;
                getLIRGen().append(new AMD64BinaryConsumer.MemoryVMConstOp(AMD64MIOp.MOV, address, (VMConstant) c, state));
                return;
            }
        }
    } else {
        JavaConstant jc = (JavaConstant) c;
        assert jc.getJavaKind().isPrimitive();
        AMD64MIOp op = AMD64MIOp.MOV;
        OperandSize size;
        long imm;
        switch(kind) {
            case BYTE:
                op = AMD64MIOp.MOVB;
                size = BYTE;
                imm = jc.asInt();
                break;
            case WORD:
                size = WORD;
                imm = jc.asInt();
                break;
            case DWORD:
                size = DWORD;
                imm = jc.asInt();
                break;
            case QWORD:
                size = QWORD;
                imm = jc.asLong();
                break;
            case SINGLE:
                size = DWORD;
                imm = Float.floatToRawIntBits(jc.asFloat());
                break;
            case DOUBLE:
                size = QWORD;
                imm = Double.doubleToRawLongBits(jc.asDouble());
                break;
            default:
                throw GraalError.shouldNotReachHere("unexpected kind " + kind);
        }
        if (NumUtil.isInt(imm)) {
            getLIRGen().append(new AMD64BinaryConsumer.MemoryConstOp(op, size, address, (int) imm, state));
            return;
        }
    }
    // fallback: load, then store
    emitStore(kind, address, getLIRGen().asAllocatable(value), state);
}
Also used : Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) VMConstant(jdk.vm.ci.meta.VMConstant) VMConstant(jdk.vm.ci.meta.VMConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) AMD64MIOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp) AMD64BinaryConsumer(org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer) OperandSize(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize)

Example 3 with VMConstant

use of jdk.vm.ci.meta.VMConstant in project graal by oracle.

the class AMD64ArithmeticLIRGenerator method emitCompareOp.

@Override
public void emitCompareOp(AMD64Kind cmpKind, Variable left, Value right) {
    OperandSize size;
    switch(cmpKind) {
        case BYTE:
            size = BYTE;
            break;
        case WORD:
            size = WORD;
            break;
        case DWORD:
            size = DWORD;
            break;
        case QWORD:
            size = QWORD;
            break;
        case SINGLE:
            getLIRGen().append(new AMD64BinaryConsumer.Op(SSEOp.UCOMIS, PS, left, getLIRGen().asAllocatable(right)));
            return;
        case DOUBLE:
            getLIRGen().append(new AMD64BinaryConsumer.Op(SSEOp.UCOMIS, PD, left, getLIRGen().asAllocatable(right)));
            return;
        default:
            throw GraalError.shouldNotReachHere("unexpected kind: " + cmpKind);
    }
    if (isConstantValue(right)) {
        Constant c = LIRValueUtil.asConstant(right);
        if (JavaConstant.isNull(c)) {
            getLIRGen().append(new AMD64BinaryConsumer.Op(TEST, size, left, left));
            return;
        } else if (c instanceof VMConstant) {
            VMConstant vc = (VMConstant) c;
            if (size == DWORD && !GeneratePIC.getValue(getOptions())) {
                getLIRGen().append(new AMD64BinaryConsumer.VMConstOp(CMP.getMIOpcode(DWORD, false), left, vc));
            } else {
                getLIRGen().append(new AMD64BinaryConsumer.DataOp(CMP.getRMOpcode(size), size, left, vc));
            }
            return;
        } else if (c instanceof JavaConstant) {
            JavaConstant jc = (JavaConstant) c;
            if (jc.isDefaultForKind()) {
                AMD64RMOp op = size == BYTE ? TESTB : TEST;
                getLIRGen().append(new AMD64BinaryConsumer.Op(op, size, left, left));
                return;
            } else if (NumUtil.is32bit(jc.asLong())) {
                getLIRGen().append(new AMD64BinaryConsumer.ConstOp(CMP, size, left, (int) jc.asLong()));
                return;
            }
        }
    }
    // fallback: load, then compare
    getLIRGen().append(new AMD64BinaryConsumer.Op(CMP.getRMOpcode(size), size, left, getLIRGen().asAllocatable(right)));
}
Also used : Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) VMConstant(jdk.vm.ci.meta.VMConstant) VMConstant(jdk.vm.ci.meta.VMConstant) AMD64RMOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp) JavaConstant(jdk.vm.ci.meta.JavaConstant) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) AMD64BinaryConsumer(org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer) OperandSize(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize)

Example 4 with VMConstant

use of jdk.vm.ci.meta.VMConstant 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 5 with VMConstant

use of jdk.vm.ci.meta.VMConstant 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)

Aggregations

VMConstant (jdk.vm.ci.meta.VMConstant)6 ConstantReference (jdk.vm.ci.code.site.ConstantReference)3 JavaConstant (jdk.vm.ci.meta.JavaConstant)3 Constant (jdk.vm.ci.meta.Constant)2 OperandSize (org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize)2 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)2 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)2 AMD64BinaryConsumer (org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer)2 ByteBuffer (java.nio.ByteBuffer)1 DataPatch (jdk.vm.ci.code.site.DataPatch)1 HotSpotConstant (jdk.vm.ci.hotspot.HotSpotConstant)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 SerializableConstant (jdk.vm.ci.meta.SerializableConstant)1 AMD64MIOp (org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp)1 AMD64RMOp (org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp)1 Data (org.graalvm.compiler.code.DataSection.Data)1 Patches (org.graalvm.compiler.code.DataSection.Patches)1 SerializableData (org.graalvm.compiler.code.DataSection.SerializableData)1 ZeroData (org.graalvm.compiler.code.DataSection.ZeroData)1 CounterKey (org.graalvm.compiler.debug.CounterKey)1