Search in sources :

Example 6 with Extent

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;
    }
}
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 7 with Extent

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;
    }
}
Also used : Extent(org.vmmagic.unboxed.Extent)

Example 8 with 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;
    }
}
Also used : Extent(org.vmmagic.unboxed.Extent)

Example 9 with 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;
    }
}
Also used : Extent(org.vmmagic.unboxed.Extent)

Example 10 with 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));
}
Also used : Address(org.vmmagic.unboxed.Address) Extent(org.vmmagic.unboxed.Extent) Test(org.junit.Test) BaseMMTkTest(org.mmtk.harness.tests.BaseMMTkTest)

Aggregations

Extent (org.vmmagic.unboxed.Extent)21 Address (org.vmmagic.unboxed.Address)11 Inline (org.vmmagic.pragma.Inline)3 Offset (org.vmmagic.unboxed.Offset)3 Test (org.junit.Test)2 BaseMMTkTest (org.mmtk.harness.tests.BaseMMTkTest)2 RawMemoryFreeList (org.mmtk.utility.RawMemoryFreeList)2 Interruptible (org.vmmagic.pragma.Interruptible)2 Word (org.vmmagic.unboxed.Word)2 Field (java.lang.reflect.Field)1 RVMField (org.jikesrvm.classloader.RVMField)1 RVMType (org.jikesrvm.classloader.RVMType)1 TypeReference (org.jikesrvm.classloader.TypeReference)1 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)1 DoubleConstantOperand (org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand)1 FloatConstantOperand (org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand)1 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)1 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)1 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)1 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)1