Search in sources :

Example 11 with JavaConstant

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

the class ReverseBytesNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
    if (forValue.isConstant()) {
        JavaConstant c = forValue.asJavaConstant();
        long reversed = getStackKind() == JavaKind.Int ? Integer.reverseBytes(c.asInt()) : Long.reverseBytes(c.asLong());
        return ConstantNode.forIntegerKind(getStackKind(), reversed);
    }
    return this;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 12 with JavaConstant

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

the class IntegerSubExactNode method canonicalXYconstant.

private ValueNode canonicalXYconstant(ValueNode forX, ValueNode forY) {
    JavaConstant xConst = forX.asJavaConstant();
    JavaConstant yConst = forY.asJavaConstant();
    assert xConst.getJavaKind() == yConst.getJavaKind();
    try {
        if (xConst.getJavaKind() == JavaKind.Int) {
            return ConstantNode.forInt(Math.subtractExact(xConst.asInt(), yConst.asInt()));
        } else {
            assert xConst.getJavaKind() == JavaKind.Long;
            return ConstantNode.forLong(Math.subtractExact(xConst.asLong(), yConst.asLong()));
        }
    } catch (ArithmeticException ex) {
    // The operation will result in an overflow exception, so do not canonicalize.
    }
    return this;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 13 with JavaConstant

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

the class SubstrateInspectedFrame method getLocalConstant.

private JavaConstant getLocalConstant(int index) {
    checkDeoptimized();
    checkLocalIndex(index);
    JavaConstant result;
    if (virtualFrame != null) {
        result = virtualFrame.getConstant(index);
        assert locals[index] == null || locals[index].equals(result) : "value before and after deoptimization must be equal";
    } else {
        result = locals[index];
        if (result == null) {
            result = getDeoptimizer().readLocalVariable(index, frameInfo);
            locals[index] = result;
        }
    }
    return result;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 14 with JavaConstant

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

the class SubstrateInspectedFrame method toString.

@Override
public String toString() {
    checkDeoptimized();
    StringBuilder result = new StringBuilder();
    final StackTraceElement sourceReference = frameInfo.getSourceReference();
    result.append(sourceReference != null ? sourceReference.toString() : "[method name not available]");
    result.append("  bci: ").append(frameInfo.getBci());
    if (virtualFrame != null) {
        result.append("  [deoptimized]");
    }
    result.append("  sp: 0x").append(Long.toHexString(sp.rawValue()));
    result.append("  ip: 0x").append(Long.toHexString(ip.rawValue()));
    if (frameInfo.getDeoptMethodOffset() != 0) {
        result.append("  deoptTarget: 0x").append(Long.toHexString(frameInfo.getDeoptMethodAddress().rawValue()));
    }
    for (int i = 0; i < frameInfo.getNumLocals(); i++) {
        JavaConstant con = getLocalConstant(i);
        if (con.getJavaKind() != JavaKind.Illegal) {
            result.append("\n    local ").append(i);
            String name = frameInfo.getLocalVariableName(i);
            if (name != null) {
                result.append(" ").append(name);
            }
            if (con.getJavaKind() == JavaKind.Object) {
                if (isVirtual(i)) {
                    result.append("  [virtual object]");
                }
                Object val = SubstrateObjectConstant.asObject(con);
                if (val == null) {
                    result.append("  null");
                } else {
                    result.append("  class: ").append(val.getClass().getName());
                    result.append("  address: 0x").append(Long.toHexString(Word.objectToUntrackedPointer(val).rawValue()));
                }
            } else {
                result.append("  kind: ").append(con.getJavaKind().toString());
                if (con.getJavaKind().isNumericInteger()) {
                    result.append("  value: ").append(con.asLong());
                }
            }
        }
    }
    return result.toString();
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 15 with JavaConstant

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

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5