< prev index next >

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

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com
rev 58567 : [mq]: rename-isHidden


  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.reflect;
  27 
  28 import java.lang.reflect.Field;
  29 import java.lang.reflect.Modifier;
  30 
  31 class UnsafeFieldAccessorFactory {
  32     static FieldAccessor newFieldAccessor(Field field, boolean override) {
  33         Class<?> type = field.getType();
  34         boolean isStatic = Modifier.isStatic(field.getModifiers());
  35         boolean isFinal = Modifier.isFinal(field.getModifiers());
  36         boolean isVolatile = Modifier.isVolatile(field.getModifiers());
  37         boolean isQualified = isFinal || isVolatile;
  38         boolean isReadOnly = isFinal && (isStatic || !override || field.getDeclaringClass().isHiddenClass());
  39         if (isStatic) {
  40             // This code path does not guarantee that the field's
  41             // declaring class has been initialized, but it must be
  42             // before performing reflective operations.
  43             UnsafeFieldAccessorImpl.unsafe.ensureClassInitialized(field.getDeclaringClass());
  44 
  45             if (!isQualified) {
  46                 if (type == Boolean.TYPE) {
  47                     return new UnsafeStaticBooleanFieldAccessorImpl(field);
  48                 } else if (type == Byte.TYPE) {
  49                     return new UnsafeStaticByteFieldAccessorImpl(field);
  50                 } else if (type == Short.TYPE) {
  51                     return new UnsafeStaticShortFieldAccessorImpl(field);
  52                 } else if (type == Character.TYPE) {
  53                     return new UnsafeStaticCharacterFieldAccessorImpl(field);
  54                 } else if (type == Integer.TYPE) {
  55                     return new UnsafeStaticIntegerFieldAccessorImpl(field);
  56                 } else if (type == Long.TYPE) {
  57                     return new UnsafeStaticLongFieldAccessorImpl(field);
  58                 } else if (type == Float.TYPE) {




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.reflect;
  27 
  28 import java.lang.reflect.Field;
  29 import java.lang.reflect.Modifier;
  30 
  31 class UnsafeFieldAccessorFactory {
  32     static FieldAccessor newFieldAccessor(Field field, boolean override) {
  33         Class<?> type = field.getType();
  34         boolean isStatic = Modifier.isStatic(field.getModifiers());
  35         boolean isFinal = Modifier.isFinal(field.getModifiers());
  36         boolean isVolatile = Modifier.isVolatile(field.getModifiers());
  37         boolean isQualified = isFinal || isVolatile;
  38         boolean isReadOnly = isFinal && (isStatic || !override || field.getDeclaringClass().isHidden());
  39         if (isStatic) {
  40             // This code path does not guarantee that the field's
  41             // declaring class has been initialized, but it must be
  42             // before performing reflective operations.
  43             UnsafeFieldAccessorImpl.unsafe.ensureClassInitialized(field.getDeclaringClass());
  44 
  45             if (!isQualified) {
  46                 if (type == Boolean.TYPE) {
  47                     return new UnsafeStaticBooleanFieldAccessorImpl(field);
  48                 } else if (type == Byte.TYPE) {
  49                     return new UnsafeStaticByteFieldAccessorImpl(field);
  50                 } else if (type == Short.TYPE) {
  51                     return new UnsafeStaticShortFieldAccessorImpl(field);
  52                 } else if (type == Character.TYPE) {
  53                     return new UnsafeStaticCharacterFieldAccessorImpl(field);
  54                 } else if (type == Integer.TYPE) {
  55                     return new UnsafeStaticIntegerFieldAccessorImpl(field);
  56                 } else if (type == Long.TYPE) {
  57                     return new UnsafeStaticLongFieldAccessorImpl(field);
  58                 } else if (type == Float.TYPE) {


< prev index next >