use of org.vmmagic.unboxed.Extent 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.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.
the class TestNullChecks_Resolved method readExtentField.
private static Extent readExtentField(ClassWithExtentField c) {
try {
Extent read = c.e;
System.out.println("Read value " + read.toLong() + " from field");
return read;
} catch (NullPointerException npe) {
System.out.println("Caught NPE when reading Extent field");
return NPE_EXTENT;
}
}
use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.
the class TestNullChecks_Unresolved_ReadFromNonNullObject method readExtentField.
private static Extent readExtentField(ClassWithExtentField c) {
try {
Extent read = c.e;
System.out.println("Read value " + read.toLong() + " from field");
return read;
} catch (NullPointerException npe) {
System.out.println("Caught NPE when reading Extent field");
return NPE_EXTENT;
}
}
use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.
the class TestNullChecks_Unresolved_ReadFromNullObject method readExtentField.
private static Extent readExtentField(ClassWithExtentField c) {
try {
Extent read = c.e;
System.out.println("Read value " + read.toLong() + " from field");
return read;
} catch (NullPointerException npe) {
System.out.println("Caught NPE when reading Extent field");
return NPE_EXTENT;
}
}
use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.
the class AbstractSpaceDescriptorTest method testIsContiguous.
@Test
public void testIsContiguous() {
Extent chunkSize = Extent.fromLong(1L << VMLayoutConstants.LOG_BYTES_IN_CHUNK);
Address base = Address.zero().plus(chunkSize);
int d = SpaceDescriptor.createDescriptor();
int c = SpaceDescriptor.createDescriptor(base, base.plus(chunkSize));
Assert.assertFalse(SpaceDescriptor.isContiguous(d));
Assert.assertTrue(SpaceDescriptor.isContiguous(c));
}
Aggregations