jdk/src/java.base/share/classes/java/lang/Class.java
changeset 32649 2ee9017c7597
parent 31671 362e0c0acece
child 33674 566777f73c32
equal deleted inserted replaced
32648:1fa861caf840 32649:2ee9017c7597
   467             Unsafe.getUnsafe().throwException(e.getTargetException());
   467             Unsafe.getUnsafe().throwException(e.getTargetException());
   468             // Not reached
   468             // Not reached
   469             return null;
   469             return null;
   470         }
   470         }
   471     }
   471     }
   472     private volatile transient Constructor<T> cachedConstructor;
   472     private transient volatile Constructor<T> cachedConstructor;
   473     private volatile transient Class<?>       newInstanceCallerCache;
   473     private transient volatile Class<?>       newInstanceCallerCache;
   474 
   474 
   475 
   475 
   476     /**
   476     /**
   477      * Determines if the specified {@code Object} is assignment-compatible
   477      * Determines if the specified {@code Object} is assignment-compatible
   478      * with the object represented by this {@code Class}.  This method is
   478      * with the object represented by this {@code Class}.  This method is
  1121         else {
  1121         else {
  1122             return new EnclosingMethodInfo(enclosingInfo);
  1122             return new EnclosingMethodInfo(enclosingInfo);
  1123         }
  1123         }
  1124     }
  1124     }
  1125 
  1125 
  1126     private final static class EnclosingMethodInfo {
  1126     private static final class EnclosingMethodInfo {
  1127         private Class<?> enclosingClass;
  1127         private Class<?> enclosingClass;
  1128         private String name;
  1128         private String name;
  1129         private String descriptor;
  1129         private String descriptor;
  1130 
  1130 
  1131         private EnclosingMethodInfo(Object[] enclosingInfo) {
  1131         private EnclosingMethodInfo(Object[] enclosingInfo) {
  2512         ReflectionData(int redefinedCount) {
  2512         ReflectionData(int redefinedCount) {
  2513             this.redefinedCount = redefinedCount;
  2513             this.redefinedCount = redefinedCount;
  2514         }
  2514         }
  2515     }
  2515     }
  2516 
  2516 
  2517     private volatile transient SoftReference<ReflectionData<T>> reflectionData;
  2517     private transient volatile SoftReference<ReflectionData<T>> reflectionData;
  2518 
  2518 
  2519     // Incremented by the VM on each call to JVM TI RedefineClasses()
  2519     // Incremented by the VM on each call to JVM TI RedefineClasses()
  2520     // that redefines this class or a superclass.
  2520     // that redefines this class or a superclass.
  2521     private volatile transient int classRedefinedCount = 0;
  2521     private transient volatile int classRedefinedCount = 0;
  2522 
  2522 
  2523     // Lazily create and cache ReflectionData
  2523     // Lazily create and cache ReflectionData
  2524     private ReflectionData<T> reflectionData() {
  2524     private ReflectionData<T> reflectionData() {
  2525         SoftReference<ReflectionData<T>> reflectionData = this.reflectionData;
  2525         SoftReference<ReflectionData<T>> reflectionData = this.reflectionData;
  2526         int classRedefinedCount = this.classRedefinedCount;
  2526         int classRedefinedCount = this.classRedefinedCount;
  2559 
  2559 
  2560     // Generic signature handling
  2560     // Generic signature handling
  2561     private native String getGenericSignature0();
  2561     private native String getGenericSignature0();
  2562 
  2562 
  2563     // Generic info repository; lazily initialized
  2563     // Generic info repository; lazily initialized
  2564     private volatile transient ClassRepository genericInfo;
  2564     private transient volatile ClassRepository genericInfo;
  2565 
  2565 
  2566     // accessor for factory
  2566     // accessor for factory
  2567     private GenericsFactory getFactory() {
  2567     private GenericsFactory getFactory() {
  2568         // create scope and factory
  2568         // create scope and factory
  2569         return CoreReflectionFactory.make(this, ClassScope.make(this));
  2569         return CoreReflectionFactory.make(this, ClassScope.make(this));
  3351             catch (InvocationTargetException | NoSuchMethodException |
  3351             catch (InvocationTargetException | NoSuchMethodException |
  3352                    IllegalAccessException ex) { return null; }
  3352                    IllegalAccessException ex) { return null; }
  3353         }
  3353         }
  3354         return enumConstants;
  3354         return enumConstants;
  3355     }
  3355     }
  3356     private volatile transient T[] enumConstants = null;
  3356     private transient volatile T[] enumConstants = null;
  3357 
  3357 
  3358     /**
  3358     /**
  3359      * Returns a map from simple name to enum constant.  This package-private
  3359      * Returns a map from simple name to enum constant.  This package-private
  3360      * method is used internally by Enum to implement
  3360      * method is used internally by Enum to implement
  3361      * {@code public static <T extends Enum<T>> T valueOf(Class<T>, String)}
  3361      * {@code public static <T extends Enum<T>> T valueOf(Class<T>, String)}
  3373                 m.put(((Enum<?>)constant).name(), constant);
  3373                 m.put(((Enum<?>)constant).name(), constant);
  3374             enumConstantDirectory = m;
  3374             enumConstantDirectory = m;
  3375         }
  3375         }
  3376         return enumConstantDirectory;
  3376         return enumConstantDirectory;
  3377     }
  3377     }
  3378     private volatile transient Map<String, T> enumConstantDirectory = null;
  3378     private transient volatile Map<String, T> enumConstantDirectory = null;
  3379 
  3379 
  3380     /**
  3380     /**
  3381      * Casts an object to the class or interface represented
  3381      * Casts an object to the class or interface represented
  3382      * by this {@code Class} object.
  3382      * by this {@code Class} object.
  3383      *
  3383      *
  3521         }
  3521         }
  3522     }
  3522     }
  3523 
  3523 
  3524     // Annotations cache
  3524     // Annotations cache
  3525     @SuppressWarnings("UnusedDeclaration")
  3525     @SuppressWarnings("UnusedDeclaration")
  3526     private volatile transient AnnotationData annotationData;
  3526     private transient volatile AnnotationData annotationData;
  3527 
  3527 
  3528     private AnnotationData annotationData() {
  3528     private AnnotationData annotationData() {
  3529         while (true) { // retry loop
  3529         while (true) { // retry loop
  3530             AnnotationData annotationData = this.annotationData;
  3530             AnnotationData annotationData = this.annotationData;
  3531             int classRedefinedCount = this.classRedefinedCount;
  3531             int classRedefinedCount = this.classRedefinedCount;
  3576     }
  3576     }
  3577 
  3577 
  3578     // Annotation types cache their internal (AnnotationType) form
  3578     // Annotation types cache their internal (AnnotationType) form
  3579 
  3579 
  3580     @SuppressWarnings("UnusedDeclaration")
  3580     @SuppressWarnings("UnusedDeclaration")
  3581     private volatile transient AnnotationType annotationType;
  3581     private transient volatile AnnotationType annotationType;
  3582 
  3582 
  3583     boolean casAnnotationType(AnnotationType oldType, AnnotationType newType) {
  3583     boolean casAnnotationType(AnnotationType oldType, AnnotationType newType) {
  3584         return Atomic.casAnnotationType(this, oldType, newType);
  3584         return Atomic.casAnnotationType(this, oldType, newType);
  3585     }
  3585     }
  3586 
  3586