Search in sources :

Example 11 with LongConstantOperand

use of org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand in project JikesRVM by JikesRVM.

the class BURS_Helpers method STORE_LONG_FOR_CONV.

/**
 * Creates a 64bit slot on the stack in memory for a conversion and
 * stores the given long.
 *
 * @param op an operand representing a long
 */
protected final void STORE_LONG_FOR_CONV(Operand op) {
    int offset = -burs.ir.stackManager.allocateSpaceForConversion();
    if (VM.BuildFor32Addr) {
        if (op instanceof RegisterOperand) {
            RegisterOperand hval = (RegisterOperand) op;
            RegisterOperand lval = new RegisterOperand(regpool.getSecondReg(hval.getRegister()), TypeReference.Int);
            EMIT(MIR_Move.create(IA32_MOV, new StackLocationOperand(true, offset + 4, DW), hval));
            EMIT(MIR_Move.create(IA32_MOV, new StackLocationOperand(true, offset, DW), lval));
        } else {
            LongConstantOperand val = LC(op);
            EMIT(MIR_Move.create(IA32_MOV, new StackLocationOperand(true, offset + 4, DW), IC(val.upper32())));
            EMIT(MIR_Move.create(IA32_MOV, new StackLocationOperand(true, offset, DW), IC(val.lower32())));
        }
    } else {
        if (op instanceof RegisterOperand) {
            RegisterOperand val = (RegisterOperand) op;
            EMIT(MIR_Move.create(IA32_MOV, new StackLocationOperand(true, offset, QW), val));
        } else {
            LongConstantOperand val = LC(op);
            EMIT(MIR_Move.create(IA32_MOV, new StackLocationOperand(true, offset, QW), val));
        }
    }
}
Also used : LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) OsrPoint(org.jikesrvm.compilers.opt.ir.OsrPoint) StackLocationOperand(org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand)

Example 12 with LongConstantOperand

use of org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand in project JikesRVM by JikesRVM.

the class BURS_MemOp_Helpers method MO_MC.

protected final MemoryOperand MO_MC(Instruction s) {
    // JTOC
    Operand base = Binary.getVal1(s);
    // float or double value
    Operand val = Binary.getVal2(s);
    if (val instanceof FloatConstantOperand) {
        FloatConstantOperand fc = (FloatConstantOperand) val;
        Offset offset = fc.offset;
        LocationOperand loc = new LocationOperand(offset);
        if (base instanceof IntConstantOperand) {
            return MO_D(offset.plus(IV(base)), DW, loc, TG());
        } else if (VM.BuildFor64Addr && base instanceof LongConstantOperand) {
            return MO_D(offset.plus(Offset.fromLong(LV(base))), DW, loc, TG());
        } else {
            return MO_BD(base, offset, DW, loc, TG());
        }
    } else {
        DoubleConstantOperand dc = (DoubleConstantOperand) val;
        Offset offset = dc.offset;
        LocationOperand loc = new LocationOperand(offset);
        if (base instanceof IntConstantOperand) {
            return MO_D(offset.plus(IV(base)), QW, loc, TG());
        } else if (VM.BuildFor64Addr && base instanceof LongConstantOperand) {
            return MO_D(offset.plus(Offset.fromLong(LV(base))), QW, loc, TG());
        } else {
            return MO_BD(Binary.getVal1(s), dc.offset, QW, loc, TG());
        }
    }
}
Also used : LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) DoubleConstantOperand(org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand) MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) FloatConstantOperand(org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) DoubleConstantOperand(org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) FloatConstantOperand(org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand) Offset(org.vmmagic.unboxed.Offset)

Example 13 with LongConstantOperand

use of org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand in project JikesRVM by JikesRVM.

the class StaticFieldReader method getFieldValueAsConstant.

public static ConstantOperand getFieldValueAsConstant(RVMField field, Object obj) throws NoSuchFieldException {
    if (VM.VerifyAssertions) {
        boolean isFinalField = field.isFinal();
        boolean isInitializedField = field.getDeclaringClass().isInitialized() || field.getDeclaringClass().isInBootImage();
        if (!(isFinalField && isInitializedField)) {
            String msg = "Error reading field " + field;
            VM._assert(VM.NOT_REACHED, msg);
        }
    }
    TypeReference type = field.getType();
    if (VM.runningVM) {
        if (type.isReferenceType() && (!type.isMagicType() || type.isUnboxedArrayType())) {
            Object value = field.getObjectValueUnchecked(obj);
            if (value != null) {
                return new ObjectConstantOperand(value, Offset.zero());
            } else {
                return new NullConstantOperand();
            }
        } else if (type.isWordLikeType()) {
            return new AddressConstantOperand(field.getWordValueUnchecked(obj).toAddress());
        } else if (type.isIntType()) {
            return new IntConstantOperand(field.getIntValueUnchecked(obj));
        } else if (type.isBooleanType()) {
            return new IntConstantOperand(field.getBooleanValueUnchecked(obj) ? 1 : 0);
        } else if (type.isByteType()) {
            return new IntConstantOperand(field.getByteValueUnchecked(obj));
        } else if (type.isCharType()) {
            return new IntConstantOperand(field.getCharValueUnchecked(obj));
        } else if (type.isDoubleType()) {
            return new DoubleConstantOperand(field.getDoubleValueUnchecked(obj));
        } else if (type.isFloatType()) {
            return new FloatConstantOperand(field.getFloatValueUnchecked(obj));
        } else if (type.isLongType()) {
            return new LongConstantOperand(field.getLongValueUnchecked(obj));
        } else if (type.isShortType()) {
            return new IntConstantOperand(field.getShortValueUnchecked(obj));
        } else {
            OptimizingCompilerException.UNREACHABLE("Unknown type " + type);
            return null;
        }
    } else {
        try {
            String cn = field.getDeclaringClass().toString();
            Field f = Class.forName(cn).getDeclaredField(field.getName().toString());
            f.setAccessible(true);
            if (type.isReferenceType() && (!type.isMagicType() || type.isUnboxedArrayType())) {
                Object value = f.get(obj);
                if (value != null) {
                    return new ObjectConstantOperand(value, Offset.zero());
                } else {
                    return new NullConstantOperand();
                }
            } else if (type.isWordLikeType()) {
                Object value = f.get(obj);
                if (type.equals(TypeReference.Word))
                    return new AddressConstantOperand((Word) value);
                else if (type.equals(TypeReference.Address))
                    return new AddressConstantOperand((Address) value);
                else if (type.equals(TypeReference.Offset))
                    return new AddressConstantOperand((Offset) value);
                else if (type.equals(TypeReference.Extent))
                    return new AddressConstantOperand((Extent) value);
                else {
                    OptimizingCompilerException.UNREACHABLE("Unknown word type " + type);
                    return null;
                }
            } else if (type.isIntType()) {
                return new IntConstantOperand(f.getInt(obj));
            } else if (type.isBooleanType()) {
                return new IntConstantOperand(f.getBoolean(obj) ? 1 : 0);
            } else if (type.isByteType()) {
                return new IntConstantOperand(f.getByte(obj));
            } else if (type.isCharType()) {
                return new IntConstantOperand(f.getChar(obj));
            } else if (type.isDoubleType()) {
                return new DoubleConstantOperand(f.getDouble(obj));
            } else if (type.isFloatType()) {
                return new FloatConstantOperand(f.getFloat(obj));
            } else if (type.isLongType()) {
                return new LongConstantOperand(f.getLong(obj));
            } else if (type.isShortType()) {
                return new IntConstantOperand(f.getShort(obj));
            } else {
                OptimizingCompilerException.UNREACHABLE(cn + "." + f.getName() + " has unknown type " + type);
                return null;
            }
        } catch (IllegalArgumentException e) {
            throwNoSuchFieldExceptionWithCause(field, e);
        } catch (IllegalAccessException e) {
            throwNoSuchFieldExceptionWithCause(field, e);
        } catch (NoSuchFieldError e) {
            throwNoSuchFieldExceptionWithCause(field, e);
        } catch (ClassNotFoundException e) {
            throwNoSuchFieldExceptionWithCause(field, e);
        } catch (NoClassDefFoundError e) {
            throwNoSuchFieldExceptionWithCause(field, e);
        } catch (IllegalAccessError e) {
            throwNoSuchFieldExceptionWithCause(field, e);
        }
        assertNotReached();
        return null;
    }
}
Also used : LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) Address(org.vmmagic.unboxed.Address) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) Extent(org.vmmagic.unboxed.Extent) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) Field(java.lang.reflect.Field) RVMField(org.jikesrvm.classloader.RVMField) DoubleConstantOperand(org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) FloatConstantOperand(org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand) TypeReference(org.jikesrvm.classloader.TypeReference)

Example 14 with LongConstantOperand

use of org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand in project JikesRVM by JikesRVM.

the class StaticFieldReader method getStaticFieldValue.

/**
 * Returns a constant operand with the current value of a static field.
 *
 * @param field the static field whose current value we want to read
 * @return a constant operand representing the current value of the field.
 * @throws NoSuchFieldException when the field could not be found
 */
public static ConstantOperand getStaticFieldValue(RVMField field) throws NoSuchFieldException {
    if (VM.VerifyAssertions) {
        boolean fieldIsReady = field.getDeclaringClass().isInitialized() || field.getDeclaringClass().isInBootImage();
        boolean isFinalField = field.isFinal();
        boolean isStaticField = field.isStatic();
        if (!(isFinalField && isStaticField && fieldIsReady)) {
            String msg = "Error reading field " + field;
            VM._assert(VM.NOT_REACHED, msg);
        }
    }
    TypeReference fieldType = field.getType();
    Offset off = field.getOffset();
    if ((fieldType == TypeReference.Address) || (fieldType == TypeReference.Word) || (fieldType == TypeReference.Offset) || (fieldType == TypeReference.Extent)) {
        Address val = getAddressStaticFieldValue(field);
        return new AddressConstantOperand(val);
    } else if (fieldType.isIntLikeType()) {
        int val = getIntStaticFieldValue(field);
        return new IntConstantOperand(val);
    } else if (fieldType.isLongType()) {
        long val = getLongStaticFieldValue(field);
        return new LongConstantOperand(val);
    } else if (fieldType.isFloatType()) {
        float val = getFloatStaticFieldValue(field);
        return new FloatConstantOperand(val, off);
    } else if (fieldType.isDoubleType()) {
        double val = getDoubleStaticFieldValue(field);
        return new DoubleConstantOperand(val, off);
    } else {
        // Reference type
        if (VM.VerifyAssertions)
            VM._assert(fieldType.isReferenceType());
        Object val = getObjectStaticFieldValue(field);
        if (val == null) {
            return new NullConstantOperand();
        } else if (fieldType == TypeReference.JavaLangString) {
            return new StringConstantOperand((String) val, off);
        } else if (fieldType == TypeReference.JavaLangClass) {
            Class<?> klass = (Class<?>) getObjectStaticFieldValue(field);
            RVMType type;
            if (VM.runningVM) {
                type = java.lang.JikesRVMSupport.getTypeForClass(klass);
            } else {
                type = TypeReference.findOrCreate(klass).resolve();
            }
            return new ClassConstantOperand(type.getClassForType(), off);
        } else {
            return new ObjectConstantOperand(val, off);
        }
    }
}
Also used : LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) StringConstantOperand(org.jikesrvm.compilers.opt.ir.operand.StringConstantOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) Address(org.vmmagic.unboxed.Address) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) RVMType(org.jikesrvm.classloader.RVMType) Offset(org.vmmagic.unboxed.Offset) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) ClassConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand) DoubleConstantOperand(org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand) FloatConstantOperand(org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) TypeReference(org.jikesrvm.classloader.TypeReference)

Example 15 with LongConstantOperand

use of org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand in project JikesRVM by JikesRVM.

the class BC2IR method _createOsrBarrier.

/* create an OSR Barrier instruction at the current position.
   */
private Instruction _createOsrBarrier() {
    ArrayList<Operand> livevars = new ArrayList<Operand>();
    /* for local variables, we have to use helper to make a register. */
    /* ltypes and stypes should be the full length
     * WARNING: what's the order of DUMMY and LONG?
     */
    int localnum = _localState.length;
    byte[] ltypes = new byte[localnum];
    int num_llocals = 0;
    for (int i = 0, n = _localState.length; i < n; i++) {
        Operand op = _localState[i];
        if ((op != null) && (op != DUMMY)) {
            livevars.add(_loadLocalForOSR(op));
            num_llocals++;
            if (op instanceof ReturnAddressOperand) {
                ltypes[i] = ReturnAddressTypeCode;
            } else {
                TypeReference typ = op.getType();
                if (typ.isWordLikeType() || (typ == TypeReference.NULL_TYPE)) {
                    ltypes[i] = WordTypeCode;
                } else {
                    ltypes[i] = typ.getName().parseForTypeCode();
                }
            }
        } else {
            ltypes[i] = VoidTypeCode;
        }
    }
    int stacknum = stack.getSize();
    byte[] stypes = new byte[stacknum];
    /* the variable on stack can be used directly ? */
    int num_lstacks = 0;
    for (int i = 0, n = stack.getSize(); i < n; i++) {
        Operand op = stack.getFromBottom(i);
        if ((op != null) && (op != DUMMY)) {
            if (op.isRegister()) {
                livevars.add(op.asRegister().copyU2U());
            } else {
                livevars.add(op.copy());
            }
            num_lstacks++;
            if (op instanceof ReturnAddressOperand) {
                stypes[i] = ReturnAddressTypeCode;
            } else {
                TypeReference typ = op.getType();
                if (typ.isWordLikeType() || (typ == TypeReference.NULL_TYPE)) {
                    stypes[i] = WordTypeCode;
                } else {
                    /* for stack operand, reverse the order for long and double */
                    byte tcode = typ.getName().parseForTypeCode();
                    if ((tcode == LongTypeCode) || (tcode == DoubleTypeCode)) {
                        stypes[i - 1] = tcode;
                        stypes[i] = VoidTypeCode;
                    } else {
                        stypes[i] = tcode;
                    }
                }
            }
        } else {
            stypes[i] = VoidTypeCode;
        }
    }
    Instruction barrier = // temporarily
    OsrBarrier.create(// temporarily
    OSR_BARRIER, // temporarily
    null, num_llocals + num_lstacks);
    for (int i = 0, n = livevars.size(); i < n; i++) {
        Operand op = livevars.get(i);
        if (op instanceof ReturnAddressOperand) {
            int tgtpc = ((ReturnAddressOperand) op).retIndex - gc.getMethod().getOsrPrologueLength();
            op = new IntConstantOperand(tgtpc);
        } else if (op instanceof LongConstantOperand) {
            op = _prepareLongConstant(op);
        } else if (op instanceof DoubleConstantOperand) {
            op = _prepareDoubleConstant(op);
        }
        if (VM.VerifyAssertions)
            opt_assert(op != null);
        OsrBarrier.setElement(barrier, i, op);
    }
    // patch type info operand
    OsrTypeInfoOperand typeinfo = new OsrTypeInfoOperand(ltypes, stypes);
    OsrBarrier.setTypeInfo(barrier, typeinfo);
    setSourcePosition(barrier);
    return barrier;
}
Also used : LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) DoubleConstantOperand(org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) OsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.OsrTypeInfoOperand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) FloatConstantOperand(org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) BranchOperand(org.jikesrvm.compilers.opt.ir.operand.BranchOperand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) ArrayList(java.util.ArrayList) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) OsrPoint(org.jikesrvm.compilers.opt.ir.OsrPoint) OsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.OsrTypeInfoOperand) DoubleConstantOperand(org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand) TypeReference(org.jikesrvm.classloader.TypeReference)

Aggregations

LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)32 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)29 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)27 DoubleConstantOperand (org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand)19 FloatConstantOperand (org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand)19 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)18 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)16 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)15 BranchOperand (org.jikesrvm.compilers.opt.ir.operand.BranchOperand)14 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)14 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)13 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)13 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)12 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)12 IA32ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ia32.IA32ConditionOperand)12 InlinedOsrTypeInfoOperand (org.jikesrvm.compilers.opt.ir.operand.InlinedOsrTypeInfoOperand)11 MemoryOperand (org.jikesrvm.compilers.opt.ir.operand.MemoryOperand)11 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)11 StackLocationOperand (org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand)11 OsrPoint (org.jikesrvm.compilers.opt.ir.OsrPoint)9