8019377: Sync j.u.c locks and atomic from 166 to tl

Reviewed-by: chegar
This commit is contained in:
Doug Lea 2013-06-28 12:12:37 +01:00
parent 0eb360620b
commit 4535f67d05
26 changed files with 267 additions and 268 deletions

View file

@ -92,7 +92,7 @@ public class AtomicBoolean implements java.io.Serializable {
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. False return indicates that * @return {@code true} if successful. False return indicates that
* the actual value was not equal to the expected value. * the actual value was not equal to the expected value.
*/ */
public final boolean compareAndSet(boolean expect, boolean update) { public final boolean compareAndSet(boolean expect, boolean update) {
@ -105,13 +105,13 @@ public class AtomicBoolean implements java.io.Serializable {
* Atomically sets the value to the given updated value * Atomically sets the value to the given updated value
* if the current value {@code ==} the expected value. * if the current value {@code ==} the expected value.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
*/ */
public boolean weakCompareAndSet(boolean expect, boolean update) { public boolean weakCompareAndSet(boolean expect, boolean update) {
int e = expect ? 1 : 0; int e = expect ? 1 : 0;

View file

@ -126,7 +126,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. False return indicates that * @return {@code true} if successful. False return indicates that
* the actual value was not equal to the expected value. * the actual value was not equal to the expected value.
*/ */
public final boolean compareAndSet(int expect, int update) { public final boolean compareAndSet(int expect, int update) {
@ -137,13 +137,13 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* Atomically sets the value to the given updated value * Atomically sets the value to the given updated value
* if the current value {@code ==} the expected value. * if the current value {@code ==} the expected value.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
*/ */
public final boolean weakCompareAndSet(int expect, int update) { public final boolean weakCompareAndSet(int expect, int update) {
return unsafe.compareAndSwapInt(this, valueOffset, expect, update); return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
@ -155,7 +155,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final int getAndIncrement() { public final int getAndIncrement() {
return getAndAdd(1); return unsafe.getAndAddInt(this, valueOffset, 1);
} }
/** /**
@ -164,7 +164,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final int getAndDecrement() { public final int getAndDecrement() {
return getAndAdd(-1); return unsafe.getAndAddInt(this, valueOffset, -1);
} }
/** /**
@ -183,7 +183,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final int incrementAndGet() { public final int incrementAndGet() {
return getAndAdd(1) + 1; return unsafe.getAndAddInt(this, valueOffset, 1) + 1;
} }
/** /**
@ -192,7 +192,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final int decrementAndGet() { public final int decrementAndGet() {
return getAndAdd(-1) - 1; return unsafe.getAndAddInt(this, valueOffset, -1) - 1;
} }
/** /**
@ -202,7 +202,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final int addAndGet(int delta) { public final int addAndGet(int delta) {
return getAndAdd(delta) + delta; return unsafe.getAndAddInt(this, valueOffset, delta) + delta;
} }
/** /**

View file

@ -157,7 +157,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @param i the index * @param i the index
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. False return indicates that * @return {@code true} if successful. False return indicates that
* the actual value was not equal to the expected value. * the actual value was not equal to the expected value.
*/ */
public final boolean compareAndSet(int i, int expect, int update) { public final boolean compareAndSet(int i, int expect, int update) {
@ -172,14 +172,14 @@ public class AtomicIntegerArray implements java.io.Serializable {
* Atomically sets the element at position {@code i} to the given * Atomically sets the element at position {@code i} to the given
* updated value if the current value {@code ==} the expected value. * updated value if the current value {@code ==} the expected value.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param i the index * @param i the index
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
*/ */
public final boolean weakCompareAndSet(int i, int expect, int update) { public final boolean weakCompareAndSet(int i, int expect, int update) {
return compareAndSet(i, expect, update); return compareAndSet(i, expect, update);
@ -247,6 +247,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
return getAndAdd(i, delta) + delta; return getAndAdd(i, delta) + delta;
} }
/** /**
* Atomically updates the element at index {@code i} with the results * Atomically updates the element at index {@code i} with the results
* of applying the given function, returning the previous value. The * of applying the given function, returning the previous value. The

View file

@ -37,14 +37,13 @@ package java.util.concurrent.atomic;
import java.util.function.IntUnaryOperator; import java.util.function.IntUnaryOperator;
import java.util.function.IntBinaryOperator; import java.util.function.IntBinaryOperator;
import sun.misc.Unsafe; import sun.misc.Unsafe;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
/** /**
* A reflection-based utility that enables atomic updates to * A reflection-based utility that enables atomic updates to
@ -81,8 +80,10 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* access control * access control
*/ */
@CallerSensitive @CallerSensitive
public static <U> AtomicIntegerFieldUpdater<U> newUpdater(Class<U> tclass, String fieldName) { public static <U> AtomicIntegerFieldUpdater<U> newUpdater(Class<U> tclass,
return new AtomicIntegerFieldUpdaterImpl<U>(tclass, fieldName, Reflection.getCallerClass()); String fieldName) {
return new AtomicIntegerFieldUpdaterImpl<U>
(tclass, fieldName, Reflection.getCallerClass());
} }
/** /**
@ -101,7 +102,7 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
* @throws ClassCastException if {@code obj} is not an instance * @throws ClassCastException if {@code obj} is not an instance
* of the class possessing the field established in the constructor * of the class possessing the field established in the constructor
*/ */
@ -114,14 +115,14 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* other calls to {@code compareAndSet} and {@code set}, but not * other calls to {@code compareAndSet} and {@code set}, but not
* necessarily with respect to other changes in the field. * necessarily with respect to other changes in the field.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
* @throws ClassCastException if {@code obj} is not an instance * @throws ClassCastException if {@code obj} is not an instance
* of the class possessing the field established in the constructor * of the class possessing the field established in the constructor
*/ */
@ -363,7 +364,8 @@ public abstract class AtomicIntegerFieldUpdater<T> {
/** /**
* Standard hotspot implementation using intrinsics * Standard hotspot implementation using intrinsics
*/ */
private static class AtomicIntegerFieldUpdaterImpl<T> extends AtomicIntegerFieldUpdater<T> { private static class AtomicIntegerFieldUpdaterImpl<T>
extends AtomicIntegerFieldUpdater<T> {
private static final Unsafe unsafe = Unsafe.getUnsafe(); private static final Unsafe unsafe = Unsafe.getUnsafe();
private final long offset; private final long offset;
private final Class<T> tclass; private final Class<T> tclass;
@ -371,8 +373,7 @@ public abstract class AtomicIntegerFieldUpdater<T> {
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass, AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
final String fieldName, final String fieldName,
final Class<?> caller) final Class<?> caller) {
{
final Field field; final Field field;
final int modifiers; final int modifiers;
try { try {

View file

@ -140,7 +140,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. False return indicates that * @return {@code true} if successful. False return indicates that
* the actual value was not equal to the expected value. * the actual value was not equal to the expected value.
*/ */
public final boolean compareAndSet(long expect, long update) { public final boolean compareAndSet(long expect, long update) {
@ -151,13 +151,13 @@ public class AtomicLong extends Number implements java.io.Serializable {
* Atomically sets the value to the given updated value * Atomically sets the value to the given updated value
* if the current value {@code ==} the expected value. * if the current value {@code ==} the expected value.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
*/ */
public final boolean weakCompareAndSet(long expect, long update) { public final boolean weakCompareAndSet(long expect, long update) {
return unsafe.compareAndSwapLong(this, valueOffset, expect, update); return unsafe.compareAndSwapLong(this, valueOffset, expect, update);
@ -169,7 +169,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final long getAndIncrement() { public final long getAndIncrement() {
return getAndAdd(1); return unsafe.getAndAddLong(this, valueOffset, 1L);
} }
/** /**
@ -178,7 +178,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final long getAndDecrement() { public final long getAndDecrement() {
return getAndAdd(-1); return unsafe.getAndAddLong(this, valueOffset, -1L);
} }
/** /**
@ -197,7 +197,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final long incrementAndGet() { public final long incrementAndGet() {
return getAndAdd(1) + 1; return unsafe.getAndAddLong(this, valueOffset, 1L) + 1L;
} }
/** /**
@ -206,7 +206,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final long decrementAndGet() { public final long decrementAndGet() {
return getAndAdd(-1) - 1; return unsafe.getAndAddLong(this, valueOffset, -1L) - 1L;
} }
/** /**
@ -216,7 +216,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final long addAndGet(long delta) { public final long addAndGet(long delta) {
return getAndAdd(delta) + delta; return unsafe.getAndAddLong(this, valueOffset, delta) + delta;
} }
/** /**

View file

@ -156,7 +156,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @param i the index * @param i the index
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. False return indicates that * @return {@code true} if successful. False return indicates that
* the actual value was not equal to the expected value. * the actual value was not equal to the expected value.
*/ */
public final boolean compareAndSet(int i, long expect, long update) { public final boolean compareAndSet(int i, long expect, long update) {
@ -171,14 +171,14 @@ public class AtomicLongArray implements java.io.Serializable {
* Atomically sets the element at position {@code i} to the given * Atomically sets the element at position {@code i} to the given
* updated value if the current value {@code ==} the expected value. * updated value if the current value {@code ==} the expected value.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param i the index * @param i the index
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
*/ */
public final boolean weakCompareAndSet(int i, long expect, long update) { public final boolean weakCompareAndSet(int i, long expect, long update) {
return compareAndSet(i, expect, update); return compareAndSet(i, expect, update);

View file

@ -37,14 +37,13 @@ package java.util.concurrent.atomic;
import java.util.function.LongUnaryOperator; import java.util.function.LongUnaryOperator;
import java.util.function.LongBinaryOperator; import java.util.function.LongBinaryOperator;
import sun.misc.Unsafe; import sun.misc.Unsafe;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
/** /**
* A reflection-based utility that enables atomic updates to * A reflection-based utility that enables atomic updates to
@ -71,17 +70,18 @@ public abstract class AtomicLongFieldUpdater<T> {
* generic types match. * generic types match.
* *
* @param tclass the class of the objects holding the field * @param tclass the class of the objects holding the field
* @param fieldName the name of the field to be updated. * @param fieldName the name of the field to be updated
* @return the updater * @return the updater
* @throws IllegalArgumentException if the field is not a * @throws IllegalArgumentException if the field is not a
* volatile long type. * volatile long type
* @throws RuntimeException with a nested reflection-based * @throws RuntimeException with a nested reflection-based
* exception if the class does not hold field or is the wrong type, * exception if the class does not hold field or is the wrong type,
* or the field is inaccessible to the caller according to Java language * or the field is inaccessible to the caller according to Java language
* access control * access control
*/ */
@CallerSensitive @CallerSensitive
public static <U> AtomicLongFieldUpdater<U> newUpdater(Class<U> tclass, String fieldName) { public static <U> AtomicLongFieldUpdater<U> newUpdater(Class<U> tclass,
String fieldName) {
Class<?> caller = Reflection.getCallerClass(); Class<?> caller = Reflection.getCallerClass();
if (AtomicLong.VM_SUPPORTS_LONG_CAS) if (AtomicLong.VM_SUPPORTS_LONG_CAS)
return new CASUpdater<U>(tclass, fieldName, caller); return new CASUpdater<U>(tclass, fieldName, caller);
@ -105,9 +105,9 @@ public abstract class AtomicLongFieldUpdater<T> {
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
* @throws ClassCastException if {@code obj} is not an instance * @throws ClassCastException if {@code obj} is not an instance
* of the class possessing the field established in the constructor. * of the class possessing the field established in the constructor
*/ */
public abstract boolean compareAndSet(T obj, long expect, long update); public abstract boolean compareAndSet(T obj, long expect, long update);
@ -118,16 +118,16 @@ public abstract class AtomicLongFieldUpdater<T> {
* other calls to {@code compareAndSet} and {@code set}, but not * other calls to {@code compareAndSet} and {@code set}, but not
* necessarily with respect to other changes in the field. * necessarily with respect to other changes in the field.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
* @throws ClassCastException if {@code obj} is not an instance * @throws ClassCastException if {@code obj} is not an instance
* of the class possessing the field established in the constructor. * of the class possessing the field established in the constructor
*/ */
public abstract boolean weakCompareAndSet(T obj, long expect, long update); public abstract boolean weakCompareAndSet(T obj, long expect, long update);
@ -370,7 +370,8 @@ public abstract class AtomicLongFieldUpdater<T> {
private final Class<T> tclass; private final Class<T> tclass;
private final Class<?> cclass; private final Class<?> cclass;
CASUpdater(final Class<T> tclass, final String fieldName, final Class<?> caller) { CASUpdater(final Class<T> tclass, final String fieldName,
final Class<?> caller) {
final Field field; final Field field;
final int modifiers; final int modifiers;
try { try {
@ -493,7 +494,8 @@ public abstract class AtomicLongFieldUpdater<T> {
private final Class<T> tclass; private final Class<T> tclass;
private final Class<?> cclass; private final Class<?> cclass;
LockedUpdater(final Class<T> tclass, final String fieldName, final Class<?> caller) { LockedUpdater(final Class<T> tclass, final String fieldName,
final Class<?> caller) {
Field field = null; Field field = null;
int modifiers = 0; int modifiers = 0;
try { try {

View file

@ -112,15 +112,15 @@ public class AtomicMarkableReference<V> {
* current reference is {@code ==} to the expected reference * current reference is {@code ==} to the expected reference
* and the current mark is equal to the expected mark. * and the current mark is equal to the expected mark.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param expectedReference the expected value of the reference * @param expectedReference the expected value of the reference
* @param newReference the new value for the reference * @param newReference the new value for the reference
* @param expectedMark the expected value of the mark * @param expectedMark the expected value of the mark
* @param newMark the new value for the mark * @param newMark the new value for the mark
* @return true if successful * @return {@code true} if successful
*/ */
public boolean weakCompareAndSet(V expectedReference, public boolean weakCompareAndSet(V expectedReference,
V newReference, V newReference,
@ -140,7 +140,7 @@ public class AtomicMarkableReference<V> {
* @param newReference the new value for the reference * @param newReference the new value for the reference
* @param expectedMark the expected value of the mark * @param expectedMark the expected value of the mark
* @param newMark the new value for the mark * @param newMark the new value for the mark
* @return true if successful * @return {@code true} if successful
*/ */
public boolean compareAndSet(V expectedReference, public boolean compareAndSet(V expectedReference,
V newReference, V newReference,
@ -178,7 +178,7 @@ public class AtomicMarkableReference<V> {
* *
* @param expectedReference the expected value of the reference * @param expectedReference the expected value of the reference
* @param newMark the new value for the mark * @param newMark the new value for the mark
* @return true if successful * @return {@code true} if successful
*/ */
public boolean attemptMark(V expectedReference, boolean newMark) { public boolean attemptMark(V expectedReference, boolean newMark) {
Pair<V> current = pair; Pair<V> current = pair;

View file

@ -109,7 +109,7 @@ public class AtomicReference<V> implements java.io.Serializable {
* if the current value {@code ==} the expected value. * if the current value {@code ==} the expected value.
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. False return indicates that * @return {@code true} if successful. False return indicates that
* the actual value was not equal to the expected value. * the actual value was not equal to the expected value.
*/ */
public final boolean compareAndSet(V expect, V update) { public final boolean compareAndSet(V expect, V update) {
@ -120,13 +120,13 @@ public class AtomicReference<V> implements java.io.Serializable {
* Atomically sets the value to the given updated value * Atomically sets the value to the given updated value
* if the current value {@code ==} the expected value. * if the current value {@code ==} the expected value.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
*/ */
public final boolean weakCompareAndSet(V expect, V update) { public final boolean weakCompareAndSet(V expect, V update) {
return unsafe.compareAndSwapObject(this, valueOffset, expect, update); return unsafe.compareAndSwapObject(this, valueOffset, expect, update);

View file

@ -34,10 +34,9 @@
*/ */
package java.util.concurrent.atomic; package java.util.concurrent.atomic;
import java.util.Arrays;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import java.util.function.BinaryOperator; import java.util.function.BinaryOperator;
import java.util.Arrays;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import sun.misc.Unsafe; import sun.misc.Unsafe;
@ -60,19 +59,18 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
private final Object[] array; // must have exact type Object[] private final Object[] array; // must have exact type Object[]
static { static {
int scale;
try { try {
unsafe = Unsafe.getUnsafe(); unsafe = Unsafe.getUnsafe();
arrayFieldOffset = unsafe.objectFieldOffset arrayFieldOffset = unsafe.objectFieldOffset
(AtomicReferenceArray.class.getDeclaredField("array")); (AtomicReferenceArray.class.getDeclaredField("array"));
base = unsafe.arrayBaseOffset(Object[].class); base = unsafe.arrayBaseOffset(Object[].class);
scale = unsafe.arrayIndexScale(Object[].class); int scale = unsafe.arrayIndexScale(Object[].class);
} catch (Exception e) {
throw new Error(e);
}
if ((scale & (scale - 1)) != 0) if ((scale & (scale - 1)) != 0)
throw new Error("data type scale not a power of two"); throw new Error("data type scale not a power of two");
shift = 31 - Integer.numberOfLeadingZeros(scale); shift = 31 - Integer.numberOfLeadingZeros(scale);
} catch (Exception e) {
throw new Error(e);
}
} }
private long checkedByteOffset(int i) { private long checkedByteOffset(int i) {
@ -173,7 +171,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
* @param i the index * @param i the index
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. False return indicates that * @return {@code true} if successful. False return indicates that
* the actual value was not equal to the expected value. * the actual value was not equal to the expected value.
*/ */
public final boolean compareAndSet(int i, E expect, E update) { public final boolean compareAndSet(int i, E expect, E update) {
@ -188,14 +186,14 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
* Atomically sets the element at position {@code i} to the given * Atomically sets the element at position {@code i} to the given
* updated value if the current value {@code ==} the expected value. * updated value if the current value {@code ==} the expected value.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param i the index * @param i the index
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
*/ */
public final boolean weakCompareAndSet(int i, E expect, E update) { public final boolean weakCompareAndSet(int i, E expect, E update) {
return compareAndSet(i, expect, update); return compareAndSet(i, expect, update);

View file

@ -37,14 +37,13 @@ package java.util.concurrent.atomic;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import java.util.function.BinaryOperator; import java.util.function.BinaryOperator;
import sun.misc.Unsafe; import sun.misc.Unsafe;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
/** /**
* A reflection-based utility that enables atomic updates to * A reflection-based utility that enables atomic updates to
@ -89,22 +88,23 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
* The Class arguments are needed to check that reflective types and * The Class arguments are needed to check that reflective types and
* generic types match. * generic types match.
* *
* @param tclass the class of the objects holding the field. * @param tclass the class of the objects holding the field
* @param vclass the class of the field * @param vclass the class of the field
* @param fieldName the name of the field to be updated. * @param fieldName the name of the field to be updated
* @return the updater * @return the updater
* @throws IllegalArgumentException if the field is not a volatile reference type. * @throws ClassCastException if the field is of the wrong type
* @throws IllegalArgumentException if the field is not volatile
* @throws RuntimeException with a nested reflection-based * @throws RuntimeException with a nested reflection-based
* exception if the class does not hold field or is the wrong type, * exception if the class does not hold field or is the wrong type,
* or the field is inaccessible to the caller according to Java language * or the field is inaccessible to the caller according to Java language
* access control * access control
*/ */
@CallerSensitive @CallerSensitive
public static <U, W> AtomicReferenceFieldUpdater<U,W> newUpdater(Class<U> tclass, Class<W> vclass, String fieldName) { public static <U,W> AtomicReferenceFieldUpdater<U,W> newUpdater(Class<U> tclass,
return new AtomicReferenceFieldUpdaterImpl<U,W>(tclass, Class<W> vclass,
vclass, String fieldName) {
fieldName, return new AtomicReferenceFieldUpdaterImpl<U,W>
Reflection.getCallerClass()); (tclass, vclass, fieldName, Reflection.getCallerClass());
} }
/** /**
@ -123,7 +123,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
*/ */
public abstract boolean compareAndSet(T obj, V expect, V update); public abstract boolean compareAndSet(T obj, V expect, V update);
@ -134,14 +134,14 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
* other calls to {@code compareAndSet} and {@code set}, but not * other calls to {@code compareAndSet} and {@code set}, but not
* necessarily with respect to other changes in the field. * necessarily with respect to other changes in the field.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful * @return {@code true} if successful
*/ */
public abstract boolean weakCompareAndSet(T obj, V expect, V update); public abstract boolean weakCompareAndSet(T obj, V expect, V update);
@ -301,10 +301,9 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
*/ */
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass, AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
Class<V> vclass, final Class<V> vclass,
final String fieldName, final String fieldName,
final Class<?> caller) final Class<?> caller) {
{
final Field field; final Field field;
final Class<?> fieldClass; final Class<?> fieldClass;
final int modifiers; final int modifiers;

View file

@ -112,15 +112,15 @@ public class AtomicStampedReference<V> {
* current reference is {@code ==} to the expected reference * current reference is {@code ==} to the expected reference
* and the current stamp is equal to the expected stamp. * and the current stamp is equal to the expected stamp.
* *
* <p>May <a href="package-summary.html#Spurious">fail spuriously</a> * <p><a href="package-summary.html#weakCompareAndSet">May fail
* and does not provide ordering guarantees, so is only rarely an * spuriously and does not provide ordering guarantees</a>, so is
* appropriate alternative to {@code compareAndSet}. * only rarely an appropriate alternative to {@code compareAndSet}.
* *
* @param expectedReference the expected value of the reference * @param expectedReference the expected value of the reference
* @param newReference the new value for the reference * @param newReference the new value for the reference
* @param expectedStamp the expected value of the stamp * @param expectedStamp the expected value of the stamp
* @param newStamp the new value for the stamp * @param newStamp the new value for the stamp
* @return true if successful * @return {@code true} if successful
*/ */
public boolean weakCompareAndSet(V expectedReference, public boolean weakCompareAndSet(V expectedReference,
V newReference, V newReference,
@ -140,7 +140,7 @@ public class AtomicStampedReference<V> {
* @param newReference the new value for the reference * @param newReference the new value for the reference
* @param expectedStamp the expected value of the stamp * @param expectedStamp the expected value of the stamp
* @param newStamp the new value for the stamp * @param newStamp the new value for the stamp
* @return true if successful * @return {@code true} if successful
*/ */
public boolean compareAndSet(V expectedReference, public boolean compareAndSet(V expectedReference,
V newReference, V newReference,
@ -178,7 +178,7 @@ public class AtomicStampedReference<V> {
* *
* @param expectedReference the expected value of the reference * @param expectedReference the expected value of the reference
* @param newStamp the new value for the stamp * @param newStamp the new value for the stamp
* @return true if successful * @return {@code true} if successful
*/ */
public boolean attemptStamp(V expectedReference, int newStamp) { public boolean attemptStamp(V expectedReference, int newStamp) {
Pair<V> current = pair; Pair<V> current = pair;

View file

@ -65,7 +65,7 @@ import java.util.function.DoubleBinaryOperator;
* <p>Class {@link DoubleAdder} provides analogs of the functionality * <p>Class {@link DoubleAdder} provides analogs of the functionality
* of this class for the common special case of maintaining sums. The * of this class for the common special case of maintaining sums. The
* call {@code new DoubleAdder()} is equivalent to {@code new * call {@code new DoubleAdder()} is equivalent to {@code new
* DoubleAccumulator((x, y) -> x + y, 0.0}. * DoubleAccumulator((x, y) -> x + y, 0.0)}.
* *
* <p>This class extends {@link Number}, but does <em>not</em> define * <p>This class extends {@link Number}, but does <em>not</em> define
* methods such as {@code equals}, {@code hashCode} and {@code * methods such as {@code equals}, {@code hashCode} and {@code
@ -84,6 +84,8 @@ public class DoubleAccumulator extends Striped64 implements Serializable {
/** /**
* Creates a new instance using the given accumulator function * Creates a new instance using the given accumulator function
* and identity element. * and identity element.
* @param accumulatorFunction a side-effect-free function of two arguments
* @param identity identity (initial value) for the accumulator function
*/ */
public DoubleAccumulator(DoubleBinaryOperator accumulatorFunction, public DoubleAccumulator(DoubleBinaryOperator accumulatorFunction,
double identity) { double identity) {

View file

@ -63,7 +63,7 @@ import java.io.Serializable;
public class DoubleAdder extends Striped64 implements Serializable { public class DoubleAdder extends Striped64 implements Serializable {
private static final long serialVersionUID = 7249069246863182397L; private static final long serialVersionUID = 7249069246863182397L;
/** /*
* Note that we must use "long" for underlying representations, * Note that we must use "long" for underlying representations,
* because there is no compareAndSet for double, due to the fact * because there is no compareAndSet for double, due to the fact
* that the bitwise equals used in any CAS implementation is not * that the bitwise equals used in any CAS implementation is not

View file

@ -86,6 +86,8 @@ public class LongAccumulator extends Striped64 implements Serializable {
/** /**
* Creates a new instance using the given accumulator function * Creates a new instance using the given accumulator function
* and identity element. * and identity element.
* @param accumulatorFunction a side-effect-free function of two arguments
* @param identity identity (initial value) for the accumulator function
*/ */
public LongAccumulator(LongBinaryOperator accumulatorFunction, public LongAccumulator(LongBinaryOperator accumulatorFunction,
long identity) { long identity) {

View file

@ -52,13 +52,13 @@ abstract class Striped64 extends Number {
* accessed directly by subclasses. * accessed directly by subclasses.
* *
* Table entries are of class Cell; a variant of AtomicLong padded * Table entries are of class Cell; a variant of AtomicLong padded
* to reduce cache contention on most processors. Padding is * (via @sun.misc.Contended) to reduce cache contention. Padding
* overkill for most Atomics because they are usually irregularly * is overkill for most Atomics because they are usually
* scattered in memory and thus don't interfere much with each * irregularly scattered in memory and thus don't interfere much
* other. But Atomic objects residing in arrays will tend to be * with each other. But Atomic objects residing in arrays will
* placed adjacent to each other, and so will most often share * tend to be placed adjacent to each other, and so will most
* cache lines (with a huge negative performance impact) without * often share cache lines (with a huge negative performance
* this precaution. * impact) without this precaution.
* *
* In part because Cells are relatively large, we avoid creating * In part because Cells are relatively large, we avoid creating
* them until they are needed. When there is no contention, all * them until they are needed. When there is no contention, all
@ -112,18 +112,13 @@ abstract class Striped64 extends Number {
/** /**
* Padded variant of AtomicLong supporting only raw accesses plus CAS. * Padded variant of AtomicLong supporting only raw accesses plus CAS.
* The value field is placed between pads, hoping that the JVM doesn't
* reorder them.
* *
* JVM intrinsics note: It would be possible to use a release-only * JVM intrinsics note: It would be possible to use a release-only
* form of CAS here, if it were provided. * form of CAS here, if it were provided.
*/ */
static final class Cell { @sun.misc.Contended static final class Cell {
volatile long p0, p1, p2, p3, p4, p5, p6;
volatile long value; volatile long value;
volatile long q0, q1, q2, q3, q4, q5, q6;
Cell(long x) { value = x; } Cell(long x) { value = x; }
final boolean cas(long cmp, long val) { final boolean cas(long cmp, long val) {
return UNSAFE.compareAndSwapLong(this, valueOffset, cmp, val); return UNSAFE.compareAndSwapLong(this, valueOffset, cmp, val);
} }

View file

@ -84,19 +84,18 @@
* write your utility method as follows: * write your utility method as follows:
* <pre> {@code * <pre> {@code
* long getAndTransform(AtomicLong var) { * long getAndTransform(AtomicLong var) {
* while (true) { * long prev, next;
* long current = var.get(); * do {
* long next = transform(current); * prev = var.get();
* if (var.compareAndSet(current, next)) * next = transform(prev);
* return current; * } while (!var.compareAndSet(prev, next));
* // return next; for transformAndGet * return prev; // return next; for transformAndGet
* }
* }}</pre> * }}</pre>
* *
* <p>The memory effects for accesses and updates of atomics generally * <p>The memory effects for accesses and updates of atomics generally
* follow the rules for volatiles, as stated in * follow the rules for volatiles, as stated in
* <a href="http://docs.oracle.com/javase/specs/jls/se7/html/index.html"> * <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4">
* The Java Language Specification, Third Edition (17.4 Memory Model)</a>: * The Java Language Specification (17.4 Memory Model)</a>:
* *
* <ul> * <ul>
* *
@ -152,13 +151,12 @@
* semantics for their array elements, which is not supported for * semantics for their array elements, which is not supported for
* ordinary arrays. * ordinary arrays.
* *
* <a name="Spurious"> * <p id="weakCompareAndSet">The atomic classes also support method
* <p>The atomic classes also support method {@code weakCompareAndSet}, * {@code weakCompareAndSet}, which has limited applicability. On some
* which has limited applicability. On some platforms, the weak version * platforms, the weak version may be more efficient than {@code
* may be more efficient than {@code compareAndSet} in the normal case, * compareAndSet} in the normal case, but differs in that any given
* but differs in that any given invocation of the * invocation of the {@code weakCompareAndSet} method may return {@code
* {@code weakCompareAndSet} method may return {@code false} * false} <em>spuriously</em> (that is, for no apparent reason). A
* <em>spuriously</em> (that is, for no apparent reason)</a>. A
* {@code false} return means only that the operation may be retried if * {@code false} return means only that the operation may be retried if
* desired, relying on the guarantee that repeated invocation when the * desired, relying on the guarantee that repeated invocation when the
* variable holds {@code expectedValue} and no other thread is also * variable holds {@code expectedValue} and no other thread is also
@ -194,7 +192,7 @@
* *
* <p>Atomic classes are not general purpose replacements for * <p>Atomic classes are not general purpose replacements for
* {@code java.lang.Integer} and related classes. They do <em>not</em> * {@code java.lang.Integer} and related classes. They do <em>not</em>
* define methods such as {@code hashCode} and * define methods such as {@code equals}, {@code hashCode} and
* {@code compareTo}. (Because atomic variables are expected to be * {@code compareTo}. (Because atomic variables are expected to be
* mutated, they are poor choices for hash table keys.) Additionally, * mutated, they are poor choices for hash table keys.) Additionally,
* classes are provided only for those types that are commonly useful in * classes are provided only for those types that are commonly useful in

View file

@ -39,7 +39,7 @@ package java.util.concurrent.locks;
* A synchronizer that may be exclusively owned by a thread. This * A synchronizer that may be exclusively owned by a thread. This
* class provides a basis for creating locks and related synchronizers * class provides a basis for creating locks and related synchronizers
* that may entail a notion of ownership. The * that may entail a notion of ownership. The
* <tt>AbstractOwnableSynchronizer</tt> class itself does not manage or * {@code AbstractOwnableSynchronizer} class itself does not manage or
* use this information. However, subclasses and tools may use * use this information. However, subclasses and tools may use
* appropriately maintained values to help control and monitor access * appropriately maintained values to help control and monitor access
* and provide diagnostics. * and provide diagnostics.
@ -64,20 +64,20 @@ public abstract class AbstractOwnableSynchronizer
private transient Thread exclusiveOwnerThread; private transient Thread exclusiveOwnerThread;
/** /**
* Sets the thread that currently owns exclusive access. A * Sets the thread that currently owns exclusive access.
* <tt>null</tt> argument indicates that no thread owns access. * A {@code null} argument indicates that no thread owns access.
* This method does not otherwise impose any synchronization or * This method does not otherwise impose any synchronization or
* <tt>volatile</tt> field accesses. * {@code volatile} field accesses.
* @param thread the owner thread
*/ */
protected final void setExclusiveOwnerThread(Thread t) { protected final void setExclusiveOwnerThread(Thread thread) {
exclusiveOwnerThread = t; exclusiveOwnerThread = thread;
} }
/** /**
* Returns the thread last set by * Returns the thread last set by {@code setExclusiveOwnerThread},
* <tt>setExclusiveOwnerThread</tt>, or <tt>null</tt> if never * or {@code null} if never set. This method does not otherwise
* set. This method does not otherwise impose any synchronization * impose any synchronization or {@code volatile} field accesses.
* or <tt>volatile</tt> field accesses.
* @return the owner thread * @return the owner thread
*/ */
protected final Thread getExclusiveOwnerThread() { protected final Thread getExclusiveOwnerThread() {

View file

@ -42,11 +42,11 @@ import sun.misc.Unsafe;
/** /**
* A version of {@link AbstractQueuedSynchronizer} in * A version of {@link AbstractQueuedSynchronizer} in
* which synchronization state is maintained as a <tt>long</tt>. * which synchronization state is maintained as a {@code long}.
* This class has exactly the same structure, properties, and methods * This class has exactly the same structure, properties, and methods
* as <tt>AbstractQueuedSynchronizer</tt> with the exception * as {@code AbstractQueuedSynchronizer} with the exception
* that all state-related parameters and results are defined * that all state-related parameters and results are defined
* as <tt>long</tt> rather than <tt>int</tt>. This class * as {@code long} rather than {@code int}. This class
* may be useful when creating synchronizers such as * may be useful when creating synchronizers such as
* multilevel locks and barriers that require * multilevel locks and barriers that require
* 64 bits of state. * 64 bits of state.
@ -71,7 +71,7 @@ public abstract class AbstractQueuedLongSynchronizer
*/ */
/** /**
* Creates a new <tt>AbstractQueuedLongSynchronizer</tt> instance * Creates a new {@code AbstractQueuedLongSynchronizer} instance
* with initial synchronization state of zero. * with initial synchronization state of zero.
*/ */
protected AbstractQueuedLongSynchronizer() { } protected AbstractQueuedLongSynchronizer() { }
@ -104,7 +104,7 @@ public abstract class AbstractQueuedLongSynchronizer
* *
* <p>Insertion into a CLH queue requires only a single atomic * <p>Insertion into a CLH queue requires only a single atomic
* operation on "tail", so there is a simple atomic point of * operation on "tail", so there is a simple atomic point of
* demarcation from unqueued to queued. Similarly, dequeing * demarcation from unqueued to queued. Similarly, dequeuing
* involves only updating the "head". However, it takes a bit * involves only updating the "head". However, it takes a bit
* more work for nodes to determine who their successors are, * more work for nodes to determine who their successors are,
* in part to deal with possible cancellation due to timeouts * in part to deal with possible cancellation due to timeouts
@ -211,7 +211,7 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* Link to predecessor node that current node/thread relies on * Link to predecessor node that current node/thread relies on
* for checking waitStatus. Assigned during enqueing, and nulled * for checking waitStatus. Assigned during enqueuing, and nulled
* out (for sake of GC) only upon dequeuing. Also, upon * out (for sake of GC) only upon dequeuing. Also, upon
* cancellation of a predecessor, we short-circuit while * cancellation of a predecessor, we short-circuit while
* finding a non-cancelled one, which will always exist * finding a non-cancelled one, which will always exist
@ -256,7 +256,7 @@ public abstract class AbstractQueuedLongSynchronizer
Node nextWaiter; Node nextWaiter;
/** /**
* Returns true if node is waiting in shared mode * Returns true if node is waiting in shared mode.
*/ */
final boolean isShared() { final boolean isShared() {
return nextWaiter == SHARED; return nextWaiter == SHARED;
@ -312,7 +312,7 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* Returns the current value of synchronization state. * Returns the current value of synchronization state.
* This operation has memory semantics of a <tt>volatile</tt> read. * This operation has memory semantics of a {@code volatile} read.
* @return current state value * @return current state value
*/ */
protected final long getState() { protected final long getState() {
@ -321,7 +321,7 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* Sets the value of synchronization state. * Sets the value of synchronization state.
* This operation has memory semantics of a <tt>volatile</tt> write. * This operation has memory semantics of a {@code volatile} write.
* @param newState the new state value * @param newState the new state value
*/ */
protected final void setState(long newState) { protected final void setState(long newState) {
@ -331,12 +331,12 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* Atomically sets synchronization state to the given updated * Atomically sets synchronization state to the given updated
* value if the current state value equals the expected value. * value if the current state value equals the expected value.
* This operation has memory semantics of a <tt>volatile</tt> read * This operation has memory semantics of a {@code volatile} read
* and write. * and write.
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. False return indicates that the actual * @return {@code true} if successful. False return indicates that the actual
* value was not equal to the expected value. * value was not equal to the expected value.
*/ */
protected final boolean compareAndSetState(long expect, long update) { protected final boolean compareAndSetState(long expect, long update) {
@ -441,7 +441,7 @@ public abstract class AbstractQueuedLongSynchronizer
} }
/** /**
* Release action for shared mode -- signal successor and ensure * Release action for shared mode -- signals successor and ensures
* propagation. (Note: For exclusive mode, release just amounts * propagation. (Note: For exclusive mode, release just amounts
* to calling unparkSuccessor of head if it needs signal.) * to calling unparkSuccessor of head if it needs signal.)
*/ */
@ -562,7 +562,7 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* Checks and updates status for a node that failed to acquire. * Checks and updates status for a node that failed to acquire.
* Returns true if thread should block. This is the main signal * Returns true if thread should block. This is the main signal
* control in all acquire loops. Requires that pred == node.prev * control in all acquire loops. Requires that pred == node.prev.
* *
* @param pred node's predecessor holding status * @param pred node's predecessor holding status
* @param node the node * @param node the node
@ -1066,7 +1066,7 @@ public abstract class AbstractQueuedLongSynchronizer
* thread is queued, possibly repeatedly blocking and unblocking, * thread is queued, possibly repeatedly blocking and unblocking,
* invoking {@link #tryAcquireShared} until success or the thread * invoking {@link #tryAcquireShared} until success or the thread
* is interrupted. * is interrupted.
* @param arg the acquire argument * @param arg the acquire argument.
* This value is conveyed to {@link #tryAcquireShared} but is * This value is conveyed to {@link #tryAcquireShared} but is
* otherwise uninterpreted and can represent anything * otherwise uninterpreted and can represent anything
* you like. * you like.
@ -1441,7 +1441,7 @@ public abstract class AbstractQueuedLongSynchronizer
* Returns true if successful. * Returns true if successful.
* @param node the node * @param node the node
* @return true if successfully transferred (else the node was * @return true if successfully transferred (else the node was
* cancelled before signal). * cancelled before signal)
*/ */
final boolean transferForSignal(Node node) { final boolean transferForSignal(Node node) {
/* /*
@ -1464,11 +1464,10 @@ public abstract class AbstractQueuedLongSynchronizer
} }
/** /**
* Transfers node, if necessary, to sync queue after a cancelled * Transfers node, if necessary, to sync queue after a cancelled wait.
* wait. Returns true if thread was cancelled before being * Returns true if thread was cancelled before being signalled.
* signalled. *
* @param current the waiting thread * @param node the node
* @param node its node
* @return true if cancelled before the node was signalled * @return true if cancelled before the node was signalled
*/ */
final boolean transferAfterCancelledWait(Node node) { final boolean transferAfterCancelledWait(Node node) {
@ -1516,7 +1515,7 @@ public abstract class AbstractQueuedLongSynchronizer
* uses this synchronizer as its lock. * uses this synchronizer as its lock.
* *
* @param condition the condition * @param condition the condition
* @return <tt>true</tt> if owned * @return {@code true} if owned
* @throws NullPointerException if the condition is null * @throws NullPointerException if the condition is null
*/ */
public final boolean owns(ConditionObject condition) { public final boolean owns(ConditionObject condition) {
@ -1526,13 +1525,13 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* Queries whether any threads are waiting on the given condition * Queries whether any threads are waiting on the given condition
* associated with this synchronizer. Note that because timeouts * associated with this synchronizer. Note that because timeouts
* and interrupts may occur at any time, a <tt>true</tt> return * and interrupts may occur at any time, a {@code true} return
* does not guarantee that a future <tt>signal</tt> will awaken * does not guarantee that a future {@code signal} will awaken
* any threads. This method is designed primarily for use in * any threads. This method is designed primarily for use in
* monitoring of the system state. * monitoring of the system state.
* *
* @param condition the condition * @param condition the condition
* @return <tt>true</tt> if there are any waiting threads * @return {@code true} if there are any waiting threads
* @throws IllegalMonitorStateException if exclusive synchronization * @throws IllegalMonitorStateException if exclusive synchronization
* is not held * is not held
* @throws IllegalArgumentException if the given condition is * @throws IllegalArgumentException if the given condition is
@ -1599,7 +1598,7 @@ public abstract class AbstractQueuedLongSynchronizer
* and Condition users. Exported versions of this class will in * and Condition users. Exported versions of this class will in
* general need to be accompanied by documentation describing * general need to be accompanied by documentation describing
* condition semantics that rely on those of the associated * condition semantics that rely on those of the associated
* <tt>AbstractQueuedLongSynchronizer</tt>. * {@code AbstractQueuedLongSynchronizer}.
* *
* <p>This class is Serializable, but all fields are transient, * <p>This class is Serializable, but all fields are transient,
* so deserialized conditions have no waiters. * so deserialized conditions have no waiters.
@ -1614,7 +1613,7 @@ public abstract class AbstractQueuedLongSynchronizer
private transient Node lastWaiter; private transient Node lastWaiter;
/** /**
* Creates a new <tt>ConditionObject</tt> instance. * Creates a new {@code ConditionObject} instance.
*/ */
public ConditionObject() { } public ConditionObject() { }
@ -1967,7 +1966,7 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* Queries whether any threads are waiting on this condition. * Queries whether any threads are waiting on this condition.
* Implements {@link AbstractQueuedLongSynchronizer#hasWaiters}. * Implements {@link AbstractQueuedLongSynchronizer#hasWaiters(ConditionObject)}.
* *
* @return {@code true} if there are any waiting threads * @return {@code true} if there are any waiting threads
* @throws IllegalMonitorStateException if {@link #isHeldExclusively} * @throws IllegalMonitorStateException if {@link #isHeldExclusively}
@ -1986,7 +1985,7 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* Returns an estimate of the number of threads waiting on * Returns an estimate of the number of threads waiting on
* this condition. * this condition.
* Implements {@link AbstractQueuedLongSynchronizer#getWaitQueueLength}. * Implements {@link AbstractQueuedLongSynchronizer#getWaitQueueLength(ConditionObject)}.
* *
* @return the estimated number of waiting threads * @return the estimated number of waiting threads
* @throws IllegalMonitorStateException if {@link #isHeldExclusively} * @throws IllegalMonitorStateException if {@link #isHeldExclusively}
@ -2006,7 +2005,7 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* Returns a collection containing those threads that may be * Returns a collection containing those threads that may be
* waiting on this Condition. * waiting on this Condition.
* Implements {@link AbstractQueuedLongSynchronizer#getWaitingThreads}. * Implements {@link AbstractQueuedLongSynchronizer#getWaitingThreads(ConditionObject)}.
* *
* @return the collection of threads * @return the collection of threads
* @throws IllegalMonitorStateException if {@link #isHeldExclusively} * @throws IllegalMonitorStateException if {@link #isHeldExclusively}

View file

@ -45,12 +45,12 @@ import sun.misc.Unsafe;
* synchronizers (semaphores, events, etc) that rely on * synchronizers (semaphores, events, etc) that rely on
* first-in-first-out (FIFO) wait queues. This class is designed to * first-in-first-out (FIFO) wait queues. This class is designed to
* be a useful basis for most kinds of synchronizers that rely on a * be a useful basis for most kinds of synchronizers that rely on a
* single atomic <tt>int</tt> value to represent state. Subclasses * single atomic {@code int} value to represent state. Subclasses
* must define the protected methods that change this state, and which * must define the protected methods that change this state, and which
* define what that state means in terms of this object being acquired * define what that state means in terms of this object being acquired
* or released. Given these, the other methods in this class carry * or released. Given these, the other methods in this class carry
* out all queuing and blocking mechanics. Subclasses can maintain * out all queuing and blocking mechanics. Subclasses can maintain
* other state fields, but only the atomically updated <tt>int</tt> * other state fields, but only the atomically updated {@code int}
* value manipulated using methods {@link #getState}, {@link * value manipulated using methods {@link #getState}, {@link
* #setState} and {@link #compareAndSetState} is tracked with respect * #setState} and {@link #compareAndSetState} is tracked with respect
* to synchronization. * to synchronization.
@ -58,7 +58,7 @@ import sun.misc.Unsafe;
* <p>Subclasses should be defined as non-public internal helper * <p>Subclasses should be defined as non-public internal helper
* classes that are used to implement the synchronization properties * classes that are used to implement the synchronization properties
* of their enclosing class. Class * of their enclosing class. Class
* <tt>AbstractQueuedSynchronizer</tt> does not implement any * {@code AbstractQueuedSynchronizer} does not implement any
* synchronization interface. Instead it defines methods such as * synchronization interface. Instead it defines methods such as
* {@link #acquireInterruptibly} that can be invoked as * {@link #acquireInterruptibly} that can be invoked as
* appropriate by concrete locks and related synchronizers to * appropriate by concrete locks and related synchronizers to
@ -85,7 +85,7 @@ import sun.misc.Unsafe;
* invoked with the current {@link #getState} value fully releases * invoked with the current {@link #getState} value fully releases
* this object, and {@link #acquire}, given this saved state value, * this object, and {@link #acquire}, given this saved state value,
* eventually restores this object to its previous acquired state. No * eventually restores this object to its previous acquired state. No
* <tt>AbstractQueuedSynchronizer</tt> method otherwise creates such a * {@code AbstractQueuedSynchronizer} method otherwise creates such a
* condition, so if this constraint cannot be met, do not use it. The * condition, so if this constraint cannot be met, do not use it. The
* behavior of {@link ConditionObject} depends of course on the * behavior of {@link ConditionObject} depends of course on the
* semantics of its synchronizer implementation. * semantics of its synchronizer implementation.
@ -93,13 +93,13 @@ import sun.misc.Unsafe;
* <p>This class provides inspection, instrumentation, and monitoring * <p>This class provides inspection, instrumentation, and monitoring
* methods for the internal queue, as well as similar methods for * methods for the internal queue, as well as similar methods for
* condition objects. These can be exported as desired into classes * condition objects. These can be exported as desired into classes
* using an <tt>AbstractQueuedSynchronizer</tt> for their * using an {@code AbstractQueuedSynchronizer} for their
* synchronization mechanics. * synchronization mechanics.
* *
* <p>Serialization of this class stores only the underlying atomic * <p>Serialization of this class stores only the underlying atomic
* integer maintaining state, so deserialized objects have empty * integer maintaining state, so deserialized objects have empty
* thread queues. Typical subclasses requiring serializability will * thread queues. Typical subclasses requiring serializability will
* define a <tt>readObject</tt> method that restores this to a known * define a {@code readObject} method that restores this to a known
* initial state upon deserialization. * initial state upon deserialization.
* *
* <h3>Usage</h3> * <h3>Usage</h3>
@ -122,7 +122,7 @@ import sun.misc.Unsafe;
* must be internally thread-safe, and should in general be short and * must be internally thread-safe, and should in general be short and
* not block. Defining these methods is the <em>only</em> supported * not block. Defining these methods is the <em>only</em> supported
* means of using this class. All other methods are declared * means of using this class. All other methods are declared
* <tt>final</tt> because they cannot be independently varied. * {@code final} because they cannot be independently varied.
* *
* <p>You may also find the inherited methods from {@link * <p>You may also find the inherited methods from {@link
* AbstractOwnableSynchronizer} useful to keep track of the thread * AbstractOwnableSynchronizer} useful to keep track of the thread
@ -148,16 +148,16 @@ import sun.misc.Unsafe;
* *
* (Shared mode is similar but may involve cascading signals.) * (Shared mode is similar but may involve cascading signals.)
* *
* <p><a name="barging">Because checks in acquire are invoked before * <p id="barging">Because checks in acquire are invoked before
* enqueuing, a newly acquiring thread may <em>barge</em> ahead of * enqueuing, a newly acquiring thread may <em>barge</em> ahead of
* others that are blocked and queued. However, you can, if desired, * others that are blocked and queued. However, you can, if desired,
* define <tt>tryAcquire</tt> and/or <tt>tryAcquireShared</tt> to * define {@code tryAcquire} and/or {@code tryAcquireShared} to
* disable barging by internally invoking one or more of the inspection * disable barging by internally invoking one or more of the inspection
* methods, thereby providing a <em>fair</em> FIFO acquisition order. * methods, thereby providing a <em>fair</em> FIFO acquisition order.
* In particular, most fair synchronizers can define <tt>tryAcquire</tt> * In particular, most fair synchronizers can define {@code tryAcquire}
* to return <tt>false</tt> if {@link #hasQueuedPredecessors} (a method * to return {@code false} if {@link #hasQueuedPredecessors} (a method
* specifically designed to be used by fair synchronizers) returns * specifically designed to be used by fair synchronizers) returns
* <tt>true</tt>. Other variations are possible. * {@code true}. Other variations are possible.
* *
* <p>Throughput and scalability are generally highest for the * <p>Throughput and scalability are generally highest for the
* default barging (also known as <em>greedy</em>, * default barging (also known as <em>greedy</em>,
@ -167,7 +167,7 @@ import sun.misc.Unsafe;
* threads, and each recontention has an unbiased chance to succeed * threads, and each recontention has an unbiased chance to succeed
* against incoming threads. Also, while acquires do not * against incoming threads. Also, while acquires do not
* &quot;spin&quot; in the usual sense, they may perform multiple * &quot;spin&quot; in the usual sense, they may perform multiple
* invocations of <tt>tryAcquire</tt> interspersed with other * invocations of {@code tryAcquire} interspersed with other
* computations before blocking. This gives most of the benefits of * computations before blocking. This gives most of the benefits of
* spins when exclusive synchronization is only briefly held, without * spins when exclusive synchronization is only briefly held, without
* most of the liabilities when it isn't. If so desired, you can * most of the liabilities when it isn't. If so desired, you can
@ -178,7 +178,7 @@ import sun.misc.Unsafe;
* *
* <p>This class provides an efficient and scalable basis for * <p>This class provides an efficient and scalable basis for
* synchronization in part by specializing its range of use to * synchronization in part by specializing its range of use to
* synchronizers that can rely on <tt>int</tt> state, acquire, and * synchronizers that can rely on {@code int} state, acquire, and
* release parameters, and an internal FIFO wait queue. When this does * release parameters, and an internal FIFO wait queue. When this does
* not suffice, you can build synchronizers from a lower level using * not suffice, you can build synchronizers from a lower level using
* {@link java.util.concurrent.atomic atomic} classes, your own custom * {@link java.util.concurrent.atomic atomic} classes, your own custom
@ -200,12 +200,12 @@ import sun.misc.Unsafe;
* *
* // Our internal helper class * // Our internal helper class
* private static class Sync extends AbstractQueuedSynchronizer { * private static class Sync extends AbstractQueuedSynchronizer {
* // Report whether in locked state * // Reports whether in locked state
* protected boolean isHeldExclusively() { * protected boolean isHeldExclusively() {
* return getState() == 1; * return getState() == 1;
* } * }
* *
* // Acquire the lock if state is zero * // Acquires the lock if state is zero
* public boolean tryAcquire(int acquires) { * public boolean tryAcquire(int acquires) {
* assert acquires == 1; // Otherwise unused * assert acquires == 1; // Otherwise unused
* if (compareAndSetState(0, 1)) { * if (compareAndSetState(0, 1)) {
@ -215,7 +215,7 @@ import sun.misc.Unsafe;
* return false; * return false;
* } * }
* *
* // Release the lock by setting state to zero * // Releases the lock by setting state to zero
* protected boolean tryRelease(int releases) { * protected boolean tryRelease(int releases) {
* assert releases == 1; // Otherwise unused * assert releases == 1; // Otherwise unused
* if (getState() == 0) throw new IllegalMonitorStateException(); * if (getState() == 0) throw new IllegalMonitorStateException();
@ -224,10 +224,10 @@ import sun.misc.Unsafe;
* return true; * return true;
* } * }
* *
* // Provide a Condition * // Provides a Condition
* Condition newCondition() { return new ConditionObject(); } * Condition newCondition() { return new ConditionObject(); }
* *
* // Deserialize properly * // Deserializes properly
* private void readObject(ObjectInputStream s) * private void readObject(ObjectInputStream s)
* throws IOException, ClassNotFoundException { * throws IOException, ClassNotFoundException {
* s.defaultReadObject(); * s.defaultReadObject();
@ -255,8 +255,8 @@ import sun.misc.Unsafe;
* *
* <p>Here is a latch class that is like a * <p>Here is a latch class that is like a
* {@link java.util.concurrent.CountDownLatch CountDownLatch} * {@link java.util.concurrent.CountDownLatch CountDownLatch}
* except that it only requires a single <tt>signal</tt> to * except that it only requires a single {@code signal} to
* fire. Because a latch is non-exclusive, it uses the <tt>shared</tt> * fire. Because a latch is non-exclusive, it uses the {@code shared}
* acquire and release methods. * acquire and release methods.
* *
* <pre> {@code * <pre> {@code
@ -293,7 +293,7 @@ public abstract class AbstractQueuedSynchronizer
private static final long serialVersionUID = 7373984972572414691L; private static final long serialVersionUID = 7373984972572414691L;
/** /**
* Creates a new <tt>AbstractQueuedSynchronizer</tt> instance * Creates a new {@code AbstractQueuedSynchronizer} instance
* with initial synchronization state of zero. * with initial synchronization state of zero.
*/ */
protected AbstractQueuedSynchronizer() { } protected AbstractQueuedSynchronizer() { }
@ -326,7 +326,7 @@ public abstract class AbstractQueuedSynchronizer
* *
* <p>Insertion into a CLH queue requires only a single atomic * <p>Insertion into a CLH queue requires only a single atomic
* operation on "tail", so there is a simple atomic point of * operation on "tail", so there is a simple atomic point of
* demarcation from unqueued to queued. Similarly, dequeing * demarcation from unqueued to queued. Similarly, dequeuing
* involves only updating the "head". However, it takes a bit * involves only updating the "head". However, it takes a bit
* more work for nodes to determine who their successors are, * more work for nodes to determine who their successors are,
* in part to deal with possible cancellation due to timeouts * in part to deal with possible cancellation due to timeouts
@ -433,7 +433,7 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* Link to predecessor node that current node/thread relies on * Link to predecessor node that current node/thread relies on
* for checking waitStatus. Assigned during enqueing, and nulled * for checking waitStatus. Assigned during enqueuing, and nulled
* out (for sake of GC) only upon dequeuing. Also, upon * out (for sake of GC) only upon dequeuing. Also, upon
* cancellation of a predecessor, we short-circuit while * cancellation of a predecessor, we short-circuit while
* finding a non-cancelled one, which will always exist * finding a non-cancelled one, which will always exist
@ -478,7 +478,7 @@ public abstract class AbstractQueuedSynchronizer
Node nextWaiter; Node nextWaiter;
/** /**
* Returns true if node is waiting in shared mode * Returns true if node is waiting in shared mode.
*/ */
final boolean isShared() { final boolean isShared() {
return nextWaiter == SHARED; return nextWaiter == SHARED;
@ -534,7 +534,7 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* Returns the current value of synchronization state. * Returns the current value of synchronization state.
* This operation has memory semantics of a <tt>volatile</tt> read. * This operation has memory semantics of a {@code volatile} read.
* @return current state value * @return current state value
*/ */
protected final int getState() { protected final int getState() {
@ -543,7 +543,7 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* Sets the value of synchronization state. * Sets the value of synchronization state.
* This operation has memory semantics of a <tt>volatile</tt> write. * This operation has memory semantics of a {@code volatile} write.
* @param newState the new state value * @param newState the new state value
*/ */
protected final void setState(int newState) { protected final void setState(int newState) {
@ -553,12 +553,12 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* Atomically sets synchronization state to the given updated * Atomically sets synchronization state to the given updated
* value if the current state value equals the expected value. * value if the current state value equals the expected value.
* This operation has memory semantics of a <tt>volatile</tt> read * This operation has memory semantics of a {@code volatile} read
* and write. * and write.
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. False return indicates that the actual * @return {@code true} if successful. False return indicates that the actual
* value was not equal to the expected value. * value was not equal to the expected value.
*/ */
protected final boolean compareAndSetState(int expect, int update) { protected final boolean compareAndSetState(int expect, int update) {
@ -663,7 +663,7 @@ public abstract class AbstractQueuedSynchronizer
} }
/** /**
* Release action for shared mode -- signal successor and ensure * Release action for shared mode -- signals successor and ensures
* propagation. (Note: For exclusive mode, release just amounts * propagation. (Note: For exclusive mode, release just amounts
* to calling unparkSuccessor of head if it needs signal.) * to calling unparkSuccessor of head if it needs signal.)
*/ */
@ -784,7 +784,7 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* Checks and updates status for a node that failed to acquire. * Checks and updates status for a node that failed to acquire.
* Returns true if thread should block. This is the main signal * Returns true if thread should block. This is the main signal
* control in all acquire loops. Requires that pred == node.prev * control in all acquire loops. Requires that pred == node.prev.
* *
* @param pred node's predecessor holding status * @param pred node's predecessor holding status
* @param node the node * @param node the node
@ -1288,7 +1288,7 @@ public abstract class AbstractQueuedSynchronizer
* thread is queued, possibly repeatedly blocking and unblocking, * thread is queued, possibly repeatedly blocking and unblocking,
* invoking {@link #tryAcquireShared} until success or the thread * invoking {@link #tryAcquireShared} until success or the thread
* is interrupted. * is interrupted.
* @param arg the acquire argument * @param arg the acquire argument.
* This value is conveyed to {@link #tryAcquireShared} but is * This value is conveyed to {@link #tryAcquireShared} but is
* otherwise uninterpreted and can represent anything * otherwise uninterpreted and can represent anything
* you like. * you like.
@ -1663,7 +1663,7 @@ public abstract class AbstractQueuedSynchronizer
* Returns true if successful. * Returns true if successful.
* @param node the node * @param node the node
* @return true if successfully transferred (else the node was * @return true if successfully transferred (else the node was
* cancelled before signal). * cancelled before signal)
*/ */
final boolean transferForSignal(Node node) { final boolean transferForSignal(Node node) {
/* /*
@ -1686,11 +1686,10 @@ public abstract class AbstractQueuedSynchronizer
} }
/** /**
* Transfers node, if necessary, to sync queue after a cancelled * Transfers node, if necessary, to sync queue after a cancelled wait.
* wait. Returns true if thread was cancelled before being * Returns true if thread was cancelled before being signalled.
* signalled. *
* @param current the waiting thread * @param node the node
* @param node its node
* @return true if cancelled before the node was signalled * @return true if cancelled before the node was signalled
*/ */
final boolean transferAfterCancelledWait(Node node) { final boolean transferAfterCancelledWait(Node node) {
@ -1738,7 +1737,7 @@ public abstract class AbstractQueuedSynchronizer
* uses this synchronizer as its lock. * uses this synchronizer as its lock.
* *
* @param condition the condition * @param condition the condition
* @return <tt>true</tt> if owned * @return {@code true} if owned
* @throws NullPointerException if the condition is null * @throws NullPointerException if the condition is null
*/ */
public final boolean owns(ConditionObject condition) { public final boolean owns(ConditionObject condition) {
@ -1748,13 +1747,13 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* Queries whether any threads are waiting on the given condition * Queries whether any threads are waiting on the given condition
* associated with this synchronizer. Note that because timeouts * associated with this synchronizer. Note that because timeouts
* and interrupts may occur at any time, a <tt>true</tt> return * and interrupts may occur at any time, a {@code true} return
* does not guarantee that a future <tt>signal</tt> will awaken * does not guarantee that a future {@code signal} will awaken
* any threads. This method is designed primarily for use in * any threads. This method is designed primarily for use in
* monitoring of the system state. * monitoring of the system state.
* *
* @param condition the condition * @param condition the condition
* @return <tt>true</tt> if there are any waiting threads * @return {@code true} if there are any waiting threads
* @throws IllegalMonitorStateException if exclusive synchronization * @throws IllegalMonitorStateException if exclusive synchronization
* is not held * is not held
* @throws IllegalArgumentException if the given condition is * @throws IllegalArgumentException if the given condition is
@ -1821,7 +1820,7 @@ public abstract class AbstractQueuedSynchronizer
* and Condition users. Exported versions of this class will in * and Condition users. Exported versions of this class will in
* general need to be accompanied by documentation describing * general need to be accompanied by documentation describing
* condition semantics that rely on those of the associated * condition semantics that rely on those of the associated
* <tt>AbstractQueuedSynchronizer</tt>. * {@code AbstractQueuedSynchronizer}.
* *
* <p>This class is Serializable, but all fields are transient, * <p>This class is Serializable, but all fields are transient,
* so deserialized conditions have no waiters. * so deserialized conditions have no waiters.
@ -1834,7 +1833,7 @@ public abstract class AbstractQueuedSynchronizer
private transient Node lastWaiter; private transient Node lastWaiter;
/** /**
* Creates a new <tt>ConditionObject</tt> instance. * Creates a new {@code ConditionObject} instance.
*/ */
public ConditionObject() { } public ConditionObject() { }
@ -2187,7 +2186,7 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* Queries whether any threads are waiting on this condition. * Queries whether any threads are waiting on this condition.
* Implements {@link AbstractQueuedSynchronizer#hasWaiters}. * Implements {@link AbstractQueuedSynchronizer#hasWaiters(ConditionObject)}.
* *
* @return {@code true} if there are any waiting threads * @return {@code true} if there are any waiting threads
* @throws IllegalMonitorStateException if {@link #isHeldExclusively} * @throws IllegalMonitorStateException if {@link #isHeldExclusively}
@ -2206,7 +2205,7 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* Returns an estimate of the number of threads waiting on * Returns an estimate of the number of threads waiting on
* this condition. * this condition.
* Implements {@link AbstractQueuedSynchronizer#getWaitQueueLength}. * Implements {@link AbstractQueuedSynchronizer#getWaitQueueLength(ConditionObject)}.
* *
* @return the estimated number of waiting threads * @return the estimated number of waiting threads
* @throws IllegalMonitorStateException if {@link #isHeldExclusively} * @throws IllegalMonitorStateException if {@link #isHeldExclusively}
@ -2226,7 +2225,7 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* Returns a collection containing those threads that may be * Returns a collection containing those threads that may be
* waiting on this Condition. * waiting on this Condition.
* Implements {@link AbstractQueuedSynchronizer#getWaitingThreads}. * Implements {@link AbstractQueuedSynchronizer#getWaitingThreads(ConditionObject)}.
* *
* @return the collection of threads * @return the collection of threads
* @throws IllegalMonitorStateException if {@link #isHeldExclusively} * @throws IllegalMonitorStateException if {@link #isHeldExclusively}

View file

@ -121,8 +121,8 @@ import java.util.concurrent.TimeUnit;
* <p>All {@code Lock} implementations <em>must</em> enforce the same * <p>All {@code Lock} implementations <em>must</em> enforce the same
* memory synchronization semantics as provided by the built-in monitor * memory synchronization semantics as provided by the built-in monitor
* lock, as described in * lock, as described in
* <a href="http://docs.oracle.com/javase/specs/jls/se7/html/index.html"> * <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4">
* The Java Language Specification, Third Edition (17.4 Memory Model)</a>: * The Java Language Specification (17.4 Memory Model)</a>:
* <ul> * <ul>
* <li>A successful {@code lock} operation has the same memory * <li>A successful {@code lock} operation has the same memory
* synchronization effects as a successful <em>Lock</em> action. * synchronization effects as a successful <em>Lock</em> action.
@ -227,7 +227,7 @@ public interface Lock {
* *
* @throws InterruptedException if the current thread is * @throws InterruptedException if the current thread is
* interrupted while acquiring the lock (and interruption * interrupted while acquiring the lock (and interruption
* of lock acquisition is supported). * of lock acquisition is supported)
*/ */
void lockInterruptibly() throws InterruptedException; void lockInterruptibly() throws InterruptedException;

View file

@ -67,10 +67,10 @@ import sun.misc.Unsafe;
* {@code blocker} object parameter. This object is recorded while * {@code blocker} object parameter. This object is recorded while
* the thread is blocked to permit monitoring and diagnostic tools to * the thread is blocked to permit monitoring and diagnostic tools to
* identify the reasons that threads are blocked. (Such tools may * identify the reasons that threads are blocked. (Such tools may
* access blockers using method {@link #getBlocker}.) The use of these * access blockers using method {@link #getBlocker(Thread)}.)
* forms rather than the original forms without this parameter is * The use of these forms rather than the original forms without this
* strongly encouraged. The normal argument to supply as a * parameter is strongly encouraged. The normal argument to supply as
* {@code blocker} within a lock implementation is {@code this}. * a {@code blocker} within a lock implementation is {@code this}.
* *
* <p>These methods are designed to be used as tools for creating * <p>These methods are designed to be used as tools for creating
* higher-level synchronization utilities, and are not in themselves * higher-level synchronization utilities, and are not in themselves

View file

@ -36,16 +36,16 @@
package java.util.concurrent.locks; package java.util.concurrent.locks;
/** /**
* A <tt>ReadWriteLock</tt> maintains a pair of associated {@link * A {@code ReadWriteLock} maintains a pair of associated {@link
* Lock locks}, one for read-only operations and one for writing. * Lock locks}, one for read-only operations and one for writing.
* The {@link #readLock read lock} may be held simultaneously by * The {@link #readLock read lock} may be held simultaneously by
* multiple reader threads, so long as there are no writers. The * multiple reader threads, so long as there are no writers. The
* {@link #writeLock write lock} is exclusive. * {@link #writeLock write lock} is exclusive.
* *
* <p>All <tt>ReadWriteLock</tt> implementations must guarantee that * <p>All {@code ReadWriteLock} implementations must guarantee that
* the memory synchronization effects of <tt>writeLock</tt> operations * the memory synchronization effects of {@code writeLock} operations
* (as specified in the {@link Lock} interface) also hold with respect * (as specified in the {@link Lock} interface) also hold with respect
* to the associated <tt>readLock</tt>. That is, a thread successfully * to the associated {@code readLock}. That is, a thread successfully
* acquiring the read lock will see all updates made upon previous * acquiring the read lock will see all updates made upon previous
* release of the write lock. * release of the write lock.
* *
@ -120,14 +120,14 @@ public interface ReadWriteLock {
/** /**
* Returns the lock used for reading. * Returns the lock used for reading.
* *
* @return the lock used for reading. * @return the lock used for reading
*/ */
Lock readLock(); Lock readLock();
/** /**
* Returns the lock used for writing. * Returns the lock used for writing.
* *
* @return the lock used for writing. * @return the lock used for writing
*/ */
Lock writeLock(); Lock writeLock();
} }

View file

@ -64,7 +64,7 @@ import java.util.Collection;
* fair lock may obtain it multiple times in succession while other * fair lock may obtain it multiple times in succession while other
* active threads are not progressing and not currently holding the * active threads are not progressing and not currently holding the
* lock. * lock.
* Also note that the untimed {@link #tryLock() tryLock} method does not * Also note that the untimed {@link #tryLock()} method does not
* honor the fairness setting. It will succeed if the lock * honor the fairness setting. It will succeed if the lock
* is available even if other threads are waiting. * is available even if other threads are waiting.
* *
@ -88,10 +88,9 @@ import java.util.Collection;
* }}</pre> * }}</pre>
* *
* <p>In addition to implementing the {@link Lock} interface, this * <p>In addition to implementing the {@link Lock} interface, this
* class defines methods {@code isLocked} and * class defines a number of {@code public} and {@code protected}
* {@code getLockQueueLength}, as well as some associated * methods for inspecting the state of the lock. Some of these
* {@code protected} access methods that may be useful for * methods are only useful for instrumentation and monitoring.
* instrumentation and monitoring.
* *
* <p>Serialization of this class behaves in the same way as built-in * <p>Serialization of this class behaves in the same way as built-in
* locks: a deserialized lock is in the unlocked state, regardless of * locks: a deserialized lock is in the unlocked state, regardless of
@ -124,9 +123,8 @@ public class ReentrantLock implements Lock, java.io.Serializable {
abstract void lock(); abstract void lock();
/** /**
* Performs non-fair tryLock. tryAcquire is * Performs non-fair tryLock. tryAcquire is implemented in
* implemented in subclasses, but both need nonfair * subclasses, but both need nonfair try for trylock method.
* try for trylock method.
*/ */
final boolean nonfairTryAcquire(int acquires) { final boolean nonfairTryAcquire(int acquires) {
final Thread current = Thread.currentThread(); final Thread current = Thread.currentThread();
@ -538,10 +536,10 @@ public class ReentrantLock implements Lock, java.io.Serializable {
/** /**
* Queries if this lock is held by the current thread. * Queries if this lock is held by the current thread.
* *
* <p>Analogous to the {@link Thread#holdsLock} method for built-in * <p>Analogous to the {@link Thread#holdsLock(Object)} method for
* monitor locks, this method is typically used for debugging and * built-in monitor locks, this method is typically used for
* testing. For example, a method that should only be called while * debugging and testing. For example, a method that should only be
* a lock is held can assert that this is the case: * called while a lock is held can assert that this is the case:
* *
* <pre> {@code * <pre> {@code
* class X { * class X {

View file

@ -366,6 +366,8 @@ public class StampedLock implements java.io.Serializable {
* Behavior under timeout and interruption matches that specified * Behavior under timeout and interruption matches that specified
* for method {@link Lock#tryLock(long,TimeUnit)}. * for method {@link Lock#tryLock(long,TimeUnit)}.
* *
* @param time the maximum time to wait for the lock
* @param unit the time unit of the {@code time} argument
* @return a stamp that can be used to unlock or convert mode, * @return a stamp that can be used to unlock or convert mode,
* or zero if the lock is not available * or zero if the lock is not available
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
@ -445,6 +447,8 @@ public class StampedLock implements java.io.Serializable {
* Behavior under timeout and interruption matches that specified * Behavior under timeout and interruption matches that specified
* for method {@link Lock#tryLock(long,TimeUnit)}. * for method {@link Lock#tryLock(long,TimeUnit)}.
* *
* @param time the maximum time to wait for the lock
* @param unit the time unit of the {@code time} argument
* @return a stamp that can be used to unlock or convert mode, * @return a stamp that can be used to unlock or convert mode,
* or zero if the lock is not available * or zero if the lock is not available
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
@ -510,7 +514,8 @@ public class StampedLock implements java.io.Serializable {
* obtained from {@link #tryOptimisticRead} or a locking method * obtained from {@link #tryOptimisticRead} or a locking method
* for this lock has no defined effect or result. * for this lock has no defined effect or result.
* *
* @return true if the lock has not been exclusively acquired * @param stamp a stamp
* @return {@code true} if the lock has not been exclusively acquired
* since issuance of the given stamp; else false * since issuance of the given stamp; else false
*/ */
public boolean validate(long stamp) { public boolean validate(long stamp) {
@ -723,7 +728,7 @@ public class StampedLock implements java.io.Serializable {
* stamp value. This method may be useful for recovery after * stamp value. This method may be useful for recovery after
* errors. * errors.
* *
* @return true if the lock was held, else false * @return {@code true} if the lock was held, else false
*/ */
public boolean tryUnlockWrite() { public boolean tryUnlockWrite() {
long s; WNode h; long s; WNode h;
@ -741,7 +746,7 @@ public class StampedLock implements java.io.Serializable {
* requiring a stamp value. This method may be useful for recovery * requiring a stamp value. This method may be useful for recovery
* after errors. * after errors.
* *
* @return true if the read lock was held, else false * @return {@code true} if the read lock was held, else false
*/ */
public boolean tryUnlockRead() { public boolean tryUnlockRead() {
long s, m; WNode h; long s, m; WNode h;
@ -773,18 +778,18 @@ public class StampedLock implements java.io.Serializable {
} }
/** /**
* Returns true if the lock is currently held exclusively. * Returns {@code true} if the lock is currently held exclusively.
* *
* @return true if the lock is currently held exclusively * @return {@code true} if the lock is currently held exclusively
*/ */
public boolean isWriteLocked() { public boolean isWriteLocked() {
return (state & WBIT) != 0L; return (state & WBIT) != 0L;
} }
/** /**
* Returns true if the lock is currently held non-exclusively. * Returns {@code true} if the lock is currently held non-exclusively.
* *
* @return true if the lock is currently held non-exclusively * @return {@code true} if the lock is currently held non-exclusively
*/ */
public boolean isReadLocked() { public boolean isReadLocked() {
return (state & RBITS) != 0L; return (state & RBITS) != 0L;