Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
          +++ new/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
↓ open down ↓ 47 lines elided ↑ open up ↑
  48   48   * method in this class are weaker than in other atomic classes.
  49   49   * Because this class cannot ensure that all uses of the field
  50   50   * are appropriate for purposes of atomic access, it can
  51   51   * guarantee atomicity only with respect to other invocations of
  52   52   * {@code compareAndSet} and {@code set} on the same updater.
  53   53   *
  54   54   * @since 1.5
  55   55   * @author Doug Lea
  56   56   * @param <T> The type of the object holding the updatable field
  57   57   */
  58      -public abstract class  AtomicLongFieldUpdater<T>  {
       58 +public abstract class  AtomicLongFieldUpdater<T> {
  59   59      /**
  60   60       * Creates and returns an updater for objects with the given field.
  61   61       * The Class argument is needed to check that reflective types and
  62   62       * generic types match.
  63   63       *
  64   64       * @param tclass the class of the objects holding the field
  65   65       * @param fieldName the name of the field to be updated.
  66   66       * @return the updater
  67   67       * @throws IllegalArgumentException if the field is not a
  68   68       * volatile long type.
↓ open down ↓ 202 lines elided ↑ open up ↑
 271  271              Field field = null;
 272  272              Class caller = null;
 273  273              int modifiers = 0;
 274  274              try {
 275  275                  field = tclass.getDeclaredField(fieldName);
 276  276                  caller = sun.reflect.Reflection.getCallerClass(3);
 277  277                  modifiers = field.getModifiers();
 278  278                  sun.reflect.misc.ReflectUtil.ensureMemberAccess(
 279  279                      caller, tclass, null, modifiers);
 280  280                  sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
 281      -            } catch(Exception ex) {
      281 +            } catch (Exception ex) {
 282  282                  throw new RuntimeException(ex);
 283  283              }
 284  284  
 285  285              Class fieldt = field.getType();
 286  286              if (fieldt != long.class)
 287  287                  throw new IllegalArgumentException("Must be long type");
 288  288  
 289  289              if (!Modifier.isVolatile(modifiers))
 290  290                  throw new IllegalArgumentException("Must be volatile type");
 291  291  
↓ open down ↓ 32 lines elided ↑ open up ↑
 324  324  
 325  325          public long get(T obj) {
 326  326              if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
 327  327              return unsafe.getLongVolatile(obj, offset);
 328  328          }
 329  329  
 330  330          private void ensureProtectedAccess(T obj) {
 331  331              if (cclass.isInstance(obj)) {
 332  332                  return;
 333  333              }
 334      -            throw new RuntimeException (
      334 +            throw new RuntimeException(
 335  335                  new IllegalAccessException("Class " +
 336  336                      cclass.getName() +
 337  337                      " can not access a protected member of class " +
 338  338                      tclass.getName() +
 339  339                      " using an instance of " +
 340  340                      obj.getClass().getName()
 341  341                  )
 342  342              );
 343  343          }
 344  344      }
↓ open down ↓ 9 lines elided ↑ open up ↑
 354  354              Field field = null;
 355  355              Class caller = null;
 356  356              int modifiers = 0;
 357  357              try {
 358  358                  field = tclass.getDeclaredField(fieldName);
 359  359                  caller = sun.reflect.Reflection.getCallerClass(3);
 360  360                  modifiers = field.getModifiers();
 361  361                  sun.reflect.misc.ReflectUtil.ensureMemberAccess(
 362  362                      caller, tclass, null, modifiers);
 363  363                  sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
 364      -            } catch(Exception ex) {
      364 +            } catch (Exception ex) {
 365  365                  throw new RuntimeException(ex);
 366  366              }
 367  367  
 368  368              Class fieldt = field.getType();
 369  369              if (fieldt != long.class)
 370  370                  throw new IllegalArgumentException("Must be long type");
 371  371  
 372  372              if (!Modifier.isVolatile(modifiers))
 373  373                  throw new IllegalArgumentException("Must be volatile type");
 374  374  
↓ open down ↓ 5 lines elided ↑ open up ↑
 380  380  
 381  381          private void fullCheck(T obj) {
 382  382              if (!tclass.isInstance(obj))
 383  383                  throw new ClassCastException();
 384  384              if (cclass != null)
 385  385                  ensureProtectedAccess(obj);
 386  386          }
 387  387  
 388  388          public boolean compareAndSet(T obj, long expect, long update) {
 389  389              if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
 390      -            synchronized(this) {
      390 +            synchronized (this) {
 391  391                  long v = unsafe.getLong(obj, offset);
 392  392                  if (v != expect)
 393  393                      return false;
 394  394                  unsafe.putLong(obj, offset, update);
 395  395                  return true;
 396  396              }
 397  397          }
 398  398  
 399  399          public boolean weakCompareAndSet(T obj, long expect, long update) {
 400  400              return compareAndSet(obj, expect, update);
 401  401          }
 402  402  
 403  403          public void set(T obj, long newValue) {
 404  404              if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
 405      -            synchronized(this) {
      405 +            synchronized (this) {
 406  406                  unsafe.putLong(obj, offset, newValue);
 407  407              }
 408  408          }
 409  409  
 410  410          public void lazySet(T obj, long newValue) {
 411  411              set(obj, newValue);
 412  412          }
 413  413  
 414  414          public long get(T obj) {
 415  415              if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
 416      -            synchronized(this) {
      416 +            synchronized (this) {
 417  417                  return unsafe.getLong(obj, offset);
 418  418              }
 419  419          }
 420  420  
 421  421          private void ensureProtectedAccess(T obj) {
 422  422              if (cclass.isInstance(obj)) {
 423  423                  return;
 424  424              }
 425      -            throw new RuntimeException (
      425 +            throw new RuntimeException(
 426  426                  new IllegalAccessException("Class " +
 427  427                      cclass.getName() +
 428  428                      " can not access a protected member of class " +
 429  429                      tclass.getName() +
 430  430                      " using an instance of " +
 431  431                      obj.getClass().getName()
 432  432                  )
 433  433              );
 434  434          }
 435  435      }
 436  436  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX