< prev index next >

src/java.base/share/classes/jdk/internal/reflect/UnsafeFieldAccessorImpl.java

Print this page

        

*** 36,82 **** memory and loading time for the dynamically-generated FieldAccessors. */ abstract class UnsafeFieldAccessorImpl extends FieldAccessorImpl { static final Unsafe unsafe = Unsafe.getUnsafe(); - private static final int FLAT_VALUE = 0x01; - private static final int CAN_BE_NULL = 0x10; protected final Field field; protected final long fieldOffset; protected final boolean isFinal; - protected final int flags; UnsafeFieldAccessorImpl(Field field) { this.field = field; if (Modifier.isStatic(field.getModifiers())) this.fieldOffset = unsafe.staticFieldOffset(field); else this.fieldOffset = unsafe.objectFieldOffset(field); this.isFinal = Modifier.isFinal(field.getModifiers()); - - int flags = 0; - if (ReflectionFactory.langReflectAccess().isFlatValue(field)) - flags |= FLAT_VALUE; - if (ReflectionFactory.langReflectAccess().canBeNull(field)) - flags |= CAN_BE_NULL; - this.flags = flags; } protected void ensureObj(Object o) { // NOTE: will throw NullPointerException, as specified, if o is null if (!field.getDeclaringClass().isAssignableFrom(o.getClass())) { throwSetIllegalArgumentException(o); } } ! protected boolean isFlatValue() { ! return (flags & FLAT_VALUE) == FLAT_VALUE; } protected boolean canBeNull() { ! return (flags & CAN_BE_NULL) == CAN_BE_NULL; } protected Object checkValue(Object value) { if (!canBeNull() && value == null) throw new NullPointerException(field + " cannot be set to null"); --- 36,72 ---- memory and loading time for the dynamically-generated FieldAccessors. */ abstract class UnsafeFieldAccessorImpl extends FieldAccessorImpl { static final Unsafe unsafe = Unsafe.getUnsafe(); protected final Field field; protected final long fieldOffset; protected final boolean isFinal; UnsafeFieldAccessorImpl(Field field) { this.field = field; if (Modifier.isStatic(field.getModifiers())) this.fieldOffset = unsafe.staticFieldOffset(field); else this.fieldOffset = unsafe.objectFieldOffset(field); this.isFinal = Modifier.isFinal(field.getModifiers()); } protected void ensureObj(Object o) { // NOTE: will throw NullPointerException, as specified, if o is null if (!field.getDeclaringClass().isAssignableFrom(o.getClass())) { throwSetIllegalArgumentException(o); } } ! protected boolean isFlattened() { ! return unsafe.isFlattened(field); } protected boolean canBeNull() { ! return field.getType() == field.getType().asBoxType(); } protected Object checkValue(Object value) { if (!canBeNull() && value == null) throw new NullPointerException(field + " cannot be set to null");
< prev index next >