ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/ConcurrentHashMapV8.java
(Generate patch)

Comparing jsr166/src/jsr166e/ConcurrentHashMapV8.java (file contents):
Revision 1.53 by jsr166, Mon Aug 13 18:13:30 2012 UTC vs.
Revision 1.69 by jsr166, Sun Oct 21 06:14:11 2012 UTC

# Line 47 | Line 47 | import java.io.Serializable;
47   * block, so may overlap with update operations (including {@code put}
48   * and {@code remove}). Retrievals reflect the results of the most
49   * recently <em>completed</em> update operations holding upon their
50 < * onset.  For aggregate operations such as {@code putAll} and {@code
51 < * clear}, concurrent retrievals may reflect insertion or removal of
52 < * only some entries.  Similarly, Iterators and Enumerations return
53 < * elements reflecting the state of the hash table at some point at or
54 < * since the creation of the iterator/enumeration.  They do
55 < * <em>not</em> throw {@link ConcurrentModificationException}.
56 < * However, iterators are designed to be used by only one thread at a
57 < * time.  Bear in mind that the results of aggregate status methods
58 < * including {@code size}, {@code isEmpty}, and {@code containsValue}
59 < * are typically useful only when a map is not undergoing concurrent
60 < * updates in other threads.  Otherwise the results of these methods
61 < * reflect transient states that may be adequate for monitoring
62 < * or estimation purposes, but not for program control.
50 > * onset. (More formally, an update operation for a given key bears a
51 > * <em>happens-before</em> relation with any (non-null) retrieval for
52 > * that key reporting the updated value.)  For aggregate operations
53 > * such as {@code putAll} and {@code clear}, concurrent retrievals may
54 > * reflect insertion or removal of only some entries.  Similarly,
55 > * Iterators and Enumerations return elements reflecting the state of
56 > * the hash table at some point at or since the creation of the
57 > * iterator/enumeration.  They do <em>not</em> throw {@link
58 > * ConcurrentModificationException}.  However, iterators are designed
59 > * to be used by only one thread at a time.  Bear in mind that the
60 > * results of aggregate status methods including {@code size}, {@code
61 > * isEmpty}, and {@code containsValue} are typically useful only when
62 > * a map is not undergoing concurrent updates in other threads.
63 > * Otherwise the results of these methods reflect transient states
64 > * that may be adequate for monitoring or estimation purposes, but not
65 > * for program control.
66   *
67   * <p> The table is dynamically expanded when there are too many
68   * collisions (i.e., keys that have distinct hash codes but fall into
# Line 537 | Line 540 | public class ConcurrentHashMapV8<K, V>
540           * unlocking lock (via a failed CAS from non-waiting LOCKED
541           * state), unlockers acquire the sync lock and perform a
542           * notifyAll.
543 +         *
544 +         * The initial sanity check on tab and bounds is not currently
545 +         * necessary in the only usages of this method, but enables
546 +         * use in other future contexts.
547           */
548          final void tryAwaitLock(Node[] tab, int i) {
549 <            if (tab != null && i >= 0 && i < tab.length) { // bounds check
549 >            if (tab != null && i >= 0 && i < tab.length) { // sanity check
550                  int r = ThreadLocalRandom.current().nextInt(); // randomize spins
551                  int spins = MAX_SPINS, h;
552                  while (tabAt(tab, i) == this && ((h = hash) & LOCKED) != 0) {
# Line 712 | Line 719 | public class ConcurrentHashMapV8<K, V>
719          }
720  
721          /**
722 <         * Return the TreeNode (or null if not found) for the given key
722 >         * Returns the TreeNode (or null if not found) for the given key
723           * starting at given root.
724           */
725 <        @SuppressWarnings("unchecked") // suppress Comparable cast warning
726 <            final TreeNode getTreeNode(int h, Object k, TreeNode p) {
725 >        @SuppressWarnings("unchecked") final TreeNode getTreeNode
726 >            (int h, Object k, TreeNode p) {
727              Class<?> c = k.getClass();
728              while (p != null) {
729                  int dir, ph;  Object pk; Class<?> pc;
# Line 776 | Line 783 | public class ConcurrentHashMapV8<K, V>
783           * Finds or adds a node.
784           * @return null if added
785           */
786 <        @SuppressWarnings("unchecked") // suppress Comparable cast warning
787 <            final TreeNode putTreeNode(int h, Object k, Object v) {
786 >        @SuppressWarnings("unchecked") final TreeNode putTreeNode
787 >            (int h, Object k, Object v) {
788              Class<?> c = k.getClass();
789              TreeNode pp = root, p = null;
790              int dir = 0;
# Line 1204 | Line 1211 | public class ConcurrentHashMapV8<K, V>
1211      }
1212  
1213      /*
1214 <     * Internal versions of the five insertion methods, each a
1214 >     * Internal versions of the six insertion methods, each a
1215       * little more complicated than the last. All have
1216       * the same basic structure as the first (internalPut):
1217       *  1. If table uninitialized, create
# Line 1222 | Line 1229 | public class ConcurrentHashMapV8<K, V>
1229       *    returns from function call.
1230       *  * compute uses the same function-call mechanics, but without
1231       *    the prescans
1232 +     *  * merge acts as putIfAbsent in the absent case, but invokes the
1233 +     *    update function if present
1234       *  * putAll attempts to pre-allocate enough table space
1235       *    and more lazily performs count updates and checks.
1236       *
# Line 1545 | Line 1554 | public class ConcurrentHashMapV8<K, V>
1554      }
1555  
1556      /** Implementation for compute */
1557 <    @SuppressWarnings("unchecked")
1558 <        private final Object internalCompute(K k, boolean onlyIfPresent,
1550 <                                             BiFun<? super K, ? super V, ? extends V> mf) {
1557 >    @SuppressWarnings("unchecked") private final Object internalCompute
1558 >        (K k, boolean onlyIfPresent, BiFun<? super K, ? super V, ? extends V> mf) {
1559          int h = spread(k.hashCode());
1560          Object val = null;
1561          int delta = 0;
# Line 1670 | Line 1678 | public class ConcurrentHashMapV8<K, V>
1678          return val;
1679      }
1680  
1681 <    private final Object internalMerge(K k, V v,
1682 <                                       BiFun<? super V, ? super V, ? extends V> mf) {
1681 >    /** Implementation for merge */
1682 >    @SuppressWarnings("unchecked") private final Object internalMerge
1683 >        (K k, V v, BiFun<? super V, ? super V, ? extends V> mf) {
1684          int h = spread(k.hashCode());
1685          Object val = null;
1686          int delta = 0;
# Line 2001 | Line 2010 | public class ConcurrentHashMapV8<K, V>
2010          for (int i = bin;;) {      // start upwards sweep
2011              int fh; Node f;
2012              if ((f = tabAt(tab, i)) == null) {
2013 <                if (bin >= 0) {    // no lock needed (or available)
2013 >                if (bin >= 0) {    // Unbuffered; no lock needed (or available)
2014                      if (!casTabAt(tab, i, f, fwd))
2015                          continue;
2016                  }
# Line 2177 | Line 2186 | public class ConcurrentHashMapV8<K, V>
2186                      try {
2187                          if (tabAt(tab, i) == f) {
2188                              for (Node p = t.first; p != null; p = p.next) {
2189 <                                p.val = null;
2190 <                                --delta;
2189 >                                if (p.val != null) { // (currently always true)
2190 >                                    p.val = null;
2191 >                                    --delta;
2192 >                                }
2193                              }
2194                              t.first = null;
2195                              t.root = null;
# Line 2200 | Line 2211 | public class ConcurrentHashMapV8<K, V>
2211                  try {
2212                      if (tabAt(tab, i) == f) {
2213                          for (Node e = f; e != null; e = e.next) {
2214 <                            e.val = null;
2215 <                            --delta;
2214 >                            if (e.val != null) {  // (currently always true)
2215 >                                e.val = null;
2216 >                                --delta;
2217 >                            }
2218                          }
2219                          setTabAt(tab, i, null);
2220                          ++i;
# Line 2222 | Line 2235 | public class ConcurrentHashMapV8<K, V>
2235  
2236      /**
2237       * Encapsulates traversal for methods such as containsValue; also
2238 <     * serves as a base class for other iterators.
2238 >     * serves as a base class for other iterators and bulk tasks.
2239       *
2240       * At each step, the iterator snapshots the key ("nextKey") and
2241       * value ("nextVal") of a valid node (i.e., one that, at point of
# Line 2260 | Line 2273 | public class ConcurrentHashMapV8<K, V>
2273       * This class extends ForkJoinTask to streamline parallel
2274       * iteration in bulk operations (see BulkTask). This adds only an
2275       * int of space overhead, which is close enough to negligible in
2276 <     * cases where it is not needed to not worry about it.
2276 >     * cases where it is not needed to not worry about it.  Because
2277 >     * ForkJoinTask is Serializable, but iterators need not be, we
2278 >     * need to add warning suppressions.
2279       */
2280 <    static class Traverser<K,V,R> extends ForkJoinTask<R> {
2280 >    @SuppressWarnings("serial") static class Traverser<K,V,R> extends ForkJoinTask<R> {
2281          final ConcurrentHashMapV8<K, V> map;
2282          Node next;           // the next entry to use
2283          Node last;           // the last entry used
# Line 2272 | Line 2287 | public class ConcurrentHashMapV8<K, V>
2287          int index;           // index of bin to use next
2288          int baseIndex;       // current index of initial table
2289          int baseLimit;       // index bound for initial table
2290 <        final int baseSize;  // initial table size
2290 >        int baseSize;        // initial table size
2291  
2292          /** Creates iterator for all entries in the table. */
2293          Traverser(ConcurrentHashMapV8<K, V> map) {
2294 <            this.tab = (this.map = map).table;
2280 <            baseLimit = baseSize = (tab == null) ? 0 : tab.length;
2294 >            this.map = map;
2295          }
2296  
2297          /** Creates iterator for split() methods */
2298 <        Traverser(Traverser<K,V,?> it, boolean split) {
2299 <            this.map = it.map;
2300 <            this.tab = it.tab;
2298 >        Traverser(Traverser<K,V,?> it) {
2299 >            ConcurrentHashMapV8<K, V> m; Node[] t;
2300 >            if ((m = this.map = it.map) == null)
2301 >                t = null;
2302 >            else if ((t = it.tab) == null && // force parent tab initialization
2303 >                     (t = it.tab = m.table) != null)
2304 >                it.baseLimit = it.baseSize = t.length;
2305 >            this.tab = t;
2306              this.baseSize = it.baseSize;
2307 <            int lo = it.baseIndex;
2308 <            int hi = this.baseLimit = it.baseLimit;
2290 <            int i;
2291 <            if (split) // adjust parent
2292 <                i = it.baseLimit = (lo + hi + 1) >>> 1;
2293 <            else       // clone parent
2294 <                i = lo;
2295 <            this.index = this.baseIndex = i;
2307 >            it.baseLimit = this.index = this.baseIndex =
2308 >                ((this.baseLimit = it.baseLimit) + it.baseIndex + 1) >>> 1;
2309          }
2310  
2311          /**
# Line 2306 | Line 2319 | public class ConcurrentHashMapV8<K, V>
2319                  if (e != null)                  // advance past used/skipped node
2320                      e = e.next;
2321                  while (e == null) {             // get to next non-null bin
2322 +                    ConcurrentHashMapV8<K, V> m;
2323                      Node[] t; int b, i, n; Object ek; // checks must use locals
2324 <                    if ((b = baseIndex) >= baseLimit || (i = index) < 0 ||
2325 <                        (t = tab) == null || i >= (n = t.length))
2324 >                    if ((t = tab) != null)
2325 >                        n = t.length;
2326 >                    else if ((m = map) != null && (t = tab = m.table) != null)
2327 >                        n = baseLimit = baseSize = t.length;
2328 >                    else
2329                          break outer;
2330 <                    else if ((e = tabAt(t, i)) != null && e.hash == MOVED) {
2330 >                    if ((b = baseIndex) >= baseLimit ||
2331 >                        (i = index) < 0 || i >= n)
2332 >                        break outer;
2333 >                    if ((e = tabAt(t, i)) != null && e.hash == MOVED) {
2334                          if ((ek = e.key) instanceof TreeBin)
2335                              e = ((TreeBin)ek).first;
2336                          else {
# Line 2327 | Line 2347 | public class ConcurrentHashMapV8<K, V>
2347          }
2348  
2349          public final void remove() {
2350 <            if (nextVal == null)
2350 >            if (nextVal == null && last == null)
2351                  advance();
2352              Node e = last;
2353              if (e == null)
# Line 2458 | Line 2478 | public class ConcurrentHashMapV8<K, V>
2478       * instead of {@link #size} because a ConcurrentHashMap may
2479       * contain more mappings than can be represented as an int. The
2480       * value returned is a snapshot; the actual count may differ if
2481 <     * there are ongoing concurrent insertions of removals.
2481 >     * there are ongoing concurrent insertions or removals.
2482       *
2483       * @return the number of mappings
2484       */
2485      public long mappingCount() {
2486          long n = counter.sum();
2487 <        return (n < 0L) ? 0L : n;
2487 >        return (n < 0L) ? 0L : n; // ignore transient negative values
2488      }
2489  
2490      /**
# Line 2478 | Line 2498 | public class ConcurrentHashMapV8<K, V>
2498       *
2499       * @throws NullPointerException if the specified key is null
2500       */
2501 <    @SuppressWarnings("unchecked")
2482 <        public V get(Object key) {
2501 >    @SuppressWarnings("unchecked") public V get(Object key) {
2502          if (key == null)
2503              throw new NullPointerException();
2504          return (V)internalGet(key);
2505      }
2506  
2507      /**
2508 +     * Returns the value to which the specified key is mapped,
2509 +     * or the given defaultValue if this map contains no mapping for the key.
2510 +     *
2511 +     * @param key the key
2512 +     * @param defaultValue the value to return if this map contains
2513 +     * no mapping for the given key
2514 +     * @return the mapping for the key, if present; else the defaultValue
2515 +     * @throws NullPointerException if the specified key is null
2516 +     */
2517 +    @SuppressWarnings("unchecked") public V getValueOrDefault(Object key, V defaultValue) {
2518 +        if (key == null)
2519 +            throw new NullPointerException();
2520 +        V v = (V) internalGet(key);
2521 +        return v == null ? defaultValue : v;
2522 +    }
2523 +
2524 +    /**
2525       * Tests if the specified object is a key in this table.
2526       *
2527       * @param  key   possible key
# Line 2554 | Line 2590 | public class ConcurrentHashMapV8<K, V>
2590       *         {@code null} if there was no mapping for {@code key}
2591       * @throws NullPointerException if the specified key or value is null
2592       */
2593 <    @SuppressWarnings("unchecked")
2558 <        public V put(K key, V value) {
2593 >    @SuppressWarnings("unchecked") public V put(K key, V value) {
2594          if (key == null || value == null)
2595              throw new NullPointerException();
2596          return (V)internalPut(key, value);
# Line 2568 | Line 2603 | public class ConcurrentHashMapV8<K, V>
2603       *         or {@code null} if there was no mapping for the key
2604       * @throws NullPointerException if the specified key or value is null
2605       */
2606 <    @SuppressWarnings("unchecked")
2572 <        public V putIfAbsent(K key, V value) {
2606 >    @SuppressWarnings("unchecked") public V putIfAbsent(K key, V value) {
2607          if (key == null || value == null)
2608              throw new NullPointerException();
2609          return (V)internalPutIfAbsent(key, value);
# Line 2616 | Line 2650 | public class ConcurrentHashMapV8<K, V>
2650       * @param key key with which the specified value is to be associated
2651       * @param mappingFunction the function to compute a value
2652       * @return the current (existing or computed) value associated with
2653 <     *         the specified key, or null if the computed value is null.
2653 >     *         the specified key, or null if the computed value is null
2654       * @throws NullPointerException if the specified key or mappingFunction
2655       *         is null
2656       * @throws IllegalStateException if the computation detectably
# Line 2625 | Line 2659 | public class ConcurrentHashMapV8<K, V>
2659       * @throws RuntimeException or Error if the mappingFunction does so,
2660       *         in which case the mapping is left unestablished
2661       */
2662 <    @SuppressWarnings("unchecked")
2663 <        public V computeIfAbsent(K key, Fun<? super K, ? extends V> mappingFunction) {
2662 >    @SuppressWarnings("unchecked") public V computeIfAbsent
2663 >        (K key, Fun<? super K, ? extends V> mappingFunction) {
2664          if (key == null || mappingFunction == null)
2665              throw new NullPointerException();
2666          return (V)internalComputeIfAbsent(key, mappingFunction);
# Line 2657 | Line 2691 | public class ConcurrentHashMapV8<K, V>
2691       *
2692       * @param key key with which the specified value is to be associated
2693       * @param remappingFunction the function to compute a value
2694 <     * @return the new value associated with
2661 <     *         the specified key, or null if none.
2694 >     * @return the new value associated with the specified key, or null if none
2695       * @throws NullPointerException if the specified key or remappingFunction
2696       *         is null
2697       * @throws IllegalStateException if the computation detectably
# Line 2667 | Line 2700 | public class ConcurrentHashMapV8<K, V>
2700       * @throws RuntimeException or Error if the remappingFunction does so,
2701       *         in which case the mapping is unchanged
2702       */
2703 <    public V computeIfPresent(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2703 >    @SuppressWarnings("unchecked") public V computeIfPresent
2704 >        (K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2705          if (key == null || remappingFunction == null)
2706              throw new NullPointerException();
2707          return (V)internalCompute(key, true, remappingFunction);
# Line 2704 | Line 2738 | public class ConcurrentHashMapV8<K, V>
2738       *
2739       * @param key key with which the specified value is to be associated
2740       * @param remappingFunction the function to compute a value
2741 <     * @return the new value associated with
2708 <     *         the specified key, or null if none.
2741 >     * @return the new value associated with the specified key, or null if none
2742       * @throws NullPointerException if the specified key or remappingFunction
2743       *         is null
2744       * @throws IllegalStateException if the computation detectably
# Line 2714 | Line 2747 | public class ConcurrentHashMapV8<K, V>
2747       * @throws RuntimeException or Error if the remappingFunction does so,
2748       *         in which case the mapping is unchanged
2749       */
2750 <    //    @SuppressWarnings("unchecked")
2751 <    public V compute(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2750 >    @SuppressWarnings("unchecked") public V compute
2751 >        (K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2752          if (key == null || remappingFunction == null)
2753              throw new NullPointerException();
2754          return (V)internalCompute(key, false, remappingFunction);
# Line 2746 | Line 2779 | public class ConcurrentHashMapV8<K, V>
2779       * so the computation should be short and simple, and must not
2780       * attempt to update any other mappings of this Map.
2781       */
2782 <    //    @SuppressWarnings("unchecked")
2783 <    public V merge(K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) {
2782 >    @SuppressWarnings("unchecked") public V merge
2783 >        (K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) {
2784          if (key == null || value == null || remappingFunction == null)
2785              throw new NullPointerException();
2786          return (V)internalMerge(key, value, remappingFunction);
# Line 2762 | Line 2795 | public class ConcurrentHashMapV8<K, V>
2795       *         {@code null} if there was no mapping for {@code key}
2796       * @throws NullPointerException if the specified key is null
2797       */
2798 <    @SuppressWarnings("unchecked")
2766 <        public V remove(Object key) {
2798 >    @SuppressWarnings("unchecked") public V remove(Object key) {
2799          if (key == null)
2800              throw new NullPointerException();
2801          return (V)internalReplace(key, null, null);
# Line 2800 | Line 2832 | public class ConcurrentHashMapV8<K, V>
2832       *         or {@code null} if there was no mapping for the key
2833       * @throws NullPointerException if the specified key or value is null
2834       */
2835 <    @SuppressWarnings("unchecked")
2804 <        public V replace(K key, V value) {
2835 >    @SuppressWarnings("unchecked") public V replace(K key, V value) {
2836          if (key == null || value == null)
2837              throw new NullPointerException();
2838          return (V)internalReplace(key, value, null);
# Line 2898 | Line 2929 | public class ConcurrentHashMapV8<K, V>
2929      }
2930  
2931      /**
2932 <     * Returns a partionable iterator of the keys in this map.
2932 >     * Returns a partitionable iterator of the keys in this map.
2933       *
2934 <     * @return a partionable iterator of the keys in this map
2934 >     * @return a partitionable iterator of the keys in this map
2935       */
2936      public Spliterator<K> keySpliterator() {
2937          return new KeyIterator<K,V>(this);
2938      }
2939  
2940      /**
2941 <     * Returns a partionable iterator of the values in this map.
2941 >     * Returns a partitionable iterator of the values in this map.
2942       *
2943 <     * @return a partionable iterator of the values in this map
2943 >     * @return a partitionable iterator of the values in this map
2944       */
2945      public Spliterator<V> valueSpliterator() {
2946          return new ValueIterator<K,V>(this);
2947      }
2948  
2949      /**
2950 <     * Returns a partionable iterator of the entries in this map.
2950 >     * Returns a partitionable iterator of the entries in this map.
2951       *
2952 <     * @return a partionable iterator of the entries in this map
2952 >     * @return a partitionable iterator of the entries in this map
2953       */
2954      public Spliterator<Map.Entry<K,V>> entrySpliterator() {
2955          return new EntryIterator<K,V>(this);
# Line 3007 | Line 3038 | public class ConcurrentHashMapV8<K, V>
3038  
3039      /* ----------------Iterators -------------- */
3040  
3041 <    static final class KeyIterator<K,V> extends Traverser<K,V,Object>
3041 >    @SuppressWarnings("serial") static final class KeyIterator<K,V> extends Traverser<K,V,Object>
3042          implements Spliterator<K>, Enumeration<K> {
3043          KeyIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3044 <        KeyIterator(Traverser<K,V,Object> it, boolean split) {
3045 <            super(it, split);
3044 >        KeyIterator(Traverser<K,V,Object> it) {
3045 >            super(it);
3046          }
3047          public KeyIterator<K,V> split() {
3048              if (last != null || (next != null && nextVal == null))
3049                  throw new IllegalStateException();
3050 <            return new KeyIterator<K,V>(this, true);
3050 >            return new KeyIterator<K,V>(this);
3051          }
3052 <        @SuppressWarnings("unchecked")
3022 <            public final K next() {
3052 >        @SuppressWarnings("unchecked") public final K next() {
3053              if (nextVal == null && advance() == null)
3054                  throw new NoSuchElementException();
3055              Object k = nextKey;
# Line 3030 | Line 3060 | public class ConcurrentHashMapV8<K, V>
3060          public final K nextElement() { return next(); }
3061      }
3062  
3063 <    static final class ValueIterator<K,V> extends Traverser<K,V,Object>
3063 >    @SuppressWarnings("serial") static final class ValueIterator<K,V> extends Traverser<K,V,Object>
3064          implements Spliterator<V>, Enumeration<V> {
3065          ValueIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3066 <        ValueIterator(Traverser<K,V,Object> it, boolean split) {
3067 <            super(it, split);
3066 >        ValueIterator(Traverser<K,V,Object> it) {
3067 >            super(it);
3068          }
3069          public ValueIterator<K,V> split() {
3070              if (last != null || (next != null && nextVal == null))
3071                  throw new IllegalStateException();
3072 <            return new ValueIterator<K,V>(this, true);
3072 >            return new ValueIterator<K,V>(this);
3073          }
3074  
3075 <        @SuppressWarnings("unchecked")
3046 <            public final V next() {
3075 >        @SuppressWarnings("unchecked") public final V next() {
3076              Object v;
3077              if ((v = nextVal) == null && (v = advance()) == null)
3078                  throw new NoSuchElementException();
# Line 3054 | Line 3083 | public class ConcurrentHashMapV8<K, V>
3083          public final V nextElement() { return next(); }
3084      }
3085  
3086 <    static final class EntryIterator<K,V> extends Traverser<K,V,Object>
3086 >    @SuppressWarnings("serial") static final class EntryIterator<K,V> extends Traverser<K,V,Object>
3087          implements Spliterator<Map.Entry<K,V>> {
3088          EntryIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3089 <        EntryIterator(Traverser<K,V,Object> it, boolean split) {
3090 <            super(it, split);
3089 >        EntryIterator(Traverser<K,V,Object> it) {
3090 >            super(it);
3091          }
3092          public EntryIterator<K,V> split() {
3093              if (last != null || (next != null && nextVal == null))
3094                  throw new IllegalStateException();
3095 <            return new EntryIterator<K,V>(this, true);
3095 >            return new EntryIterator<K,V>(this);
3096          }
3097  
3098 <        @SuppressWarnings("unchecked")
3070 <            public final Map.Entry<K,V> next() {
3098 >        @SuppressWarnings("unchecked") public final Map.Entry<K,V> next() {
3099              Object v;
3100              if ((v = nextVal) == null && (v = advance()) == null)
3101                  throw new NoSuchElementException();
# Line 3162 | Line 3190 | public class ConcurrentHashMapV8<K, V>
3190              return (i == n) ? r : Arrays.copyOf(r, i);
3191          }
3192  
3193 <        @SuppressWarnings("unchecked")
3166 <            public final <T> T[] toArray(T[] a) {
3193 >        @SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) {
3194              long sz = map.mappingCount();
3195              if (sz > (long)(MAX_ARRAY_SIZE))
3196                  throw new OutOfMemoryError(oomeMsg);
# Line 3359 | Line 3386 | public class ConcurrentHashMapV8<K, V>
3386       * for each key-value mapping, followed by a null pair.
3387       * The key-value mappings are emitted in no particular order.
3388       */
3389 <    @SuppressWarnings("unchecked")
3363 <        private void writeObject(java.io.ObjectOutputStream s)
3389 >    @SuppressWarnings("unchecked") private void writeObject(java.io.ObjectOutputStream s)
3390          throws java.io.IOException {
3391          if (segments == null) { // for serialization compatibility
3392              segments = (Segment<K,V>[])
# Line 3384 | Line 3410 | public class ConcurrentHashMapV8<K, V>
3410       * Reconstitutes the instance from a stream (that is, deserializes it).
3411       * @param s the stream
3412       */
3413 <    @SuppressWarnings("unchecked")
3388 <        private void readObject(java.io.ObjectInputStream s)
3413 >    @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s)
3414          throws java.io.IOException, ClassNotFoundException {
3415          s.defaultReadObject();
3416          this.segments = null; // unneeded
# Line 3518 | Line 3543 | public class ConcurrentHashMapV8<K, V>
3543  
3544      /**
3545       * An extended view of a ConcurrentHashMap supporting bulk
3546 <     * parallel operations. These operations are designed to be be
3546 >     * parallel operations. These operations are designed to be
3547       * safely, and often sensibly, applied even with maps that are
3548       * being concurrently updated by other threads; for example, when
3549       * computing a snapshot summary of the values in a shared
# Line 3646 | Line 3671 | public class ConcurrentHashMapV8<K, V>
3671           * of each (key, value).
3672           *
3673           * @param transformer a function returning the transformation
3674 <         * for an element, or null of there is no transformation (in
3675 <         * which case the action is not applied).
3674 >         * for an element, or null if there is no transformation (in
3675 >         * which case the action is not applied)
3676           * @param action the action
3677           */
3678          public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
# Line 3658 | Line 3683 | public class ConcurrentHashMapV8<K, V>
3683  
3684          /**
3685           * Returns a non-null result from applying the given search
3686 <         * function on each (key, value), or null if none.  Further
3687 <         * element processing is suppressed upon success. However,
3688 <         * this method does not return until other in-progress
3689 <         * parallel invocations of the search function also complete.
3686 >         * function on each (key, value), or null if none.  Upon
3687 >         * success, further element processing is suppressed and the
3688 >         * results of any other parallel invocations of the search
3689 >         * function are ignored.
3690           *
3691           * @param searchFunction a function returning a non-null
3692           * result on success, else null
# Line 3679 | Line 3704 | public class ConcurrentHashMapV8<K, V>
3704           * combine values, or null if none.
3705           *
3706           * @param transformer a function returning the transformation
3707 <         * for an element, or null of there is no transformation (in
3708 <         * which case it is not combined).
3707 >         * for an element, or null if there is no transformation (in
3708 >         * which case it is not combined)
3709           * @param reducer a commutative associative combining function
3710           * @return the result of accumulating the given transformation
3711           * of all (key, value) pairs
# Line 3720 | Line 3745 | public class ConcurrentHashMapV8<K, V>
3745           * @param basis the identity (initial default value) for the reduction
3746           * @param reducer a commutative associative combining function
3747           * @return the result of accumulating the given transformation
3748 <         * of all (key, value) pairs using the given reducer to
3724 <         * combine values, and the given basis as an identity value.
3748 >         * of all (key, value) pairs
3749           */
3750          public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer,
3751                                   long basis,
# Line 3750 | Line 3774 | public class ConcurrentHashMapV8<K, V>
3774          }
3775  
3776          /**
3777 <         * Performs the given action for each key
3777 >         * Performs the given action for each key.
3778           *
3779           * @param action the action
3780           */
# Line 3761 | Line 3785 | public class ConcurrentHashMapV8<K, V>
3785  
3786          /**
3787           * Performs the given action for each non-null transformation
3788 <         * of each key
3788 >         * of each key.
3789           *
3790           * @param transformer a function returning the transformation
3791 <         * for an element, or null of there is no transformation (in
3792 <         * which case the action is not applied).
3791 >         * for an element, or null if there is no transformation (in
3792 >         * which case the action is not applied)
3793           * @param action the action
3794           */
3795          public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
# Line 3776 | Line 3800 | public class ConcurrentHashMapV8<K, V>
3800  
3801          /**
3802           * Returns a non-null result from applying the given search
3803 <         * function on each key, or null if none.  Further element
3804 <         * processing is suppressed upon success. However, this method
3805 <         * does not return until other in-progress parallel
3806 <         * invocations of the search function also complete.
3803 >         * function on each key, or null if none. Upon success,
3804 >         * further element processing is suppressed and the results of
3805 >         * any other parallel invocations of the search function are
3806 >         * ignored.
3807           *
3808           * @param searchFunction a function returning a non-null
3809           * result on success, else null
# Line 3810 | Line 3834 | public class ConcurrentHashMapV8<K, V>
3834           * null if none.
3835           *
3836           * @param transformer a function returning the transformation
3837 <         * for an element, or null of there is no transformation (in
3838 <         * which case it is not combined).
3837 >         * for an element, or null if there is no transformation (in
3838 >         * which case it is not combined)
3839           * @param reducer a commutative associative combining function
3840           * @return the result of accumulating the given transformation
3841           * of all keys
# Line 3880 | Line 3904 | public class ConcurrentHashMapV8<K, V>
3904          }
3905  
3906          /**
3907 <         * Performs the given action for each value
3907 >         * Performs the given action for each value.
3908           *
3909           * @param action the action
3910           */
# Line 3891 | Line 3915 | public class ConcurrentHashMapV8<K, V>
3915  
3916          /**
3917           * Performs the given action for each non-null transformation
3918 <         * of each value
3918 >         * of each value.
3919           *
3920           * @param transformer a function returning the transformation
3921 <         * for an element, or null of there is no transformation (in
3922 <         * which case the action is not applied).
3921 >         * for an element, or null if there is no transformation (in
3922 >         * which case the action is not applied)
3923           */
3924          public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3925                                       Action<U> action) {
# Line 3905 | Line 3929 | public class ConcurrentHashMapV8<K, V>
3929  
3930          /**
3931           * Returns a non-null result from applying the given search
3932 <         * function on each value, or null if none.  Further element
3933 <         * processing is suppressed upon success. However, this method
3934 <         * does not return until other in-progress parallel
3935 <         * invocations of the search function also complete.
3932 >         * function on each value, or null if none.  Upon success,
3933 >         * further element processing is suppressed and the results of
3934 >         * any other parallel invocations of the search function are
3935 >         * ignored.
3936           *
3937           * @param searchFunction a function returning a non-null
3938           * result on success, else null
3939           * @return a non-null result from applying the given search
3940           * function on each value, or null if none
3917         *
3941           */
3942          public <U> U searchValues(Fun<? super V, ? extends U> searchFunction) {
3943              return fjp.invoke(ForkJoinTasks.searchValues
# Line 3939 | Line 3962 | public class ConcurrentHashMapV8<K, V>
3962           * null if none.
3963           *
3964           * @param transformer a function returning the transformation
3965 <         * for an element, or null of there is no transformation (in
3966 <         * which case it is not combined).
3965 >         * for an element, or null if there is no transformation (in
3966 >         * which case it is not combined)
3967           * @param reducer a commutative associative combining function
3968           * @return the result of accumulating the given transformation
3969           * of all values
# Line 4009 | Line 4032 | public class ConcurrentHashMapV8<K, V>
4032          }
4033  
4034          /**
4035 <         * Perform the given action for each entry
4035 >         * Performs the given action for each entry.
4036           *
4037           * @param action the action
4038           */
# Line 4019 | Line 4042 | public class ConcurrentHashMapV8<K, V>
4042          }
4043  
4044          /**
4045 <         * Perform the given action for each non-null transformation
4046 <         * of each entry
4045 >         * Performs the given action for each non-null transformation
4046 >         * of each entry.
4047           *
4048           * @param transformer a function returning the transformation
4049 <         * for an element, or null of there is no transformation (in
4050 <         * which case the action is not applied).
4049 >         * for an element, or null if there is no transformation (in
4050 >         * which case the action is not applied)
4051           * @param action the action
4052           */
4053          public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
# Line 4035 | Line 4058 | public class ConcurrentHashMapV8<K, V>
4058  
4059          /**
4060           * Returns a non-null result from applying the given search
4061 <         * function on each entry, or null if none.  Further element
4062 <         * processing is suppressed upon success. However, this method
4063 <         * does not return until other in-progress parallel
4064 <         * invocations of the search function also complete.
4061 >         * function on each entry, or null if none.  Upon success,
4062 >         * further element processing is suppressed and the results of
4063 >         * any other parallel invocations of the search function are
4064 >         * ignored.
4065           *
4066           * @param searchFunction a function returning a non-null
4067           * result on success, else null
# Line 4068 | Line 4091 | public class ConcurrentHashMapV8<K, V>
4091           * or null if none.
4092           *
4093           * @param transformer a function returning the transformation
4094 <         * for an element, or null of there is no transformation (in
4094 >         * for an element, or null if there is no transformation (in
4095           * which case it is not combined).
4096           * @param reducer a commutative associative combining function
4097           * @return the result of accumulating the given transformation
# Line 4163 | Line 4186 | public class ConcurrentHashMapV8<K, V>
4186              (ConcurrentHashMapV8<K,V> map,
4187               BiAction<K,V> action) {
4188              if (action == null) throw new NullPointerException();
4189 <            return new ForEachMappingTask<K,V>(map, action);
4189 >            return new ForEachMappingTask<K,V>(map, null, -1, action);
4190          }
4191  
4192          /**
# Line 4172 | Line 4195 | public class ConcurrentHashMapV8<K, V>
4195           *
4196           * @param map the map
4197           * @param transformer a function returning the transformation
4198 <         * for an element, or null of there is no transformation (in
4199 <         * which case the action is not applied).
4198 >         * for an element, or null if there is no transformation (in
4199 >         * which case the action is not applied)
4200           * @param action the action
4201           * @return the task
4202           */
# Line 4184 | Line 4207 | public class ConcurrentHashMapV8<K, V>
4207              if (transformer == null || action == null)
4208                  throw new NullPointerException();
4209              return new ForEachTransformedMappingTask<K,V,U>
4210 <                (map, transformer, action);
4210 >                (map, null, -1, transformer, action);
4211          }
4212  
4213          /**
4214 <         * Returns a task that when invoked, returns a non-null
4215 <         * result from applying the given search function on each
4216 <         * (key, value), or null if none.  Further element processing
4217 <         * is suppressed upon success. However, this method does not
4218 <         * return until other in-progress parallel invocations of the
4196 <         * search function also complete.
4214 >         * Returns a task that when invoked, returns a non-null result
4215 >         * from applying the given search function on each (key,
4216 >         * value), or null if none. Upon success, further element
4217 >         * processing is suppressed and the results of any other
4218 >         * parallel invocations of the search function are ignored.
4219           *
4220           * @param map the map
4221           * @param searchFunction a function returning a non-null
# Line 4205 | Line 4227 | public class ConcurrentHashMapV8<K, V>
4227               BiFun<? super K, ? super V, ? extends U> searchFunction) {
4228              if (searchFunction == null) throw new NullPointerException();
4229              return new SearchMappingsTask<K,V,U>
4230 <                (map, searchFunction,
4230 >                (map, null, -1, searchFunction,
4231                   new AtomicReference<U>());
4232          }
4233  
# Line 4216 | Line 4238 | public class ConcurrentHashMapV8<K, V>
4238           *
4239           * @param map the map
4240           * @param transformer a function returning the transformation
4241 <         * for an element, or null of there is no transformation (in
4241 >         * for an element, or null if there is no transformation (in
4242           * which case it is not combined).
4243           * @param reducer a commutative associative combining function
4244           * @return the task
# Line 4228 | Line 4250 | public class ConcurrentHashMapV8<K, V>
4250              if (transformer == null || reducer == null)
4251                  throw new NullPointerException();
4252              return new MapReduceMappingsTask<K,V,U>
4253 <                (map, transformer, reducer);
4253 >                (map, null, -1, null, transformer, reducer);
4254          }
4255  
4256          /**
# Line 4252 | Line 4274 | public class ConcurrentHashMapV8<K, V>
4274              if (transformer == null || reducer == null)
4275                  throw new NullPointerException();
4276              return new MapReduceMappingsToDoubleTask<K,V>
4277 <                (map, transformer, basis, reducer);
4277 >                (map, null, -1, null, transformer, basis, reducer);
4278          }
4279  
4280          /**
# Line 4276 | Line 4298 | public class ConcurrentHashMapV8<K, V>
4298              if (transformer == null || reducer == null)
4299                  throw new NullPointerException();
4300              return new MapReduceMappingsToLongTask<K,V>
4301 <                (map, transformer, basis, reducer);
4301 >                (map, null, -1, null, transformer, basis, reducer);
4302          }
4303  
4304          /**
# Line 4299 | Line 4321 | public class ConcurrentHashMapV8<K, V>
4321              if (transformer == null || reducer == null)
4322                  throw new NullPointerException();
4323              return new MapReduceMappingsToIntTask<K,V>
4324 <                (map, transformer, basis, reducer);
4324 >                (map, null, -1, null, transformer, basis, reducer);
4325          }
4326  
4327          /**
4328           * Returns a task that when invoked, performs the given action
4329 <         * for each key
4329 >         * for each key.
4330           *
4331           * @param map the map
4332           * @param action the action
# Line 4314 | Line 4336 | public class ConcurrentHashMapV8<K, V>
4336              (ConcurrentHashMapV8<K,V> map,
4337               Action<K> action) {
4338              if (action == null) throw new NullPointerException();
4339 <            return new ForEachKeyTask<K,V>(map, action);
4339 >            return new ForEachKeyTask<K,V>(map, null, -1, action);
4340          }
4341  
4342          /**
4343           * Returns a task that when invoked, performs the given action
4344 <         * for each non-null transformation of each key
4344 >         * for each non-null transformation of each key.
4345           *
4346           * @param map the map
4347           * @param transformer a function returning the transformation
4348 <         * for an element, or null of there is no transformation (in
4349 <         * which case the action is not applied).
4348 >         * for an element, or null if there is no transformation (in
4349 >         * which case the action is not applied)
4350           * @param action the action
4351           * @return the task
4352           */
# Line 4335 | Line 4357 | public class ConcurrentHashMapV8<K, V>
4357              if (transformer == null || action == null)
4358                  throw new NullPointerException();
4359              return new ForEachTransformedKeyTask<K,V,U>
4360 <                (map, transformer, action);
4360 >                (map, null, -1, transformer, action);
4361          }
4362  
4363          /**
4364           * Returns a task that when invoked, returns a non-null result
4365           * from applying the given search function on each key, or
4366 <         * null if none.  Further element processing is suppressed
4367 <         * upon success. However, this method does not return until
4368 <         * other in-progress parallel invocations of the search
4347 <         * function also complete.
4366 >         * null if none.  Upon success, further element processing is
4367 >         * suppressed and the results of any other parallel
4368 >         * invocations of the search function are ignored.
4369           *
4370           * @param map the map
4371           * @param searchFunction a function returning a non-null
# Line 4356 | Line 4377 | public class ConcurrentHashMapV8<K, V>
4377               Fun<? super K, ? extends U> searchFunction) {
4378              if (searchFunction == null) throw new NullPointerException();
4379              return new SearchKeysTask<K,V,U>
4380 <                (map, searchFunction,
4380 >                (map, null, -1, searchFunction,
4381                   new AtomicReference<U>());
4382          }
4383  
# Line 4374 | Line 4395 | public class ConcurrentHashMapV8<K, V>
4395               BiFun<? super K, ? super K, ? extends K> reducer) {
4396              if (reducer == null) throw new NullPointerException();
4397              return new ReduceKeysTask<K,V>
4398 <                (map, reducer);
4398 >                (map, null, -1, null, reducer);
4399          }
4400 +
4401          /**
4402           * Returns a task that when invoked, returns the result of
4403           * accumulating the given transformation of all keys using the given
# Line 4383 | Line 4405 | public class ConcurrentHashMapV8<K, V>
4405           *
4406           * @param map the map
4407           * @param transformer a function returning the transformation
4408 <         * for an element, or null of there is no transformation (in
4408 >         * for an element, or null if there is no transformation (in
4409           * which case it is not combined).
4410           * @param reducer a commutative associative combining function
4411           * @return the task
# Line 4395 | Line 4417 | public class ConcurrentHashMapV8<K, V>
4417              if (transformer == null || reducer == null)
4418                  throw new NullPointerException();
4419              return new MapReduceKeysTask<K,V,U>
4420 <                (map, transformer, reducer);
4420 >                (map, null, -1, null, transformer, reducer);
4421          }
4422  
4423          /**
# Line 4419 | Line 4441 | public class ConcurrentHashMapV8<K, V>
4441              if (transformer == null || reducer == null)
4442                  throw new NullPointerException();
4443              return new MapReduceKeysToDoubleTask<K,V>
4444 <                (map, transformer, basis, reducer);
4444 >                (map, null, -1, null, transformer, basis, reducer);
4445          }
4446  
4447          /**
# Line 4443 | Line 4465 | public class ConcurrentHashMapV8<K, V>
4465              if (transformer == null || reducer == null)
4466                  throw new NullPointerException();
4467              return new MapReduceKeysToLongTask<K,V>
4468 <                (map, transformer, basis, reducer);
4468 >                (map, null, -1, null, transformer, basis, reducer);
4469          }
4470  
4471          /**
# Line 4467 | Line 4489 | public class ConcurrentHashMapV8<K, V>
4489              if (transformer == null || reducer == null)
4490                  throw new NullPointerException();
4491              return new MapReduceKeysToIntTask<K,V>
4492 <                (map, transformer, basis, reducer);
4492 >                (map, null, -1, null, transformer, basis, reducer);
4493          }
4494  
4495          /**
4496           * Returns a task that when invoked, performs the given action
4497 <         * for each value
4497 >         * for each value.
4498           *
4499           * @param map the map
4500           * @param action the action
# Line 4481 | Line 4503 | public class ConcurrentHashMapV8<K, V>
4503              (ConcurrentHashMapV8<K,V> map,
4504               Action<V> action) {
4505              if (action == null) throw new NullPointerException();
4506 <            return new ForEachValueTask<K,V>(map, action);
4506 >            return new ForEachValueTask<K,V>(map, null, -1, action);
4507          }
4508  
4509          /**
4510           * Returns a task that when invoked, performs the given action
4511 <         * for each non-null transformation of each value
4511 >         * for each non-null transformation of each value.
4512           *
4513           * @param map the map
4514           * @param transformer a function returning the transformation
4515 <         * for an element, or null of there is no transformation (in
4516 <         * which case the action is not applied).
4515 >         * for an element, or null if there is no transformation (in
4516 >         * which case the action is not applied)
4517           * @param action the action
4518           */
4519          public static <K,V,U> ForkJoinTask<Void> forEachValue
# Line 4501 | Line 4523 | public class ConcurrentHashMapV8<K, V>
4523              if (transformer == null || action == null)
4524                  throw new NullPointerException();
4525              return new ForEachTransformedValueTask<K,V,U>
4526 <                (map, transformer, action);
4526 >                (map, null, -1, transformer, action);
4527          }
4528  
4529          /**
4530           * Returns a task that when invoked, returns a non-null result
4531           * from applying the given search function on each value, or
4532 <         * null if none.  Further element processing is suppressed
4533 <         * upon success. However, this method does not return until
4534 <         * other in-progress parallel invocations of the search
4513 <         * function also complete.
4532 >         * null if none.  Upon success, further element processing is
4533 >         * suppressed and the results of any other parallel
4534 >         * invocations of the search function are ignored.
4535           *
4536           * @param map the map
4537           * @param searchFunction a function returning a non-null
4538           * result on success, else null
4539           * @return the task
4519         *
4540           */
4541          public static <K,V,U> ForkJoinTask<U> searchValues
4542              (ConcurrentHashMapV8<K,V> map,
4543               Fun<? super V, ? extends U> searchFunction) {
4544              if (searchFunction == null) throw new NullPointerException();
4545              return new SearchValuesTask<K,V,U>
4546 <                (map, searchFunction,
4546 >                (map, null, -1, searchFunction,
4547                   new AtomicReference<U>());
4548          }
4549  
# Line 4541 | Line 4561 | public class ConcurrentHashMapV8<K, V>
4561               BiFun<? super V, ? super V, ? extends V> reducer) {
4562              if (reducer == null) throw new NullPointerException();
4563              return new ReduceValuesTask<K,V>
4564 <                (map, reducer);
4564 >                (map, null, -1, null, reducer);
4565          }
4566  
4567          /**
# Line 4551 | Line 4571 | public class ConcurrentHashMapV8<K, V>
4571           *
4572           * @param map the map
4573           * @param transformer a function returning the transformation
4574 <         * for an element, or null of there is no transformation (in
4574 >         * for an element, or null if there is no transformation (in
4575           * which case it is not combined).
4576           * @param reducer a commutative associative combining function
4577           * @return the task
# Line 4563 | Line 4583 | public class ConcurrentHashMapV8<K, V>
4583              if (transformer == null || reducer == null)
4584                  throw new NullPointerException();
4585              return new MapReduceValuesTask<K,V,U>
4586 <                (map, transformer, reducer);
4586 >                (map, null, -1, null, transformer, reducer);
4587          }
4588  
4589          /**
# Line 4587 | Line 4607 | public class ConcurrentHashMapV8<K, V>
4607              if (transformer == null || reducer == null)
4608                  throw new NullPointerException();
4609              return new MapReduceValuesToDoubleTask<K,V>
4610 <                (map, transformer, basis, reducer);
4610 >                (map, null, -1, null, transformer, basis, reducer);
4611          }
4612  
4613          /**
# Line 4611 | Line 4631 | public class ConcurrentHashMapV8<K, V>
4631              if (transformer == null || reducer == null)
4632                  throw new NullPointerException();
4633              return new MapReduceValuesToLongTask<K,V>
4634 <                (map, transformer, basis, reducer);
4634 >                (map, null, -1, null, transformer, basis, reducer);
4635          }
4636  
4637          /**
# Line 4635 | Line 4655 | public class ConcurrentHashMapV8<K, V>
4655              if (transformer == null || reducer == null)
4656                  throw new NullPointerException();
4657              return new MapReduceValuesToIntTask<K,V>
4658 <                (map, transformer, basis, reducer);
4658 >                (map, null, -1, null, transformer, basis, reducer);
4659          }
4660  
4661          /**
4662           * Returns a task that when invoked, perform the given action
4663 <         * for each entry
4663 >         * for each entry.
4664           *
4665           * @param map the map
4666           * @param action the action
# Line 4649 | Line 4669 | public class ConcurrentHashMapV8<K, V>
4669              (ConcurrentHashMapV8<K,V> map,
4670               Action<Map.Entry<K,V>> action) {
4671              if (action == null) throw new NullPointerException();
4672 <            return new ForEachEntryTask<K,V>(map, action);
4672 >            return new ForEachEntryTask<K,V>(map, null, -1, action);
4673          }
4674  
4675          /**
4676           * Returns a task that when invoked, perform the given action
4677 <         * for each non-null transformation of each entry
4677 >         * for each non-null transformation of each entry.
4678           *
4679           * @param map the map
4680           * @param transformer a function returning the transformation
4681 <         * for an element, or null of there is no transformation (in
4682 <         * which case the action is not applied).
4681 >         * for an element, or null if there is no transformation (in
4682 >         * which case the action is not applied)
4683           * @param action the action
4684           */
4685          public static <K,V,U> ForkJoinTask<Void> forEachEntry
# Line 4669 | Line 4689 | public class ConcurrentHashMapV8<K, V>
4689              if (transformer == null || action == null)
4690                  throw new NullPointerException();
4691              return new ForEachTransformedEntryTask<K,V,U>
4692 <                (map, transformer, action);
4692 >                (map, null, -1, transformer, action);
4693          }
4694  
4695          /**
4696           * Returns a task that when invoked, returns a non-null result
4697           * from applying the given search function on each entry, or
4698 <         * null if none.  Further element processing is suppressed
4699 <         * upon success. However, this method does not return until
4700 <         * other in-progress parallel invocations of the search
4681 <         * function also complete.
4698 >         * null if none.  Upon success, further element processing is
4699 >         * suppressed and the results of any other parallel
4700 >         * invocations of the search function are ignored.
4701           *
4702           * @param map the map
4703           * @param searchFunction a function returning a non-null
4704           * result on success, else null
4705           * @return the task
4687         *
4706           */
4707          public static <K,V,U> ForkJoinTask<U> searchEntries
4708              (ConcurrentHashMapV8<K,V> map,
4709               Fun<Map.Entry<K,V>, ? extends U> searchFunction) {
4710              if (searchFunction == null) throw new NullPointerException();
4711              return new SearchEntriesTask<K,V,U>
4712 <                (map, searchFunction,
4712 >                (map, null, -1, searchFunction,
4713                   new AtomicReference<U>());
4714          }
4715  
# Line 4709 | Line 4727 | public class ConcurrentHashMapV8<K, V>
4727               BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
4728              if (reducer == null) throw new NullPointerException();
4729              return new ReduceEntriesTask<K,V>
4730 <                (map, reducer);
4730 >                (map, null, -1, null, reducer);
4731          }
4732  
4733          /**
# Line 4719 | Line 4737 | public class ConcurrentHashMapV8<K, V>
4737           *
4738           * @param map the map
4739           * @param transformer a function returning the transformation
4740 <         * for an element, or null of there is no transformation (in
4740 >         * for an element, or null if there is no transformation (in
4741           * which case it is not combined).
4742           * @param reducer a commutative associative combining function
4743           * @return the task
# Line 4731 | Line 4749 | public class ConcurrentHashMapV8<K, V>
4749              if (transformer == null || reducer == null)
4750                  throw new NullPointerException();
4751              return new MapReduceEntriesTask<K,V,U>
4752 <                (map, transformer, reducer);
4752 >                (map, null, -1, null, transformer, reducer);
4753          }
4754  
4755          /**
# Line 4755 | Line 4773 | public class ConcurrentHashMapV8<K, V>
4773              if (transformer == null || reducer == null)
4774                  throw new NullPointerException();
4775              return new MapReduceEntriesToDoubleTask<K,V>
4776 <                (map, transformer, basis, reducer);
4776 >                (map, null, -1, null, transformer, basis, reducer);
4777          }
4778  
4779          /**
# Line 4779 | Line 4797 | public class ConcurrentHashMapV8<K, V>
4797              if (transformer == null || reducer == null)
4798                  throw new NullPointerException();
4799              return new MapReduceEntriesToLongTask<K,V>
4800 <                (map, transformer, basis, reducer);
4800 >                (map, null, -1, null, transformer, basis, reducer);
4801          }
4802  
4803          /**
# Line 4803 | Line 4821 | public class ConcurrentHashMapV8<K, V>
4821              if (transformer == null || reducer == null)
4822                  throw new NullPointerException();
4823              return new MapReduceEntriesToIntTask<K,V>
4824 <                (map, transformer, basis, reducer);
4824 >                (map, null, -1, null, transformer, basis, reducer);
4825          }
4826      }
4827  
# Line 4811 | Line 4829 | public class ConcurrentHashMapV8<K, V>
4829  
4830      /**
4831       * Base for FJ tasks for bulk operations. This adds a variant of
4832 <     * CountedCompleters and some split and merge bookeeping to
4832 >     * CountedCompleters and some split and merge bookkeeping to
4833       * iterator functionality. The forEach and reduce methods are
4834       * similar to those illustrated in CountedCompleter documentation,
4835       * except that bottom-up reduction completions perform them within
# Line 4820 | Line 4838 | public class ConcurrentHashMapV8<K, V>
4838       * exceptions are handled in a simpler manner, by just trying to
4839       * complete root task exceptionally.
4840       */
4841 <    static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> {
4841 >    @SuppressWarnings("serial") static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> {
4842          final BulkTask<K,V,?> parent;  // completion target
4843 <        int batch;                     // split control
4843 >        int batch;                     // split control; -1 for unknown
4844          int pending;                   // completion control
4845  
4846 <        /** Constructor for root tasks */
4847 <        BulkTask(ConcurrentHashMapV8<K,V> map) {
4846 >        BulkTask(ConcurrentHashMapV8<K,V> map, BulkTask<K,V,?> parent,
4847 >                 int batch) {
4848              super(map);
4831            this.parent = null;
4832            this.batch = -1; // force call to batch() on execution
4833        }
4834
4835        /** Constructor for subtasks */
4836        BulkTask(BulkTask<K,V,?> parent, int batch, boolean split) {
4837            super(parent, split);
4849              this.parent = parent;
4850              this.batch = batch;
4851 +            if (parent != null && map != null) { // split parent
4852 +                Node[] t;
4853 +                if ((t = parent.tab) == null &&
4854 +                    (t = parent.tab = map.table) != null)
4855 +                    parent.baseLimit = parent.baseSize = t.length;
4856 +                this.tab = t;
4857 +                this.baseSize = parent.baseSize;
4858 +                int hi = this.baseLimit = parent.baseLimit;
4859 +                parent.baseLimit = this.index = this.baseIndex =
4860 +                    (hi + parent.baseIndex + 1) >>> 1;
4861 +            }
4862          }
4863  
4864          // FJ methods
4865  
4866          /**
4867 <         * Propagate completion. Note that all reduce actions
4867 >         * Propagates completion. Note that all reduce actions
4868           * bypass this method to combine while completing.
4869           */
4870          final void tryComplete() {
# Line 4860 | Line 4882 | public class ConcurrentHashMapV8<K, V>
4882          }
4883  
4884          /**
4885 <         * Force root task to throw exception unless already complete.
4885 >         * Forces root task to complete.
4886 >         * @param ex if null, complete normally, else exceptionally
4887 >         * @return false to simplify use
4888           */
4889 <        final void tryAbortComputation(Throwable ex) {
4889 >        final boolean tryCompleteComputation(Throwable ex) {
4890              for (BulkTask<K,V,?> a = this;;) {
4891                  BulkTask<K,V,?> p = a.parent;
4892                  if (p == null) {
4893 <                    a.completeExceptionally(ex);
4894 <                    break;
4893 >                    if (ex != null)
4894 >                        a.completeExceptionally(ex);
4895 >                    else
4896 >                        a.quietlyComplete();
4897 >                    return false;
4898                  }
4899                  a = p;
4900              }
4901          }
4902  
4903 <        public final boolean exec() {
4904 <            try {
4905 <                compute();
4906 <            }
4907 <            catch (Throwable ex) {
4881 <                tryAbortComputation(ex);
4882 <            }
4883 <            return false;
4903 >        /**
4904 >         * Version of tryCompleteComputation for function screening checks
4905 >         */
4906 >        final boolean abortOnNullFunction() {
4907 >            return tryCompleteComputation(new Error("Unexpected null function"));
4908          }
4909  
4886        public abstract void compute();
4887
4910          // utilities
4911  
4912          /** CompareAndSet pending count */
# Line 4893 | Line 4915 | public class ConcurrentHashMapV8<K, V>
4915          }
4916  
4917          /**
4918 <         * Return approx exp2 of the number of times (minus one) to
4918 >         * Returns approx exp2 of the number of times (minus one) to
4919           * split task by two before executing leaf action. This value
4920           * is faster to compute and more convenient to use as a guide
4921           * to splitting than is the depth, since it is used while
4922           * dividing by two anyway.
4923           */
4924          final int batch() {
4925 <            int b = batch;
4926 <            if (b < 0) {
4927 <                long n = map.counter.sum();
4928 <                int sp = getPool().getParallelism() << 3; // slack of 8
4929 <                b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp;
4925 >            ConcurrentHashMapV8<K, V> m; int b; Node[] t;
4926 >            if ((b = batch) < 0 && (m = map) != null) { // force initialization
4927 >                if ((t = tab) == null && (t = tab = m.table) != null)
4928 >                    baseLimit = baseSize = t.length;
4929 >                if (t != null) {
4930 >                    long n = m.counter.sum();
4931 >                    int sp = getPool().getParallelism() << 3; // slack of 8
4932 >                    b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp;
4933 >                }
4934              }
4935              return b;
4936          }
4937  
4938          /**
4939 <         * Error message for hoisted null checks of functions
4914 <         */
4915 <        static final String NullFunctionMessage =
4916 <            "Unexpected null function";
4917 <
4918 <        /**
4919 <         * Return exportable snapshot entry
4939 >         * Returns exportable snapshot entry.
4940           */
4941          static <K,V> AbstractMap.SimpleEntry<K,V> entryFor(K k, V v) {
4942 <            return new AbstractMap.SimpleEntry(k, v);
4942 >            return new AbstractMap.SimpleEntry<K,V>(k, v);
4943          }
4944  
4945          // Unsafe mechanics
# Line 4927 | Line 4947 | public class ConcurrentHashMapV8<K, V>
4947          private static final long PENDING;
4948          static {
4949              try {
4950 <                U = sun.misc.Unsafe.getUnsafe();
4950 >                U = getUnsafe();
4951                  PENDING = U.objectFieldOffset
4952                      (BulkTask.class.getDeclaredField("pending"));
4953              } catch (Exception e) {
# Line 4942 | Line 4962 | public class ConcurrentHashMapV8<K, V>
4962       * others.
4963       */
4964  
4965 <    static final class ForEachKeyTask<K,V>
4965 >    @SuppressWarnings("serial") static final class ForEachKeyTask<K,V>
4966          extends BulkTask<K,V,Void> {
4967          final Action<K> action;
4968          ForEachKeyTask
4969 <            (ConcurrentHashMapV8<K,V> m,
4950 <             Action<K> action) {
4951 <            super(m);
4952 <            this.action = action;
4953 <        }
4954 <        ForEachKeyTask
4955 <            (BulkTask<K,V,?> p, int b, boolean split,
4969 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
4970               Action<K> action) {
4971 <            super(p, b, split);
4971 >            super(m, p, b);
4972              this.action = action;
4973          }
4974 <        public final void compute() {
4974 >        @SuppressWarnings("unchecked") public final boolean exec() {
4975              final Action<K> action = this.action;
4976              if (action == null)
4977 <                throw new Error(NullFunctionMessage);
4978 <            int b = batch(), c;
4979 <            while (b > 1 && baseIndex != baseLimit) {
4980 <                do {} while (!casPending(c = pending, c+1));
4981 <                new ForEachKeyTask<K,V>(this, b >>>= 1, true, action).fork();
4977 >                return abortOnNullFunction();
4978 >            try {
4979 >                int b = batch(), c;
4980 >                while (b > 1 && baseIndex != baseLimit) {
4981 >                    do {} while (!casPending(c = pending, c+1));
4982 >                    new ForEachKeyTask<K,V>(map, this, b >>>= 1, action).fork();
4983 >                }
4984 >                while (advance() != null)
4985 >                    action.apply((K)nextKey);
4986 >                tryComplete();
4987 >            } catch (Throwable ex) {
4988 >                return tryCompleteComputation(ex);
4989              }
4990 <            while (advance() != null)
4970 <                action.apply((K)nextKey);
4971 <            tryComplete();
4990 >            return false;
4991          }
4992      }
4993  
4994 <    static final class ForEachValueTask<K,V>
4994 >    @SuppressWarnings("serial") static final class ForEachValueTask<K,V>
4995          extends BulkTask<K,V,Void> {
4996          final Action<V> action;
4997          ForEachValueTask
4998 <            (ConcurrentHashMapV8<K,V> m,
4980 <             Action<V> action) {
4981 <            super(m);
4982 <            this.action = action;
4983 <        }
4984 <        ForEachValueTask
4985 <            (BulkTask<K,V,?> p, int b, boolean split,
4998 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
4999               Action<V> action) {
5000 <            super(p, b, split);
5000 >            super(m, p, b);
5001              this.action = action;
5002          }
5003 <        public final void compute() {
5003 >        @SuppressWarnings("unchecked") public final boolean exec() {
5004              final Action<V> action = this.action;
5005              if (action == null)
5006 <                throw new Error(NullFunctionMessage);
5007 <            int b = batch(), c;
5008 <            while (b > 1 && baseIndex != baseLimit) {
5009 <                do {} while (!casPending(c = pending, c+1));
5010 <                new ForEachValueTask<K,V>(this, b >>>= 1, true, action).fork();
5006 >                return abortOnNullFunction();
5007 >            try {
5008 >                int b = batch(), c;
5009 >                while (b > 1 && baseIndex != baseLimit) {
5010 >                    do {} while (!casPending(c = pending, c+1));
5011 >                    new ForEachValueTask<K,V>(map, this, b >>>= 1, action).fork();
5012 >                }
5013 >                Object v;
5014 >                while ((v = advance()) != null)
5015 >                    action.apply((V)v);
5016 >                tryComplete();
5017 >            } catch (Throwable ex) {
5018 >                return tryCompleteComputation(ex);
5019              }
5020 <            Object v;
5000 <            while ((v = advance()) != null)
5001 <                action.apply((V)v);
5002 <            tryComplete();
5020 >            return false;
5021          }
5022      }
5023  
5024 <    static final class ForEachEntryTask<K,V>
5024 >    @SuppressWarnings("serial") static final class ForEachEntryTask<K,V>
5025          extends BulkTask<K,V,Void> {
5026          final Action<Entry<K,V>> action;
5027          ForEachEntryTask
5028 <            (ConcurrentHashMapV8<K,V> m,
5011 <             Action<Entry<K,V>> action) {
5012 <            super(m);
5013 <            this.action = action;
5014 <        }
5015 <        ForEachEntryTask
5016 <            (BulkTask<K,V,?> p, int b, boolean split,
5028 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5029               Action<Entry<K,V>> action) {
5030 <            super(p, b, split);
5030 >            super(m, p, b);
5031              this.action = action;
5032          }
5033 <        public final void compute() {
5033 >        @SuppressWarnings("unchecked") public final boolean exec() {
5034              final Action<Entry<K,V>> action = this.action;
5035              if (action == null)
5036 <                throw new Error(NullFunctionMessage);
5037 <            int b = batch(), c;
5038 <            while (b > 1 && baseIndex != baseLimit) {
5039 <                do {} while (!casPending(c = pending, c+1));
5040 <                new ForEachEntryTask<K,V>(this, b >>>= 1, true, action).fork();
5036 >                return abortOnNullFunction();
5037 >            try {
5038 >                int b = batch(), c;
5039 >                while (b > 1 && baseIndex != baseLimit) {
5040 >                    do {} while (!casPending(c = pending, c+1));
5041 >                    new ForEachEntryTask<K,V>(map, this, b >>>= 1, action).fork();
5042 >                }
5043 >                Object v;
5044 >                while ((v = advance()) != null)
5045 >                    action.apply(entryFor((K)nextKey, (V)v));
5046 >                tryComplete();
5047 >            } catch (Throwable ex) {
5048 >                return tryCompleteComputation(ex);
5049              }
5050 <            Object v;
5031 <            while ((v = advance()) != null)
5032 <                action.apply(entryFor((K)nextKey, (V)v));
5033 <            tryComplete();
5050 >            return false;
5051          }
5052      }
5053  
5054 <    static final class ForEachMappingTask<K,V>
5054 >    @SuppressWarnings("serial") static final class ForEachMappingTask<K,V>
5055          extends BulkTask<K,V,Void> {
5056          final BiAction<K,V> action;
5057          ForEachMappingTask
5058 <            (ConcurrentHashMapV8<K,V> m,
5042 <             BiAction<K,V> action) {
5043 <            super(m);
5044 <            this.action = action;
5045 <        }
5046 <        ForEachMappingTask
5047 <            (BulkTask<K,V,?> p, int b, boolean split,
5058 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5059               BiAction<K,V> action) {
5060 <            super(p, b, split);
5060 >            super(m, p, b);
5061              this.action = action;
5062          }
5063 <
5053 <        public final void compute() {
5063 >        @SuppressWarnings("unchecked") public final boolean exec() {
5064              final BiAction<K,V> action = this.action;
5065              if (action == null)
5066 <                throw new Error(NullFunctionMessage);
5067 <            int b = batch(), c;
5068 <            while (b > 1 && baseIndex != baseLimit) {
5069 <                do {} while (!casPending(c = pending, c+1));
5070 <                new ForEachMappingTask<K,V>(this, b >>>= 1, true,
5071 <                                            action).fork();
5066 >                return abortOnNullFunction();
5067 >            try {
5068 >                int b = batch(), c;
5069 >                while (b > 1 && baseIndex != baseLimit) {
5070 >                    do {} while (!casPending(c = pending, c+1));
5071 >                    new ForEachMappingTask<K,V>(map, this, b >>>= 1,
5072 >                                                action).fork();
5073 >                }
5074 >                Object v;
5075 >                while ((v = advance()) != null)
5076 >                    action.apply((K)nextKey, (V)v);
5077 >                tryComplete();
5078 >            } catch (Throwable ex) {
5079 >                return tryCompleteComputation(ex);
5080              }
5081 <            Object v;
5064 <            while ((v = advance()) != null)
5065 <                action.apply((K)nextKey, (V)v);
5066 <            tryComplete();
5081 >            return false;
5082          }
5083      }
5084  
5085 <    static final class ForEachTransformedKeyTask<K,V,U>
5085 >    @SuppressWarnings("serial") static final class ForEachTransformedKeyTask<K,V,U>
5086          extends BulkTask<K,V,Void> {
5087          final Fun<? super K, ? extends U> transformer;
5088          final Action<U> action;
5089          ForEachTransformedKeyTask
5090 <            (ConcurrentHashMapV8<K,V> m,
5090 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5091               Fun<? super K, ? extends U> transformer,
5092               Action<U> action) {
5093 <            super(m);
5093 >            super(m, p, b);
5094              this.transformer = transformer;
5095              this.action = action;
5096  
5097          }
5098 <        ForEachTransformedKeyTask
5084 <            (BulkTask<K,V,?> p, int b, boolean split,
5085 <             Fun<? super K, ? extends U> transformer,
5086 <             Action<U> action) {
5087 <            super(p, b, split);
5088 <            this.transformer = transformer;
5089 <            this.action = action;
5090 <        }
5091 <        public final void compute() {
5098 >        @SuppressWarnings("unchecked") public final boolean exec() {
5099              final Fun<? super K, ? extends U> transformer =
5100                  this.transformer;
5101              final Action<U> action = this.action;
5102              if (transformer == null || action == null)
5103 <                throw new Error(NullFunctionMessage);
5104 <            int b = batch(), c;
5105 <            while (b > 1 && baseIndex != baseLimit) {
5106 <                do {} while (!casPending(c = pending, c+1));
5107 <                new ForEachTransformedKeyTask<K,V,U>
5108 <                    (this, b >>>= 1, true, transformer, action).fork();
5109 <            }
5110 <            U u;
5111 <            while (advance() != null) {
5112 <                if ((u = transformer.apply((K)nextKey)) != null)
5113 <                    action.apply(u);
5103 >                return abortOnNullFunction();
5104 >            try {
5105 >                int b = batch(), c;
5106 >                while (b > 1 && baseIndex != baseLimit) {
5107 >                    do {} while (!casPending(c = pending, c+1));
5108 >                    new ForEachTransformedKeyTask<K,V,U>
5109 >                        (map, this, b >>>= 1, transformer, action).fork();
5110 >                }
5111 >                U u;
5112 >                while (advance() != null) {
5113 >                    if ((u = transformer.apply((K)nextKey)) != null)
5114 >                        action.apply(u);
5115 >                }
5116 >                tryComplete();
5117 >            } catch (Throwable ex) {
5118 >                return tryCompleteComputation(ex);
5119              }
5120 <            tryComplete();
5120 >            return false;
5121          }
5122      }
5123  
5124 <    static final class ForEachTransformedValueTask<K,V,U>
5124 >    @SuppressWarnings("serial") static final class ForEachTransformedValueTask<K,V,U>
5125          extends BulkTask<K,V,Void> {
5126          final Fun<? super V, ? extends U> transformer;
5127          final Action<U> action;
5128          ForEachTransformedValueTask
5129 <            (ConcurrentHashMapV8<K,V> m,
5129 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5130               Fun<? super V, ? extends U> transformer,
5131               Action<U> action) {
5132 <            super(m);
5132 >            super(m, p, b);
5133              this.transformer = transformer;
5134              this.action = action;
5135  
5136          }
5137 <        ForEachTransformedValueTask
5126 <            (BulkTask<K,V,?> p, int b, boolean split,
5127 <             Fun<? super V, ? extends U> transformer,
5128 <             Action<U> action) {
5129 <            super(p, b, split);
5130 <            this.transformer = transformer;
5131 <            this.action = action;
5132 <        }
5133 <        public final void compute() {
5137 >        @SuppressWarnings("unchecked") public final boolean exec() {
5138              final Fun<? super V, ? extends U> transformer =
5139                  this.transformer;
5140              final Action<U> action = this.action;
5141              if (transformer == null || action == null)
5142 <                throw new Error(NullFunctionMessage);
5143 <            int b = batch(), c;
5144 <            while (b > 1 && baseIndex != baseLimit) {
5145 <                do {} while (!casPending(c = pending, c+1));
5146 <                new ForEachTransformedValueTask<K,V,U>
5147 <                    (this, b >>>= 1, true, transformer, action).fork();
5148 <            }
5149 <            Object v; U u;
5150 <            while ((v = advance()) != null) {
5151 <                if ((u = transformer.apply((V)v)) != null)
5152 <                    action.apply(u);
5142 >                return abortOnNullFunction();
5143 >            try {
5144 >                int b = batch(), c;
5145 >                while (b > 1 && baseIndex != baseLimit) {
5146 >                    do {} while (!casPending(c = pending, c+1));
5147 >                    new ForEachTransformedValueTask<K,V,U>
5148 >                        (map, this, b >>>= 1, transformer, action).fork();
5149 >                }
5150 >                Object v; U u;
5151 >                while ((v = advance()) != null) {
5152 >                    if ((u = transformer.apply((V)v)) != null)
5153 >                        action.apply(u);
5154 >                }
5155 >                tryComplete();
5156 >            } catch (Throwable ex) {
5157 >                return tryCompleteComputation(ex);
5158              }
5159 <            tryComplete();
5159 >            return false;
5160          }
5161      }
5162  
5163 <    static final class ForEachTransformedEntryTask<K,V,U>
5163 >    @SuppressWarnings("serial") static final class ForEachTransformedEntryTask<K,V,U>
5164          extends BulkTask<K,V,Void> {
5165          final Fun<Map.Entry<K,V>, ? extends U> transformer;
5166          final Action<U> action;
5167          ForEachTransformedEntryTask
5168 <            (ConcurrentHashMapV8<K,V> m,
5168 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5169               Fun<Map.Entry<K,V>, ? extends U> transformer,
5170               Action<U> action) {
5171 <            super(m);
5171 >            super(m, p, b);
5172              this.transformer = transformer;
5173              this.action = action;
5174  
5175          }
5176 <        ForEachTransformedEntryTask
5168 <            (BulkTask<K,V,?> p, int b, boolean split,
5169 <             Fun<Map.Entry<K,V>, ? extends U> transformer,
5170 <             Action<U> action) {
5171 <            super(p, b, split);
5172 <            this.transformer = transformer;
5173 <            this.action = action;
5174 <        }
5175 <        public final void compute() {
5176 >        @SuppressWarnings("unchecked") public final boolean exec() {
5177              final Fun<Map.Entry<K,V>, ? extends U> transformer =
5178                  this.transformer;
5179              final Action<U> action = this.action;
5180              if (transformer == null || action == null)
5181 <                throw new Error(NullFunctionMessage);
5182 <            int b = batch(), c;
5183 <            while (b > 1 && baseIndex != baseLimit) {
5184 <                do {} while (!casPending(c = pending, c+1));
5185 <                new ForEachTransformedEntryTask<K,V,U>
5186 <                    (this, b >>>= 1, true, transformer, action).fork();
5187 <            }
5188 <            Object v; U u;
5189 <            while ((v = advance()) != null) {
5190 <                if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5191 <                    action.apply(u);
5181 >                return abortOnNullFunction();
5182 >            try {
5183 >                int b = batch(), c;
5184 >                while (b > 1 && baseIndex != baseLimit) {
5185 >                    do {} while (!casPending(c = pending, c+1));
5186 >                    new ForEachTransformedEntryTask<K,V,U>
5187 >                        (map, this, b >>>= 1, transformer, action).fork();
5188 >                }
5189 >                Object v; U u;
5190 >                while ((v = advance()) != null) {
5191 >                    if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5192 >                        action.apply(u);
5193 >                }
5194 >                tryComplete();
5195 >            } catch (Throwable ex) {
5196 >                return tryCompleteComputation(ex);
5197              }
5198 <            tryComplete();
5198 >            return false;
5199          }
5200      }
5201  
5202 <    static final class ForEachTransformedMappingTask<K,V,U>
5202 >    @SuppressWarnings("serial") static final class ForEachTransformedMappingTask<K,V,U>
5203          extends BulkTask<K,V,Void> {
5204          final BiFun<? super K, ? super V, ? extends U> transformer;
5205          final Action<U> action;
5206          ForEachTransformedMappingTask
5207 <            (ConcurrentHashMapV8<K,V> m,
5207 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5208               BiFun<? super K, ? super V, ? extends U> transformer,
5209               Action<U> action) {
5210 <            super(m);
5210 >            super(m, p, b);
5211              this.transformer = transformer;
5212              this.action = action;
5213  
5214          }
5215 <        ForEachTransformedMappingTask
5210 <            (BulkTask<K,V,?> p, int b, boolean split,
5211 <             BiFun<? super K, ? super V, ? extends U> transformer,
5212 <             Action<U> action) {
5213 <            super(p, b, split);
5214 <            this.transformer = transformer;
5215 <            this.action = action;
5216 <        }
5217 <        public final void compute() {
5215 >        @SuppressWarnings("unchecked") public final boolean exec() {
5216              final BiFun<? super K, ? super V, ? extends U> transformer =
5217                  this.transformer;
5218              final Action<U> action = this.action;
5219              if (transformer == null || action == null)
5220 <                throw new Error(NullFunctionMessage);
5221 <            int b = batch(), c;
5222 <            while (b > 1 && baseIndex != baseLimit) {
5223 <                do {} while (!casPending(c = pending, c+1));
5224 <                new ForEachTransformedMappingTask<K,V,U>
5225 <                    (this, b >>>= 1, true, transformer, action).fork();
5226 <            }
5227 <            Object v; U u;
5228 <            while ((v = advance()) != null) {
5229 <                if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5230 <                    action.apply(u);
5220 >                return abortOnNullFunction();
5221 >            try {
5222 >                int b = batch(), c;
5223 >                while (b > 1 && baseIndex != baseLimit) {
5224 >                    do {} while (!casPending(c = pending, c+1));
5225 >                    new ForEachTransformedMappingTask<K,V,U>
5226 >                        (map, this, b >>>= 1, transformer, action).fork();
5227 >                }
5228 >                Object v; U u;
5229 >                while ((v = advance()) != null) {
5230 >                    if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5231 >                        action.apply(u);
5232 >                }
5233 >                tryComplete();
5234 >            } catch (Throwable ex) {
5235 >                return tryCompleteComputation(ex);
5236              }
5237 <            tryComplete();
5237 >            return false;
5238          }
5239      }
5240  
5241 <    static final class SearchKeysTask<K,V,U>
5241 >    @SuppressWarnings("serial") static final class SearchKeysTask<K,V,U>
5242          extends BulkTask<K,V,U> {
5243          final Fun<? super K, ? extends U> searchFunction;
5244          final AtomicReference<U> result;
5245          SearchKeysTask
5246 <            (ConcurrentHashMapV8<K,V> m,
5244 <             Fun<? super K, ? extends U> searchFunction,
5245 <             AtomicReference<U> result) {
5246 <            super(m);
5247 <            this.searchFunction = searchFunction; this.result = result;
5248 <        }
5249 <        SearchKeysTask
5250 <            (BulkTask<K,V,?> p, int b, boolean split,
5246 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5247               Fun<? super K, ? extends U> searchFunction,
5248               AtomicReference<U> result) {
5249 <            super(p, b, split);
5249 >            super(m, p, b);
5250              this.searchFunction = searchFunction; this.result = result;
5251          }
5252 <        public final void compute() {
5252 >        @SuppressWarnings("unchecked") public final boolean exec() {
5253              AtomicReference<U> result = this.result;
5254              final Fun<? super K, ? extends U> searchFunction =
5255                  this.searchFunction;
5256              if (searchFunction == null || result == null)
5257 <                throw new Error(NullFunctionMessage);
5258 <            int b = batch(), c;
5259 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5260 <                do {} while (!casPending(c = pending, c+1));
5261 <                new SearchKeysTask<K,V,U>(this, b >>>= 1, true,
5262 <                                          searchFunction, result).fork();
5263 <            }
5264 <            U u;
5265 <            while (result.get() == null && advance() != null) {
5266 <                if ((u = searchFunction.apply((K)nextKey)) != null) {
5267 <                    result.compareAndSet(null, u);
5268 <                    break;
5257 >                return abortOnNullFunction();
5258 >            try {
5259 >                int b = batch(), c;
5260 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5261 >                    do {} while (!casPending(c = pending, c+1));
5262 >                    new SearchKeysTask<K,V,U>(map, this, b >>>= 1,
5263 >                                              searchFunction, result).fork();
5264 >                }
5265 >                U u;
5266 >                while (result.get() == null && advance() != null) {
5267 >                    if ((u = searchFunction.apply((K)nextKey)) != null) {
5268 >                        if (result.compareAndSet(null, u))
5269 >                            tryCompleteComputation(null);
5270 >                        break;
5271 >                    }
5272                  }
5273 +                tryComplete();
5274 +            } catch (Throwable ex) {
5275 +                return tryCompleteComputation(ex);
5276              }
5277 <            tryComplete();
5277 >            return false;
5278          }
5279          public final U getRawResult() { return result.get(); }
5280      }
5281  
5282 <    static final class SearchValuesTask<K,V,U>
5282 >    @SuppressWarnings("serial") static final class SearchValuesTask<K,V,U>
5283          extends BulkTask<K,V,U> {
5284          final Fun<? super V, ? extends U> searchFunction;
5285          final AtomicReference<U> result;
5286          SearchValuesTask
5287 <            (ConcurrentHashMapV8<K,V> m,
5286 <             Fun<? super V, ? extends U> searchFunction,
5287 <             AtomicReference<U> result) {
5288 <            super(m);
5289 <            this.searchFunction = searchFunction; this.result = result;
5290 <        }
5291 <        SearchValuesTask
5292 <            (BulkTask<K,V,?> p, int b, boolean split,
5287 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5288               Fun<? super V, ? extends U> searchFunction,
5289               AtomicReference<U> result) {
5290 <            super(p, b, split);
5290 >            super(m, p, b);
5291              this.searchFunction = searchFunction; this.result = result;
5292          }
5293 <        public final void compute() {
5293 >        @SuppressWarnings("unchecked") public final boolean exec() {
5294              AtomicReference<U> result = this.result;
5295              final Fun<? super V, ? extends U> searchFunction =
5296                  this.searchFunction;
5297              if (searchFunction == null || result == null)
5298 <                throw new Error(NullFunctionMessage);
5299 <            int b = batch(), c;
5300 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5301 <                do {} while (!casPending(c = pending, c+1));
5302 <                new SearchValuesTask<K,V,U>(this, b >>>= 1, true,
5303 <                                            searchFunction, result).fork();
5304 <            }
5305 <            Object v; U u;
5306 <            while (result.get() == null && (v = advance()) != null) {
5307 <                if ((u = searchFunction.apply((V)v)) != null) {
5308 <                    result.compareAndSet(null, u);
5309 <                    break;
5298 >                return abortOnNullFunction();
5299 >            try {
5300 >                int b = batch(), c;
5301 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5302 >                    do {} while (!casPending(c = pending, c+1));
5303 >                    new SearchValuesTask<K,V,U>(map, this, b >>>= 1,
5304 >                                                searchFunction, result).fork();
5305 >                }
5306 >                Object v; U u;
5307 >                while (result.get() == null && (v = advance()) != null) {
5308 >                    if ((u = searchFunction.apply((V)v)) != null) {
5309 >                        if (result.compareAndSet(null, u))
5310 >                            tryCompleteComputation(null);
5311 >                        break;
5312 >                    }
5313                  }
5314 +                tryComplete();
5315 +            } catch (Throwable ex) {
5316 +                return tryCompleteComputation(ex);
5317              }
5318 <            tryComplete();
5318 >            return false;
5319          }
5320          public final U getRawResult() { return result.get(); }
5321      }
5322  
5323 <    static final class SearchEntriesTask<K,V,U>
5323 >    @SuppressWarnings("serial") static final class SearchEntriesTask<K,V,U>
5324          extends BulkTask<K,V,U> {
5325          final Fun<Entry<K,V>, ? extends U> searchFunction;
5326          final AtomicReference<U> result;
5327          SearchEntriesTask
5328 <            (ConcurrentHashMapV8<K,V> m,
5328 <             Fun<Entry<K,V>, ? extends U> searchFunction,
5329 <             AtomicReference<U> result) {
5330 <            super(m);
5331 <            this.searchFunction = searchFunction; this.result = result;
5332 <        }
5333 <        SearchEntriesTask
5334 <            (BulkTask<K,V,?> p, int b, boolean split,
5328 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5329               Fun<Entry<K,V>, ? extends U> searchFunction,
5330               AtomicReference<U> result) {
5331 <            super(p, b, split);
5331 >            super(m, p, b);
5332              this.searchFunction = searchFunction; this.result = result;
5333          }
5334 <        public final void compute() {
5334 >        @SuppressWarnings("unchecked") public final boolean exec() {
5335              AtomicReference<U> result = this.result;
5336              final Fun<Entry<K,V>, ? extends U> searchFunction =
5337                  this.searchFunction;
5338              if (searchFunction == null || result == null)
5339 <                throw new Error(NullFunctionMessage);
5340 <            int b = batch(), c;
5341 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5342 <                do {} while (!casPending(c = pending, c+1));
5343 <                new SearchEntriesTask<K,V,U>(this, b >>>= 1, true,
5344 <                                             searchFunction, result).fork();
5345 <            }
5346 <            Object v; U u;
5347 <            while (result.get() == null && (v = advance()) != null) {
5348 <                if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) {
5349 <                    result.compareAndSet(null, u);
5350 <                    break;
5339 >                return abortOnNullFunction();
5340 >            try {
5341 >                int b = batch(), c;
5342 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5343 >                    do {} while (!casPending(c = pending, c+1));
5344 >                    new SearchEntriesTask<K,V,U>(map, this, b >>>= 1,
5345 >                                                 searchFunction, result).fork();
5346 >                }
5347 >                Object v; U u;
5348 >                while (result.get() == null && (v = advance()) != null) {
5349 >                    if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) {
5350 >                        if (result.compareAndSet(null, u))
5351 >                            tryCompleteComputation(null);
5352 >                        break;
5353 >                    }
5354                  }
5355 +                tryComplete();
5356 +            } catch (Throwable ex) {
5357 +                return tryCompleteComputation(ex);
5358              }
5359 <            tryComplete();
5359 >            return false;
5360          }
5361          public final U getRawResult() { return result.get(); }
5362      }
5363  
5364 <    static final class SearchMappingsTask<K,V,U>
5364 >    @SuppressWarnings("serial") static final class SearchMappingsTask<K,V,U>
5365          extends BulkTask<K,V,U> {
5366          final BiFun<? super K, ? super V, ? extends U> searchFunction;
5367          final AtomicReference<U> result;
5368          SearchMappingsTask
5369 <            (ConcurrentHashMapV8<K,V> m,
5370 <             BiFun<? super K, ? super V, ? extends U> searchFunction,
5371 <             AtomicReference<U> result) {
5372 <            super(m);
5373 <            this.searchFunction = searchFunction; this.result = result;
5374 <        }
5375 <        SearchMappingsTask
5376 <            (BulkTask<K,V,?> p, int b, boolean split,
5369 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5370               BiFun<? super K, ? super V, ? extends U> searchFunction,
5371               AtomicReference<U> result) {
5372 <            super(p, b, split);
5372 >            super(m, p, b);
5373              this.searchFunction = searchFunction; this.result = result;
5374          }
5375 <        public final void compute() {
5375 >        @SuppressWarnings("unchecked") public final boolean exec() {
5376              AtomicReference<U> result = this.result;
5377              final BiFun<? super K, ? super V, ? extends U> searchFunction =
5378                  this.searchFunction;
5379              if (searchFunction == null || result == null)
5380 <                throw new Error(NullFunctionMessage);
5381 <            int b = batch(), c;
5382 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5383 <                do {} while (!casPending(c = pending, c+1));
5384 <                new SearchMappingsTask<K,V,U>(this, b >>>= 1, true,
5385 <                                              searchFunction, result).fork();
5386 <            }
5387 <            Object v; U u;
5388 <            while (result.get() == null && (v = advance()) != null) {
5389 <                if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) {
5390 <                    result.compareAndSet(null, u);
5391 <                    break;
5380 >                return abortOnNullFunction();
5381 >            try {
5382 >                int b = batch(), c;
5383 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5384 >                    do {} while (!casPending(c = pending, c+1));
5385 >                    new SearchMappingsTask<K,V,U>(map, this, b >>>= 1,
5386 >                                                  searchFunction, result).fork();
5387 >                }
5388 >                Object v; U u;
5389 >                while (result.get() == null && (v = advance()) != null) {
5390 >                    if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) {
5391 >                        if (result.compareAndSet(null, u))
5392 >                            tryCompleteComputation(null);
5393 >                        break;
5394 >                    }
5395                  }
5396 +                tryComplete();
5397 +            } catch (Throwable ex) {
5398 +                return tryCompleteComputation(ex);
5399              }
5400 <            tryComplete();
5400 >            return false;
5401          }
5402          public final U getRawResult() { return result.get(); }
5403      }
5404  
5405 <    static final class ReduceKeysTask<K,V>
5405 >    @SuppressWarnings("serial") static final class ReduceKeysTask<K,V>
5406          extends BulkTask<K,V,K> {
5407          final BiFun<? super K, ? super K, ? extends K> reducer;
5408          K result;
5409 <        ReduceKeysTask<K,V> sibling;
5411 <        ReduceKeysTask
5412 <            (ConcurrentHashMapV8<K,V> m,
5413 <             BiFun<? super K, ? super K, ? extends K> reducer) {
5414 <            super(m);
5415 <            this.reducer = reducer;
5416 <        }
5409 >        ReduceKeysTask<K,V> rights, nextRight;
5410          ReduceKeysTask
5411 <            (BulkTask<K,V,?> p, int b, boolean split,
5411 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5412 >             ReduceKeysTask<K,V> nextRight,
5413               BiFun<? super K, ? super K, ? extends K> reducer) {
5414 <            super(p, b, split);
5414 >            super(m, p, b); this.nextRight = nextRight;
5415              this.reducer = reducer;
5416          }
5417 <
5424 <        public final void compute() {
5425 <            ReduceKeysTask<K,V> t = this;
5417 >        @SuppressWarnings("unchecked") public final boolean exec() {
5418              final BiFun<? super K, ? super K, ? extends K> reducer =
5419                  this.reducer;
5420              if (reducer == null)
5421 <                throw new Error(NullFunctionMessage);
5422 <            int b = batch();
5423 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5424 <                b >>>= 1;
5425 <                t.pending = 1;
5426 <                ReduceKeysTask<K,V> rt =
5427 <                    new ReduceKeysTask<K,V>
5428 <                    (t, b, true, reducer);
5429 <                t = new ReduceKeysTask<K,V>
5430 <                    (t, b, false, reducer);
5431 <                t.sibling = rt;
5440 <                rt.sibling = t;
5441 <                rt.fork();
5442 <            }
5443 <            K r = null;
5444 <            while (t.advance() != null) {
5445 <                K u = (K)t.nextKey;
5446 <                r = (r == null) ? u : reducer.apply(r, u);
5447 <            }
5448 <            t.result = r;
5449 <            for (;;) {
5450 <                int c; BulkTask<K,V,?> par; ReduceKeysTask<K,V> s, p; K u;
5451 <                if ((par = t.parent) == null ||
5452 <                    !(par instanceof ReduceKeysTask)) {
5453 <                    t.quietlyComplete();
5454 <                    break;
5421 >                return abortOnNullFunction();
5422 >            try {
5423 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5424 >                    do {} while (!casPending(c = pending, c+1));
5425 >                    (rights = new ReduceKeysTask<K,V>
5426 >                     (map, this, b >>>= 1, rights, reducer)).fork();
5427 >                }
5428 >                K r = null;
5429 >                while (advance() != null) {
5430 >                    K u = (K)nextKey;
5431 >                    r = (r == null) ? u : reducer.apply(r, u);
5432                  }
5433 <                else if ((c = (p = (ReduceKeysTask<K,V>)par).pending) == 0) {
5434 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5435 <                        r = (r == null) ? u : reducer.apply(r, u);
5436 <                    (t = p).result = r;
5433 >                result = r;
5434 >                for (ReduceKeysTask<K,V> t = this, s;;) {
5435 >                    int c; BulkTask<K,V,?> par; K tr, sr;
5436 >                    if ((c = t.pending) == 0) {
5437 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5438 >                            if ((sr = s.result) != null)
5439 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5440 >                        }
5441 >                        if ((par = t.parent) == null ||
5442 >                            !(par instanceof ReduceKeysTask)) {
5443 >                            t.quietlyComplete();
5444 >                            break;
5445 >                        }
5446 >                        t = (ReduceKeysTask<K,V>)par;
5447 >                    }
5448 >                    else if (t.casPending(c, c - 1))
5449 >                        break;
5450                  }
5451 <                else if (p.casPending(c, 0))
5452 <                    break;
5451 >            } catch (Throwable ex) {
5452 >                return tryCompleteComputation(ex);
5453              }
5454 +            return false;
5455          }
5456          public final K getRawResult() { return result; }
5457      }
5458  
5459 <    static final class ReduceValuesTask<K,V>
5459 >    @SuppressWarnings("serial") static final class ReduceValuesTask<K,V>
5460          extends BulkTask<K,V,V> {
5461          final BiFun<? super V, ? super V, ? extends V> reducer;
5462          V result;
5463 <        ReduceValuesTask<K,V> sibling;
5473 <        ReduceValuesTask
5474 <            (ConcurrentHashMapV8<K,V> m,
5475 <             BiFun<? super V, ? super V, ? extends V> reducer) {
5476 <            super(m);
5477 <            this.reducer = reducer;
5478 <        }
5463 >        ReduceValuesTask<K,V> rights, nextRight;
5464          ReduceValuesTask
5465 <            (BulkTask<K,V,?> p, int b, boolean split,
5465 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5466 >             ReduceValuesTask<K,V> nextRight,
5467               BiFun<? super V, ? super V, ? extends V> reducer) {
5468 <            super(p, b, split);
5468 >            super(m, p, b); this.nextRight = nextRight;
5469              this.reducer = reducer;
5470          }
5471 <
5486 <        public final void compute() {
5487 <            ReduceValuesTask<K,V> t = this;
5471 >        @SuppressWarnings("unchecked") public final boolean exec() {
5472              final BiFun<? super V, ? super V, ? extends V> reducer =
5473                  this.reducer;
5474              if (reducer == null)
5475 <                throw new Error(NullFunctionMessage);
5476 <            int b = batch();
5477 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5478 <                b >>>= 1;
5479 <                t.pending = 1;
5480 <                ReduceValuesTask<K,V> rt =
5481 <                    new ReduceValuesTask<K,V>
5482 <                    (t, b, true, reducer);
5483 <                t = new ReduceValuesTask<K,V>
5484 <                    (t, b, false, reducer);
5485 <                t.sibling = rt;
5486 <                rt.sibling = t;
5503 <                rt.fork();
5504 <            }
5505 <            V r = null;
5506 <            Object v;
5507 <            while ((v = t.advance()) != null) {
5508 <                V u = (V)v;
5509 <                r = (r == null) ? u : reducer.apply(r, u);
5510 <            }
5511 <            t.result = r;
5512 <            for (;;) {
5513 <                int c; BulkTask<K,V,?> par; ReduceValuesTask<K,V> s, p; V u;
5514 <                if ((par = t.parent) == null ||
5515 <                    !(par instanceof ReduceValuesTask)) {
5516 <                    t.quietlyComplete();
5517 <                    break;
5475 >                return abortOnNullFunction();
5476 >            try {
5477 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5478 >                    do {} while (!casPending(c = pending, c+1));
5479 >                    (rights = new ReduceValuesTask<K,V>
5480 >                     (map, this, b >>>= 1, rights, reducer)).fork();
5481 >                }
5482 >                V r = null;
5483 >                Object v;
5484 >                while ((v = advance()) != null) {
5485 >                    V u = (V)v;
5486 >                    r = (r == null) ? u : reducer.apply(r, u);
5487                  }
5488 <                else if ((c = (p = (ReduceValuesTask<K,V>)par).pending) == 0) {
5489 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5490 <                        r = (r == null) ? u : reducer.apply(r, u);
5491 <                    (t = p).result = r;
5488 >                result = r;
5489 >                for (ReduceValuesTask<K,V> t = this, s;;) {
5490 >                    int c; BulkTask<K,V,?> par; V tr, sr;
5491 >                    if ((c = t.pending) == 0) {
5492 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5493 >                            if ((sr = s.result) != null)
5494 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5495 >                        }
5496 >                        if ((par = t.parent) == null ||
5497 >                            !(par instanceof ReduceValuesTask)) {
5498 >                            t.quietlyComplete();
5499 >                            break;
5500 >                        }
5501 >                        t = (ReduceValuesTask<K,V>)par;
5502 >                    }
5503 >                    else if (t.casPending(c, c - 1))
5504 >                        break;
5505                  }
5506 <                else if (p.casPending(c, 0))
5507 <                    break;
5506 >            } catch (Throwable ex) {
5507 >                return tryCompleteComputation(ex);
5508              }
5509 +            return false;
5510          }
5511          public final V getRawResult() { return result; }
5512      }
5513  
5514 <    static final class ReduceEntriesTask<K,V>
5514 >    @SuppressWarnings("serial") static final class ReduceEntriesTask<K,V>
5515          extends BulkTask<K,V,Map.Entry<K,V>> {
5516          final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer;
5517          Map.Entry<K,V> result;
5518 <        ReduceEntriesTask<K,V> sibling;
5518 >        ReduceEntriesTask<K,V> rights, nextRight;
5519          ReduceEntriesTask
5520 <            (ConcurrentHashMapV8<K,V> m,
5520 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5521 >             ReduceEntriesTask<K,V> nextRight,
5522               BiFun<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5523 <            super(m);
5540 <            this.reducer = reducer;
5541 <        }
5542 <        ReduceEntriesTask
5543 <            (BulkTask<K,V,?> p, int b, boolean split,
5544 <             BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5545 <            super(p, b, split);
5523 >            super(m, p, b); this.nextRight = nextRight;
5524              this.reducer = reducer;
5525          }
5526 <
5549 <        public final void compute() {
5550 <            ReduceEntriesTask<K,V> t = this;
5526 >        @SuppressWarnings("unchecked") public final boolean exec() {
5527              final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer =
5528                  this.reducer;
5529              if (reducer == null)
5530 <                throw new Error(NullFunctionMessage);
5531 <            int b = batch();
5532 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5533 <                b >>>= 1;
5534 <                t.pending = 1;
5535 <                ReduceEntriesTask<K,V> rt =
5536 <                    new ReduceEntriesTask<K,V>
5537 <                    (t, b, true, reducer);
5538 <                t = new ReduceEntriesTask<K,V>
5539 <                    (t, b, false, reducer);
5540 <                t.sibling = rt;
5541 <                rt.sibling = t;
5566 <                rt.fork();
5567 <            }
5568 <            Map.Entry<K,V> r = null;
5569 <            Object v;
5570 <            while ((v = t.advance()) != null) {
5571 <                Map.Entry<K,V> u = entryFor((K)t.nextKey, (V)v);
5572 <                r = (r == null) ? u : reducer.apply(r, u);
5573 <            }
5574 <            t.result = r;
5575 <            for (;;) {
5576 <                int c; BulkTask<K,V,?> par; ReduceEntriesTask<K,V> s, p;
5577 <                Map.Entry<K,V> u;
5578 <                if ((par = t.parent) == null ||
5579 <                    !(par instanceof ReduceEntriesTask)) {
5580 <                    t.quietlyComplete();
5581 <                    break;
5530 >                return abortOnNullFunction();
5531 >            try {
5532 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5533 >                    do {} while (!casPending(c = pending, c+1));
5534 >                    (rights = new ReduceEntriesTask<K,V>
5535 >                     (map, this, b >>>= 1, rights, reducer)).fork();
5536 >                }
5537 >                Map.Entry<K,V> r = null;
5538 >                Object v;
5539 >                while ((v = advance()) != null) {
5540 >                    Map.Entry<K,V> u = entryFor((K)nextKey, (V)v);
5541 >                    r = (r == null) ? u : reducer.apply(r, u);
5542                  }
5543 <                else if ((c = (p = (ReduceEntriesTask<K,V>)par).pending) == 0) {
5544 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5545 <                        r = (r == null) ? u : reducer.apply(r, u);
5546 <                    (t = p).result = r;
5543 >                result = r;
5544 >                for (ReduceEntriesTask<K,V> t = this, s;;) {
5545 >                    int c; BulkTask<K,V,?> par; Map.Entry<K,V> tr, sr;
5546 >                    if ((c = t.pending) == 0) {
5547 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5548 >                            if ((sr = s.result) != null)
5549 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5550 >                        }
5551 >                        if ((par = t.parent) == null ||
5552 >                            !(par instanceof ReduceEntriesTask)) {
5553 >                            t.quietlyComplete();
5554 >                            break;
5555 >                        }
5556 >                        t = (ReduceEntriesTask<K,V>)par;
5557 >                    }
5558 >                    else if (t.casPending(c, c - 1))
5559 >                        break;
5560                  }
5561 <                else if (p.casPending(c, 0))
5562 <                    break;
5561 >            } catch (Throwable ex) {
5562 >                return tryCompleteComputation(ex);
5563              }
5564 +            return false;
5565          }
5566          public final Map.Entry<K,V> getRawResult() { return result; }
5567      }
5568  
5569 <    static final class MapReduceKeysTask<K,V,U>
5569 >    @SuppressWarnings("serial") static final class MapReduceKeysTask<K,V,U>
5570          extends BulkTask<K,V,U> {
5571          final Fun<? super K, ? extends U> transformer;
5572          final BiFun<? super U, ? super U, ? extends U> reducer;
5573          U result;
5574 <        MapReduceKeysTask<K,V,U> sibling;
5574 >        MapReduceKeysTask<K,V,U> rights, nextRight;
5575          MapReduceKeysTask
5576 <            (ConcurrentHashMapV8<K,V> m,
5576 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5577 >             MapReduceKeysTask<K,V,U> nextRight,
5578               Fun<? super K, ? extends U> transformer,
5579               BiFun<? super U, ? super U, ? extends U> reducer) {
5580 <            super(m);
5580 >            super(m, p, b); this.nextRight = nextRight;
5581              this.transformer = transformer;
5582              this.reducer = reducer;
5583          }
5584 <        MapReduceKeysTask
5610 <            (BulkTask<K,V,?> p, int b, boolean split,
5611 <             Fun<? super K, ? extends U> transformer,
5612 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5613 <            super(p, b, split);
5614 <            this.transformer = transformer;
5615 <            this.reducer = reducer;
5616 <        }
5617 <        public final void compute() {
5618 <            MapReduceKeysTask<K,V,U> t = this;
5584 >        @SuppressWarnings("unchecked") public final boolean exec() {
5585              final Fun<? super K, ? extends U> transformer =
5586                  this.transformer;
5587              final BiFun<? super U, ? super U, ? extends U> reducer =
5588                  this.reducer;
5589              if (transformer == null || reducer == null)
5590 <                throw new Error(NullFunctionMessage);
5591 <            int b = batch();
5592 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5593 <                b >>>= 1;
5594 <                t.pending = 1;
5595 <                MapReduceKeysTask<K,V,U> rt =
5596 <                    new MapReduceKeysTask<K,V,U>
5597 <                    (t, b, true, transformer, reducer);
5598 <                t = new MapReduceKeysTask<K,V,U>
5599 <                    (t, b, false, transformer, reducer);
5634 <                t.sibling = rt;
5635 <                rt.sibling = t;
5636 <                rt.fork();
5637 <            }
5638 <            U r = null, u;
5639 <            while (t.advance() != null) {
5640 <                if ((u = transformer.apply((K)t.nextKey)) != null)
5641 <                    r = (r == null) ? u : reducer.apply(r, u);
5642 <            }
5643 <            t.result = r;
5644 <            for (;;) {
5645 <                int c; BulkTask<K,V,?> par; MapReduceKeysTask<K,V,U> s, p;
5646 <                if ((par = t.parent) == null ||
5647 <                    !(par instanceof MapReduceKeysTask)) {
5648 <                    t.quietlyComplete();
5649 <                    break;
5650 <                }
5651 <                else if ((c = (p = (MapReduceKeysTask<K,V,U>)par).pending) == 0) {
5652 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5590 >                return abortOnNullFunction();
5591 >            try {
5592 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5593 >                    do {} while (!casPending(c = pending, c+1));
5594 >                    (rights = new MapReduceKeysTask<K,V,U>
5595 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5596 >                }
5597 >                U r = null, u;
5598 >                while (advance() != null) {
5599 >                    if ((u = transformer.apply((K)nextKey)) != null)
5600                          r = (r == null) ? u : reducer.apply(r, u);
5654                    (t = p).result = r;
5601                  }
5602 <                else if (p.casPending(c, 0))
5603 <                    break;
5602 >                result = r;
5603 >                for (MapReduceKeysTask<K,V,U> t = this, s;;) {
5604 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5605 >                    if ((c = t.pending) == 0) {
5606 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5607 >                            if ((sr = s.result) != null)
5608 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5609 >                        }
5610 >                        if ((par = t.parent) == null ||
5611 >                            !(par instanceof MapReduceKeysTask)) {
5612 >                            t.quietlyComplete();
5613 >                            break;
5614 >                        }
5615 >                        t = (MapReduceKeysTask<K,V,U>)par;
5616 >                    }
5617 >                    else if (t.casPending(c, c - 1))
5618 >                        break;
5619 >                }
5620 >            } catch (Throwable ex) {
5621 >                return tryCompleteComputation(ex);
5622              }
5623 +            return false;
5624          }
5625          public final U getRawResult() { return result; }
5626      }
5627  
5628 <    static final class MapReduceValuesTask<K,V,U>
5628 >    @SuppressWarnings("serial") static final class MapReduceValuesTask<K,V,U>
5629          extends BulkTask<K,V,U> {
5630          final Fun<? super V, ? extends U> transformer;
5631          final BiFun<? super U, ? super U, ? extends U> reducer;
5632          U result;
5633 <        MapReduceValuesTask<K,V,U> sibling;
5669 <        MapReduceValuesTask
5670 <            (ConcurrentHashMapV8<K,V> m,
5671 <             Fun<? super V, ? extends U> transformer,
5672 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5673 <            super(m);
5674 <            this.transformer = transformer;
5675 <            this.reducer = reducer;
5676 <        }
5633 >        MapReduceValuesTask<K,V,U> rights, nextRight;
5634          MapReduceValuesTask
5635 <            (BulkTask<K,V,?> p, int b, boolean split,
5635 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5636 >             MapReduceValuesTask<K,V,U> nextRight,
5637               Fun<? super V, ? extends U> transformer,
5638               BiFun<? super U, ? super U, ? extends U> reducer) {
5639 <            super(p, b, split);
5639 >            super(m, p, b); this.nextRight = nextRight;
5640              this.transformer = transformer;
5641              this.reducer = reducer;
5642          }
5643 <        public final void compute() {
5686 <            MapReduceValuesTask<K,V,U> t = this;
5643 >        @SuppressWarnings("unchecked") public final boolean exec() {
5644              final Fun<? super V, ? extends U> transformer =
5645                  this.transformer;
5646              final BiFun<? super U, ? super U, ? extends U> reducer =
5647                  this.reducer;
5648              if (transformer == null || reducer == null)
5649 <                throw new Error(NullFunctionMessage);
5650 <            int b = batch();
5651 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5652 <                b >>>= 1;
5653 <                t.pending = 1;
5654 <                MapReduceValuesTask<K,V,U> rt =
5655 <                    new MapReduceValuesTask<K,V,U>
5656 <                    (t, b, true, transformer, reducer);
5657 <                t = new MapReduceValuesTask<K,V,U>
5658 <                    (t, b, false, transformer, reducer);
5659 <                t.sibling = rt;
5703 <                rt.sibling = t;
5704 <                rt.fork();
5705 <            }
5706 <            U r = null, u;
5707 <            Object v;
5708 <            while ((v = t.advance()) != null) {
5709 <                if ((u = transformer.apply((V)v)) != null)
5710 <                    r = (r == null) ? u : reducer.apply(r, u);
5711 <            }
5712 <            t.result = r;
5713 <            for (;;) {
5714 <                int c; BulkTask<K,V,?> par; MapReduceValuesTask<K,V,U> s, p;
5715 <                if ((par = t.parent) == null ||
5716 <                    !(par instanceof MapReduceValuesTask)) {
5717 <                    t.quietlyComplete();
5718 <                    break;
5719 <                }
5720 <                else if ((c = (p = (MapReduceValuesTask<K,V,U>)par).pending) == 0) {
5721 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5649 >                return abortOnNullFunction();
5650 >            try {
5651 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5652 >                    do {} while (!casPending(c = pending, c+1));
5653 >                    (rights = new MapReduceValuesTask<K,V,U>
5654 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5655 >                }
5656 >                U r = null, u;
5657 >                Object v;
5658 >                while ((v = advance()) != null) {
5659 >                    if ((u = transformer.apply((V)v)) != null)
5660                          r = (r == null) ? u : reducer.apply(r, u);
5723                    (t = p).result = r;
5661                  }
5662 <                else if (p.casPending(c, 0))
5663 <                    break;
5662 >                result = r;
5663 >                for (MapReduceValuesTask<K,V,U> t = this, s;;) {
5664 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5665 >                    if ((c = t.pending) == 0) {
5666 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5667 >                            if ((sr = s.result) != null)
5668 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5669 >                        }
5670 >                        if ((par = t.parent) == null ||
5671 >                            !(par instanceof MapReduceValuesTask)) {
5672 >                            t.quietlyComplete();
5673 >                            break;
5674 >                        }
5675 >                        t = (MapReduceValuesTask<K,V,U>)par;
5676 >                    }
5677 >                    else if (t.casPending(c, c - 1))
5678 >                        break;
5679 >                }
5680 >            } catch (Throwable ex) {
5681 >                return tryCompleteComputation(ex);
5682              }
5683 +            return false;
5684          }
5685          public final U getRawResult() { return result; }
5686      }
5687  
5688 <    static final class MapReduceEntriesTask<K,V,U>
5688 >    @SuppressWarnings("serial") static final class MapReduceEntriesTask<K,V,U>
5689          extends BulkTask<K,V,U> {
5690          final Fun<Map.Entry<K,V>, ? extends U> transformer;
5691          final BiFun<? super U, ? super U, ? extends U> reducer;
5692          U result;
5693 <        MapReduceEntriesTask<K,V,U> sibling;
5693 >        MapReduceEntriesTask<K,V,U> rights, nextRight;
5694          MapReduceEntriesTask
5695 <            (ConcurrentHashMapV8<K,V> m,
5695 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5696 >             MapReduceEntriesTask<K,V,U> nextRight,
5697               Fun<Map.Entry<K,V>, ? extends U> transformer,
5698               BiFun<? super U, ? super U, ? extends U> reducer) {
5699 <            super(m);
5699 >            super(m, p, b); this.nextRight = nextRight;
5700              this.transformer = transformer;
5701              this.reducer = reducer;
5702          }
5703 <        MapReduceEntriesTask
5747 <            (BulkTask<K,V,?> p, int b, boolean split,
5748 <             Fun<Map.Entry<K,V>, ? extends U> transformer,
5749 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5750 <            super(p, b, split);
5751 <            this.transformer = transformer;
5752 <            this.reducer = reducer;
5753 <        }
5754 <        public final void compute() {
5755 <            MapReduceEntriesTask<K,V,U> t = this;
5703 >        @SuppressWarnings("unchecked") public final boolean exec() {
5704              final Fun<Map.Entry<K,V>, ? extends U> transformer =
5705                  this.transformer;
5706              final BiFun<? super U, ? super U, ? extends U> reducer =
5707                  this.reducer;
5708              if (transformer == null || reducer == null)
5709 <                throw new Error(NullFunctionMessage);
5710 <            int b = batch();
5711 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5712 <                b >>>= 1;
5713 <                t.pending = 1;
5714 <                MapReduceEntriesTask<K,V,U> rt =
5715 <                    new MapReduceEntriesTask<K,V,U>
5716 <                    (t, b, true, transformer, reducer);
5717 <                t = new MapReduceEntriesTask<K,V,U>
5718 <                    (t, b, false, transformer, reducer);
5719 <                t.sibling = rt;
5772 <                rt.sibling = t;
5773 <                rt.fork();
5774 <            }
5775 <            U r = null, u;
5776 <            Object v;
5777 <            while ((v = t.advance()) != null) {
5778 <                if ((u = transformer.apply(entryFor((K)t.nextKey, (V)v))) != null)
5779 <                    r = (r == null) ? u : reducer.apply(r, u);
5780 <            }
5781 <            t.result = r;
5782 <            for (;;) {
5783 <                int c; BulkTask<K,V,?> par; MapReduceEntriesTask<K,V,U> s, p;
5784 <                if ((par = t.parent) == null ||
5785 <                    !(par instanceof MapReduceEntriesTask)) {
5786 <                    t.quietlyComplete();
5787 <                    break;
5788 <                }
5789 <                else if ((c = (p = (MapReduceEntriesTask<K,V,U>)par).pending) == 0) {
5790 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5709 >                return abortOnNullFunction();
5710 >            try {
5711 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5712 >                    do {} while (!casPending(c = pending, c+1));
5713 >                    (rights = new MapReduceEntriesTask<K,V,U>
5714 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5715 >                }
5716 >                U r = null, u;
5717 >                Object v;
5718 >                while ((v = advance()) != null) {
5719 >                    if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5720                          r = (r == null) ? u : reducer.apply(r, u);
5792                    (t = p).result = r;
5721                  }
5722 <                else if (p.casPending(c, 0))
5723 <                    break;
5722 >                result = r;
5723 >                for (MapReduceEntriesTask<K,V,U> t = this, s;;) {
5724 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5725 >                    if ((c = t.pending) == 0) {
5726 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5727 >                            if ((sr = s.result) != null)
5728 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5729 >                        }
5730 >                        if ((par = t.parent) == null ||
5731 >                            !(par instanceof MapReduceEntriesTask)) {
5732 >                            t.quietlyComplete();
5733 >                            break;
5734 >                        }
5735 >                        t = (MapReduceEntriesTask<K,V,U>)par;
5736 >                    }
5737 >                    else if (t.casPending(c, c - 1))
5738 >                        break;
5739 >                }
5740 >            } catch (Throwable ex) {
5741 >                return tryCompleteComputation(ex);
5742              }
5743 +            return false;
5744          }
5745          public final U getRawResult() { return result; }
5746      }
5747  
5748 <    static final class MapReduceMappingsTask<K,V,U>
5748 >    @SuppressWarnings("serial") static final class MapReduceMappingsTask<K,V,U>
5749          extends BulkTask<K,V,U> {
5750          final BiFun<? super K, ? super V, ? extends U> transformer;
5751          final BiFun<? super U, ? super U, ? extends U> reducer;
5752          U result;
5753 <        MapReduceMappingsTask<K,V,U> sibling;
5807 <        MapReduceMappingsTask
5808 <            (ConcurrentHashMapV8<K,V> m,
5809 <             BiFun<? super K, ? super V, ? extends U> transformer,
5810 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5811 <            super(m);
5812 <            this.transformer = transformer;
5813 <            this.reducer = reducer;
5814 <        }
5753 >        MapReduceMappingsTask<K,V,U> rights, nextRight;
5754          MapReduceMappingsTask
5755 <            (BulkTask<K,V,?> p, int b, boolean split,
5755 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5756 >             MapReduceMappingsTask<K,V,U> nextRight,
5757               BiFun<? super K, ? super V, ? extends U> transformer,
5758               BiFun<? super U, ? super U, ? extends U> reducer) {
5759 <            super(p, b, split);
5759 >            super(m, p, b); this.nextRight = nextRight;
5760              this.transformer = transformer;
5761              this.reducer = reducer;
5762          }
5763 <        public final void compute() {
5824 <            MapReduceMappingsTask<K,V,U> t = this;
5763 >        @SuppressWarnings("unchecked") public final boolean exec() {
5764              final BiFun<? super K, ? super V, ? extends U> transformer =
5765                  this.transformer;
5766              final BiFun<? super U, ? super U, ? extends U> reducer =
5767                  this.reducer;
5768              if (transformer == null || reducer == null)
5769 <                throw new Error(NullFunctionMessage);
5770 <            int b = batch();
5771 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5772 <                b >>>= 1;
5773 <                t.pending = 1;
5774 <                MapReduceMappingsTask<K,V,U> rt =
5775 <                    new MapReduceMappingsTask<K,V,U>
5776 <                    (t, b, true, transformer, reducer);
5777 <                t = new MapReduceMappingsTask<K,V,U>
5778 <                    (t, b, false, transformer, reducer);
5779 <                t.sibling = rt;
5841 <                rt.sibling = t;
5842 <                rt.fork();
5843 <            }
5844 <            U r = null, u;
5845 <            Object v;
5846 <            while ((v = t.advance()) != null) {
5847 <                if ((u = transformer.apply((K)t.nextKey, (V)v)) != null)
5848 <                    r = (r == null) ? u : reducer.apply(r, u);
5849 <            }
5850 <            for (;;) {
5851 <                int c; BulkTask<K,V,?> par; MapReduceMappingsTask<K,V,U> s, p;
5852 <                if ((par = t.parent) == null ||
5853 <                    !(par instanceof MapReduceMappingsTask)) {
5854 <                    t.quietlyComplete();
5855 <                    break;
5856 <                }
5857 <                else if ((c = (p = (MapReduceMappingsTask<K,V,U>)par).pending) == 0) {
5858 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5769 >                return abortOnNullFunction();
5770 >            try {
5771 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5772 >                    do {} while (!casPending(c = pending, c+1));
5773 >                    (rights = new MapReduceMappingsTask<K,V,U>
5774 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5775 >                }
5776 >                U r = null, u;
5777 >                Object v;
5778 >                while ((v = advance()) != null) {
5779 >                    if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5780                          r = (r == null) ? u : reducer.apply(r, u);
5860                    (t = p).result = r;
5781                  }
5782 <                else if (p.casPending(c, 0))
5783 <                    break;
5782 >                result = r;
5783 >                for (MapReduceMappingsTask<K,V,U> t = this, s;;) {
5784 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5785 >                    if ((c = t.pending) == 0) {
5786 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5787 >                            if ((sr = s.result) != null)
5788 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5789 >                        }
5790 >                        if ((par = t.parent) == null ||
5791 >                            !(par instanceof MapReduceMappingsTask)) {
5792 >                            t.quietlyComplete();
5793 >                            break;
5794 >                        }
5795 >                        t = (MapReduceMappingsTask<K,V,U>)par;
5796 >                    }
5797 >                    else if (t.casPending(c, c - 1))
5798 >                        break;
5799 >                }
5800 >            } catch (Throwable ex) {
5801 >                return tryCompleteComputation(ex);
5802              }
5803 +            return false;
5804          }
5805          public final U getRawResult() { return result; }
5806      }
5807  
5808 <    static final class MapReduceKeysToDoubleTask<K,V>
5808 >    @SuppressWarnings("serial") static final class MapReduceKeysToDoubleTask<K,V>
5809          extends BulkTask<K,V,Double> {
5810          final ObjectToDouble<? super K> transformer;
5811          final DoubleByDoubleToDouble reducer;
5812          final double basis;
5813          double result;
5814 <        MapReduceKeysToDoubleTask<K,V> sibling;
5876 <        MapReduceKeysToDoubleTask
5877 <            (ConcurrentHashMapV8<K,V> m,
5878 <             ObjectToDouble<? super K> transformer,
5879 <             double basis,
5880 <             DoubleByDoubleToDouble reducer) {
5881 <            super(m);
5882 <            this.transformer = transformer;
5883 <            this.basis = basis; this.reducer = reducer;
5884 <        }
5814 >        MapReduceKeysToDoubleTask<K,V> rights, nextRight;
5815          MapReduceKeysToDoubleTask
5816 <            (BulkTask<K,V,?> p, int b, boolean split,
5816 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5817 >             MapReduceKeysToDoubleTask<K,V> nextRight,
5818               ObjectToDouble<? super K> transformer,
5819               double basis,
5820               DoubleByDoubleToDouble reducer) {
5821 <            super(p, b, split);
5821 >            super(m, p, b); this.nextRight = nextRight;
5822              this.transformer = transformer;
5823              this.basis = basis; this.reducer = reducer;
5824          }
5825 <        public final void compute() {
5895 <            MapReduceKeysToDoubleTask<K,V> t = this;
5825 >        @SuppressWarnings("unchecked") public final boolean exec() {
5826              final ObjectToDouble<? super K> transformer =
5827                  this.transformer;
5828              final DoubleByDoubleToDouble reducer = this.reducer;
5829              if (transformer == null || reducer == null)
5830 <                throw new Error(NullFunctionMessage);
5831 <            final double id = this.basis;
5832 <            int b = batch();
5833 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5834 <                b >>>= 1;
5835 <                t.pending = 1;
5836 <                MapReduceKeysToDoubleTask<K,V> rt =
5837 <                    new MapReduceKeysToDoubleTask<K,V>
5838 <                    (t, b, true, transformer, id, reducer);
5839 <                t = new MapReduceKeysToDoubleTask<K,V>
5840 <                    (t, b, false, transformer, id, reducer);
5841 <                t.sibling = rt;
5842 <                rt.sibling = t;
5843 <                rt.fork();
5844 <            }
5845 <            double r = id;
5846 <            while (t.advance() != null)
5847 <                r = reducer.apply(r, transformer.apply((K)t.nextKey));
5848 <            t.result = r;
5849 <            for (;;) {
5850 <                int c; BulkTask<K,V,?> par; MapReduceKeysToDoubleTask<K,V> s, p;
5851 <                if ((par = t.parent) == null ||
5852 <                    !(par instanceof MapReduceKeysToDoubleTask)) {
5853 <                    t.quietlyComplete();
5854 <                    break;
5855 <                }
5856 <                else if ((c = (p = (MapReduceKeysToDoubleTask<K,V>)par).pending) == 0) {
5927 <                    if ((s = t.sibling) != null)
5928 <                        r = reducer.apply(r, s.result);
5929 <                    (t = p).result = r;
5830 >                return abortOnNullFunction();
5831 >            try {
5832 >                final double id = this.basis;
5833 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5834 >                    do {} while (!casPending(c = pending, c+1));
5835 >                    (rights = new MapReduceKeysToDoubleTask<K,V>
5836 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
5837 >                }
5838 >                double r = id;
5839 >                while (advance() != null)
5840 >                    r = reducer.apply(r, transformer.apply((K)nextKey));
5841 >                result = r;
5842 >                for (MapReduceKeysToDoubleTask<K,V> t = this, s;;) {
5843 >                    int c; BulkTask<K,V,?> par;
5844 >                    if ((c = t.pending) == 0) {
5845 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5846 >                            t.result = reducer.apply(t.result, s.result);
5847 >                        }
5848 >                        if ((par = t.parent) == null ||
5849 >                            !(par instanceof MapReduceKeysToDoubleTask)) {
5850 >                            t.quietlyComplete();
5851 >                            break;
5852 >                        }
5853 >                        t = (MapReduceKeysToDoubleTask<K,V>)par;
5854 >                    }
5855 >                    else if (t.casPending(c, c - 1))
5856 >                        break;
5857                  }
5858 <                else if (p.casPending(c, 0))
5859 <                    break;
5858 >            } catch (Throwable ex) {
5859 >                return tryCompleteComputation(ex);
5860              }
5861 +            return false;
5862          }
5863          public final Double getRawResult() { return result; }
5864      }
5865  
5866 <    static final class MapReduceValuesToDoubleTask<K,V>
5866 >    @SuppressWarnings("serial") static final class MapReduceValuesToDoubleTask<K,V>
5867          extends BulkTask<K,V,Double> {
5868          final ObjectToDouble<? super V> transformer;
5869          final DoubleByDoubleToDouble reducer;
5870          final double basis;
5871          double result;
5872 <        MapReduceValuesToDoubleTask<K,V> sibling;
5945 <        MapReduceValuesToDoubleTask
5946 <            (ConcurrentHashMapV8<K,V> m,
5947 <             ObjectToDouble<? super V> transformer,
5948 <             double basis,
5949 <             DoubleByDoubleToDouble reducer) {
5950 <            super(m);
5951 <            this.transformer = transformer;
5952 <            this.basis = basis; this.reducer = reducer;
5953 <        }
5872 >        MapReduceValuesToDoubleTask<K,V> rights, nextRight;
5873          MapReduceValuesToDoubleTask
5874 <            (BulkTask<K,V,?> p, int b, boolean split,
5874 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5875 >             MapReduceValuesToDoubleTask<K,V> nextRight,
5876               ObjectToDouble<? super V> transformer,
5877               double basis,
5878               DoubleByDoubleToDouble reducer) {
5879 <            super(p, b, split);
5879 >            super(m, p, b); this.nextRight = nextRight;
5880              this.transformer = transformer;
5881              this.basis = basis; this.reducer = reducer;
5882          }
5883 <        public final void compute() {
5964 <            MapReduceValuesToDoubleTask<K,V> t = this;
5883 >        @SuppressWarnings("unchecked") public final boolean exec() {
5884              final ObjectToDouble<? super V> transformer =
5885                  this.transformer;
5886              final DoubleByDoubleToDouble reducer = this.reducer;
5887              if (transformer == null || reducer == null)
5888 <                throw new Error(NullFunctionMessage);
5889 <            final double id = this.basis;
5890 <            int b = batch();
5891 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5892 <                b >>>= 1;
5893 <                t.pending = 1;
5894 <                MapReduceValuesToDoubleTask<K,V> rt =
5895 <                    new MapReduceValuesToDoubleTask<K,V>
5896 <                    (t, b, true, transformer, id, reducer);
5897 <                t = new MapReduceValuesToDoubleTask<K,V>
5898 <                    (t, b, false, transformer, id, reducer);
5899 <                t.sibling = rt;
5900 <                rt.sibling = t;
5901 <                rt.fork();
5902 <            }
5903 <            double r = id;
5904 <            Object v;
5905 <            while ((v = t.advance()) != null)
5906 <                r = reducer.apply(r, transformer.apply((V)v));
5907 <            t.result = r;
5908 <            for (;;) {
5909 <                int c; BulkTask<K,V,?> par; MapReduceValuesToDoubleTask<K,V> s, p;
5910 <                if ((par = t.parent) == null ||
5911 <                    !(par instanceof MapReduceValuesToDoubleTask)) {
5912 <                    t.quietlyComplete();
5913 <                    break;
5914 <                }
5915 <                else if ((c = (p = (MapReduceValuesToDoubleTask<K,V>)par).pending) == 0) {
5997 <                    if ((s = t.sibling) != null)
5998 <                        r = reducer.apply(r, s.result);
5999 <                    (t = p).result = r;
5888 >                return abortOnNullFunction();
5889 >            try {
5890 >                final double id = this.basis;
5891 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5892 >                    do {} while (!casPending(c = pending, c+1));
5893 >                    (rights = new MapReduceValuesToDoubleTask<K,V>
5894 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
5895 >                }
5896 >                double r = id;
5897 >                Object v;
5898 >                while ((v = advance()) != null)
5899 >                    r = reducer.apply(r, transformer.apply((V)v));
5900 >                result = r;
5901 >                for (MapReduceValuesToDoubleTask<K,V> t = this, s;;) {
5902 >                    int c; BulkTask<K,V,?> par;
5903 >                    if ((c = t.pending) == 0) {
5904 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5905 >                            t.result = reducer.apply(t.result, s.result);
5906 >                        }
5907 >                        if ((par = t.parent) == null ||
5908 >                            !(par instanceof MapReduceValuesToDoubleTask)) {
5909 >                            t.quietlyComplete();
5910 >                            break;
5911 >                        }
5912 >                        t = (MapReduceValuesToDoubleTask<K,V>)par;
5913 >                    }
5914 >                    else if (t.casPending(c, c - 1))
5915 >                        break;
5916                  }
5917 <                else if (p.casPending(c, 0))
5918 <                    break;
5917 >            } catch (Throwable ex) {
5918 >                return tryCompleteComputation(ex);
5919              }
5920 +            return false;
5921          }
5922          public final Double getRawResult() { return result; }
5923      }
5924  
5925 <    static final class MapReduceEntriesToDoubleTask<K,V>
5925 >    @SuppressWarnings("serial") static final class MapReduceEntriesToDoubleTask<K,V>
5926          extends BulkTask<K,V,Double> {
5927          final ObjectToDouble<Map.Entry<K,V>> transformer;
5928          final DoubleByDoubleToDouble reducer;
5929          final double basis;
5930          double result;
5931 <        MapReduceEntriesToDoubleTask<K,V> sibling;
6015 <        MapReduceEntriesToDoubleTask
6016 <            (ConcurrentHashMapV8<K,V> m,
6017 <             ObjectToDouble<Map.Entry<K,V>> transformer,
6018 <             double basis,
6019 <             DoubleByDoubleToDouble reducer) {
6020 <            super(m);
6021 <            this.transformer = transformer;
6022 <            this.basis = basis; this.reducer = reducer;
6023 <        }
5931 >        MapReduceEntriesToDoubleTask<K,V> rights, nextRight;
5932          MapReduceEntriesToDoubleTask
5933 <            (BulkTask<K,V,?> p, int b, boolean split,
5933 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5934 >             MapReduceEntriesToDoubleTask<K,V> nextRight,
5935               ObjectToDouble<Map.Entry<K,V>> transformer,
5936               double basis,
5937               DoubleByDoubleToDouble reducer) {
5938 <            super(p, b, split);
5938 >            super(m, p, b); this.nextRight = nextRight;
5939              this.transformer = transformer;
5940              this.basis = basis; this.reducer = reducer;
5941          }
5942 <        public final void compute() {
6034 <            MapReduceEntriesToDoubleTask<K,V> t = this;
5942 >        @SuppressWarnings("unchecked") public final boolean exec() {
5943              final ObjectToDouble<Map.Entry<K,V>> transformer =
5944                  this.transformer;
5945              final DoubleByDoubleToDouble reducer = this.reducer;
5946              if (transformer == null || reducer == null)
5947 <                throw new Error(NullFunctionMessage);
5948 <            final double id = this.basis;
5949 <            int b = batch();
5950 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5951 <                b >>>= 1;
5952 <                t.pending = 1;
5953 <                MapReduceEntriesToDoubleTask<K,V> rt =
5954 <                    new MapReduceEntriesToDoubleTask<K,V>
5955 <                    (t, b, true, transformer, id, reducer);
5956 <                t = new MapReduceEntriesToDoubleTask<K,V>
5957 <                    (t, b, false, transformer, id, reducer);
5958 <                t.sibling = rt;
5959 <                rt.sibling = t;
5960 <                rt.fork();
5961 <            }
5962 <            double r = id;
5963 <            Object v;
5964 <            while ((v = t.advance()) != null)
5965 <                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
5966 <            t.result = r;
5967 <            for (;;) {
5968 <                int c; BulkTask<K,V,?> par; MapReduceEntriesToDoubleTask<K,V> s, p;
5969 <                if ((par = t.parent) == null ||
5970 <                    !(par instanceof MapReduceEntriesToDoubleTask)) {
5971 <                    t.quietlyComplete();
5972 <                    break;
5973 <                }
5974 <                else if ((c = (p = (MapReduceEntriesToDoubleTask<K,V>)par).pending) == 0) {
6067 <                    if ((s = t.sibling) != null)
6068 <                        r = reducer.apply(r, s.result);
6069 <                    (t = p).result = r;
5947 >                return abortOnNullFunction();
5948 >            try {
5949 >                final double id = this.basis;
5950 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5951 >                    do {} while (!casPending(c = pending, c+1));
5952 >                    (rights = new MapReduceEntriesToDoubleTask<K,V>
5953 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
5954 >                }
5955 >                double r = id;
5956 >                Object v;
5957 >                while ((v = advance()) != null)
5958 >                    r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v)));
5959 >                result = r;
5960 >                for (MapReduceEntriesToDoubleTask<K,V> t = this, s;;) {
5961 >                    int c; BulkTask<K,V,?> par;
5962 >                    if ((c = t.pending) == 0) {
5963 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5964 >                            t.result = reducer.apply(t.result, s.result);
5965 >                        }
5966 >                        if ((par = t.parent) == null ||
5967 >                            !(par instanceof MapReduceEntriesToDoubleTask)) {
5968 >                            t.quietlyComplete();
5969 >                            break;
5970 >                        }
5971 >                        t = (MapReduceEntriesToDoubleTask<K,V>)par;
5972 >                    }
5973 >                    else if (t.casPending(c, c - 1))
5974 >                        break;
5975                  }
5976 <                else if (p.casPending(c, 0))
5977 <                    break;
5976 >            } catch (Throwable ex) {
5977 >                return tryCompleteComputation(ex);
5978              }
5979 +            return false;
5980          }
5981          public final Double getRawResult() { return result; }
5982      }
5983  
5984 <    static final class MapReduceMappingsToDoubleTask<K,V>
5984 >    @SuppressWarnings("serial") static final class MapReduceMappingsToDoubleTask<K,V>
5985          extends BulkTask<K,V,Double> {
5986          final ObjectByObjectToDouble<? super K, ? super V> transformer;
5987          final DoubleByDoubleToDouble reducer;
5988          final double basis;
5989          double result;
5990 <        MapReduceMappingsToDoubleTask<K,V> sibling;
6085 <        MapReduceMappingsToDoubleTask
6086 <            (ConcurrentHashMapV8<K,V> m,
6087 <             ObjectByObjectToDouble<? super K, ? super V> transformer,
6088 <             double basis,
6089 <             DoubleByDoubleToDouble reducer) {
6090 <            super(m);
6091 <            this.transformer = transformer;
6092 <            this.basis = basis; this.reducer = reducer;
6093 <        }
5990 >        MapReduceMappingsToDoubleTask<K,V> rights, nextRight;
5991          MapReduceMappingsToDoubleTask
5992 <            (BulkTask<K,V,?> p, int b, boolean split,
5992 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5993 >             MapReduceMappingsToDoubleTask<K,V> nextRight,
5994               ObjectByObjectToDouble<? super K, ? super V> transformer,
5995               double basis,
5996               DoubleByDoubleToDouble reducer) {
5997 <            super(p, b, split);
5997 >            super(m, p, b); this.nextRight = nextRight;
5998              this.transformer = transformer;
5999              this.basis = basis; this.reducer = reducer;
6000          }
6001 <        public final void compute() {
6104 <            MapReduceMappingsToDoubleTask<K,V> t = this;
6001 >        @SuppressWarnings("unchecked") public final boolean exec() {
6002              final ObjectByObjectToDouble<? super K, ? super V> transformer =
6003                  this.transformer;
6004              final DoubleByDoubleToDouble reducer = this.reducer;
6005              if (transformer == null || reducer == null)
6006 <                throw new Error(NullFunctionMessage);
6007 <            final double id = this.basis;
6008 <            int b = batch();
6009 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6010 <                b >>>= 1;
6011 <                t.pending = 1;
6012 <                MapReduceMappingsToDoubleTask<K,V> rt =
6013 <                    new MapReduceMappingsToDoubleTask<K,V>
6014 <                    (t, b, true, transformer, id, reducer);
6015 <                t = new MapReduceMappingsToDoubleTask<K,V>
6016 <                    (t, b, false, transformer, id, reducer);
6017 <                t.sibling = rt;
6018 <                rt.sibling = t;
6019 <                rt.fork();
6020 <            }
6021 <            double r = id;
6022 <            Object v;
6023 <            while ((v = t.advance()) != null)
6024 <                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6025 <            t.result = r;
6026 <            for (;;) {
6027 <                int c; BulkTask<K,V,?> par; MapReduceMappingsToDoubleTask<K,V> s, p;
6028 <                if ((par = t.parent) == null ||
6029 <                    !(par instanceof MapReduceMappingsToDoubleTask)) {
6030 <                    t.quietlyComplete();
6031 <                    break;
6032 <                }
6033 <                else if ((c = (p = (MapReduceMappingsToDoubleTask<K,V>)par).pending) == 0) {
6137 <                    if ((s = t.sibling) != null)
6138 <                        r = reducer.apply(r, s.result);
6139 <                    (t = p).result = r;
6006 >                return abortOnNullFunction();
6007 >            try {
6008 >                final double id = this.basis;
6009 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6010 >                    do {} while (!casPending(c = pending, c+1));
6011 >                    (rights = new MapReduceMappingsToDoubleTask<K,V>
6012 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6013 >                }
6014 >                double r = id;
6015 >                Object v;
6016 >                while ((v = advance()) != null)
6017 >                    r = reducer.apply(r, transformer.apply((K)nextKey, (V)v));
6018 >                result = r;
6019 >                for (MapReduceMappingsToDoubleTask<K,V> t = this, s;;) {
6020 >                    int c; BulkTask<K,V,?> par;
6021 >                    if ((c = t.pending) == 0) {
6022 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6023 >                            t.result = reducer.apply(t.result, s.result);
6024 >                        }
6025 >                        if ((par = t.parent) == null ||
6026 >                            !(par instanceof MapReduceMappingsToDoubleTask)) {
6027 >                            t.quietlyComplete();
6028 >                            break;
6029 >                        }
6030 >                        t = (MapReduceMappingsToDoubleTask<K,V>)par;
6031 >                    }
6032 >                    else if (t.casPending(c, c - 1))
6033 >                        break;
6034                  }
6035 <                else if (p.casPending(c, 0))
6036 <                    break;
6035 >            } catch (Throwable ex) {
6036 >                return tryCompleteComputation(ex);
6037              }
6038 +            return false;
6039          }
6040          public final Double getRawResult() { return result; }
6041      }
6042  
6043 <    static final class MapReduceKeysToLongTask<K,V>
6043 >    @SuppressWarnings("serial") static final class MapReduceKeysToLongTask<K,V>
6044          extends BulkTask<K,V,Long> {
6045          final ObjectToLong<? super K> transformer;
6046          final LongByLongToLong reducer;
6047          final long basis;
6048          long result;
6049 <        MapReduceKeysToLongTask<K,V> sibling;
6155 <        MapReduceKeysToLongTask
6156 <            (ConcurrentHashMapV8<K,V> m,
6157 <             ObjectToLong<? super K> transformer,
6158 <             long basis,
6159 <             LongByLongToLong reducer) {
6160 <            super(m);
6161 <            this.transformer = transformer;
6162 <            this.basis = basis; this.reducer = reducer;
6163 <        }
6049 >        MapReduceKeysToLongTask<K,V> rights, nextRight;
6050          MapReduceKeysToLongTask
6051 <            (BulkTask<K,V,?> p, int b, boolean split,
6051 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6052 >             MapReduceKeysToLongTask<K,V> nextRight,
6053               ObjectToLong<? super K> transformer,
6054               long basis,
6055               LongByLongToLong reducer) {
6056 <            super(p, b, split);
6056 >            super(m, p, b); this.nextRight = nextRight;
6057              this.transformer = transformer;
6058              this.basis = basis; this.reducer = reducer;
6059          }
6060 <        public final void compute() {
6174 <            MapReduceKeysToLongTask<K,V> t = this;
6060 >        @SuppressWarnings("unchecked") public final boolean exec() {
6061              final ObjectToLong<? super K> transformer =
6062                  this.transformer;
6063              final LongByLongToLong reducer = this.reducer;
6064              if (transformer == null || reducer == null)
6065 <                throw new Error(NullFunctionMessage);
6066 <            final long id = this.basis;
6067 <            int b = batch();
6068 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6069 <                b >>>= 1;
6070 <                t.pending = 1;
6071 <                MapReduceKeysToLongTask<K,V> rt =
6072 <                    new MapReduceKeysToLongTask<K,V>
6073 <                    (t, b, true, transformer, id, reducer);
6074 <                t = new MapReduceKeysToLongTask<K,V>
6075 <                    (t, b, false, transformer, id, reducer);
6076 <                t.sibling = rt;
6077 <                rt.sibling = t;
6078 <                rt.fork();
6079 <            }
6080 <            long r = id;
6081 <            while (t.advance() != null)
6082 <                r = reducer.apply(r, transformer.apply((K)t.nextKey));
6083 <            t.result = r;
6084 <            for (;;) {
6085 <                int c; BulkTask<K,V,?> par; MapReduceKeysToLongTask<K,V> s, p;
6086 <                if ((par = t.parent) == null ||
6087 <                    !(par instanceof MapReduceKeysToLongTask)) {
6088 <                    t.quietlyComplete();
6089 <                    break;
6090 <                }
6091 <                else if ((c = (p = (MapReduceKeysToLongTask<K,V>)par).pending) == 0) {
6206 <                    if ((s = t.sibling) != null)
6207 <                        r = reducer.apply(r, s.result);
6208 <                    (t = p).result = r;
6065 >                return abortOnNullFunction();
6066 >            try {
6067 >                final long id = this.basis;
6068 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6069 >                    do {} while (!casPending(c = pending, c+1));
6070 >                    (rights = new MapReduceKeysToLongTask<K,V>
6071 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6072 >                }
6073 >                long r = id;
6074 >                while (advance() != null)
6075 >                    r = reducer.apply(r, transformer.apply((K)nextKey));
6076 >                result = r;
6077 >                for (MapReduceKeysToLongTask<K,V> t = this, s;;) {
6078 >                    int c; BulkTask<K,V,?> par;
6079 >                    if ((c = t.pending) == 0) {
6080 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6081 >                            t.result = reducer.apply(t.result, s.result);
6082 >                        }
6083 >                        if ((par = t.parent) == null ||
6084 >                            !(par instanceof MapReduceKeysToLongTask)) {
6085 >                            t.quietlyComplete();
6086 >                            break;
6087 >                        }
6088 >                        t = (MapReduceKeysToLongTask<K,V>)par;
6089 >                    }
6090 >                    else if (t.casPending(c, c - 1))
6091 >                        break;
6092                  }
6093 <                else if (p.casPending(c, 0))
6094 <                    break;
6093 >            } catch (Throwable ex) {
6094 >                return tryCompleteComputation(ex);
6095              }
6096 +            return false;
6097          }
6098          public final Long getRawResult() { return result; }
6099      }
6100  
6101 <    static final class MapReduceValuesToLongTask<K,V>
6101 >    @SuppressWarnings("serial") static final class MapReduceValuesToLongTask<K,V>
6102          extends BulkTask<K,V,Long> {
6103          final ObjectToLong<? super V> transformer;
6104          final LongByLongToLong reducer;
6105          final long basis;
6106          long result;
6107 <        MapReduceValuesToLongTask<K,V> sibling;
6224 <        MapReduceValuesToLongTask
6225 <            (ConcurrentHashMapV8<K,V> m,
6226 <             ObjectToLong<? super V> transformer,
6227 <             long basis,
6228 <             LongByLongToLong reducer) {
6229 <            super(m);
6230 <            this.transformer = transformer;
6231 <            this.basis = basis; this.reducer = reducer;
6232 <        }
6107 >        MapReduceValuesToLongTask<K,V> rights, nextRight;
6108          MapReduceValuesToLongTask
6109 <            (BulkTask<K,V,?> p, int b, boolean split,
6109 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6110 >             MapReduceValuesToLongTask<K,V> nextRight,
6111               ObjectToLong<? super V> transformer,
6112               long basis,
6113               LongByLongToLong reducer) {
6114 <            super(p, b, split);
6114 >            super(m, p, b); this.nextRight = nextRight;
6115              this.transformer = transformer;
6116              this.basis = basis; this.reducer = reducer;
6117          }
6118 <        public final void compute() {
6243 <            MapReduceValuesToLongTask<K,V> t = this;
6118 >        @SuppressWarnings("unchecked") public final boolean exec() {
6119              final ObjectToLong<? super V> transformer =
6120                  this.transformer;
6121              final LongByLongToLong reducer = this.reducer;
6122              if (transformer == null || reducer == null)
6123 <                throw new Error(NullFunctionMessage);
6124 <            final long id = this.basis;
6125 <            int b = batch();
6126 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6127 <                b >>>= 1;
6128 <                t.pending = 1;
6129 <                MapReduceValuesToLongTask<K,V> rt =
6130 <                    new MapReduceValuesToLongTask<K,V>
6131 <                    (t, b, true, transformer, id, reducer);
6132 <                t = new MapReduceValuesToLongTask<K,V>
6133 <                    (t, b, false, transformer, id, reducer);
6134 <                t.sibling = rt;
6135 <                rt.sibling = t;
6136 <                rt.fork();
6137 <            }
6138 <            long r = id;
6139 <            Object v;
6140 <            while ((v = t.advance()) != null)
6141 <                r = reducer.apply(r, transformer.apply((V)v));
6142 <            t.result = r;
6143 <            for (;;) {
6144 <                int c; BulkTask<K,V,?> par; MapReduceValuesToLongTask<K,V> s, p;
6145 <                if ((par = t.parent) == null ||
6146 <                    !(par instanceof MapReduceValuesToLongTask)) {
6147 <                    t.quietlyComplete();
6148 <                    break;
6149 <                }
6150 <                else if ((c = (p = (MapReduceValuesToLongTask<K,V>)par).pending) == 0) {
6276 <                    if ((s = t.sibling) != null)
6277 <                        r = reducer.apply(r, s.result);
6278 <                    (t = p).result = r;
6123 >                return abortOnNullFunction();
6124 >            try {
6125 >                final long id = this.basis;
6126 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6127 >                    do {} while (!casPending(c = pending, c+1));
6128 >                    (rights = new MapReduceValuesToLongTask<K,V>
6129 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6130 >                }
6131 >                long r = id;
6132 >                Object v;
6133 >                while ((v = advance()) != null)
6134 >                    r = reducer.apply(r, transformer.apply((V)v));
6135 >                result = r;
6136 >                for (MapReduceValuesToLongTask<K,V> t = this, s;;) {
6137 >                    int c; BulkTask<K,V,?> par;
6138 >                    if ((c = t.pending) == 0) {
6139 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6140 >                            t.result = reducer.apply(t.result, s.result);
6141 >                        }
6142 >                        if ((par = t.parent) == null ||
6143 >                            !(par instanceof MapReduceValuesToLongTask)) {
6144 >                            t.quietlyComplete();
6145 >                            break;
6146 >                        }
6147 >                        t = (MapReduceValuesToLongTask<K,V>)par;
6148 >                    }
6149 >                    else if (t.casPending(c, c - 1))
6150 >                        break;
6151                  }
6152 <                else if (p.casPending(c, 0))
6153 <                    break;
6152 >            } catch (Throwable ex) {
6153 >                return tryCompleteComputation(ex);
6154              }
6155 +            return false;
6156          }
6157          public final Long getRawResult() { return result; }
6158      }
6159  
6160 <    static final class MapReduceEntriesToLongTask<K,V>
6160 >    @SuppressWarnings("serial") static final class MapReduceEntriesToLongTask<K,V>
6161          extends BulkTask<K,V,Long> {
6162          final ObjectToLong<Map.Entry<K,V>> transformer;
6163          final LongByLongToLong reducer;
6164          final long basis;
6165          long result;
6166 <        MapReduceEntriesToLongTask<K,V> sibling;
6166 >        MapReduceEntriesToLongTask<K,V> rights, nextRight;
6167          MapReduceEntriesToLongTask
6168 <            (ConcurrentHashMapV8<K,V> m,
6168 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6169 >             MapReduceEntriesToLongTask<K,V> nextRight,
6170               ObjectToLong<Map.Entry<K,V>> transformer,
6171               long basis,
6172               LongByLongToLong reducer) {
6173 <            super(m);
6173 >            super(m, p, b); this.nextRight = nextRight;
6174              this.transformer = transformer;
6175              this.basis = basis; this.reducer = reducer;
6176          }
6177 <        MapReduceEntriesToLongTask
6304 <            (BulkTask<K,V,?> p, int b, boolean split,
6305 <             ObjectToLong<Map.Entry<K,V>> transformer,
6306 <             long basis,
6307 <             LongByLongToLong reducer) {
6308 <            super(p, b, split);
6309 <            this.transformer = transformer;
6310 <            this.basis = basis; this.reducer = reducer;
6311 <        }
6312 <        public final void compute() {
6313 <            MapReduceEntriesToLongTask<K,V> t = this;
6177 >        @SuppressWarnings("unchecked") public final boolean exec() {
6178              final ObjectToLong<Map.Entry<K,V>> transformer =
6179                  this.transformer;
6180              final LongByLongToLong reducer = this.reducer;
6181              if (transformer == null || reducer == null)
6182 <                throw new Error(NullFunctionMessage);
6183 <            final long id = this.basis;
6184 <            int b = batch();
6185 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6186 <                b >>>= 1;
6187 <                t.pending = 1;
6188 <                MapReduceEntriesToLongTask<K,V> rt =
6189 <                    new MapReduceEntriesToLongTask<K,V>
6190 <                    (t, b, true, transformer, id, reducer);
6191 <                t = new MapReduceEntriesToLongTask<K,V>
6192 <                    (t, b, false, transformer, id, reducer);
6193 <                t.sibling = rt;
6194 <                rt.sibling = t;
6195 <                rt.fork();
6196 <            }
6197 <            long r = id;
6198 <            Object v;
6199 <            while ((v = t.advance()) != null)
6200 <                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6201 <            t.result = r;
6202 <            for (;;) {
6203 <                int c; BulkTask<K,V,?> par; MapReduceEntriesToLongTask<K,V> s, p;
6204 <                if ((par = t.parent) == null ||
6205 <                    !(par instanceof MapReduceEntriesToLongTask)) {
6206 <                    t.quietlyComplete();
6207 <                    break;
6208 <                }
6209 <                else if ((c = (p = (MapReduceEntriesToLongTask<K,V>)par).pending) == 0) {
6346 <                    if ((s = t.sibling) != null)
6347 <                        r = reducer.apply(r, s.result);
6348 <                    (t = p).result = r;
6182 >                return abortOnNullFunction();
6183 >            try {
6184 >                final long id = this.basis;
6185 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6186 >                    do {} while (!casPending(c = pending, c+1));
6187 >                    (rights = new MapReduceEntriesToLongTask<K,V>
6188 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6189 >                }
6190 >                long r = id;
6191 >                Object v;
6192 >                while ((v = advance()) != null)
6193 >                    r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v)));
6194 >                result = r;
6195 >                for (MapReduceEntriesToLongTask<K,V> t = this, s;;) {
6196 >                    int c; BulkTask<K,V,?> par;
6197 >                    if ((c = t.pending) == 0) {
6198 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6199 >                            t.result = reducer.apply(t.result, s.result);
6200 >                        }
6201 >                        if ((par = t.parent) == null ||
6202 >                            !(par instanceof MapReduceEntriesToLongTask)) {
6203 >                            t.quietlyComplete();
6204 >                            break;
6205 >                        }
6206 >                        t = (MapReduceEntriesToLongTask<K,V>)par;
6207 >                    }
6208 >                    else if (t.casPending(c, c - 1))
6209 >                        break;
6210                  }
6211 <                else if (p.casPending(c, 0))
6212 <                    break;
6211 >            } catch (Throwable ex) {
6212 >                return tryCompleteComputation(ex);
6213              }
6214 +            return false;
6215          }
6216          public final Long getRawResult() { return result; }
6217      }
6218  
6219 <    static final class MapReduceMappingsToLongTask<K,V>
6219 >    @SuppressWarnings("serial") static final class MapReduceMappingsToLongTask<K,V>
6220          extends BulkTask<K,V,Long> {
6221          final ObjectByObjectToLong<? super K, ? super V> transformer;
6222          final LongByLongToLong reducer;
6223          final long basis;
6224          long result;
6225 <        MapReduceMappingsToLongTask<K,V> sibling;
6364 <        MapReduceMappingsToLongTask
6365 <            (ConcurrentHashMapV8<K,V> m,
6366 <             ObjectByObjectToLong<? super K, ? super V> transformer,
6367 <             long basis,
6368 <             LongByLongToLong reducer) {
6369 <            super(m);
6370 <            this.transformer = transformer;
6371 <            this.basis = basis; this.reducer = reducer;
6372 <        }
6225 >        MapReduceMappingsToLongTask<K,V> rights, nextRight;
6226          MapReduceMappingsToLongTask
6227 <            (BulkTask<K,V,?> p, int b, boolean split,
6227 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6228 >             MapReduceMappingsToLongTask<K,V> nextRight,
6229               ObjectByObjectToLong<? super K, ? super V> transformer,
6230               long basis,
6231               LongByLongToLong reducer) {
6232 <            super(p, b, split);
6232 >            super(m, p, b); this.nextRight = nextRight;
6233              this.transformer = transformer;
6234              this.basis = basis; this.reducer = reducer;
6235          }
6236 <        public final void compute() {
6383 <            MapReduceMappingsToLongTask<K,V> t = this;
6236 >        @SuppressWarnings("unchecked") public final boolean exec() {
6237              final ObjectByObjectToLong<? super K, ? super V> transformer =
6238                  this.transformer;
6239              final LongByLongToLong reducer = this.reducer;
6240              if (transformer == null || reducer == null)
6241 <                throw new Error(NullFunctionMessage);
6242 <            final long id = this.basis;
6243 <            int b = batch();
6244 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6245 <                b >>>= 1;
6246 <                t.pending = 1;
6247 <                MapReduceMappingsToLongTask<K,V> rt =
6248 <                    new MapReduceMappingsToLongTask<K,V>
6249 <                    (t, b, true, transformer, id, reducer);
6250 <                t = new MapReduceMappingsToLongTask<K,V>
6251 <                    (t, b, false, transformer, id, reducer);
6252 <                t.sibling = rt;
6253 <                rt.sibling = t;
6254 <                rt.fork();
6255 <            }
6256 <            long r = id;
6257 <            Object v;
6258 <            while ((v = t.advance()) != null)
6259 <                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6260 <            t.result = r;
6261 <            for (;;) {
6262 <                int c; BulkTask<K,V,?> par; MapReduceMappingsToLongTask<K,V> s, p;
6263 <                if ((par = t.parent) == null ||
6264 <                    !(par instanceof MapReduceMappingsToLongTask)) {
6265 <                    t.quietlyComplete();
6266 <                    break;
6267 <                }
6268 <                else if ((c = (p = (MapReduceMappingsToLongTask<K,V>)par).pending) == 0) {
6416 <                    if ((s = t.sibling) != null)
6417 <                        r = reducer.apply(r, s.result);
6418 <                    (t = p).result = r;
6241 >                return abortOnNullFunction();
6242 >            try {
6243 >                final long id = this.basis;
6244 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6245 >                    do {} while (!casPending(c = pending, c+1));
6246 >                    (rights = new MapReduceMappingsToLongTask<K,V>
6247 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6248 >                }
6249 >                long r = id;
6250 >                Object v;
6251 >                while ((v = advance()) != null)
6252 >                    r = reducer.apply(r, transformer.apply((K)nextKey, (V)v));
6253 >                result = r;
6254 >                for (MapReduceMappingsToLongTask<K,V> t = this, s;;) {
6255 >                    int c; BulkTask<K,V,?> par;
6256 >                    if ((c = t.pending) == 0) {
6257 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6258 >                            t.result = reducer.apply(t.result, s.result);
6259 >                        }
6260 >                        if ((par = t.parent) == null ||
6261 >                            !(par instanceof MapReduceMappingsToLongTask)) {
6262 >                            t.quietlyComplete();
6263 >                            break;
6264 >                        }
6265 >                        t = (MapReduceMappingsToLongTask<K,V>)par;
6266 >                    }
6267 >                    else if (t.casPending(c, c - 1))
6268 >                        break;
6269                  }
6270 <                else if (p.casPending(c, 0))
6271 <                    break;
6270 >            } catch (Throwable ex) {
6271 >                return tryCompleteComputation(ex);
6272              }
6273 +            return false;
6274          }
6275          public final Long getRawResult() { return result; }
6276      }
6277  
6278 <    static final class MapReduceKeysToIntTask<K,V>
6278 >    @SuppressWarnings("serial") static final class MapReduceKeysToIntTask<K,V>
6279          extends BulkTask<K,V,Integer> {
6280          final ObjectToInt<? super K> transformer;
6281          final IntByIntToInt reducer;
6282          final int basis;
6283          int result;
6284 <        MapReduceKeysToIntTask<K,V> sibling;
6434 <        MapReduceKeysToIntTask
6435 <            (ConcurrentHashMapV8<K,V> m,
6436 <             ObjectToInt<? super K> transformer,
6437 <             int basis,
6438 <             IntByIntToInt reducer) {
6439 <            super(m);
6440 <            this.transformer = transformer;
6441 <            this.basis = basis; this.reducer = reducer;
6442 <        }
6284 >        MapReduceKeysToIntTask<K,V> rights, nextRight;
6285          MapReduceKeysToIntTask
6286 <            (BulkTask<K,V,?> p, int b, boolean split,
6286 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6287 >             MapReduceKeysToIntTask<K,V> nextRight,
6288               ObjectToInt<? super K> transformer,
6289               int basis,
6290               IntByIntToInt reducer) {
6291 <            super(p, b, split);
6291 >            super(m, p, b); this.nextRight = nextRight;
6292              this.transformer = transformer;
6293              this.basis = basis; this.reducer = reducer;
6294          }
6295 <        public final void compute() {
6453 <            MapReduceKeysToIntTask<K,V> t = this;
6295 >        @SuppressWarnings("unchecked") public final boolean exec() {
6296              final ObjectToInt<? super K> transformer =
6297                  this.transformer;
6298              final IntByIntToInt reducer = this.reducer;
6299              if (transformer == null || reducer == null)
6300 <                throw new Error(NullFunctionMessage);
6301 <            final int id = this.basis;
6302 <            int b = batch();
6303 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6304 <                b >>>= 1;
6305 <                t.pending = 1;
6306 <                MapReduceKeysToIntTask<K,V> rt =
6307 <                    new MapReduceKeysToIntTask<K,V>
6308 <                    (t, b, true, transformer, id, reducer);
6309 <                t = new MapReduceKeysToIntTask<K,V>
6310 <                    (t, b, false, transformer, id, reducer);
6311 <                t.sibling = rt;
6312 <                rt.sibling = t;
6313 <                rt.fork();
6314 <            }
6315 <            int r = id;
6316 <            while (t.advance() != null)
6317 <                r = reducer.apply(r, transformer.apply((K)t.nextKey));
6318 <            t.result = r;
6319 <            for (;;) {
6320 <                int c; BulkTask<K,V,?> par; MapReduceKeysToIntTask<K,V> s, p;
6321 <                if ((par = t.parent) == null ||
6322 <                    !(par instanceof MapReduceKeysToIntTask)) {
6323 <                    t.quietlyComplete();
6324 <                    break;
6325 <                }
6326 <                else if ((c = (p = (MapReduceKeysToIntTask<K,V>)par).pending) == 0) {
6485 <                    if ((s = t.sibling) != null)
6486 <                        r = reducer.apply(r, s.result);
6487 <                    (t = p).result = r;
6300 >                return abortOnNullFunction();
6301 >            try {
6302 >                final int id = this.basis;
6303 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6304 >                    do {} while (!casPending(c = pending, c+1));
6305 >                    (rights = new MapReduceKeysToIntTask<K,V>
6306 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6307 >                }
6308 >                int r = id;
6309 >                while (advance() != null)
6310 >                    r = reducer.apply(r, transformer.apply((K)nextKey));
6311 >                result = r;
6312 >                for (MapReduceKeysToIntTask<K,V> t = this, s;;) {
6313 >                    int c; BulkTask<K,V,?> par;
6314 >                    if ((c = t.pending) == 0) {
6315 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6316 >                            t.result = reducer.apply(t.result, s.result);
6317 >                        }
6318 >                        if ((par = t.parent) == null ||
6319 >                            !(par instanceof MapReduceKeysToIntTask)) {
6320 >                            t.quietlyComplete();
6321 >                            break;
6322 >                        }
6323 >                        t = (MapReduceKeysToIntTask<K,V>)par;
6324 >                    }
6325 >                    else if (t.casPending(c, c - 1))
6326 >                        break;
6327                  }
6328 <                else if (p.casPending(c, 0))
6329 <                    break;
6328 >            } catch (Throwable ex) {
6329 >                return tryCompleteComputation(ex);
6330              }
6331 +            return false;
6332          }
6333          public final Integer getRawResult() { return result; }
6334      }
6335  
6336 <    static final class MapReduceValuesToIntTask<K,V>
6336 >    @SuppressWarnings("serial") static final class MapReduceValuesToIntTask<K,V>
6337          extends BulkTask<K,V,Integer> {
6338          final ObjectToInt<? super V> transformer;
6339          final IntByIntToInt reducer;
6340          final int basis;
6341          int result;
6342 <        MapReduceValuesToIntTask<K,V> sibling;
6503 <        MapReduceValuesToIntTask
6504 <            (ConcurrentHashMapV8<K,V> m,
6505 <             ObjectToInt<? super V> transformer,
6506 <             int basis,
6507 <             IntByIntToInt reducer) {
6508 <            super(m);
6509 <            this.transformer = transformer;
6510 <            this.basis = basis; this.reducer = reducer;
6511 <        }
6342 >        MapReduceValuesToIntTask<K,V> rights, nextRight;
6343          MapReduceValuesToIntTask
6344 <            (BulkTask<K,V,?> p, int b, boolean split,
6344 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6345 >             MapReduceValuesToIntTask<K,V> nextRight,
6346               ObjectToInt<? super V> transformer,
6347               int basis,
6348               IntByIntToInt reducer) {
6349 <            super(p, b, split);
6349 >            super(m, p, b); this.nextRight = nextRight;
6350              this.transformer = transformer;
6351              this.basis = basis; this.reducer = reducer;
6352          }
6353 <        public final void compute() {
6522 <            MapReduceValuesToIntTask<K,V> t = this;
6353 >        @SuppressWarnings("unchecked") public final boolean exec() {
6354              final ObjectToInt<? super V> transformer =
6355                  this.transformer;
6356              final IntByIntToInt reducer = this.reducer;
6357              if (transformer == null || reducer == null)
6358 <                throw new Error(NullFunctionMessage);
6359 <            final int id = this.basis;
6360 <            int b = batch();
6361 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6362 <                b >>>= 1;
6363 <                t.pending = 1;
6364 <                MapReduceValuesToIntTask<K,V> rt =
6365 <                    new MapReduceValuesToIntTask<K,V>
6366 <                    (t, b, true, transformer, id, reducer);
6367 <                t = new MapReduceValuesToIntTask<K,V>
6368 <                    (t, b, false, transformer, id, reducer);
6369 <                t.sibling = rt;
6370 <                rt.sibling = t;
6371 <                rt.fork();
6372 <            }
6373 <            int r = id;
6374 <            Object v;
6375 <            while ((v = t.advance()) != null)
6376 <                r = reducer.apply(r, transformer.apply((V)v));
6377 <            t.result = r;
6378 <            for (;;) {
6379 <                int c; BulkTask<K,V,?> par; MapReduceValuesToIntTask<K,V> s, p;
6380 <                if ((par = t.parent) == null ||
6381 <                    !(par instanceof MapReduceValuesToIntTask)) {
6382 <                    t.quietlyComplete();
6383 <                    break;
6384 <                }
6385 <                else if ((c = (p = (MapReduceValuesToIntTask<K,V>)par).pending) == 0) {
6555 <                    if ((s = t.sibling) != null)
6556 <                        r = reducer.apply(r, s.result);
6557 <                    (t = p).result = r;
6358 >                return abortOnNullFunction();
6359 >            try {
6360 >                final int id = this.basis;
6361 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6362 >                    do {} while (!casPending(c = pending, c+1));
6363 >                    (rights = new MapReduceValuesToIntTask<K,V>
6364 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6365 >                }
6366 >                int r = id;
6367 >                Object v;
6368 >                while ((v = advance()) != null)
6369 >                    r = reducer.apply(r, transformer.apply((V)v));
6370 >                result = r;
6371 >                for (MapReduceValuesToIntTask<K,V> t = this, s;;) {
6372 >                    int c; BulkTask<K,V,?> par;
6373 >                    if ((c = t.pending) == 0) {
6374 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6375 >                            t.result = reducer.apply(t.result, s.result);
6376 >                        }
6377 >                        if ((par = t.parent) == null ||
6378 >                            !(par instanceof MapReduceValuesToIntTask)) {
6379 >                            t.quietlyComplete();
6380 >                            break;
6381 >                        }
6382 >                        t = (MapReduceValuesToIntTask<K,V>)par;
6383 >                    }
6384 >                    else if (t.casPending(c, c - 1))
6385 >                        break;
6386                  }
6387 <                else if (p.casPending(c, 0))
6388 <                    break;
6387 >            } catch (Throwable ex) {
6388 >                return tryCompleteComputation(ex);
6389              }
6390 +            return false;
6391          }
6392          public final Integer getRawResult() { return result; }
6393      }
6394  
6395 <    static final class MapReduceEntriesToIntTask<K,V>
6395 >    @SuppressWarnings("serial") static final class MapReduceEntriesToIntTask<K,V>
6396          extends BulkTask<K,V,Integer> {
6397          final ObjectToInt<Map.Entry<K,V>> transformer;
6398          final IntByIntToInt reducer;
6399          final int basis;
6400          int result;
6401 <        MapReduceEntriesToIntTask<K,V> sibling;
6573 <        MapReduceEntriesToIntTask
6574 <            (ConcurrentHashMapV8<K,V> m,
6575 <             ObjectToInt<Map.Entry<K,V>> transformer,
6576 <             int basis,
6577 <             IntByIntToInt reducer) {
6578 <            super(m);
6579 <            this.transformer = transformer;
6580 <            this.basis = basis; this.reducer = reducer;
6581 <        }
6401 >        MapReduceEntriesToIntTask<K,V> rights, nextRight;
6402          MapReduceEntriesToIntTask
6403 <            (BulkTask<K,V,?> p, int b, boolean split,
6403 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6404 >             MapReduceEntriesToIntTask<K,V> nextRight,
6405               ObjectToInt<Map.Entry<K,V>> transformer,
6406               int basis,
6407               IntByIntToInt reducer) {
6408 <            super(p, b, split);
6408 >            super(m, p, b); this.nextRight = nextRight;
6409              this.transformer = transformer;
6410              this.basis = basis; this.reducer = reducer;
6411          }
6412 <        public final void compute() {
6592 <            MapReduceEntriesToIntTask<K,V> t = this;
6412 >        @SuppressWarnings("unchecked") public final boolean exec() {
6413              final ObjectToInt<Map.Entry<K,V>> transformer =
6414                  this.transformer;
6415              final IntByIntToInt reducer = this.reducer;
6416              if (transformer == null || reducer == null)
6417 <                throw new Error(NullFunctionMessage);
6418 <            final int id = this.basis;
6419 <            int b = batch();
6420 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6421 <                b >>>= 1;
6422 <                t.pending = 1;
6423 <                MapReduceEntriesToIntTask<K,V> rt =
6424 <                    new MapReduceEntriesToIntTask<K,V>
6425 <                    (t, b, true, transformer, id, reducer);
6426 <                t = new MapReduceEntriesToIntTask<K,V>
6427 <                    (t, b, false, transformer, id, reducer);
6428 <                t.sibling = rt;
6429 <                rt.sibling = t;
6430 <                rt.fork();
6431 <            }
6432 <            int r = id;
6433 <            Object v;
6434 <            while ((v = t.advance()) != null)
6435 <                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6436 <            t.result = r;
6437 <            for (;;) {
6438 <                int c; BulkTask<K,V,?> par; MapReduceEntriesToIntTask<K,V> s, p;
6439 <                if ((par = t.parent) == null ||
6440 <                    !(par instanceof MapReduceEntriesToIntTask)) {
6441 <                    t.quietlyComplete();
6442 <                    break;
6443 <                }
6444 <                else if ((c = (p = (MapReduceEntriesToIntTask<K,V>)par).pending) == 0) {
6625 <                    if ((s = t.sibling) != null)
6626 <                        r = reducer.apply(r, s.result);
6627 <                    (t = p).result = r;
6417 >                return abortOnNullFunction();
6418 >            try {
6419 >                final int id = this.basis;
6420 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6421 >                    do {} while (!casPending(c = pending, c+1));
6422 >                    (rights = new MapReduceEntriesToIntTask<K,V>
6423 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6424 >                }
6425 >                int r = id;
6426 >                Object v;
6427 >                while ((v = advance()) != null)
6428 >                    r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v)));
6429 >                result = r;
6430 >                for (MapReduceEntriesToIntTask<K,V> t = this, s;;) {
6431 >                    int c; BulkTask<K,V,?> par;
6432 >                    if ((c = t.pending) == 0) {
6433 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6434 >                            t.result = reducer.apply(t.result, s.result);
6435 >                        }
6436 >                        if ((par = t.parent) == null ||
6437 >                            !(par instanceof MapReduceEntriesToIntTask)) {
6438 >                            t.quietlyComplete();
6439 >                            break;
6440 >                        }
6441 >                        t = (MapReduceEntriesToIntTask<K,V>)par;
6442 >                    }
6443 >                    else if (t.casPending(c, c - 1))
6444 >                        break;
6445                  }
6446 <                else if (p.casPending(c, 0))
6447 <                    break;
6446 >            } catch (Throwable ex) {
6447 >                return tryCompleteComputation(ex);
6448              }
6449 +            return false;
6450          }
6451          public final Integer getRawResult() { return result; }
6452      }
6453  
6454 <    static final class MapReduceMappingsToIntTask<K,V>
6454 >    @SuppressWarnings("serial") static final class MapReduceMappingsToIntTask<K,V>
6455          extends BulkTask<K,V,Integer> {
6456          final ObjectByObjectToInt<? super K, ? super V> transformer;
6457          final IntByIntToInt reducer;
6458          final int basis;
6459          int result;
6460 <        MapReduceMappingsToIntTask<K,V> sibling;
6643 <        MapReduceMappingsToIntTask
6644 <            (ConcurrentHashMapV8<K,V> m,
6645 <             ObjectByObjectToInt<? super K, ? super V> transformer,
6646 <             int basis,
6647 <             IntByIntToInt reducer) {
6648 <            super(m);
6649 <            this.transformer = transformer;
6650 <            this.basis = basis; this.reducer = reducer;
6651 <        }
6460 >        MapReduceMappingsToIntTask<K,V> rights, nextRight;
6461          MapReduceMappingsToIntTask
6462 <            (BulkTask<K,V,?> p, int b, boolean split,
6462 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6463 >             MapReduceMappingsToIntTask<K,V> rights,
6464               ObjectByObjectToInt<? super K, ? super V> transformer,
6465               int basis,
6466               IntByIntToInt reducer) {
6467 <            super(p, b, split);
6467 >            super(m, p, b); this.nextRight = nextRight;
6468              this.transformer = transformer;
6469              this.basis = basis; this.reducer = reducer;
6470          }
6471 <        public final void compute() {
6662 <            MapReduceMappingsToIntTask<K,V> t = this;
6471 >        @SuppressWarnings("unchecked") public final boolean exec() {
6472              final ObjectByObjectToInt<? super K, ? super V> transformer =
6473                  this.transformer;
6474              final IntByIntToInt reducer = this.reducer;
6475              if (transformer == null || reducer == null)
6476 <                throw new Error(NullFunctionMessage);
6477 <            final int id = this.basis;
6478 <            int b = batch();
6479 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6480 <                b >>>= 1;
6481 <                t.pending = 1;
6482 <                MapReduceMappingsToIntTask<K,V> rt =
6483 <                    new MapReduceMappingsToIntTask<K,V>
6484 <                    (t, b, true, transformer, id, reducer);
6485 <                t = new MapReduceMappingsToIntTask<K,V>
6486 <                    (t, b, false, transformer, id, reducer);
6487 <                t.sibling = rt;
6488 <                rt.sibling = t;
6489 <                rt.fork();
6490 <            }
6491 <            int r = id;
6492 <            Object v;
6493 <            while ((v = t.advance()) != null)
6494 <                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6495 <            t.result = r;
6496 <            for (;;) {
6497 <                int c; BulkTask<K,V,?> par; MapReduceMappingsToIntTask<K,V> s, p;
6498 <                if ((par = t.parent) == null ||
6499 <                    !(par instanceof MapReduceMappingsToIntTask)) {
6500 <                    t.quietlyComplete();
6501 <                    break;
6502 <                }
6503 <                else if ((c = (p = (MapReduceMappingsToIntTask<K,V>)par).pending) == 0) {
6695 <                    if ((s = t.sibling) != null)
6696 <                        r = reducer.apply(r, s.result);
6697 <                    (t = p).result = r;
6476 >                return abortOnNullFunction();
6477 >            try {
6478 >                final int id = this.basis;
6479 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6480 >                    do {} while (!casPending(c = pending, c+1));
6481 >                    (rights = new MapReduceMappingsToIntTask<K,V>
6482 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6483 >                }
6484 >                int r = id;
6485 >                Object v;
6486 >                while ((v = advance()) != null)
6487 >                    r = reducer.apply(r, transformer.apply((K)nextKey, (V)v));
6488 >                result = r;
6489 >                for (MapReduceMappingsToIntTask<K,V> t = this, s;;) {
6490 >                    int c; BulkTask<K,V,?> par;
6491 >                    if ((c = t.pending) == 0) {
6492 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6493 >                            t.result = reducer.apply(t.result, s.result);
6494 >                        }
6495 >                        if ((par = t.parent) == null ||
6496 >                            !(par instanceof MapReduceMappingsToIntTask)) {
6497 >                            t.quietlyComplete();
6498 >                            break;
6499 >                        }
6500 >                        t = (MapReduceMappingsToIntTask<K,V>)par;
6501 >                    }
6502 >                    else if (t.casPending(c, c - 1))
6503 >                        break;
6504                  }
6505 <                else if (p.casPending(c, 0))
6506 <                    break;
6505 >            } catch (Throwable ex) {
6506 >                return tryCompleteComputation(ex);
6507              }
6508 +            return false;
6509          }
6510          public final Integer getRawResult() { return result; }
6511      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines