350 * @param x the update value
351 * @param accumulatorFunction a side-effect-free function of two arguments
352 * @return the updated value
353 * @since 1.8
354 */
355 public final int accumulateAndGet(T obj, int x,
356 IntBinaryOperator accumulatorFunction) {
357 int prev, next;
358 do {
359 prev = get(obj);
360 next = accumulatorFunction.applyAsInt(prev, x);
361 } while (!compareAndSet(obj, prev, next));
362 return next;
363 }
364
365 /**
366 * Standard hotspot implementation using intrinsics.
367 */
368 private static class AtomicIntegerFieldUpdaterImpl<T>
369 extends AtomicIntegerFieldUpdater<T> {
370 private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
371 private final long offset;
372 private final Class<T> tclass;
373 private final Class<?> cclass;
374
375 AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
376 final String fieldName,
377 final Class<?> caller) {
378 final Field field;
379 final int modifiers;
380 try {
381 field = AccessController.doPrivileged(
382 new PrivilegedExceptionAction<Field>() {
383 public Field run() throws NoSuchFieldException {
384 return tclass.getDeclaredField(fieldName);
385 }
386 });
387 modifiers = field.getModifiers();
388 sun.reflect.misc.ReflectUtil.ensureMemberAccess(
389 caller, tclass, null, modifiers);
390 ClassLoader cl = tclass.getClassLoader();
|
350 * @param x the update value
351 * @param accumulatorFunction a side-effect-free function of two arguments
352 * @return the updated value
353 * @since 1.8
354 */
355 public final int accumulateAndGet(T obj, int x,
356 IntBinaryOperator accumulatorFunction) {
357 int prev, next;
358 do {
359 prev = get(obj);
360 next = accumulatorFunction.applyAsInt(prev, x);
361 } while (!compareAndSet(obj, prev, next));
362 return next;
363 }
364
365 /**
366 * Standard hotspot implementation using intrinsics.
367 */
368 private static class AtomicIntegerFieldUpdaterImpl<T>
369 extends AtomicIntegerFieldUpdater<T> {
370 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
371 private final long offset;
372 private final Class<T> tclass;
373 private final Class<?> cclass;
374
375 AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
376 final String fieldName,
377 final Class<?> caller) {
378 final Field field;
379 final int modifiers;
380 try {
381 field = AccessController.doPrivileged(
382 new PrivilegedExceptionAction<Field>() {
383 public Field run() throws NoSuchFieldException {
384 return tclass.getDeclaredField(fieldName);
385 }
386 });
387 modifiers = field.getModifiers();
388 sun.reflect.misc.ReflectUtil.ensureMemberAccess(
389 caller, tclass, null, modifiers);
390 ClassLoader cl = tclass.getClassLoader();
|