8211283: Miscellaneous changes imported from jsr166 CVS 2018-11

Reviewed-by: martin, chegar
This commit is contained in:
Doug Lea 2018-11-28 15:25:14 -08:00
parent 5a5aa52772
commit 53d3a4f50c
14 changed files with 218 additions and 213 deletions

View file

@ -37,7 +37,6 @@ package java.util;
import java.io.Serializable;
import java.util.function.Consumer;
import java.util.function.Predicate;
import jdk.internal.access.SharedSecrets;
/**

View file

@ -2542,6 +2542,8 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
setTabAt(tab, i, fwd);
advance = true;
}
else if (f instanceof ReservationNode)
throw new IllegalStateException("Recursive update");
}
}
}

View file

@ -564,8 +564,8 @@ public class Exchanger<V> {
Object item = (x == null) ? NULL_ITEM : x; // translate null args
if (((a = arena) != null ||
(v = slotExchange(item, false, 0L)) == null) &&
((Thread.interrupted() || // disambiguates null return
(v = arenaExchange(item, false, 0L)) == null)))
(Thread.interrupted() || // disambiguates null return
(v = arenaExchange(item, false, 0L)) == null))
throw new InterruptedException();
return (v == NULL_ITEM) ? null : (V)v;
}
@ -620,8 +620,8 @@ public class Exchanger<V> {
long ns = unit.toNanos(timeout);
if ((arena != null ||
(v = slotExchange(item, true, ns)) == null) &&
((Thread.interrupted() ||
(v = arenaExchange(item, true, ns)) == null)))
(Thread.interrupted() ||
(v = arenaExchange(item, true, ns)) == null))
throw new InterruptedException();
if (v == TIMED_OUT)
throw new TimeoutException();

View file

@ -1230,14 +1230,13 @@ public abstract class ForkJoinTask<V> implements Future<V>, Serializable {
/**
* Immediately performs the base action of this task and returns
* true if, upon return from this method, this task is guaranteed
* to have completed normally. This method may return false
* otherwise, to indicate that this task is not necessarily
* complete (or is not known to be complete), for example in
* asynchronous actions that require explicit invocations of
* completion methods. This method may also throw an (unchecked)
* exception to indicate abnormal exit. This method is designed to
* support extensions, and should not in general be called
* otherwise.
* to have completed. This method may return false otherwise, to
* indicate that this task is not necessarily complete (or is not
* known to be complete), for example in asynchronous actions that
* require explicit invocations of completion methods. This method
* may also throw an (unchecked) exception to indicate abnormal
* exit. This method is designed to support extensions, and should
* not in general be called otherwise.
*
* @return {@code true} if this task is known to have completed normally
*/

View file

@ -199,10 +199,11 @@ public class LockSupport {
* Disables the current thread for thread scheduling purposes, for up to
* the specified waiting time, unless the permit is available.
*
* <p>If the permit is available then it is consumed and the call
* returns immediately; otherwise the current thread becomes disabled
* for thread scheduling purposes and lies dormant until one of four
* things happens:
* <p>If the specified waiting time is zero or negative, the
* method does nothing. Otherwise, if the permit is available then
* it is consumed and the call returns immediately; otherwise the
* current thread becomes disabled for thread scheduling purposes
* and lies dormant until one of four things happens:
*
* <ul>
* <li>Some other thread invokes {@link #unpark unpark} with the
@ -327,10 +328,11 @@ public class LockSupport {
* Disables the current thread for thread scheduling purposes, for up to
* the specified waiting time, unless the permit is available.
*
* <p>If the permit is available then it is consumed and the call
* returns immediately; otherwise the current thread becomes disabled
* for thread scheduling purposes and lies dormant until one of four
* things happens:
* <p>If the specified waiting time is zero or negative, the
* method does nothing. Otherwise, if the permit is available then
* it is consumed and the call returns immediately; otherwise the
* current thread becomes disabled for thread scheduling purposes
* and lies dormant until one of four things happens:
*
* <ul>
* <li>Some other thread invokes {@link #unpark unpark} with the

View file

@ -65,22 +65,23 @@ import jdk.internal.vm.annotation.ReservedStackAccess;
* and timed versions of {@code tryReadLock} are also provided.
*
* <li><b>Optimistic Reading.</b> Method {@link #tryOptimisticRead}
* returns a non-zero stamp only if the lock is not currently held
* in write mode. Method {@link #validate} returns true if the lock
* has not been acquired in write mode since obtaining a given
* stamp. This mode can be thought of as an extremely weak version
* of a read-lock, that can be broken by a writer at any time. The
* use of optimistic mode for short read-only code segments often
* reduces contention and improves throughput. However, its use is
* inherently fragile. Optimistic read sections should only read
* fields and hold them in local variables for later use after
* validation. Fields read while in optimistic mode may be wildly
* inconsistent, so usage applies only when you are familiar enough
* with data representations to check consistency and/or repeatedly
* invoke method {@code validate()}. For example, such steps are
* typically required when first reading an object or array
* reference, and then accessing one of its fields, elements or
* methods.
* returns a non-zero stamp only if the lock is not currently held in
* write mode. Method {@link #validate} returns true if the lock has not
* been acquired in write mode since obtaining a given stamp, in which
* case all actions prior to the most recent write lock release
* happen-before actions following the call to {@code tryOptimisticRead}.
* This mode can be thought of as an extremely weak version of a
* read-lock, that can be broken by a writer at any time. The use of
* optimistic read mode for short read-only code segments often reduces
* contention and improves throughput. However, its use is inherently
* fragile. Optimistic read sections should only read fields and hold
* them in local variables for later use after validation. Fields read
* while in optimistic read mode may be wildly inconsistent, so usage
* applies only when you are familiar enough with data representations to
* check consistency and/or repeatedly invoke method {@code validate()}.
* For example, such steps are typically required when first reading an
* object or array reference, and then accessing one of its fields,
* elements or methods.
*
* </ul>
*
@ -88,8 +89,8 @@ import jdk.internal.vm.annotation.ReservedStackAccess;
* conversions across the three modes. For example, method {@link
* #tryConvertToWriteLock} attempts to "upgrade" a mode, returning
* a valid write stamp if (1) already in writing mode (2) in reading
* mode and there are no other readers or (3) in optimistic mode and
* the lock is available. The forms of these methods are designed to
* mode and there are no other readers or (3) in optimistic read mode
* and the lock is available. The forms of these methods are designed to
* help reduce some of the code bloat that otherwise occurs in
* retry-based designs.
*
@ -129,6 +130,19 @@ import jdk.internal.vm.annotation.ReservedStackAccess;
* #asReadWriteLock()} in applications requiring only the associated
* set of functionality.
*
* <p><b>Memory Synchronization.</b> Methods with the effect of
* successfully locking in any mode have the same memory
* synchronization effects as a <em>Lock</em> action described in
* <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.4">
* Chapter 17 of <cite>The Java&trade; Language Specification</cite></a>.
* Methods successfully unlocking in write mode have the same memory
* synchronization effects as an <em>Unlock</em> action. In optimistic
* read usages, actions prior to the most recent write mode unlock action
* are guaranteed to happen-before those following a tryOptimisticRead
* only if a later validate returns true; otherwise there is no guarantee
* that the reads between tryOptimisticRead and validate obtain a
* consistent snapshot.
*
* <p><b>Sample Usage.</b> The following illustrates some usage idioms
* in a class that maintains simple two-dimensional points. The sample
* code illustrates some try/catch conventions even though they are