Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
          +++ new/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
↓ open down ↓ 37 lines elided ↑ open up ↑
  38   38  import java.lang.reflect.*;
  39   39  
  40   40  /**
  41   41   * A reflection-based utility that enables atomic updates to
  42   42   * designated {@code volatile} reference fields of designated
  43   43   * classes.  This class is designed for use in atomic data structures
  44   44   * in which several reference fields of the same node are
  45   45   * independently subject to atomic updates. For example, a tree node
  46   46   * might be declared as
  47   47   *
  48      - * <pre>
       48 + *  <pre> {@code
  49   49   * class Node {
  50   50   *   private volatile Node left, right;
  51   51   *
  52      - *   private static final AtomicReferenceFieldUpdater&lt;Node, Node&gt; leftUpdater =
       52 + *   private static final AtomicReferenceFieldUpdater<Node, Node> leftUpdater =
  53   53   *     AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "left");
  54      - *   private static AtomicReferenceFieldUpdater&lt;Node, Node&gt; rightUpdater =
       54 + *   private static AtomicReferenceFieldUpdater<Node, Node> rightUpdater =
  55   55   *     AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "right");
  56   56   *
  57   57   *   Node getLeft() { return left;  }
  58   58   *   boolean compareAndSetLeft(Node expect, Node update) {
  59   59   *     return leftUpdater.compareAndSet(this, expect, update);
  60   60   *   }
  61   61   *   // ... and so on
  62      - * }
  63      - * </pre>
       62 + * }}</pre>
  64   63   *
  65   64   * <p>Note that the guarantees of the {@code compareAndSet}
  66   65   * method in this class are weaker than in other atomic classes.
  67   66   * Because this class cannot ensure that all uses of the field
  68   67   * are appropriate for purposes of atomic access, it can
  69   68   * guarantee atomicity only with respect to other invocations of
  70   69   * {@code compareAndSet} and {@code set} on the same updater.
  71   70   *
  72   71   * @since 1.5
  73   72   * @author Doug Lea
  74   73   * @param <T> The type of the object holding the updatable field
  75   74   * @param <V> The type of the field
  76   75   */
  77      -public abstract class AtomicReferenceFieldUpdater<T, V>  {
       76 +public abstract class AtomicReferenceFieldUpdater<T, V> {
  78   77  
  79   78      /**
  80   79       * Creates and returns an updater for objects with the given field.
  81   80       * The Class arguments are needed to check that reflective types and
  82   81       * generic types match.
  83   82       *
  84   83       * @param tclass the class of the objects holding the field.
  85   84       * @param vclass the class of the field
  86   85       * @param fieldName the name of the field to be updated.
  87   86       * @return the updater
↓ open down ↓ 196 lines elided ↑ open up ↑
 284  283          public V get(T obj) {
 285  284              if (obj == null || obj.getClass() != tclass || cclass != null)
 286  285                  targetCheck(obj);
 287  286              return (V)unsafe.getObjectVolatile(obj, offset);
 288  287          }
 289  288  
 290  289          private void ensureProtectedAccess(T obj) {
 291  290              if (cclass.isInstance(obj)) {
 292  291                  return;
 293  292              }
 294      -            throw new RuntimeException (
      293 +            throw new RuntimeException(
 295  294                  new IllegalAccessException("Class " +
 296  295                      cclass.getName() +
 297  296                      " can not access a protected member of class " +
 298  297                      tclass.getName() +
 299  298                      " using an instance of " +
 300  299                      obj.getClass().getName()
 301  300                  )
 302  301              );
 303  302          }
 304  303      }
 305  304  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX