jdk/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongArray.java
changeset 39725 9548f8d846e9
parent 36936 bfcdf736a998
child 40733 8d1263354d62
equal deleted inserted replaced
39724:d935d42f6d93 39725:9548f8d846e9
    33  * http://creativecommons.org/publicdomain/zero/1.0/
    33  * http://creativecommons.org/publicdomain/zero/1.0/
    34  */
    34  */
    35 
    35 
    36 package java.util.concurrent.atomic;
    36 package java.util.concurrent.atomic;
    37 
    37 
       
    38 import java.lang.invoke.MethodHandles;
       
    39 import java.lang.invoke.VarHandle;
    38 import java.util.function.LongBinaryOperator;
    40 import java.util.function.LongBinaryOperator;
    39 import java.util.function.LongUnaryOperator;
    41 import java.util.function.LongUnaryOperator;
    40 
    42 
    41 /**
    43 /**
    42  * A {@code long} array in which elements may be updated atomically.
    44  * A {@code long} array in which elements may be updated atomically.
    43  * See the {@link java.util.concurrent.atomic} package specification
    45  * See the {@link VarHandle} specification for descriptions of the
    44  * for description of the properties of atomic variables.
    46  * properties of atomic accesses.
    45  * @since 1.5
    47  * @since 1.5
    46  * @author Doug Lea
    48  * @author Doug Lea
    47  */
    49  */
    48 public class AtomicLongArray implements java.io.Serializable {
    50 public class AtomicLongArray implements java.io.Serializable {
    49     private static final long serialVersionUID = -2308431214976778248L;
    51     private static final long serialVersionUID = -2308431214976778248L;
    50 
    52     private static final VarHandle AA
    51     private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
    53         = MethodHandles.arrayElementVarHandle(long[].class);
    52     private static final int ABASE;
       
    53     private static final int ASHIFT;
       
    54     private final long[] array;
    54     private final long[] array;
    55 
       
    56     static {
       
    57         ABASE = U.arrayBaseOffset(long[].class);
       
    58         int scale = U.arrayIndexScale(long[].class);
       
    59         if ((scale & (scale - 1)) != 0)
       
    60             throw new Error("array index scale not a power of two");
       
    61         ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
       
    62     }
       
    63 
       
    64     private long checkedByteOffset(int i) {
       
    65         if (i < 0 || i >= array.length)
       
    66             throw new IndexOutOfBoundsException("index " + i);
       
    67 
       
    68         return byteOffset(i);
       
    69     }
       
    70 
       
    71     private static long byteOffset(int i) {
       
    72         return ((long) i << ASHIFT) + ABASE;
       
    73     }
       
    74 
    55 
    75     /**
    56     /**
    76      * Creates a new AtomicLongArray of the given length, with all
    57      * Creates a new AtomicLongArray of the given length, with all
    77      * elements initially zero.
    58      * elements initially zero.
    78      *
    59      *
   102     public final int length() {
    83     public final int length() {
   103         return array.length;
    84         return array.length;
   104     }
    85     }
   105 
    86 
   106     /**
    87     /**
   107      * Gets the current value at position {@code i}.
    88      * Returns the current value of the element at index {@code i},
       
    89      * with memory effects as specified by {@link VarHandle#getVolatile}.
   108      *
    90      *
   109      * @param i the index
    91      * @param i the index
   110      * @return the current value
    92      * @return the current value
   111      */
    93      */
   112     public final long get(int i) {
    94     public final long get(int i) {
   113         return getRaw(checkedByteOffset(i));
    95         return (long)AA.getVolatile(array, i);
   114     }
    96     }
   115 
    97 
   116     private long getRaw(long offset) {
    98     /**
   117         return U.getLongVolatile(array, offset);
    99      * Sets the element at index {@code i} to {@code newValue},
   118     }
   100      * with memory effects as specified by {@link VarHandle#setVolatile}.
   119 
       
   120     /**
       
   121      * Sets the element at position {@code i} to the given value.
       
   122      *
   101      *
   123      * @param i the index
   102      * @param i the index
   124      * @param newValue the new value
   103      * @param newValue the new value
   125      */
   104      */
   126     public final void set(int i, long newValue) {
   105     public final void set(int i, long newValue) {
   127         U.putLongVolatile(array, checkedByteOffset(i), newValue);
   106         AA.setVolatile(array, i, newValue);
   128     }
   107     }
   129 
   108 
   130     /**
   109     /**
   131      * Eventually sets the element at position {@code i} to the given value.
   110      * Sets the element at index {@code i} to {@code newValue},
       
   111      * with memory effects as specified by {@link VarHandle#setRelease}.
   132      *
   112      *
   133      * @param i the index
   113      * @param i the index
   134      * @param newValue the new value
   114      * @param newValue the new value
   135      * @since 1.6
   115      * @since 1.6
   136      */
   116      */
   137     public final void lazySet(int i, long newValue) {
   117     public final void lazySet(int i, long newValue) {
   138         U.putLongRelease(array, checkedByteOffset(i), newValue);
   118         AA.setRelease(array, i, newValue);
   139     }
   119     }
   140 
   120 
   141     /**
   121     /**
   142      * Atomically sets the element at position {@code i} to the given value
   122      * Atomically sets the element at index {@code i} to {@code
   143      * and returns the old value.
   123      * newValue} and returns the old value,
       
   124      * with memory effects as specified by {@link VarHandle#getAndSet}.
   144      *
   125      *
   145      * @param i the index
   126      * @param i the index
   146      * @param newValue the new value
   127      * @param newValue the new value
   147      * @return the previous value
   128      * @return the previous value
   148      */
   129      */
   149     public final long getAndSet(int i, long newValue) {
   130     public final long getAndSet(int i, long newValue) {
   150         return U.getAndSetLong(array, checkedByteOffset(i), newValue);
   131         return (long)AA.getAndSet(array, i, newValue);
   151     }
   132     }
   152 
   133 
   153     /**
   134     /**
   154      * Atomically sets the element at position {@code i} to the given
   135      * Atomically sets the element at index {@code i} to {@code newValue}
   155      * updated value if the current value {@code ==} the expected value.
   136      * if the element's current value {@code == expectedValue},
   156      *
   137      * with memory effects as specified by {@link VarHandle#compareAndSet}.
   157      * @param i the index
   138      *
   158      * @param expect the expected value
   139      * @param i the index
   159      * @param update the new value
   140      * @param expectedValue the expected value
       
   141      * @param newValue the new value
   160      * @return {@code true} if successful. False return indicates that
   142      * @return {@code true} if successful. False return indicates that
   161      * the actual value was not equal to the expected value.
   143      * the actual value was not equal to the expected value.
   162      */
   144      */
   163     public final boolean compareAndSet(int i, long expect, long update) {
   145     public final boolean compareAndSet(int i, long expectedValue, long newValue) {
   164         return compareAndSetRaw(checkedByteOffset(i), expect, update);
   146         return AA.compareAndSet(array, i, expectedValue, newValue);
   165     }
   147     }
   166 
   148 
   167     private boolean compareAndSetRaw(long offset, long expect, long update) {
   149     /**
   168         return U.compareAndSwapLong(array, offset, expect, update);
   150      * Possibly atomically sets the element at index {@code i} to
   169     }
   151      * {@code newValue} if the element's current value {@code == expectedValue},
   170 
   152      * with memory effects as specified by {@link VarHandle#weakCompareAndSet}.
   171     /**
   153      *
   172      * Atomically sets the element at position {@code i} to the given
   154      * @param i the index
   173      * updated value if the current value {@code ==} the expected value.
   155      * @param expectedValue the expected value
   174      *
   156      * @param newValue the new value
   175      * <p><a href="package-summary.html#weakCompareAndSet">May fail
       
   176      * spuriously and does not provide ordering guarantees</a>, so is
       
   177      * only rarely an appropriate alternative to {@code compareAndSet}.
       
   178      *
       
   179      * @param i the index
       
   180      * @param expect the expected value
       
   181      * @param update the new value
       
   182      * @return {@code true} if successful
   157      * @return {@code true} if successful
   183      */
   158      */
   184     public final boolean weakCompareAndSet(int i, long expect, long update) {
   159     public final boolean weakCompareAndSet(int i, long expectedValue, long newValue) {
   185         return compareAndSet(i, expect, update);
   160         return AA.weakCompareAndSet(array, i, expectedValue, newValue);
   186     }
   161     }
   187 
   162 
   188     /**
   163     /**
   189      * Atomically increments by one the element at index {@code i}.
   164      * Atomically increments the value of the element at index {@code i},
       
   165      * with memory effects as specified by {@link VarHandle#getAndAdd}.
       
   166      *
       
   167      * <p>Equivalent to {@code getAndAdd(i, 1)}.
   190      *
   168      *
   191      * @param i the index
   169      * @param i the index
   192      * @return the previous value
   170      * @return the previous value
   193      */
   171      */
   194     public final long getAndIncrement(int i) {
   172     public final long getAndIncrement(int i) {
   195         return getAndAdd(i, 1);
   173         return (long)AA.getAndAdd(array, i, 1L);
   196     }
   174     }
   197 
   175 
   198     /**
   176     /**
   199      * Atomically decrements by one the element at index {@code i}.
   177      * Atomically decrements the value of the element at index {@code i},
       
   178      * with memory effects as specified by {@link VarHandle#getAndAdd}.
       
   179      *
       
   180      * <p>Equivalent to {@code getAndAdd(i, -1)}.
   200      *
   181      *
   201      * @param i the index
   182      * @param i the index
   202      * @return the previous value
   183      * @return the previous value
   203      */
   184      */
   204     public final long getAndDecrement(int i) {
   185     public final long getAndDecrement(int i) {
   205         return getAndAdd(i, -1);
   186         return (long)AA.getAndAdd(array, i, -1L);
   206     }
   187     }
   207 
   188 
   208     /**
   189     /**
   209      * Atomically adds the given value to the element at index {@code i}.
   190      * Atomically adds the given value to the element at index {@code i},
       
   191      * with memory effects as specified by {@link VarHandle#getAndAdd}.
   210      *
   192      *
   211      * @param i the index
   193      * @param i the index
   212      * @param delta the value to add
   194      * @param delta the value to add
   213      * @return the previous value
   195      * @return the previous value
   214      */
   196      */
   215     public final long getAndAdd(int i, long delta) {
   197     public final long getAndAdd(int i, long delta) {
   216         return U.getAndAddLong(array, checkedByteOffset(i), delta);
   198         return (long)AA.getAndAdd(array, i, delta);
   217     }
   199     }
   218 
   200 
   219     /**
   201     /**
   220      * Atomically increments by one the element at index {@code i}.
   202      * Atomically increments the value of the element at index {@code i},
       
   203      * with memory effects as specified by {@link VarHandle#addAndGet}.
       
   204      *
       
   205      * <p>Equivalent to {@code addAndGet(i, 1)}.
   221      *
   206      *
   222      * @param i the index
   207      * @param i the index
   223      * @return the updated value
   208      * @return the updated value
   224      */
   209      */
   225     public final long incrementAndGet(int i) {
   210     public final long incrementAndGet(int i) {
   226         return getAndAdd(i, 1) + 1;
   211         return (long)AA.addAndGet(array, i, 1L);
   227     }
   212     }
   228 
   213 
   229     /**
   214     /**
   230      * Atomically decrements by one the element at index {@code i}.
   215      * Atomically decrements the value of the element at index {@code i},
       
   216      * with memory effects as specified by {@link VarHandle#addAndGet}.
       
   217      *
       
   218      * <p>Equivalent to {@code addAndGet(i, -1)}.
   231      *
   219      *
   232      * @param i the index
   220      * @param i the index
   233      * @return the updated value
   221      * @return the updated value
   234      */
   222      */
   235     public final long decrementAndGet(int i) {
   223     public final long decrementAndGet(int i) {
   236         return getAndAdd(i, -1) - 1;
   224         return (long)AA.addAndGet(array, i, -1L);
   237     }
   225     }
   238 
   226 
   239     /**
   227     /**
   240      * Atomically adds the given value to the element at index {@code i}.
   228      * Atomically adds the given value to the element at index {@code i},
       
   229      * with memory effects as specified by {@link VarHandle#addAndGet}.
   241      *
   230      *
   242      * @param i the index
   231      * @param i the index
   243      * @param delta the value to add
   232      * @param delta the value to add
   244      * @return the updated value
   233      * @return the updated value
   245      */
   234      */
   246     public long addAndGet(int i, long delta) {
   235     public long addAndGet(int i, long delta) {
   247         return getAndAdd(i, delta) + delta;
   236         return (long)AA.addAndGet(array, i, delta);
   248     }
   237     }
   249 
   238 
   250     /**
   239     /**
   251      * Atomically updates the element at index {@code i} with the results
   240      * Atomically updates the element at index {@code i} with the results
   252      * of applying the given function, returning the previous value. The
   241      * of applying the given function, returning the previous value. The
   257      * @param updateFunction a side-effect-free function
   246      * @param updateFunction a side-effect-free function
   258      * @return the previous value
   247      * @return the previous value
   259      * @since 1.8
   248      * @since 1.8
   260      */
   249      */
   261     public final long getAndUpdate(int i, LongUnaryOperator updateFunction) {
   250     public final long getAndUpdate(int i, LongUnaryOperator updateFunction) {
   262         long offset = checkedByteOffset(i);
   251         long prev = get(i), next = 0L;
   263         long prev, next;
   252         for (boolean haveNext = false;;) {
   264         do {
   253             if (!haveNext)
   265             prev = getRaw(offset);
   254                 next = updateFunction.applyAsLong(prev);
   266             next = updateFunction.applyAsLong(prev);
   255             if (weakCompareAndSetVolatile(i, prev, next))
   267         } while (!compareAndSetRaw(offset, prev, next));
   256                 return prev;
   268         return prev;
   257             haveNext = (prev == (prev = get(i)));
       
   258         }
   269     }
   259     }
   270 
   260 
   271     /**
   261     /**
   272      * Atomically updates the element at index {@code i} with the results
   262      * Atomically updates the element at index {@code i} with the results
   273      * of applying the given function, returning the updated value. The
   263      * of applying the given function, returning the updated value. The
   278      * @param updateFunction a side-effect-free function
   268      * @param updateFunction a side-effect-free function
   279      * @return the updated value
   269      * @return the updated value
   280      * @since 1.8
   270      * @since 1.8
   281      */
   271      */
   282     public final long updateAndGet(int i, LongUnaryOperator updateFunction) {
   272     public final long updateAndGet(int i, LongUnaryOperator updateFunction) {
   283         long offset = checkedByteOffset(i);
   273         long prev = get(i), next = 0L;
   284         long prev, next;
   274         for (boolean haveNext = false;;) {
   285         do {
   275             if (!haveNext)
   286             prev = getRaw(offset);
   276                 next = updateFunction.applyAsLong(prev);
   287             next = updateFunction.applyAsLong(prev);
   277             if (weakCompareAndSetVolatile(i, prev, next))
   288         } while (!compareAndSetRaw(offset, prev, next));
   278                 return next;
   289         return next;
   279             haveNext = (prev == (prev = get(i)));
       
   280         }
   290     }
   281     }
   291 
   282 
   292     /**
   283     /**
   293      * Atomically updates the element at index {@code i} with the
   284      * Atomically updates the element at index {@code i} with the
   294      * results of applying the given function to the current and
   285      * results of applying the given function to the current and given
   295      * given values, returning the previous value. The function should
   286      * values, returning the previous value. The function should be
   296      * be side-effect-free, since it may be re-applied when attempted
   287      * side-effect-free, since it may be re-applied when attempted
   297      * updates fail due to contention among threads.  The function is
   288      * updates fail due to contention among threads.  The function is
   298      * applied with the current value at index {@code i} as its first
   289      * applied with the current value of the element at index {@code i}
   299      * argument, and the given update as the second argument.
   290      * as its first argument, and the given update as the second
       
   291      * argument.
   300      *
   292      *
   301      * @param i the index
   293      * @param i the index
   302      * @param x the update value
   294      * @param x the update value
   303      * @param accumulatorFunction a side-effect-free function of two arguments
   295      * @param accumulatorFunction a side-effect-free function of two arguments
   304      * @return the previous value
   296      * @return the previous value
   305      * @since 1.8
   297      * @since 1.8
   306      */
   298      */
   307     public final long getAndAccumulate(int i, long x,
   299     public final long getAndAccumulate(int i, long x,
   308                                       LongBinaryOperator accumulatorFunction) {
   300                                       LongBinaryOperator accumulatorFunction) {
   309         long offset = checkedByteOffset(i);
   301         long prev = get(i), next = 0L;
   310         long prev, next;
   302         for (boolean haveNext = false;;) {
   311         do {
   303             if (!haveNext)
   312             prev = getRaw(offset);
   304                 next = accumulatorFunction.applyAsLong(prev, x);
   313             next = accumulatorFunction.applyAsLong(prev, x);
   305             if (weakCompareAndSetVolatile(i, prev, next))
   314         } while (!compareAndSetRaw(offset, prev, next));
   306                 return prev;
   315         return prev;
   307             haveNext = (prev == (prev = get(i)));
       
   308         }
   316     }
   309     }
   317 
   310 
   318     /**
   311     /**
   319      * Atomically updates the element at index {@code i} with the
   312      * Atomically updates the element at index {@code i} with the
   320      * results of applying the given function to the current and
   313      * results of applying the given function to the current and given
   321      * given values, returning the updated value. The function should
   314      * values, returning the updated value. The function should be
   322      * be side-effect-free, since it may be re-applied when attempted
   315      * side-effect-free, since it may be re-applied when attempted
   323      * updates fail due to contention among threads.  The function is
   316      * updates fail due to contention among threads.  The function is
   324      * applied with the current value at index {@code i} as its first
   317      * applied with the current value of the element at index {@code i}
   325      * argument, and the given update as the second argument.
   318      * as its first argument, and the given update as the second
       
   319      * argument.
   326      *
   320      *
   327      * @param i the index
   321      * @param i the index
   328      * @param x the update value
   322      * @param x the update value
   329      * @param accumulatorFunction a side-effect-free function of two arguments
   323      * @param accumulatorFunction a side-effect-free function of two arguments
   330      * @return the updated value
   324      * @return the updated value
   331      * @since 1.8
   325      * @since 1.8
   332      */
   326      */
   333     public final long accumulateAndGet(int i, long x,
   327     public final long accumulateAndGet(int i, long x,
   334                                       LongBinaryOperator accumulatorFunction) {
   328                                       LongBinaryOperator accumulatorFunction) {
   335         long offset = checkedByteOffset(i);
   329         long prev = get(i), next = 0L;
   336         long prev, next;
   330         for (boolean haveNext = false;;) {
   337         do {
   331             if (!haveNext)
   338             prev = getRaw(offset);
   332                 next = accumulatorFunction.applyAsLong(prev, x);
   339             next = accumulatorFunction.applyAsLong(prev, x);
   333             if (weakCompareAndSetVolatile(i, prev, next))
   340         } while (!compareAndSetRaw(offset, prev, next));
   334                 return next;
   341         return next;
   335             haveNext = (prev == (prev = get(i)));
       
   336         }
   342     }
   337     }
   343 
   338 
   344     /**
   339     /**
   345      * Returns the String representation of the current values of array.
   340      * Returns the String representation of the current values of array.
   346      * @return the String representation of the current values of array
   341      * @return the String representation of the current values of array
   351             return "[]";
   346             return "[]";
   352 
   347 
   353         StringBuilder b = new StringBuilder();
   348         StringBuilder b = new StringBuilder();
   354         b.append('[');
   349         b.append('[');
   355         for (int i = 0; ; i++) {
   350         for (int i = 0; ; i++) {
   356             b.append(getRaw(byteOffset(i)));
   351             b.append(get(i));
   357             if (i == iMax)
   352             if (i == iMax)
   358                 return b.append(']').toString();
   353                 return b.append(']').toString();
   359             b.append(',').append(' ');
   354             b.append(',').append(' ');
   360         }
   355         }
   361     }
   356     }
   362 
   357 
       
   358     // jdk9
       
   359 
       
   360     /**
       
   361      * Returns the current value of the element at index {@code i},
       
   362      * with memory semantics of reading as if the variable was declared
       
   363      * non-{@code volatile}.
       
   364      *
       
   365      * @param i the index
       
   366      * @return the value
       
   367      * @since 9
       
   368      */
       
   369     public final long getPlain(int i) {
       
   370         return (long)AA.get(array, i);
       
   371     }
       
   372 
       
   373     /**
       
   374      * Sets the element at index {@code i} to {@code newValue},
       
   375      * with memory semantics of setting as if the variable was
       
   376      * declared non-{@code volatile} and non-{@code final}.
       
   377      *
       
   378      * @param i the index
       
   379      * @param newValue the new value
       
   380      * @since 9
       
   381      */
       
   382     public final void setPlain(int i, long newValue) {
       
   383         AA.set(array, i, newValue);
       
   384     }
       
   385 
       
   386     /**
       
   387      * Returns the current value of the element at index {@code i},
       
   388      * with memory effects as specified by {@link VarHandle#getOpaque}.
       
   389      *
       
   390      * @param i the index
       
   391      * @return the value
       
   392      * @since 9
       
   393      */
       
   394     public final long getOpaque(int i) {
       
   395         return (long)AA.getOpaque(array, i);
       
   396     }
       
   397 
       
   398     /**
       
   399      * Sets the element at index {@code i} to {@code newValue},
       
   400      * with memory effects as specified by {@link VarHandle#setOpaque}.
       
   401      *
       
   402      * @param i the index
       
   403      * @param newValue the new value
       
   404      * @since 9
       
   405      */
       
   406     public final void setOpaque(int i, long newValue) {
       
   407         AA.setOpaque(array, i, newValue);
       
   408     }
       
   409 
       
   410     /**
       
   411      * Returns the current value of the element at index {@code i},
       
   412      * with memory effects as specified by {@link VarHandle#getAcquire}.
       
   413      *
       
   414      * @param i the index
       
   415      * @return the value
       
   416      * @since 9
       
   417      */
       
   418     public final long getAcquire(int i) {
       
   419         return (long)AA.getAcquire(array, i);
       
   420     }
       
   421 
       
   422     /**
       
   423      * Sets the element at index {@code i} to {@code newValue},
       
   424      * with memory effects as specified by {@link VarHandle#setRelease}.
       
   425      *
       
   426      * @param i the index
       
   427      * @param newValue the new value
       
   428      * @since 9
       
   429      */
       
   430     public final void setRelease(int i, long newValue) {
       
   431         AA.setRelease(array, i, newValue);
       
   432     }
       
   433 
       
   434     /**
       
   435      * Atomically sets the element at index {@code i} to {@code newValue}
       
   436      * if the element's current value, referred to as the <em>witness
       
   437      * value</em>, {@code == expectedValue},
       
   438      * with memory effects as specified by
       
   439      * {@link VarHandle#compareAndExchange}.
       
   440      *
       
   441      * @param i the index
       
   442      * @param expectedValue the expected value
       
   443      * @param newValue the new value
       
   444      * @return the witness value, which will be the same as the
       
   445      * expected value if successful
       
   446      * @since 9
       
   447      */
       
   448     public final long compareAndExchange(int i, long expectedValue, long newValue) {
       
   449         return (long)AA.compareAndExchange(array, i, expectedValue, newValue);
       
   450     }
       
   451 
       
   452     /**
       
   453      * Atomically sets the element at index {@code i} to {@code newValue}
       
   454      * if the element's current value, referred to as the <em>witness
       
   455      * value</em>, {@code == expectedValue},
       
   456      * with memory effects as specified by
       
   457      * {@link VarHandle#compareAndExchangeAcquire}.
       
   458      *
       
   459      * @param i the index
       
   460      * @param expectedValue the expected value
       
   461      * @param newValue the new value
       
   462      * @return the witness value, which will be the same as the
       
   463      * expected value if successful
       
   464      * @since 9
       
   465      */
       
   466     public final long compareAndExchangeAcquire(int i, long expectedValue, long newValue) {
       
   467         return (long)AA.compareAndExchangeAcquire(array, i, expectedValue, newValue);
       
   468     }
       
   469 
       
   470     /**
       
   471      * Atomically sets the element at index {@code i} to {@code newValue}
       
   472      * if the element's current value, referred to as the <em>witness
       
   473      * value</em>, {@code == expectedValue},
       
   474      * with memory effects as specified by
       
   475      * {@link VarHandle#compareAndExchangeRelease}.
       
   476      *
       
   477      * @param i the index
       
   478      * @param expectedValue the expected value
       
   479      * @param newValue the new value
       
   480      * @return the witness value, which will be the same as the
       
   481      * expected value if successful
       
   482      * @since 9
       
   483      */
       
   484     public final long compareAndExchangeRelease(int i, long expectedValue, long newValue) {
       
   485         return (long)AA.compareAndExchangeRelease(array, i, expectedValue, newValue);
       
   486     }
       
   487 
       
   488     /**
       
   489      * Possibly atomically sets the element at index {@code i} to
       
   490      * {@code newValue} if the element's current value {@code == expectedValue},
       
   491      * with memory effects as specified by
       
   492      * {@link VarHandle#weakCompareAndSetVolatile}.
       
   493      *
       
   494      * @param i the index
       
   495      * @param expectedValue the expected value
       
   496      * @param newValue the new value
       
   497      * @return {@code true} if successful
       
   498      * @since 9
       
   499      */
       
   500     public final boolean weakCompareAndSetVolatile(int i, long expectedValue, long newValue) {
       
   501         return AA.weakCompareAndSetVolatile(array, i, expectedValue, newValue);
       
   502     }
       
   503 
       
   504     /**
       
   505      * Possibly atomically sets the element at index {@code i} to
       
   506      * {@code newValue} if the element's current value {@code == expectedValue},
       
   507      * with memory effects as specified by
       
   508      * {@link VarHandle#weakCompareAndSetAcquire}.
       
   509      *
       
   510      * @param i the index
       
   511      * @param expectedValue the expected value
       
   512      * @param newValue the new value
       
   513      * @return {@code true} if successful
       
   514      * @since 9
       
   515      */
       
   516     public final boolean weakCompareAndSetAcquire(int i, long expectedValue, long newValue) {
       
   517         return AA.weakCompareAndSetAcquire(array, i, expectedValue, newValue);
       
   518     }
       
   519 
       
   520     /**
       
   521      * Possibly atomically sets the element at index {@code i} to
       
   522      * {@code newValue} if the element's current value {@code == expectedValue},
       
   523      * with memory effects as specified by
       
   524      * {@link VarHandle#weakCompareAndSetRelease}.
       
   525      *
       
   526      * @param i the index
       
   527      * @param expectedValue the expected value
       
   528      * @param newValue the new value
       
   529      * @return {@code true} if successful
       
   530      * @since 9
       
   531      */
       
   532     public final boolean weakCompareAndSetRelease(int i, long expectedValue, long newValue) {
       
   533         return AA.weakCompareAndSetRelease(array, i, expectedValue, newValue);
       
   534     }
       
   535 
   363 }
   536 }