jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
changeset 11134 9ff7640994bf
parent 9242 ef138d47df58
child 12674 5f9829b7fc7e
equal deleted inserted replaced
11133:e05aee7c8611 11134:9ff7640994bf
   181         extends AtomicReferenceFieldUpdater<T,V> {
   181         extends AtomicReferenceFieldUpdater<T,V> {
   182         private static final Unsafe unsafe = Unsafe.getUnsafe();
   182         private static final Unsafe unsafe = Unsafe.getUnsafe();
   183         private final long offset;
   183         private final long offset;
   184         private final Class<T> tclass;
   184         private final Class<T> tclass;
   185         private final Class<V> vclass;
   185         private final Class<V> vclass;
   186         private final Class cclass;
   186         private final Class<?> cclass;
   187 
   187 
   188         /*
   188         /*
   189          * Internal type checks within all update methods contain
   189          * Internal type checks within all update methods contain
   190          * internal inlined optimizations checking for the common
   190          * internal inlined optimizations checking for the common
   191          * cases where the class is final (in which case a simple
   191          * cases where the class is final (in which case a simple
   199 
   199 
   200         AtomicReferenceFieldUpdaterImpl(Class<T> tclass,
   200         AtomicReferenceFieldUpdaterImpl(Class<T> tclass,
   201                                         Class<V> vclass,
   201                                         Class<V> vclass,
   202                                         String fieldName) {
   202                                         String fieldName) {
   203             Field field = null;
   203             Field field = null;
   204             Class fieldClass = null;
   204             Class<?> fieldClass = null;
   205             Class caller = null;
   205             Class<?> caller = null;
   206             int modifiers = 0;
   206             int modifiers = 0;
   207             try {
   207             try {
   208                 field = tclass.getDeclaredField(fieldName);
   208                 field = tclass.getDeclaredField(fieldName);
   209                 caller = sun.reflect.Reflection.getCallerClass(3);
   209                 caller = sun.reflect.Reflection.getCallerClass(3);
   210                 modifiers = field.getModifiers();
   210                 modifiers = field.getModifiers();
   278                  vclass != newValue.getClass()))
   278                  vclass != newValue.getClass()))
   279                 updateCheck(obj, newValue);
   279                 updateCheck(obj, newValue);
   280             unsafe.putOrderedObject(obj, offset, newValue);
   280             unsafe.putOrderedObject(obj, offset, newValue);
   281         }
   281         }
   282 
   282 
       
   283         @SuppressWarnings("unchecked")
   283         public V get(T obj) {
   284         public V get(T obj) {
   284             if (obj == null || obj.getClass() != tclass || cclass != null)
   285             if (obj == null || obj.getClass() != tclass || cclass != null)
   285                 targetCheck(obj);
   286                 targetCheck(obj);
   286             return (V)unsafe.getObjectVolatile(obj, offset);
   287             return (V)unsafe.getObjectVolatile(obj, offset);
   287         }
   288         }