< prev index next >

src/java.base/share/classes/java/lang/Class.java

Print this page




2887     /**
2888      * Atomic operations support.
2889      */
2890     private static class Atomic {
2891         // initialize Unsafe machinery here, since we need to call Class.class instance method
2892         // and have to avoid calling it in the static initializer of the Class class...
2893         private static final Unsafe unsafe = Unsafe.getUnsafe();
2894         // offset of Class.reflectionData instance field
2895         private static final long reflectionDataOffset
2896                 = unsafe.objectFieldOffset(Class.class, "reflectionData");
2897         // offset of Class.annotationType instance field
2898         private static final long annotationTypeOffset
2899                 = unsafe.objectFieldOffset(Class.class, "annotationType");
2900         // offset of Class.annotationData instance field
2901         private static final long annotationDataOffset
2902                 = unsafe.objectFieldOffset(Class.class, "annotationData");
2903 
2904         static <T> boolean casReflectionData(Class<?> clazz,
2905                                              SoftReference<ReflectionData<T>> oldData,
2906                                              SoftReference<ReflectionData<T>> newData) {
2907             return unsafe.compareAndSetObject(clazz, reflectionDataOffset, oldData, newData);
2908         }
2909 
2910         static <T> boolean casAnnotationType(Class<?> clazz,
2911                                              AnnotationType oldType,
2912                                              AnnotationType newType) {
2913             return unsafe.compareAndSetObject(clazz, annotationTypeOffset, oldType, newType);
2914         }
2915 
2916         static <T> boolean casAnnotationData(Class<?> clazz,
2917                                              AnnotationData oldData,
2918                                              AnnotationData newData) {
2919             return unsafe.compareAndSetObject(clazz, annotationDataOffset, oldData, newData);
2920         }
2921     }
2922 
2923     /**
2924      * Reflection support.
2925      */
2926 
2927     // Reflection data caches various derived names and reflective members. Cached
2928     // values may be invalidated when JVM TI RedefineClasses() is called
2929     private static class ReflectionData<T> {
2930         volatile Field[] declaredFields;
2931         volatile Field[] publicFields;
2932         volatile Method[] declaredMethods;
2933         volatile Method[] publicMethods;
2934         volatile Constructor<T>[] declaredConstructors;
2935         volatile Constructor<T>[] publicConstructors;
2936         // Intermediate results for getFields and getMethods
2937         volatile Field[] declaredPublicFields;
2938         volatile Method[] declaredPublicMethods;
2939         volatile Class<?>[] interfaces;




2887     /**
2888      * Atomic operations support.
2889      */
2890     private static class Atomic {
2891         // initialize Unsafe machinery here, since we need to call Class.class instance method
2892         // and have to avoid calling it in the static initializer of the Class class...
2893         private static final Unsafe unsafe = Unsafe.getUnsafe();
2894         // offset of Class.reflectionData instance field
2895         private static final long reflectionDataOffset
2896                 = unsafe.objectFieldOffset(Class.class, "reflectionData");
2897         // offset of Class.annotationType instance field
2898         private static final long annotationTypeOffset
2899                 = unsafe.objectFieldOffset(Class.class, "annotationType");
2900         // offset of Class.annotationData instance field
2901         private static final long annotationDataOffset
2902                 = unsafe.objectFieldOffset(Class.class, "annotationData");
2903 
2904         static <T> boolean casReflectionData(Class<?> clazz,
2905                                              SoftReference<ReflectionData<T>> oldData,
2906                                              SoftReference<ReflectionData<T>> newData) {
2907             return unsafe.compareAndSetReference(clazz, reflectionDataOffset, oldData, newData);
2908         }
2909 
2910         static <T> boolean casAnnotationType(Class<?> clazz,
2911                                              AnnotationType oldType,
2912                                              AnnotationType newType) {
2913             return unsafe.compareAndSetReference(clazz, annotationTypeOffset, oldType, newType);
2914         }
2915 
2916         static <T> boolean casAnnotationData(Class<?> clazz,
2917                                              AnnotationData oldData,
2918                                              AnnotationData newData) {
2919             return unsafe.compareAndSetReference(clazz, annotationDataOffset, oldData, newData);
2920         }
2921     }
2922 
2923     /**
2924      * Reflection support.
2925      */
2926 
2927     // Reflection data caches various derived names and reflective members. Cached
2928     // values may be invalidated when JVM TI RedefineClasses() is called
2929     private static class ReflectionData<T> {
2930         volatile Field[] declaredFields;
2931         volatile Field[] publicFields;
2932         volatile Method[] declaredMethods;
2933         volatile Method[] publicMethods;
2934         volatile Constructor<T>[] declaredConstructors;
2935         volatile Constructor<T>[] publicConstructors;
2936         // Intermediate results for getFields and getMethods
2937         volatile Field[] declaredPublicFields;
2938         volatile Method[] declaredPublicMethods;
2939         volatile Class<?>[] interfaces;


< prev index next >