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));
}
}
}
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());
}
}
}
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;
}
}
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);
}
}
}
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;
}
Aggregations