ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java (file contents):
Revision 1.238 by jsr166, Thu Jul 18 18:21:22 2013 UTC vs.
Revision 1.254 by jsr166, Sun Dec 1 16:56:07 2013 UTC

# Line 14 | Line 14 | import java.util.AbstractMap;
14   import java.util.Arrays;
15   import java.util.Collection;
16   import java.util.Comparator;
17 import java.util.ConcurrentModificationException;
17   import java.util.Enumeration;
18   import java.util.HashMap;
19   import java.util.Hashtable;
# Line 65 | Line 64 | import java.util.stream.Stream;
64   * that key reporting the updated value.)  For aggregate operations
65   * such as {@code putAll} and {@code clear}, concurrent retrievals may
66   * reflect insertion or removal of only some entries.  Similarly,
67 < * Iterators and Enumerations return elements reflecting the state of
68 < * the hash table at some point at or since the creation of the
67 > * Iterators, Spliterators and Enumerations return elements reflecting the
68 > * state of the hash table at some point at or since the creation of the
69   * iterator/enumeration.  They do <em>not</em> throw {@link
70 < * ConcurrentModificationException}.  However, iterators are designed
71 < * to be used by only one thread at a time.  Bear in mind that the
72 < * results of aggregate status methods including {@code size}, {@code
73 < * isEmpty}, and {@code containsValue} are typically useful only when
74 < * a map is not undergoing concurrent updates in other threads.
70 > * java.util.ConcurrentModificationException ConcurrentModificationException}.
71 > * However, iterators are designed to be used by only one thread at a time.
72 > * Bear in mind that the results of aggregate status methods including
73 > * {@code size}, {@code isEmpty}, and {@code containsValue} are typically
74 > * useful only when a map is not undergoing concurrent updates in other threads.
75   * Otherwise the results of these methods reflect transient states
76   * that may be adequate for monitoring or estimation purposes, but not
77   * for program control.
# Line 236 | Line 235 | import java.util.stream.Stream;
235   * @param <K> the type of keys maintained by this map
236   * @param <V> the type of mapped values
237   */
238 < public class ConcurrentHashMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>, Serializable {
238 > public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
239 >    implements ConcurrentMap<K,V>, Serializable {
240      private static final long serialVersionUID = 7249069246763182397L;
241  
242      /*
# Line 344 | Line 344 | public class ConcurrentHashMap<K,V> exte
344       * The table is resized when occupancy exceeds a percentage
345       * threshold (nominally, 0.75, but see below).  Any thread
346       * noticing an overfull bin may assist in resizing after the
347 <     * initiating thread allocates and sets up the replacement
348 <     * array. However, rather than stalling, these other threads may
349 <     * proceed with insertions etc.  The use of TreeBins shields us
350 <     * from the worst case effects of overfilling while resizes are in
347 >     * initiating thread allocates and sets up the replacement array.
348 >     * However, rather than stalling, these other threads may proceed
349 >     * with insertions etc.  The use of TreeBins shields us from the
350 >     * worst case effects of overfilling while resizes are in
351       * progress.  Resizing proceeds by transferring bins, one by one,
352 <     * from the table to the next table. To enable concurrency, the
353 <     * next table must be (incrementally) prefilled with place-holders
354 <     * serving as reverse forwarders to the old table.  Because we are
352 >     * from the table to the next table. However, threads claim small
353 >     * blocks of indices to transfer (via field transferIndex) before
354 >     * doing so, reducing contention.  A generation stamp in field
355 >     * sizeCtl ensures that resizings do not overlap. Because we are
356       * using power-of-two expansion, the elements from each bin must
357       * either stay at same index, or move with a power of two
358       * offset. We eliminate unnecessary node creation by catching
# Line 372 | Line 373 | public class ConcurrentHashMap<K,V> exte
373       * locks, average aggregate waits become shorter as resizing
374       * progresses.  The transfer operation must also ensure that all
375       * accessible bins in both the old and new table are usable by any
376 <     * traversal.  This is arranged by proceeding from the last bin
377 <     * (table.length - 1) up towards the first.  Upon seeing a
378 <     * forwarding node, traversals (see class Traverser) arrange to
379 <     * move to the new table without revisiting nodes.  However, to
380 <     * ensure that no intervening nodes are skipped, bin splitting can
381 <     * only begin after the associated reverse-forwarders are in
382 <     * place.
376 >     * traversal.  This is arranged in part by proceeding from the
377 >     * last bin (table.length - 1) up towards the first.  Upon seeing
378 >     * a forwarding node, traversals (see class Traverser) arrange to
379 >     * move to the new table without revisiting nodes.  To ensure that
380 >     * no intervening nodes are skipped even when moved out of order,
381 >     * a stack (see class TableStack) is created on first encounter of
382 >     * a forwarding node during a traversal, to maintain its place if
383 >     * later processing the current table. The need for these
384 >     * save/restore mechanics is relatively rare, but when one
385 >     * forwarding node is encountered, typically many more will be.
386 >     * So Traversers use a simple caching scheme to avoid creating so
387 >     * many new TableStack nodes. (Thanks to Peter Levart for
388 >     * suggesting use of a stack here.)
389       *
390       * The traversal scheme also applies to partial traversals of
391       * ranges of bins (via an alternate Traverser constructor)
# Line 410 | Line 417 | public class ConcurrentHashMap<K,V> exte
417       * related operations (which is the main reason we cannot use
418       * existing collections such as TreeMaps). TreeBins contain
419       * Comparable elements, but may contain others, as well as
420 <     * elements that are Comparable but not necessarily Comparable
421 <     * for the same T, so we cannot invoke compareTo among them. To
422 <     * handle this, the tree is ordered primarily by hash value, then
423 <     * by Comparable.compareTo order if applicable.  On lookup at a
424 <     * node, if elements are not comparable or compare as 0 then both
425 <     * left and right children may need to be searched in the case of
426 <     * tied hash values. (This corresponds to the full list search
427 <     * that would be necessary if all elements were non-Comparable and
428 <     * had tied hashes.)  The red-black balancing code is updated from
429 <     * pre-jdk-collections
420 >     * elements that are Comparable but not necessarily Comparable for
421 >     * the same T, so we cannot invoke compareTo among them. To handle
422 >     * this, the tree is ordered primarily by hash value, then by
423 >     * Comparable.compareTo order if applicable.  On lookup at a node,
424 >     * if elements are not comparable or compare as 0 then both left
425 >     * and right children may need to be searched in the case of tied
426 >     * hash values. (This corresponds to the full list search that
427 >     * would be necessary if all elements were non-Comparable and had
428 >     * tied hashes.) On insertion, to keep a total ordering (or as
429 >     * close as is required here) across rebalancings, we compare
430 >     * classes and identityHashCodes as tie-breakers. The red-black
431 >     * balancing code is updated from pre-jdk-collections
432       * (http://gee.cs.oswego.edu/dl/classes/collections/RBCell.java)
433       * based in turn on Cormen, Leiserson, and Rivest "Introduction to
434       * Algorithms" (CLR).
# Line 449 | Line 458 | public class ConcurrentHashMap<K,V> exte
458       * unused "Segment" class that is instantiated in minimal form
459       * only when serializing.
460       *
461 +     * Also, solely for compatibility with previous versions of this
462 +     * class, it extends AbstractMap, even though all of its methods
463 +     * are overridden, so it is just useless baggage.
464 +     *
465       * This file is organized to make things a little easier to follow
466       * while reading than they might otherwise: First the main static
467       * declarations and utilities, then fields, then main public
# Line 529 | Line 542 | public class ConcurrentHashMap<K,V> exte
542       */
543      private static final int MIN_TRANSFER_STRIDE = 16;
544  
545 +    /**
546 +     * The number of bits used for generation stamp in sizeCtl.
547 +     * Must be at least 6 for 32bit arrays.
548 +     */
549 +    private static int RESIZE_STAMP_BITS = 16;
550 +
551 +    /**
552 +     * The maximum number of threads that can help resize.
553 +     * Must fit in 32 - RESIZE_STAMP_BITS bits.
554 +     */
555 +    private static final int MAX_RESIZERS = (1 << (32 - RESIZE_STAMP_BITS)) - 1;
556 +
557 +    /**
558 +     * The bit shift for recording size stamp in sizeCtl.
559 +     */
560 +    private static final int RESIZE_STAMP_SHIFT = 32 - RESIZE_STAMP_BITS;
561 +
562      /*
563       * Encodings for Node hash fields. See above for explanation.
564       */
# Line 686 | Line 716 | public class ConcurrentHashMap<K,V> exte
716       * errors by users, these checks must operate on local variables,
717       * which accounts for some odd-looking inline assignments below.
718       * Note that calls to setTabAt always occur within locked regions,
719 <     * and so in principle require only release ordering, not need
719 >     * and so in principle require only release ordering, not
720       * full volatile semantics, but are currently coded as volatile
721       * writes to be conservative.
722       */
# Line 741 | Line 771 | public class ConcurrentHashMap<K,V> exte
771      private transient volatile int transferIndex;
772  
773      /**
744     * The least available table index to split while resizing.
745     */
746    private transient volatile int transferOrigin;
747
748    /**
774       * Spinlock (locked via CAS) used when resizing and/or creating CounterCells.
775       */
776      private transient volatile int cellsBusy;
# Line 1164 | Line 1189 | public class ConcurrentHashMap<K,V> exte
1189       * operations.  It does not support the {@code add} or
1190       * {@code addAll} operations.
1191       *
1192 <     * <p>The view's {@code iterator} is a "weakly consistent" iterator
1193 <     * that will never throw {@link ConcurrentModificationException},
1194 <     * and guarantees to traverse elements as they existed upon
1195 <     * construction of the iterator, and may (but is not guaranteed to)
1196 <     * reflect any modifications subsequent to construction.
1192 >     * <p>The view's iterators and spliterators are
1193 >     * <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>.
1194 >     *
1195 >     * <p>The view's {@code spliterator} reports {@link Spliterator#CONCURRENT},
1196 >     * {@link Spliterator#DISTINCT}, and {@link Spliterator#NONNULL}.
1197       *
1198       * @return the set view
1199       */
# Line 1187 | Line 1212 | public class ConcurrentHashMap<K,V> exte
1212       * {@code retainAll}, and {@code clear} operations.  It does not
1213       * support the {@code add} or {@code addAll} operations.
1214       *
1215 <     * <p>The view's {@code iterator} is a "weakly consistent" iterator
1216 <     * that will never throw {@link ConcurrentModificationException},
1217 <     * and guarantees to traverse elements as they existed upon
1218 <     * construction of the iterator, and may (but is not guaranteed to)
1219 <     * reflect any modifications subsequent to construction.
1215 >     * <p>The view's iterators and spliterators are
1216 >     * <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>.
1217 >     *
1218 >     * <p>The view's {@code spliterator} reports {@link Spliterator#CONCURRENT}
1219 >     * and {@link Spliterator#NONNULL}.
1220       *
1221       * @return the collection view
1222       */
# Line 1209 | Line 1234 | public class ConcurrentHashMap<K,V> exte
1234       * {@code removeAll}, {@code retainAll}, and {@code clear}
1235       * operations.
1236       *
1237 <     * <p>The view's {@code iterator} is a "weakly consistent" iterator
1238 <     * that will never throw {@link ConcurrentModificationException},
1239 <     * and guarantees to traverse elements as they existed upon
1240 <     * construction of the iterator, and may (but is not guaranteed to)
1241 <     * reflect any modifications subsequent to construction.
1237 >     * <p>The view's iterators and spliterators are
1238 >     * <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>.
1239 >     *
1240 >     * <p>The view's {@code spliterator} reports {@link Spliterator#CONCURRENT},
1241 >     * {@link Spliterator#DISTINCT}, and {@link Spliterator#NONNULL}.
1242       *
1243       * @return the set view
1244       */
# Line 1341 | Line 1366 | public class ConcurrentHashMap<K,V> exte
1366          }
1367          int segmentShift = 32 - sshift;
1368          int segmentMask = ssize - 1;
1369 <        @SuppressWarnings("unchecked") Segment<K,V>[] segments = (Segment<K,V>[])
1369 >        @SuppressWarnings("unchecked")
1370 >        Segment<K,V>[] segments = (Segment<K,V>[])
1371              new Segment<?,?>[DEFAULT_CONCURRENCY_LEVEL];
1372          for (int i = 0; i < segments.length; ++i)
1373              segments[i] = new Segment<K,V>(LOAD_FACTOR);
# Line 1384 | Line 1410 | public class ConcurrentHashMap<K,V> exte
1410          long size = 0L;
1411          Node<K,V> p = null;
1412          for (;;) {
1413 <            @SuppressWarnings("unchecked") K k = (K) s.readObject();
1414 <            @SuppressWarnings("unchecked") V v = (V) s.readObject();
1413 >            @SuppressWarnings("unchecked")
1414 >            K k = (K) s.readObject();
1415 >            @SuppressWarnings("unchecked")
1416 >            V v = (V) s.readObject();
1417              if (k != null && v != null) {
1418                  p = new Node<K,V>(spread(k.hashCode()), k, v, p);
1419                  ++size;
# Line 1403 | Line 1431 | public class ConcurrentHashMap<K,V> exte
1431                  int sz = (int)size;
1432                  n = tableSizeFor(sz + (sz >>> 1) + 1);
1433              }
1434 <            @SuppressWarnings({"rawtypes","unchecked"})
1435 <                Node<K,V>[] tab = (Node<K,V>[])new Node[n];
1434 >            @SuppressWarnings("unchecked")
1435 >            Node<K,V>[] tab = (Node<K,V>[])new Node<?,?>[n];
1436              int mask = n - 1;
1437              long added = 0L;
1438              while (p != null) {
# Line 1993 | Line 2021 | public class ConcurrentHashMap<K,V> exte
2021  
2022      /**
2023       * Legacy method testing if some key maps into the specified value
2024 <     * in this table.  This method is identical in functionality to
2024 >     * in this table.
2025 >     *
2026 >     * @deprecated This method is identical in functionality to
2027       * {@link #containsValue(Object)}, and exists solely to ensure
2028       * full compatibility with class {@link java.util.Hashtable},
2029       * which supported this method prior to introduction of the
# Line 2006 | Line 2036 | public class ConcurrentHashMap<K,V> exte
2036       *         {@code false} otherwise
2037       * @throws NullPointerException if the specified value is null
2038       */
2039 <    @Deprecated public boolean contains(Object value) {
2039 >    @Deprecated
2040 >    public boolean contains(Object value) {
2041          return containsValue(value);
2042      }
2043  
# Line 2071 | Line 2102 | public class ConcurrentHashMap<K,V> exte
2102       * @param initialCapacity The implementation performs internal
2103       * sizing to accommodate this many elements.
2104       * @param <K> the element type of the returned set
2105 +     * @return the new set
2106       * @throws IllegalArgumentException if the initial capacity of
2107       * elements is negative
2076     * @return the new set
2108       * @since 1.8
2109       */
2110      public static <K> KeySetView<K,Boolean> newKeySet(int initialCapacity) {
# Line 2153 | Line 2184 | public class ConcurrentHashMap<K,V> exte
2184      /* ---------------- Table Initialization and Resizing -------------- */
2185  
2186      /**
2187 +     * Returns the stamp bits for resizing a table of size n.
2188 +     * Must be negative when shifted left by RESIZE_STAMP_SHIFT.
2189 +     */
2190 +    static final int resizeStamp(int n) {
2191 +        return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1));
2192 +    }
2193 +
2194 +    /**
2195       * Initializes table, using the size recorded in sizeCtl.
2196       */
2197      private final Node<K,V>[] initTable() {
# Line 2164 | Line 2203 | public class ConcurrentHashMap<K,V> exte
2203                  try {
2204                      if ((tab = table) == null || tab.length == 0) {
2205                          int n = (sc > 0) ? sc : DEFAULT_CAPACITY;
2206 <                        @SuppressWarnings({"rawtypes","unchecked"})
2207 <                            Node<K,V>[] nt = (Node<K,V>[])new Node[n];
2206 >                        @SuppressWarnings("unchecked")
2207 >                        Node<K,V>[] nt = (Node<K,V>[])new Node<?,?>[n];
2208                          table = tab = nt;
2209                          sc = n - (n >>> 2);
2210                      }
# Line 2206 | Line 2245 | public class ConcurrentHashMap<K,V> exte
2245              s = sumCount();
2246          }
2247          if (check >= 0) {
2248 <            Node<K,V>[] tab, nt; int sc;
2248 >            Node<K,V>[] tab, nt; int n, sc;
2249              while (s >= (long)(sc = sizeCtl) && (tab = table) != null &&
2250 <                   tab.length < MAXIMUM_CAPACITY) {
2250 >                   (n = tab.length) < MAXIMUM_CAPACITY) {
2251 >                int rs = resizeStamp(n);
2252                  if (sc < 0) {
2253 <                    if (sc == -1 || transferIndex <= transferOrigin ||
2254 <                        (nt = nextTable) == null)
2253 >                    if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2254 >                        sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
2255 >                        transferIndex <= 0)
2256                          break;
2257 <                    if (U.compareAndSwapInt(this, SIZECTL, sc, sc - 1))
2257 >                    if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1))
2258                          transfer(tab, nt);
2259                  }
2260 <                else if (U.compareAndSwapInt(this, SIZECTL, sc, -2))
2260 >                else if (U.compareAndSwapInt(this, SIZECTL, sc,
2261 >                                             (rs << RESIZE_STAMP_SHIFT) + 2))
2262                      transfer(tab, null);
2263                  s = sumCount();
2264              }
# Line 2228 | Line 2270 | public class ConcurrentHashMap<K,V> exte
2270       */
2271      final Node<K,V>[] helpTransfer(Node<K,V>[] tab, Node<K,V> f) {
2272          Node<K,V>[] nextTab; int sc;
2273 <        if ((f instanceof ForwardingNode) &&
2273 >        if (tab != null && (f instanceof ForwardingNode) &&
2274              (nextTab = ((ForwardingNode<K,V>)f).nextTable) != null) {
2275 <            if (nextTab == nextTable && tab == table &&
2276 <                transferIndex > transferOrigin && (sc = sizeCtl) < -1 &&
2277 <                U.compareAndSwapInt(this, SIZECTL, sc, sc - 1))
2278 <                transfer(tab, nextTab);
2275 >            int rs = resizeStamp(tab.length);
2276 >            while (nextTab == nextTable && table == tab &&
2277 >                   (sc = sizeCtl) < 0) {
2278 >                if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2279 >                    sc == rs + MAX_RESIZERS || transferIndex <= 0)
2280 >                    break;
2281 >                if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) {
2282 >                    transfer(tab, nextTab);
2283 >                    break;
2284 >                }
2285 >            }
2286              return nextTab;
2287          }
2288          return table;
# Line 2255 | Line 2304 | public class ConcurrentHashMap<K,V> exte
2304                  if (U.compareAndSwapInt(this, SIZECTL, sc, -1)) {
2305                      try {
2306                          if (table == tab) {
2307 <                            @SuppressWarnings({"rawtypes","unchecked"})
2308 <                                Node<K,V>[] nt = (Node<K,V>[])new Node[n];
2307 >                            @SuppressWarnings("unchecked")
2308 >                            Node<K,V>[] nt = (Node<K,V>[])new Node<?,?>[n];
2309                              table = nt;
2310                              sc = n - (n >>> 2);
2311                          }
# Line 2267 | Line 2316 | public class ConcurrentHashMap<K,V> exte
2316              }
2317              else if (c <= sc || n >= MAXIMUM_CAPACITY)
2318                  break;
2319 <            else if (tab == table &&
2320 <                     U.compareAndSwapInt(this, SIZECTL, sc, -2))
2321 <                transfer(tab, null);
2319 >            else if (tab == table) {
2320 >                int rs = resizeStamp(n);
2321 >                if (sc < 0) {
2322 >                    Node<K,V>[] nt;
2323 >                    if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2324 >                        sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
2325 >                        transferIndex <= 0)
2326 >                        break;
2327 >                    if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1))
2328 >                        transfer(tab, nt);
2329 >                }
2330 >                else if (U.compareAndSwapInt(this, SIZECTL, sc,
2331 >                                             (rs << RESIZE_STAMP_SHIFT) + 2))
2332 >                    transfer(tab, null);
2333 >            }
2334          }
2335      }
2336  
# Line 2283 | Line 2344 | public class ConcurrentHashMap<K,V> exte
2344              stride = MIN_TRANSFER_STRIDE; // subdivide range
2345          if (nextTab == null) {            // initiating
2346              try {
2347 <                @SuppressWarnings({"rawtypes","unchecked"})
2348 <                    Node<K,V>[] nt = (Node<K,V>[])new Node[n << 1];
2347 >                @SuppressWarnings("unchecked")
2348 >                Node<K,V>[] nt = (Node<K,V>[])new Node<?,?>[n << 1];
2349                  nextTab = nt;
2350              } catch (Throwable ex) {      // try to cope with OOME
2351                  sizeCtl = Integer.MAX_VALUE;
2352                  return;
2353              }
2354              nextTable = nextTab;
2294            transferOrigin = n;
2355              transferIndex = n;
2296            ForwardingNode<K,V> rev = new ForwardingNode<K,V>(tab);
2297            for (int k = n; k > 0;) {    // progressively reveal ready slots
2298                int nextk = (k > stride) ? k - stride : 0;
2299                for (int m = nextk; m < k; ++m)
2300                    nextTab[m] = rev;
2301                for (int m = n + nextk; m < n + k; ++m)
2302                    nextTab[m] = rev;
2303                U.putOrderedInt(this, TRANSFERORIGIN, k = nextk);
2304            }
2356          }
2357          int nextn = nextTab.length;
2358          ForwardingNode<K,V> fwd = new ForwardingNode<K,V>(nextTab);
2359          boolean advance = true;
2360          boolean finishing = false; // to ensure sweep before committing nextTab
2361          for (int i = 0, bound = 0;;) {
2362 <            int nextIndex, nextBound, fh; Node<K,V> f;
2362 >            Node<K,V> f; int fh;
2363              while (advance) {
2364 +                int nextIndex, nextBound;
2365                  if (--i >= bound || finishing)
2366                      advance = false;
2367 <                else if ((nextIndex = transferIndex) <= transferOrigin) {
2367 >                else if ((nextIndex = transferIndex) <= 0) {
2368                      i = -1;
2369                      advance = false;
2370                  }
# Line 2326 | Line 2378 | public class ConcurrentHashMap<K,V> exte
2378                  }
2379              }
2380              if (i < 0 || i >= n || i + n >= nextn) {
2381 +                int sc;
2382                  if (finishing) {
2383                      nextTable = null;
2384                      table = nextTab;
2385                      sizeCtl = (n << 1) - (n >>> 1);
2386                      return;
2387                  }
2388 <                for (int sc;;) {
2389 <                    if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, ++sc)) {
2390 <                        if (sc != -1)
2391 <                            return;
2392 <                        finishing = advance = true;
2340 <                        i = n; // recheck before commit
2341 <                        break;
2342 <                    }
2343 <                }
2344 <            }
2345 <            else if ((f = tabAt(tab, i)) == null) {
2346 <                if (casTabAt(tab, i, null, fwd)) {
2347 <                    setTabAt(nextTab, i, null);
2348 <                    setTabAt(nextTab, i + n, null);
2349 <                    advance = true;
2388 >                if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, sc - 1)) {
2389 >                    if ((sc - 2) != resizeStamp(n))
2390 >                        return;
2391 >                    finishing = advance = true;
2392 >                    i = n; // recheck before commit
2393                  }
2394              }
2395 +            else if ((f = tabAt(tab, i)) == null)
2396 +                advance = casTabAt(tab, i, null, fwd);
2397              else if ((fh = f.hash) == MOVED)
2398                  advance = true; // already processed
2399              else {
# Line 2540 | Line 2585 | public class ConcurrentHashMap<K,V> exte
2585      private final void treeifyBin(Node<K,V>[] tab, int index) {
2586          Node<K,V> b; int n, sc;
2587          if (tab != null) {
2588 <            if ((n = tab.length) < MIN_TREEIFY_CAPACITY) {
2589 <                if (tab == table && (sc = sizeCtl) >= 0 &&
2545 <                    U.compareAndSwapInt(this, SIZECTL, sc, -2))
2546 <                    transfer(tab, null);
2547 <            }
2588 >            if ((n = tab.length) < MIN_TREEIFY_CAPACITY)
2589 >                tryPresize(n << 1);
2590              else if ((b = tabAt(tab, index)) != null && b.hash >= 0) {
2591                  synchronized (b) {
2592                      if (tabAt(tab, index) == b) {
# Line 2620 | Line 2662 | public class ConcurrentHashMap<K,V> exte
2662                          p = pr;
2663                      else if ((pk = p.key) == k || (pk != null && k.equals(pk)))
2664                          return p;
2665 <                    else if (pl == null && pr == null)
2666 <                        break;
2665 >                    else if (pl == null)
2666 >                        p = pr;
2667 >                    else if (pr == null)
2668 >                        p = pl;
2669                      else if ((kc != null ||
2670                                (kc = comparableClassFor(k)) != null) &&
2671                               (dir = compareComparables(kc, k, pk)) != 0)
2672                          p = (dir < 0) ? pl : pr;
2673 <                    else if (pl == null)
2630 <                        p = pr;
2631 <                    else if (pr == null ||
2632 <                             (q = pr.findTreeNode(h, k, kc)) == null)
2633 <                        p = pl;
2634 <                    else
2673 >                    else if ((q = pr.findTreeNode(h, k, kc)) != null)
2674                          return q;
2675 +                    else
2676 +                        p = pl;
2677                  } while (p != null);
2678              }
2679              return null;
# Line 2659 | Line 2700 | public class ConcurrentHashMap<K,V> exte
2700          static final int READER = 4; // increment value for setting read lock
2701  
2702          /**
2703 +         * Tie-breaking utility for ordering insertions when equal
2704 +         * hashCodes and non-comparable. We don't require a total
2705 +         * order, just a consistent insertion rule to maintain
2706 +         * equivalence across rebalancings. Tie-breaking further than
2707 +         * necessary simplifies testing a bit.
2708 +         */
2709 +        static int tieBreakOrder(Object a, Object b) {
2710 +            int d;
2711 +            if (a == null || b == null ||
2712 +                (d = a.getClass().getName().
2713 +                 compareTo(b.getClass().getName())) == 0)
2714 +                d = (System.identityHashCode(a) <= System.identityHashCode(b) ?
2715 +                     -1 : 1);
2716 +            return d;
2717 +        }
2718 +
2719 +        /**
2720           * Creates bin with initial set of nodes headed by b.
2721           */
2722          TreeBin(TreeNode<K,V> b) {
# Line 2674 | Line 2732 | public class ConcurrentHashMap<K,V> exte
2732                      r = x;
2733                  }
2734                  else {
2735 <                    Object key = x.key;
2736 <                    int hash = x.hash;
2735 >                    K k = x.key;
2736 >                    int h = x.hash;
2737                      Class<?> kc = null;
2738                      for (TreeNode<K,V> p = r;;) {
2739                          int dir, ph;
2740 <                        if ((ph = p.hash) > hash)
2740 >                        K pk = p.key;
2741 >                        if ((ph = p.hash) > h)
2742                              dir = -1;
2743 <                        else if (ph < hash)
2743 >                        else if (ph < h)
2744                              dir = 1;
2745 <                        else if ((kc != null ||
2746 <                                  (kc = comparableClassFor(key)) != null))
2747 <                            dir = compareComparables(kc, key, p.key);
2748 <                        else
2749 <                            dir = 0;
2691 <                        TreeNode<K,V> xp = p;
2745 >                        else if ((kc == null &&
2746 >                                  (kc = comparableClassFor(k)) == null) ||
2747 >                                 (dir = compareComparables(kc, k, pk)) == 0)
2748 >                            dir = tieBreakOrder(k, pk);
2749 >                            TreeNode<K,V> xp = p;
2750                          if ((p = (dir <= 0) ? p.left : p.right) == null) {
2751                              x.parent = xp;
2752                              if (dir <= 0)
# Line 2702 | Line 2760 | public class ConcurrentHashMap<K,V> exte
2760                  }
2761              }
2762              this.root = r;
2763 +            assert checkInvariants(root);
2764          }
2765  
2766          /**
# Line 2725 | Line 2784 | public class ConcurrentHashMap<K,V> exte
2784          private final void contendedLock() {
2785              boolean waiting = false;
2786              for (int s;;) {
2787 <                if (((s = lockState) & WRITER) == 0) {
2787 >                if (((s = lockState) & ~WAITER) == 0) {
2788                      if (U.compareAndSwapInt(this, LOCKSTATE, s, WRITER)) {
2789                          if (waiting)
2790                              waiter = null;
2791                          return;
2792                      }
2793                  }
2794 <                else if ((s | WAITER) == 0) {
2794 >                else if ((s & WAITER) == 0) {
2795                      if (U.compareAndSwapInt(this, LOCKSTATE, s, s | WAITER)) {
2796                          waiting = true;
2797                          waiter = Thread.currentThread();
# Line 2750 | Line 2809 | public class ConcurrentHashMap<K,V> exte
2809           */
2810          final Node<K,V> find(int h, Object k) {
2811              if (k != null) {
2812 <                for (Node<K,V> e = first; e != null; e = e.next) {
2812 >                for (Node<K,V> e = first; e != null; ) {
2813                      int s; K ek;
2814                      if (((s = lockState) & (WAITER|WRITER)) != 0) {
2815                          if (e.hash == h &&
2816                              ((ek = e.key) == k || (ek != null && k.equals(ek))))
2817                              return e;
2818 +                        e = e.next;
2819                      }
2820                      else if (U.compareAndSwapInt(this, LOCKSTATE, s,
2821                                                   s + READER)) {
# Line 2782 | Line 2842 | public class ConcurrentHashMap<K,V> exte
2842           */
2843          final TreeNode<K,V> putTreeVal(int h, K k, V v) {
2844              Class<?> kc = null;
2845 +            boolean searched = false;
2846              for (TreeNode<K,V> p = root;;) {
2847 <                int dir, ph; K pk; TreeNode<K,V> q, pr;
2847 >                int dir, ph; K pk;
2848                  if (p == null) {
2849                      first = root = new TreeNode<K,V>(h, k, v, null, null);
2850                      break;
# Line 2797 | Line 2858 | public class ConcurrentHashMap<K,V> exte
2858                  else if ((kc == null &&
2859                            (kc = comparableClassFor(k)) == null) ||
2860                           (dir = compareComparables(kc, k, pk)) == 0) {
2861 <                    if (p.left == null)
2862 <                        dir = 1;
2863 <                    else if ((pr = p.right) == null ||
2864 <                             (q = pr.findTreeNode(h, k, kc)) == null)
2865 <                        dir = -1;
2866 <                    else
2867 <                        return q;
2861 >                    if (!searched) {
2862 >                        TreeNode<K,V> q, ch;
2863 >                        searched = true;
2864 >                        if (((ch = p.left) != null &&
2865 >                             (q = ch.findTreeNode(h, k, kc)) != null) ||
2866 >                            ((ch = p.right) != null &&
2867 >                             (q = ch.findTreeNode(h, k, kc)) != null))
2868 >                            return q;
2869 >                    }
2870 >                    dir = tieBreakOrder(k, pk);
2871                  }
2872 +
2873                  TreeNode<K,V> xp = p;
2874 <                if ((p = (dir < 0) ? p.left : p.right) == null) {
2874 >                if ((p = (dir <= 0) ? p.left : p.right) == null) {
2875                      TreeNode<K,V> x, f = first;
2876                      first = x = new TreeNode<K,V>(h, k, v, f, xp);
2877                      if (f != null)
2878                          f.prev = x;
2879 <                    if (dir < 0)
2879 >                    if (dir <= 0)
2880                          xp.left = x;
2881                      else
2882                          xp.right = x;
# Line 3166 | Line 3231 | public class ConcurrentHashMap<K,V> exte
3231      /* ----------------Table Traversal -------------- */
3232  
3233      /**
3234 +     * Records the table, its length, and current traversal index for a
3235 +     * traverser that must process a region of a forwarded table before
3236 +     * proceeding with current table.
3237 +     */
3238 +    static final class TableStack<K,V> {
3239 +        int length;
3240 +        int index;
3241 +        Node<K,V>[] tab;
3242 +        TableStack<K,V> next;
3243 +    }
3244 +
3245 +    /**
3246       * Encapsulates traversal for methods such as containsValue; also
3247       * serves as a base class for other iterators and spliterators.
3248       *
# Line 3189 | Line 3266 | public class ConcurrentHashMap<K,V> exte
3266      static class Traverser<K,V> {
3267          Node<K,V>[] tab;        // current table; updated if resized
3268          Node<K,V> next;         // the next entry to use
3269 +        TableStack<K,V> stack, spare; // to save/restore on ForwardingNodes
3270          int index;              // index of bin to use next
3271          int baseIndex;          // current index of initial table
3272          int baseLimit;          // index bound for initial table
# Line 3210 | Line 3288 | public class ConcurrentHashMap<K,V> exte
3288              if ((e = next) != null)
3289                  e = e.next;
3290              for (;;) {
3291 <                Node<K,V>[] t; int i, n; K ek;  // must use locals in checks
3291 >                Node<K,V>[] t; int i, n;  // must use locals in checks
3292                  if (e != null)
3293                      return next = e;
3294                  if (baseIndex >= baseLimit || (t = tab) == null ||
3295                      (n = t.length) <= (i = index) || i < 0)
3296                      return next = null;
3297 <                if ((e = tabAt(t, index)) != null && e.hash < 0) {
3297 >                if ((e = tabAt(t, i)) != null && e.hash < 0) {
3298                      if (e instanceof ForwardingNode) {
3299                          tab = ((ForwardingNode<K,V>)e).nextTable;
3300                          e = null;
3301 +                        pushState(t, i, n);
3302                          continue;
3303                      }
3304                      else if (e instanceof TreeBin)
# Line 3227 | Line 3306 | public class ConcurrentHashMap<K,V> exte
3306                      else
3307                          e = null;
3308                  }
3309 <                if ((index += baseSize) >= n)
3310 <                    index = ++baseIndex;    // visit upper slots if present
3309 >                if (stack != null)
3310 >                    recoverState(n);
3311 >                else if ((index = i + baseSize) >= n)
3312 >                    index = ++baseIndex; // visit upper slots if present
3313              }
3314          }
3315 +
3316 +        /**
3317 +         * Saves traversal state upon encountering a forwarding node.
3318 +         */
3319 +        private void pushState(Node<K,V>[] t, int i, int n) {
3320 +            TableStack<K,V> s = spare;  // reuse if possible
3321 +            if (s != null)
3322 +                spare = s.next;
3323 +            else
3324 +                s = new TableStack<K,V>();
3325 +            s.tab = t;
3326 +            s.length = n;
3327 +            s.index = i;
3328 +            s.next = stack;
3329 +            stack = s;
3330 +        }
3331 +
3332 +        /**
3333 +         * Possibly pops traversal state.
3334 +         *
3335 +         * @param n length of current table
3336 +         */
3337 +        private void recoverState(int n) {
3338 +            TableStack<K,V> s; int len;
3339 +            while ((s = stack) != null && (index += (len = s.length)) >= n) {
3340 +                n = len;
3341 +                index = s.index;
3342 +                tab = s.tab;
3343 +                s.tab = null;
3344 +                TableStack<K,V> next = s.next;
3345 +                s.next = spare; // save for reuse
3346 +                stack = next;
3347 +                spare = s;
3348 +            }
3349 +            if (s == null && (index += baseSize) >= n)
3350 +                index = ++baseIndex;
3351 +        }
3352      }
3353  
3354      /**
# Line 4250 | Line 4368 | public class ConcurrentHashMap<K,V> exte
4368          // implementations below rely on concrete classes supplying these
4369          // abstract methods
4370          /**
4371 <         * Returns a "weakly consistent" iterator that will never
4372 <         * throw {@link ConcurrentModificationException}, and
4373 <         * guarantees to traverse elements as they existed upon
4374 <         * construction of the iterator, and may (but is not
4375 <         * guaranteed to) reflect any modifications subsequent to
4376 <         * construction.
4371 >         * Returns an iterator over the elements in this collection.
4372 >         *
4373 >         * <p>The returned iterator is
4374 >         * <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>.
4375 >         *
4376 >         * @return an iterator over the elements in this collection
4377           */
4378          public abstract Iterator<E> iterator();
4379          public abstract boolean contains(Object o);
# Line 4353 | Line 4471 | public class ConcurrentHashMap<K,V> exte
4471          }
4472  
4473          public final boolean removeAll(Collection<?> c) {
4474 +            if (c == null) throw new NullPointerException();
4475              boolean modified = false;
4476              for (Iterator<E> it = iterator(); it.hasNext();) {
4477                  if (c.contains(it.next())) {
# Line 4364 | Line 4483 | public class ConcurrentHashMap<K,V> exte
4483          }
4484  
4485          public final boolean retainAll(Collection<?> c) {
4486 +            if (c == null) throw new NullPointerException();
4487              boolean modified = false;
4488              for (Iterator<E> it = iterator(); it.hasNext();) {
4489                  if (!c.contains(it.next())) {
# Line 4658 | Line 4778 | public class ConcurrentHashMap<K,V> exte
4778       * Base class for bulk tasks. Repeats some fields and code from
4779       * class Traverser, because we need to subclass CountedCompleter.
4780       */
4781 +    @SuppressWarnings("serial")
4782      abstract static class BulkTask<K,V,R> extends CountedCompleter<R> {
4783          Node<K,V>[] tab;        // same as Traverser
4784          Node<K,V> next;
4785 +        TableStack<K,V> stack, spare;
4786          int index;
4787          int baseIndex;
4788          int baseLimit;
# Line 4689 | Line 4811 | public class ConcurrentHashMap<K,V> exte
4811              if ((e = next) != null)
4812                  e = e.next;
4813              for (;;) {
4814 <                Node<K,V>[] t; int i, n; K ek;  // must use locals in checks
4814 >                Node<K,V>[] t; int i, n;
4815                  if (e != null)
4816                      return next = e;
4817                  if (baseIndex >= baseLimit || (t = tab) == null ||
4818                      (n = t.length) <= (i = index) || i < 0)
4819                      return next = null;
4820 <                if ((e = tabAt(t, index)) != null && e.hash < 0) {
4820 >                if ((e = tabAt(t, i)) != null && e.hash < 0) {
4821                      if (e instanceof ForwardingNode) {
4822                          tab = ((ForwardingNode<K,V>)e).nextTable;
4823                          e = null;
4824 +                        pushState(t, i, n);
4825                          continue;
4826                      }
4827                      else if (e instanceof TreeBin)
# Line 4706 | Line 4829 | public class ConcurrentHashMap<K,V> exte
4829                      else
4830                          e = null;
4831                  }
4832 <                if ((index += baseSize) >= n)
4833 <                    index = ++baseIndex;    // visit upper slots if present
4832 >                if (stack != null)
4833 >                    recoverState(n);
4834 >                else if ((index = i + baseSize) >= n)
4835 >                    index = ++baseIndex;
4836 >            }
4837 >        }
4838 >
4839 >        private void pushState(Node<K,V>[] t, int i, int n) {
4840 >            TableStack<K,V> s = spare;
4841 >            if (s != null)
4842 >                spare = s.next;
4843 >            else
4844 >                s = new TableStack<K,V>();
4845 >            s.tab = t;
4846 >            s.length = n;
4847 >            s.index = i;
4848 >            s.next = stack;
4849 >            stack = s;
4850 >        }
4851 >
4852 >        private void recoverState(int n) {
4853 >            TableStack<K,V> s; int len;
4854 >            while ((s = stack) != null && (index += (len = s.length)) >= n) {
4855 >                n = len;
4856 >                index = s.index;
4857 >                tab = s.tab;
4858 >                s.tab = null;
4859 >                TableStack<K,V> next = s.next;
4860 >                s.next = spare; // save for reuse
4861 >                stack = next;
4862 >                spare = s;
4863              }
4864 +            if (s == null && (index += baseSize) >= n)
4865 +                index = ++baseIndex;
4866          }
4867      }
4868  
# Line 5168 | Line 5322 | public class ConcurrentHashMap<K,V> exte
5322                  result = r;
5323                  CountedCompleter<?> c;
5324                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5325 <                    @SuppressWarnings("unchecked") ReduceKeysTask<K,V>
5325 >                    @SuppressWarnings("unchecked")
5326 >                    ReduceKeysTask<K,V>
5327                          t = (ReduceKeysTask<K,V>)c,
5328                          s = t.rights;
5329                      while (s != null) {
# Line 5215 | Line 5370 | public class ConcurrentHashMap<K,V> exte
5370                  result = r;
5371                  CountedCompleter<?> c;
5372                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5373 <                    @SuppressWarnings("unchecked") ReduceValuesTask<K,V>
5373 >                    @SuppressWarnings("unchecked")
5374 >                    ReduceValuesTask<K,V>
5375                          t = (ReduceValuesTask<K,V>)c,
5376                          s = t.rights;
5377                      while (s != null) {
# Line 5260 | Line 5416 | public class ConcurrentHashMap<K,V> exte
5416                  result = r;
5417                  CountedCompleter<?> c;
5418                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5419 <                    @SuppressWarnings("unchecked") ReduceEntriesTask<K,V>
5419 >                    @SuppressWarnings("unchecked")
5420 >                    ReduceEntriesTask<K,V>
5421                          t = (ReduceEntriesTask<K,V>)c,
5422                          s = t.rights;
5423                      while (s != null) {
# Line 5313 | Line 5470 | public class ConcurrentHashMap<K,V> exte
5470                  result = r;
5471                  CountedCompleter<?> c;
5472                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5473 <                    @SuppressWarnings("unchecked") MapReduceKeysTask<K,V,U>
5473 >                    @SuppressWarnings("unchecked")
5474 >                    MapReduceKeysTask<K,V,U>
5475                          t = (MapReduceKeysTask<K,V,U>)c,
5476                          s = t.rights;
5477                      while (s != null) {
# Line 5366 | Line 5524 | public class ConcurrentHashMap<K,V> exte
5524                  result = r;
5525                  CountedCompleter<?> c;
5526                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5527 <                    @SuppressWarnings("unchecked") MapReduceValuesTask<K,V,U>
5527 >                    @SuppressWarnings("unchecked")
5528 >                    MapReduceValuesTask<K,V,U>
5529                          t = (MapReduceValuesTask<K,V,U>)c,
5530                          s = t.rights;
5531                      while (s != null) {
# Line 5419 | Line 5578 | public class ConcurrentHashMap<K,V> exte
5578                  result = r;
5579                  CountedCompleter<?> c;
5580                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5581 <                    @SuppressWarnings("unchecked") MapReduceEntriesTask<K,V,U>
5581 >                    @SuppressWarnings("unchecked")
5582 >                    MapReduceEntriesTask<K,V,U>
5583                          t = (MapReduceEntriesTask<K,V,U>)c,
5584                          s = t.rights;
5585                      while (s != null) {
# Line 5472 | Line 5632 | public class ConcurrentHashMap<K,V> exte
5632                  result = r;
5633                  CountedCompleter<?> c;
5634                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5635 <                    @SuppressWarnings("unchecked") MapReduceMappingsTask<K,V,U>
5635 >                    @SuppressWarnings("unchecked")
5636 >                    MapReduceMappingsTask<K,V,U>
5637                          t = (MapReduceMappingsTask<K,V,U>)c,
5638                          s = t.rights;
5639                      while (s != null) {
# Line 5524 | Line 5685 | public class ConcurrentHashMap<K,V> exte
5685                  result = r;
5686                  CountedCompleter<?> c;
5687                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5688 <                    @SuppressWarnings("unchecked") MapReduceKeysToDoubleTask<K,V>
5688 >                    @SuppressWarnings("unchecked")
5689 >                    MapReduceKeysToDoubleTask<K,V>
5690                          t = (MapReduceKeysToDoubleTask<K,V>)c,
5691                          s = t.rights;
5692                      while (s != null) {
# Line 5573 | Line 5735 | public class ConcurrentHashMap<K,V> exte
5735                  result = r;
5736                  CountedCompleter<?> c;
5737                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5738 <                    @SuppressWarnings("unchecked") MapReduceValuesToDoubleTask<K,V>
5738 >                    @SuppressWarnings("unchecked")
5739 >                    MapReduceValuesToDoubleTask<K,V>
5740                          t = (MapReduceValuesToDoubleTask<K,V>)c,
5741                          s = t.rights;
5742                      while (s != null) {
# Line 5622 | Line 5785 | public class ConcurrentHashMap<K,V> exte
5785                  result = r;
5786                  CountedCompleter<?> c;
5787                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5788 <                    @SuppressWarnings("unchecked") MapReduceEntriesToDoubleTask<K,V>
5788 >                    @SuppressWarnings("unchecked")
5789 >                    MapReduceEntriesToDoubleTask<K,V>
5790                          t = (MapReduceEntriesToDoubleTask<K,V>)c,
5791                          s = t.rights;
5792                      while (s != null) {
# Line 5671 | Line 5835 | public class ConcurrentHashMap<K,V> exte
5835                  result = r;
5836                  CountedCompleter<?> c;
5837                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5838 <                    @SuppressWarnings("unchecked") MapReduceMappingsToDoubleTask<K,V>
5838 >                    @SuppressWarnings("unchecked")
5839 >                    MapReduceMappingsToDoubleTask<K,V>
5840                          t = (MapReduceMappingsToDoubleTask<K,V>)c,
5841                          s = t.rights;
5842                      while (s != null) {
# Line 5720 | Line 5885 | public class ConcurrentHashMap<K,V> exte
5885                  result = r;
5886                  CountedCompleter<?> c;
5887                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5888 <                    @SuppressWarnings("unchecked") MapReduceKeysToLongTask<K,V>
5888 >                    @SuppressWarnings("unchecked")
5889 >                    MapReduceKeysToLongTask<K,V>
5890                          t = (MapReduceKeysToLongTask<K,V>)c,
5891                          s = t.rights;
5892                      while (s != null) {
# Line 5769 | Line 5935 | public class ConcurrentHashMap<K,V> exte
5935                  result = r;
5936                  CountedCompleter<?> c;
5937                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5938 <                    @SuppressWarnings("unchecked") MapReduceValuesToLongTask<K,V>
5938 >                    @SuppressWarnings("unchecked")
5939 >                    MapReduceValuesToLongTask<K,V>
5940                          t = (MapReduceValuesToLongTask<K,V>)c,
5941                          s = t.rights;
5942                      while (s != null) {
# Line 5818 | Line 5985 | public class ConcurrentHashMap<K,V> exte
5985                  result = r;
5986                  CountedCompleter<?> c;
5987                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
5988 <                    @SuppressWarnings("unchecked") MapReduceEntriesToLongTask<K,V>
5988 >                    @SuppressWarnings("unchecked")
5989 >                    MapReduceEntriesToLongTask<K,V>
5990                          t = (MapReduceEntriesToLongTask<K,V>)c,
5991                          s = t.rights;
5992                      while (s != null) {
# Line 5867 | Line 6035 | public class ConcurrentHashMap<K,V> exte
6035                  result = r;
6036                  CountedCompleter<?> c;
6037                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
6038 <                    @SuppressWarnings("unchecked") MapReduceMappingsToLongTask<K,V>
6038 >                    @SuppressWarnings("unchecked")
6039 >                    MapReduceMappingsToLongTask<K,V>
6040                          t = (MapReduceMappingsToLongTask<K,V>)c,
6041                          s = t.rights;
6042                      while (s != null) {
# Line 5916 | Line 6085 | public class ConcurrentHashMap<K,V> exte
6085                  result = r;
6086                  CountedCompleter<?> c;
6087                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
6088 <                    @SuppressWarnings("unchecked") MapReduceKeysToIntTask<K,V>
6088 >                    @SuppressWarnings("unchecked")
6089 >                    MapReduceKeysToIntTask<K,V>
6090                          t = (MapReduceKeysToIntTask<K,V>)c,
6091                          s = t.rights;
6092                      while (s != null) {
# Line 5965 | Line 6135 | public class ConcurrentHashMap<K,V> exte
6135                  result = r;
6136                  CountedCompleter<?> c;
6137                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
6138 <                    @SuppressWarnings("unchecked") MapReduceValuesToIntTask<K,V>
6138 >                    @SuppressWarnings("unchecked")
6139 >                    MapReduceValuesToIntTask<K,V>
6140                          t = (MapReduceValuesToIntTask<K,V>)c,
6141                          s = t.rights;
6142                      while (s != null) {
# Line 6014 | Line 6185 | public class ConcurrentHashMap<K,V> exte
6185                  result = r;
6186                  CountedCompleter<?> c;
6187                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
6188 <                    @SuppressWarnings("unchecked") MapReduceEntriesToIntTask<K,V>
6188 >                    @SuppressWarnings("unchecked")
6189 >                    MapReduceEntriesToIntTask<K,V>
6190                          t = (MapReduceEntriesToIntTask<K,V>)c,
6191                          s = t.rights;
6192                      while (s != null) {
# Line 6063 | Line 6235 | public class ConcurrentHashMap<K,V> exte
6235                  result = r;
6236                  CountedCompleter<?> c;
6237                  for (c = firstComplete(); c != null; c = c.nextComplete()) {
6238 <                    @SuppressWarnings("unchecked") MapReduceMappingsToIntTask<K,V>
6238 >                    @SuppressWarnings("unchecked")
6239 >                    MapReduceMappingsToIntTask<K,V>
6240                          t = (MapReduceMappingsToIntTask<K,V>)c,
6241                          s = t.rights;
6242                      while (s != null) {
# Line 6079 | Line 6252 | public class ConcurrentHashMap<K,V> exte
6252      private static final sun.misc.Unsafe U;
6253      private static final long SIZECTL;
6254      private static final long TRANSFERINDEX;
6082    private static final long TRANSFERORIGIN;
6255      private static final long BASECOUNT;
6256      private static final long CELLSBUSY;
6257      private static final long CELLVALUE;
# Line 6094 | Line 6266 | public class ConcurrentHashMap<K,V> exte
6266                  (k.getDeclaredField("sizeCtl"));
6267              TRANSFERINDEX = U.objectFieldOffset
6268                  (k.getDeclaredField("transferIndex"));
6097            TRANSFERORIGIN = U.objectFieldOffset
6098                (k.getDeclaredField("transferOrigin"));
6269              BASECOUNT = U.objectFieldOffset
6270                  (k.getDeclaredField("baseCount"));
6271              CELLSBUSY = U.objectFieldOffset

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines