< prev index next >

src/java.base/share/classes/java/lang/reflect/Field.java

Print this page
rev 55117 : 8223350: [lworld] Use inline classes instead of value classes


 151             throw new IllegalArgumentException("Can not copy a non-root Field");
 152 
 153         Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 154         res.root = this;
 155         // Might as well eagerly propagate this if already present
 156         res.fieldAccessor = fieldAccessor;
 157         res.overrideFieldAccessor = overrideFieldAccessor;
 158 
 159         return res;
 160     }
 161 
 162     /**
 163      * @throws InaccessibleObjectException {@inheritDoc}
 164      * @throws SecurityException {@inheritDoc}
 165      */
 166     @Override
 167     @CallerSensitive
 168     public void setAccessible(boolean flag) {
 169         AccessibleObject.checkPermission();
 170 
 171         if (flag) {
 172             if (clazz.isValue()) {
 173                 throw new InaccessibleObjectException(
 174                     "Unable to make a value class field \"" + this + "\" accessible");
 175             }
 176 
 177             checkCanSetAccessible(Reflection.getCallerClass());
 178         }
 179         setAccessible0(flag);
 180     }
 181 
 182     @Override
 183     void checkCanSetAccessible(Class<?> caller) {
 184         checkCanSetAccessible(caller, clazz);
 185     }
 186 
 187     /**
 188      * Returns the {@code Class} object representing
 189      * {@linkplain Class#asBoxType() the box type} of the class or interface
 190      * that declares the field represented by this {@code Field} object.
 191      */
 192     @Override
 193     public Class<?> getDeclaringClass() {
 194         return clazz;
 195     }
 196 


1088     {
1089         ensureNotValueClass();
1090 
1091         if (!override) {
1092             Class<?> caller = Reflection.getCallerClass();
1093             checkAccess(caller, obj);
1094         }
1095         getFieldAccessor(obj).setDouble(obj, d);
1096     }
1097 
1098     // check access to field
1099     private void checkAccess(Class<?> caller, Object obj)
1100         throws IllegalAccessException
1101     {
1102         checkAccess(caller, clazz,
1103                     Modifier.isStatic(modifiers) ? null : obj.getClass(),
1104                     modifiers);
1105     }
1106 
1107     /*
1108      * Ensure the declaring class is not a value class.
1109      */
1110     private void ensureNotValueClass() throws IllegalAccessException {
1111         if (clazz.isValue()) {
1112             throw new IllegalAccessException("cannot set this field of a value class "
1113                 + clazz.getName());
1114         }
1115     }
1116 
1117     // security check is done before calling this method
1118     private FieldAccessor getFieldAccessor(Object obj)
1119         throws IllegalAccessException
1120     {
1121         boolean ov = override;
1122         FieldAccessor a = (ov) ? overrideFieldAccessor : fieldAccessor;
1123         return (a != null) ? a : acquireFieldAccessor(ov);
1124     }
1125 
1126     // NOTE that there is no synchronization used here. It is correct
1127     // (though not efficient) to generate more than one FieldAccessor
1128     // for a given Field. However, avoiding synchronization will
1129     // probably make the implementation more scalable.
1130     private FieldAccessor acquireFieldAccessor(boolean overrideFinalCheck) {
1131         // First check to see if one has been created yet, and take it
1132         // if so




 151             throw new IllegalArgumentException("Can not copy a non-root Field");
 152 
 153         Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 154         res.root = this;
 155         // Might as well eagerly propagate this if already present
 156         res.fieldAccessor = fieldAccessor;
 157         res.overrideFieldAccessor = overrideFieldAccessor;
 158 
 159         return res;
 160     }
 161 
 162     /**
 163      * @throws InaccessibleObjectException {@inheritDoc}
 164      * @throws SecurityException {@inheritDoc}
 165      */
 166     @Override
 167     @CallerSensitive
 168     public void setAccessible(boolean flag) {
 169         AccessibleObject.checkPermission();
 170 

 171         if (clazz.isValue()) {
 172             throw new InaccessibleObjectException("cannot make a field accessible of inline class "
 173                     + clazz.getName());
 174         }
 175         if (flag) {
 176             checkCanSetAccessible(Reflection.getCallerClass());
 177         }
 178         setAccessible0(flag);
 179     }
 180 
 181     @Override
 182     void checkCanSetAccessible(Class<?> caller) {
 183         checkCanSetAccessible(caller, clazz);
 184     }
 185 
 186     /**
 187      * Returns the {@code Class} object representing
 188      * {@linkplain Class#asBoxType() the box type} of the class or interface
 189      * that declares the field represented by this {@code Field} object.
 190      */
 191     @Override
 192     public Class<?> getDeclaringClass() {
 193         return clazz;
 194     }
 195 


1087     {
1088         ensureNotValueClass();
1089 
1090         if (!override) {
1091             Class<?> caller = Reflection.getCallerClass();
1092             checkAccess(caller, obj);
1093         }
1094         getFieldAccessor(obj).setDouble(obj, d);
1095     }
1096 
1097     // check access to field
1098     private void checkAccess(Class<?> caller, Object obj)
1099         throws IllegalAccessException
1100     {
1101         checkAccess(caller, clazz,
1102                     Modifier.isStatic(modifiers) ? null : obj.getClass(),
1103                     modifiers);
1104     }
1105 
1106     /*
1107      * Ensure the declaring class is not an inline class.
1108      */
1109     private void ensureNotValueClass() throws IllegalAccessException {
1110         if (clazz.isValue()) {
1111             throw new IllegalAccessException("cannot set field \"" + this + "\" of inline class "
1112                 + clazz.getName());
1113         }
1114     }
1115 
1116     // security check is done before calling this method
1117     private FieldAccessor getFieldAccessor(Object obj)
1118         throws IllegalAccessException
1119     {
1120         boolean ov = override;
1121         FieldAccessor a = (ov) ? overrideFieldAccessor : fieldAccessor;
1122         return (a != null) ? a : acquireFieldAccessor(ov);
1123     }
1124 
1125     // NOTE that there is no synchronization used here. It is correct
1126     // (though not efficient) to generate more than one FieldAccessor
1127     // for a given Field. However, avoiding synchronization will
1128     // probably make the implementation more scalable.
1129     private FieldAccessor acquireFieldAccessor(boolean overrideFinalCheck) {
1130         // First check to see if one has been created yet, and take it
1131         // if so


< prev index next >