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.57 by dl, Mon Aug 13 19:52:33 2012 UTC vs.
Revision 1.74 by jsr166, Tue Oct 30 16:54:26 2012 UTC

# Line 5 | Line 5
5   */
6  
7   package jsr166e;
8 import jsr166e.LongAdder;
9 import jsr166e.ForkJoinPool;
10 import jsr166e.ForkJoinTask;
8  
9   import java.util.Comparator;
10   import java.util.Arrays;
# Line 47 | Line 44 | import java.io.Serializable;
44   * block, so may overlap with update operations (including {@code put}
45   * and {@code remove}). Retrievals reflect the results of the most
46   * recently <em>completed</em> update operations holding upon their
47 < * onset.  For aggregate operations such as {@code putAll} and {@code
48 < * clear}, concurrent retrievals may reflect insertion or removal of
49 < * only some entries.  Similarly, Iterators and Enumerations return
50 < * elements reflecting the state of the hash table at some point at or
51 < * since the creation of the iterator/enumeration.  They do
52 < * <em>not</em> throw {@link ConcurrentModificationException}.
53 < * However, iterators are designed to be used by only one thread at a
54 < * time.  Bear in mind that the results of aggregate status methods
55 < * including {@code size}, {@code isEmpty}, and {@code containsValue}
56 < * are typically useful only when a map is not undergoing concurrent
57 < * updates in other threads.  Otherwise the results of these methods
58 < * reflect transient states that may be adequate for monitoring
59 < * or estimation purposes, but not for program control.
47 > * onset. (More formally, an update operation for a given key bears a
48 > * <em>happens-before</em> relation with any (non-null) retrieval for
49 > * that key reporting the updated value.)  For aggregate operations
50 > * such as {@code putAll} and {@code clear}, concurrent retrievals may
51 > * reflect insertion or removal of only some entries.  Similarly,
52 > * Iterators and Enumerations return elements reflecting the state of
53 > * the hash table at some point at or since the creation of the
54 > * iterator/enumeration.  They do <em>not</em> throw {@link
55 > * ConcurrentModificationException}.  However, iterators are designed
56 > * to be used by only one thread at a time.  Bear in mind that the
57 > * results of aggregate status methods including {@code size}, {@code
58 > * isEmpty}, and {@code containsValue} are typically useful only when
59 > * a map is not undergoing concurrent updates in other threads.
60 > * Otherwise the results of these methods reflect transient states
61 > * that may be adequate for monitoring or estimation purposes, but not
62 > * for program control.
63   *
64   * <p> The table is dynamically expanded when there are too many
65   * collisions (i.e., keys that have distinct hash codes but fall into
# Line 82 | Line 82 | import java.io.Serializable;
82   * {@code hashCode()} is a sure way to slow down performance of any
83   * hash table.
84   *
85 + * <p> A {@link Set} projection of a ConcurrentHashMapV8 may be created
86 + * (using {@link #newKeySet()} or {@link #newKeySet(int)}), or viewed
87 + * (using {@link #keySet(Object)} when only keys are of interest, and the
88 + * mapped values are (perhaps transiently) not used or all take the
89 + * same mapping value.
90 + *
91 + * <p> A ConcurrentHashMapV8 can be used as scalable frequency map (a
92 + * form of histogram or multiset) by using {@link LongAdder} values
93 + * and initializing via {@link #computeIfAbsent}. For example, to add
94 + * a count to a {@code ConcurrentHashMapV8<String,LongAdder> freqs}, you
95 + * can use {@code freqs.computeIfAbsent(k -> new
96 + * LongAdder()).increment();}
97 + *
98   * <p>This class and its views and iterators implement all of the
99   * <em>optional</em> methods of the {@link Map} and {@link Iterator}
100   * interfaces.
# Line 89 | Line 102 | import java.io.Serializable;
102   * <p> Like {@link Hashtable} but unlike {@link HashMap}, this class
103   * does <em>not</em> allow {@code null} to be used as a key or value.
104   *
105 + * <p>ConcurrentHashMapV8s support parallel operations using the {@link
106 + * ForkJoinPool#commonPool}. (Tasks that may be used in other contexts
107 + * are available in class {@link ForkJoinTasks}). These operations are
108 + * designed to be safely, and often sensibly, applied even with maps
109 + * that are being concurrently updated by other threads; for example,
110 + * when computing a snapshot summary of the values in a shared
111 + * registry.  There are three kinds of operation, each with four
112 + * forms, accepting functions with Keys, Values, Entries, and (Key,
113 + * Value) arguments and/or return values. Because the elements of a
114 + * ConcurrentHashMapV8 are not ordered in any particular way, and may be
115 + * processed in different orders in different parallel executions, the
116 + * correctness of supplied functions should not depend on any
117 + * ordering, or on any other objects or values that may transiently
118 + * change while computation is in progress; and except for forEach
119 + * actions, should ideally be side-effect-free.
120 + *
121 + * <ul>
122 + * <li> forEach: Perform a given action on each element.
123 + * A variant form applies a given transformation on each element
124 + * before performing the action.</li>
125 + *
126 + * <li> search: Return the first available non-null result of
127 + * applying a given function on each element; skipping further
128 + * search when a result is found.</li>
129 + *
130 + * <li> reduce: Accumulate each element.  The supplied reduction
131 + * function cannot rely on ordering (more formally, it should be
132 + * both associative and commutative).  There are five variants:
133 + *
134 + * <ul>
135 + *
136 + * <li> Plain reductions. (There is not a form of this method for
137 + * (key, value) function arguments since there is no corresponding
138 + * return type.)</li>
139 + *
140 + * <li> Mapped reductions that accumulate the results of a given
141 + * function applied to each element.</li>
142 + *
143 + * <li> Reductions to scalar doubles, longs, and ints, using a
144 + * given basis value.</li>
145 + *
146 + * </li>
147 + * </ul>
148 + * </ul>
149 + *
150 + * <p>The concurrency properties of bulk operations follow
151 + * from those of ConcurrentHashMapV8: Any non-null result returned
152 + * from {@code get(key)} and related access methods bears a
153 + * happens-before relation with the associated insertion or
154 + * update.  The result of any bulk operation reflects the
155 + * composition of these per-element relations (but is not
156 + * necessarily atomic with respect to the map as a whole unless it
157 + * is somehow known to be quiescent).  Conversely, because keys
158 + * and values in the map are never null, null serves as a reliable
159 + * atomic indicator of the current lack of any result.  To
160 + * maintain this property, null serves as an implicit basis for
161 + * all non-scalar reduction operations. For the double, long, and
162 + * int versions, the basis should be one that, when combined with
163 + * any other value, returns that other value (more formally, it
164 + * should be the identity element for the reduction). Most common
165 + * reductions have these properties; for example, computing a sum
166 + * with basis 0 or a minimum with basis MAX_VALUE.
167 + *
168 + * <p>Search and transformation functions provided as arguments
169 + * should similarly return null to indicate the lack of any result
170 + * (in which case it is not used). In the case of mapped
171 + * reductions, this also enables transformations to serve as
172 + * filters, returning null (or, in the case of primitive
173 + * specializations, the identity basis) if the element should not
174 + * be combined. You can create compound transformations and
175 + * filterings by composing them yourself under this "null means
176 + * there is nothing there now" rule before using them in search or
177 + * reduce operations.
178 + *
179 + * <p>Methods accepting and/or returning Entry arguments maintain
180 + * key-value associations. They may be useful for example when
181 + * finding the key for the greatest value. Note that "plain" Entry
182 + * arguments can be supplied using {@code new
183 + * AbstractMap.SimpleEntry(k,v)}.
184 + *
185 + * <p> Bulk operations may complete abruptly, throwing an
186 + * exception encountered in the application of a supplied
187 + * function. Bear in mind when handling such exceptions that other
188 + * concurrently executing functions could also have thrown
189 + * exceptions, or would have done so if the first exception had
190 + * not occurred.
191 + *
192 + * <p>Parallel speedups for bulk operations compared to sequential
193 + * processing are common but not guaranteed.  Operations involving
194 + * brief functions on small maps may execute more slowly than
195 + * sequential loops if the underlying work to parallelize the
196 + * computation is more expensive than the computation itself.
197 + * Similarly, parallelization may not lead to much actual parallelism
198 + * if all processors are busy performing unrelated tasks.
199 + *
200 + * <p> All arguments to all task methods must be non-null.
201 + *
202 + * <p><em>jsr166e note: During transition, this class
203 + * uses nested functional interfaces with different names but the
204 + * same forms as those expected for JDK8.<em>
205 + *
206   * <p>This class is a member of the
207   * <a href="{@docRoot}/../technotes/guides/collections/index.html">
208   * Java Collections Framework</a>.
209   *
96 * <p><em>jsr166e note: This class is a candidate replacement for
97 * java.util.concurrent.ConcurrentHashMap.  During transition, this
98 * class declares and uses nested functional interfaces with different
99 * names but the same forms as those expected for JDK8.<em>
100 *
210   * @since 1.5
211   * @author Doug Lea
212   * @param <K> the type of keys maintained by this map
# Line 176 | Line 285 | public class ConcurrentHashMapV8<K, V>
285          Spliterator<T> split();
286      }
287  
288 +    /**
289 +     * A view of a ConcurrentHashMapV8 as a {@link Set} of keys, in
290 +     * which additions may optionally be enabled by mapping to a
291 +     * common value.  This class cannot be directly instantiated. See
292 +     * {@link #keySet}, {@link #keySet(Object)}, {@link #newKeySet()},
293 +     * {@link #newKeySet(int)}.
294 +     *
295 +     * <p>The view's {@code iterator} is a "weakly consistent" iterator
296 +     * that will never throw {@link ConcurrentModificationException},
297 +     * and guarantees to traverse elements as they existed upon
298 +     * construction of the iterator, and may (but is not guaranteed to)
299 +     * reflect any modifications subsequent to construction.
300 +     */
301 +    public static class KeySetView<K,V> extends CHMView<K,V> implements Set<K>, java.io.Serializable {
302 +        private static final long serialVersionUID = 7249069246763182397L;
303 +        private final V value;
304 +        KeySetView(ConcurrentHashMapV8<K, V> map, V value) {  // non-public
305 +            super(map);
306 +            this.value = value;
307 +        }
308 +
309 +        /**
310 +         * Returns the map backing this view.
311 +         *
312 +         * @return the map backing this view
313 +         */
314 +        public ConcurrentHashMapV8<K,V> getMap() { return map; }
315 +
316 +        /**
317 +         * Returns the default mapped value for additions,
318 +         * or {@code null} if additions are not supported.
319 +         *
320 +         * @return the default mapped value for additions, or {@code null}
321 +         * if not supported.
322 +         */
323 +        public V getMappedValue() { return value; }
324 +
325 +        // implement Set API
326 +
327 +        public boolean contains(Object o) { return map.containsKey(o); }
328 +        public boolean remove(Object o)   { return map.remove(o) != null; }
329 +        public Iterator<K> iterator()     { return new KeyIterator<K,V>(map); }
330 +        public boolean add(K e) {
331 +            V v;
332 +            if ((v = value) == null)
333 +                throw new UnsupportedOperationException();
334 +            if (e == null)
335 +                throw new NullPointerException();
336 +            return map.internalPutIfAbsent(e, v) == null;
337 +        }
338 +        public boolean addAll(Collection<? extends K> c) {
339 +            boolean added = false;
340 +            V v;
341 +            if ((v = value) == null)
342 +                throw new UnsupportedOperationException();
343 +            for (K e : c) {
344 +                if (e == null)
345 +                    throw new NullPointerException();
346 +                if (map.internalPutIfAbsent(e, v) == null)
347 +                    added = true;
348 +            }
349 +            return added;
350 +        }
351 +        public boolean equals(Object o) {
352 +            Set<?> c;
353 +            return ((o instanceof Set) &&
354 +                    ((c = (Set<?>)o) == this ||
355 +                     (containsAll(c) && c.containsAll(this))));
356 +        }
357 +    }
358 +
359      /*
360       * Overview:
361       *
# Line 458 | Line 638 | public class ConcurrentHashMapV8<K, V>
638      private transient volatile int sizeCtl;
639  
640      // views
641 <    private transient KeySet<K,V> keySet;
641 >    private transient KeySetView<K,V> keySet;
642      private transient Values<K,V> values;
643      private transient EntrySet<K,V> entrySet;
644  
# Line 537 | Line 717 | public class ConcurrentHashMapV8<K, V>
717           * unlocking lock (via a failed CAS from non-waiting LOCKED
718           * state), unlockers acquire the sync lock and perform a
719           * notifyAll.
720 +         *
721 +         * The initial sanity check on tab and bounds is not currently
722 +         * necessary in the only usages of this method, but enables
723 +         * use in other future contexts.
724           */
725          final void tryAwaitLock(Node[] tab, int i) {
726 <            if (tab != null && i >= 0 && i < tab.length) { // bounds check
726 >            if (tab != null && i >= 0 && i < tab.length) { // sanity check
727                  int r = ThreadLocalRandom.current().nextInt(); // randomize spins
728                  int spins = MAX_SPINS, h;
729                  while (tabAt(tab, i) == this && ((h = hash) & LOCKED) != 0) {
# Line 715 | Line 899 | public class ConcurrentHashMapV8<K, V>
899           * Returns the TreeNode (or null if not found) for the given key
900           * starting at given root.
901           */
902 <        @SuppressWarnings("unchecked") // suppress Comparable cast warning
903 <            final TreeNode getTreeNode(int h, Object k, TreeNode p) {
902 >        @SuppressWarnings("unchecked") final TreeNode getTreeNode
903 >            (int h, Object k, TreeNode p) {
904              Class<?> c = k.getClass();
905              while (p != null) {
906                  int dir, ph;  Object pk; Class<?> pc;
# Line 776 | Line 960 | public class ConcurrentHashMapV8<K, V>
960           * Finds or adds a node.
961           * @return null if added
962           */
963 <        @SuppressWarnings("unchecked") // suppress Comparable cast warning
964 <            final TreeNode putTreeNode(int h, Object k, Object v) {
963 >        @SuppressWarnings("unchecked") final TreeNode putTreeNode
964 >            (int h, Object k, Object v) {
965              Class<?> c = k.getClass();
966              TreeNode pp = root, p = null;
967              int dir = 0;
# Line 1204 | Line 1388 | public class ConcurrentHashMapV8<K, V>
1388      }
1389  
1390      /*
1391 <     * Internal versions of the five insertion methods, each a
1391 >     * Internal versions of the six insertion methods, each a
1392       * little more complicated than the last. All have
1393       * the same basic structure as the first (internalPut):
1394       *  1. If table uninitialized, create
# Line 1222 | Line 1406 | public class ConcurrentHashMapV8<K, V>
1406       *    returns from function call.
1407       *  * compute uses the same function-call mechanics, but without
1408       *    the prescans
1409 +     *  * merge acts as putIfAbsent in the absent case, but invokes the
1410 +     *    update function if present
1411       *  * putAll attempts to pre-allocate enough table space
1412       *    and more lazily performs count updates and checks.
1413       *
# Line 1545 | Line 1731 | public class ConcurrentHashMapV8<K, V>
1731      }
1732  
1733      /** Implementation for compute */
1734 <    @SuppressWarnings("unchecked")
1735 <        private final Object internalCompute(K k, boolean onlyIfPresent,
1550 <                                             BiFun<? super K, ? super V, ? extends V> mf) {
1734 >    @SuppressWarnings("unchecked") private final Object internalCompute
1735 >        (K k, boolean onlyIfPresent, BiFun<? super K, ? super V, ? extends V> mf) {
1736          int h = spread(k.hashCode());
1737          Object val = null;
1738          int delta = 0;
# Line 1670 | Line 1855 | public class ConcurrentHashMapV8<K, V>
1855          return val;
1856      }
1857  
1858 <    private final Object internalMerge(K k, V v,
1859 <                                       BiFun<? super V, ? super V, ? extends V> mf) {
1858 >    /** Implementation for merge */
1859 >    @SuppressWarnings("unchecked") private final Object internalMerge
1860 >        (K k, V v, BiFun<? super V, ? super V, ? extends V> mf) {
1861          int h = spread(k.hashCode());
1862          Object val = null;
1863          int delta = 0;
# Line 2001 | Line 2187 | public class ConcurrentHashMapV8<K, V>
2187          for (int i = bin;;) {      // start upwards sweep
2188              int fh; Node f;
2189              if ((f = tabAt(tab, i)) == null) {
2190 <                if (bin >= 0) {    // no lock needed (or available)
2190 >                if (bin >= 0) {    // Unbuffered; no lock needed (or available)
2191                      if (!casTabAt(tab, i, f, fwd))
2192                          continue;
2193                  }
# Line 2177 | Line 2363 | public class ConcurrentHashMapV8<K, V>
2363                      try {
2364                          if (tabAt(tab, i) == f) {
2365                              for (Node p = t.first; p != null; p = p.next) {
2366 <                                p.val = null;
2367 <                                --delta;
2366 >                                if (p.val != null) { // (currently always true)
2367 >                                    p.val = null;
2368 >                                    --delta;
2369 >                                }
2370                              }
2371                              t.first = null;
2372                              t.root = null;
# Line 2200 | Line 2388 | public class ConcurrentHashMapV8<K, V>
2388                  try {
2389                      if (tabAt(tab, i) == f) {
2390                          for (Node e = f; e != null; e = e.next) {
2391 <                            e.val = null;
2392 <                            --delta;
2391 >                            if (e.val != null) {  // (currently always true)
2392 >                                e.val = null;
2393 >                                --delta;
2394 >                            }
2395                          }
2396                          setTabAt(tab, i, null);
2397                          ++i;
# Line 2222 | Line 2412 | public class ConcurrentHashMapV8<K, V>
2412  
2413      /**
2414       * Encapsulates traversal for methods such as containsValue; also
2415 <     * serves as a base class for other iterators.
2415 >     * serves as a base class for other iterators and bulk tasks.
2416       *
2417       * At each step, the iterator snapshots the key ("nextKey") and
2418       * value ("nextVal") of a valid node (i.e., one that, at point of
# Line 2230 | Line 2420 | public class ConcurrentHashMapV8<K, V>
2420       * change (including to null, indicating deletion), field nextVal
2421       * might not be accurate at point of use, but still maintains the
2422       * weak consistency property of holding a value that was once
2423 <     * valid.
2423 >     * valid. To support iterator.remove, the nextKey field is not
2424 >     * updated (nulled out) when the iterator cannot advance.
2425       *
2426       * Internal traversals directly access these fields, as in:
2427       * {@code while (it.advance() != null) { process(it.nextKey); }}
# Line 2260 | Line 2451 | public class ConcurrentHashMapV8<K, V>
2451       * This class extends ForkJoinTask to streamline parallel
2452       * iteration in bulk operations (see BulkTask). This adds only an
2453       * int of space overhead, which is close enough to negligible in
2454 <     * cases where it is not needed to not worry about it.
2454 >     * cases where it is not needed to not worry about it.  Because
2455 >     * ForkJoinTask is Serializable, but iterators need not be, we
2456 >     * need to add warning suppressions.
2457       */
2458 <    static class Traverser<K,V,R> extends ForkJoinTask<R> {
2458 >    @SuppressWarnings("serial") static class Traverser<K,V,R> extends ForkJoinTask<R> {
2459          final ConcurrentHashMapV8<K, V> map;
2460          Node next;           // the next entry to use
2268        Node last;           // the last entry used
2461          Object nextKey;      // cached key field of next
2462          Object nextVal;      // cached val field of next
2463          Node[] tab;          // current table; updated if resized
2464          int index;           // index of bin to use next
2465          int baseIndex;       // current index of initial table
2466          int baseLimit;       // index bound for initial table
2467 <        final int baseSize;  // initial table size
2467 >        int baseSize;        // initial table size
2468  
2469          /** Creates iterator for all entries in the table. */
2470          Traverser(ConcurrentHashMapV8<K, V> map) {
2471 <            this.tab = (this.map = map).table;
2280 <            baseLimit = baseSize = (tab == null) ? 0 : tab.length;
2471 >            this.map = map;
2472          }
2473  
2474          /** Creates iterator for split() methods */
2475 <        Traverser(Traverser<K,V,?> it, boolean split) {
2476 <            this.map = it.map;
2477 <            this.tab = it.tab;
2475 >        Traverser(Traverser<K,V,?> it) {
2476 >            ConcurrentHashMapV8<K, V> m; Node[] t;
2477 >            if ((m = this.map = it.map) == null)
2478 >                t = null;
2479 >            else if ((t = it.tab) == null && // force parent tab initialization
2480 >                     (t = it.tab = m.table) != null)
2481 >                it.baseLimit = it.baseSize = t.length;
2482 >            this.tab = t;
2483              this.baseSize = it.baseSize;
2484 <            int lo = it.baseIndex;
2485 <            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;
2484 >            it.baseLimit = this.index = this.baseIndex =
2485 >                ((this.baseLimit = it.baseLimit) + it.baseIndex + 1) >>> 1;
2486          }
2487  
2488          /**
# Line 2300 | Line 2490 | public class ConcurrentHashMapV8<K, V>
2490           * See above for explanation.
2491           */
2492          final Object advance() {
2493 <            Node e = last = next;
2493 >            Node e = next;
2494              Object ev = null;
2495              outer: do {
2496                  if (e != null)                  // advance past used/skipped node
2497                      e = e.next;
2498                  while (e == null) {             // get to next non-null bin
2499 +                    ConcurrentHashMapV8<K, V> m;
2500                      Node[] t; int b, i, n; Object ek; // checks must use locals
2501 <                    if ((b = baseIndex) >= baseLimit || (i = index) < 0 ||
2502 <                        (t = tab) == null || i >= (n = t.length))
2501 >                    if ((t = tab) != null)
2502 >                        n = t.length;
2503 >                    else if ((m = map) != null && (t = tab = m.table) != null)
2504 >                        n = baseLimit = baseSize = t.length;
2505 >                    else
2506 >                        break outer;
2507 >                    if ((b = baseIndex) >= baseLimit ||
2508 >                        (i = index) < 0 || i >= n)
2509                          break outer;
2510 <                    else if ((e = tabAt(t, i)) != null && e.hash == MOVED) {
2510 >                    if ((e = tabAt(t, i)) != null && e.hash == MOVED) {
2511                          if ((ek = e.key) instanceof TreeBin)
2512                              e = ((TreeBin)ek).first;
2513                          else {
# Line 2327 | Line 2524 | public class ConcurrentHashMapV8<K, V>
2524          }
2525  
2526          public final void remove() {
2527 <            if (nextVal == null && last == null)
2528 <                advance();
2332 <            Node e = last;
2333 <            if (e == null)
2527 >            Object k = nextKey;
2528 >            if (k == null && (advance() == null || (k = nextKey) == null))
2529                  throw new IllegalStateException();
2530 <            last = null;
2336 <            map.remove(e.key);
2530 >            map.internalReplace(k, null, null);
2531          }
2532  
2533          public final boolean hasNext() {
# Line 2437 | Line 2631 | public class ConcurrentHashMapV8<K, V>
2631      }
2632  
2633      /**
2634 +     * Creates a new {@link Set} backed by a ConcurrentHashMapV8
2635 +     * from the given type to {@code Boolean.TRUE}.
2636 +     *
2637 +     * @return the new set
2638 +     */
2639 +    public static <K> KeySetView<K,Boolean> newKeySet() {
2640 +        return new KeySetView<K,Boolean>(new ConcurrentHashMapV8<K,Boolean>(),
2641 +                                      Boolean.TRUE);
2642 +    }
2643 +
2644 +    /**
2645 +     * Creates a new {@link Set} backed by a ConcurrentHashMapV8
2646 +     * from the given type to {@code Boolean.TRUE}.
2647 +     *
2648 +     * @param initialCapacity The implementation performs internal
2649 +     * sizing to accommodate this many elements.
2650 +     * @throws IllegalArgumentException if the initial capacity of
2651 +     * elements is negative
2652 +     * @return the new set
2653 +     */
2654 +    public static <K> KeySetView<K,Boolean> newKeySet(int initialCapacity) {
2655 +        return new KeySetView<K,Boolean>(new ConcurrentHashMapV8<K,Boolean>(initialCapacity),
2656 +                                      Boolean.TRUE);
2657 +    }
2658 +
2659 +    /**
2660       * {@inheritDoc}
2661       */
2662      public boolean isEmpty() {
# Line 2455 | Line 2675 | public class ConcurrentHashMapV8<K, V>
2675  
2676      /**
2677       * Returns the number of mappings. This method should be used
2678 <     * instead of {@link #size} because a ConcurrentHashMap may
2678 >     * instead of {@link #size} because a ConcurrentHashMapV8 may
2679       * contain more mappings than can be represented as an int. The
2680       * value returned is a snapshot; the actual count may differ if
2681 <     * there are ongoing concurrent insertions of removals.
2681 >     * there are ongoing concurrent insertions or removals.
2682       *
2683       * @return the number of mappings
2684       */
2685      public long mappingCount() {
2686          long n = counter.sum();
2687 <        return (n < 0L) ? 0L : n;
2687 >        return (n < 0L) ? 0L : n; // ignore transient negative values
2688      }
2689  
2690      /**
# Line 2478 | Line 2698 | public class ConcurrentHashMapV8<K, V>
2698       *
2699       * @throws NullPointerException if the specified key is null
2700       */
2701 <    @SuppressWarnings("unchecked")
2482 <        public V get(Object key) {
2701 >    @SuppressWarnings("unchecked") public V get(Object key) {
2702          if (key == null)
2703              throw new NullPointerException();
2704          return (V)internalGet(key);
2705      }
2706  
2707      /**
2708 +     * Returns the value to which the specified key is mapped,
2709 +     * or the given defaultValue if this map contains no mapping for the key.
2710 +     *
2711 +     * @param key the key
2712 +     * @param defaultValue the value to return if this map contains
2713 +     * no mapping for the given key
2714 +     * @return the mapping for the key, if present; else the defaultValue
2715 +     * @throws NullPointerException if the specified key is null
2716 +     */
2717 +    @SuppressWarnings("unchecked") public V getValueOrDefault(Object key, V defaultValue) {
2718 +        if (key == null)
2719 +            throw new NullPointerException();
2720 +        V v = (V) internalGet(key);
2721 +        return v == null ? defaultValue : v;
2722 +    }
2723 +
2724 +    /**
2725       * Tests if the specified object is a key in this table.
2726       *
2727       * @param  key   possible key
# Line 2554 | Line 2790 | public class ConcurrentHashMapV8<K, V>
2790       *         {@code null} if there was no mapping for {@code key}
2791       * @throws NullPointerException if the specified key or value is null
2792       */
2793 <    @SuppressWarnings("unchecked")
2558 <        public V put(K key, V value) {
2793 >    @SuppressWarnings("unchecked") public V put(K key, V value) {
2794          if (key == null || value == null)
2795              throw new NullPointerException();
2796          return (V)internalPut(key, value);
# Line 2568 | Line 2803 | public class ConcurrentHashMapV8<K, V>
2803       *         or {@code null} if there was no mapping for the key
2804       * @throws NullPointerException if the specified key or value is null
2805       */
2806 <    @SuppressWarnings("unchecked")
2572 <        public V putIfAbsent(K key, V value) {
2806 >    @SuppressWarnings("unchecked") public V putIfAbsent(K key, V value) {
2807          if (key == null || value == null)
2808              throw new NullPointerException();
2809          return (V)internalPutIfAbsent(key, value);
# Line 2616 | Line 2850 | public class ConcurrentHashMapV8<K, V>
2850       * @param key key with which the specified value is to be associated
2851       * @param mappingFunction the function to compute a value
2852       * @return the current (existing or computed) value associated with
2853 <     *         the specified key, or null if the computed value is null.
2853 >     *         the specified key, or null if the computed value is null
2854       * @throws NullPointerException if the specified key or mappingFunction
2855       *         is null
2856       * @throws IllegalStateException if the computation detectably
# Line 2625 | Line 2859 | public class ConcurrentHashMapV8<K, V>
2859       * @throws RuntimeException or Error if the mappingFunction does so,
2860       *         in which case the mapping is left unestablished
2861       */
2862 <    @SuppressWarnings("unchecked")
2863 <        public V computeIfAbsent(K key, Fun<? super K, ? extends V> mappingFunction) {
2862 >    @SuppressWarnings("unchecked") public V computeIfAbsent
2863 >        (K key, Fun<? super K, ? extends V> mappingFunction) {
2864          if (key == null || mappingFunction == null)
2865              throw new NullPointerException();
2866          return (V)internalComputeIfAbsent(key, mappingFunction);
# Line 2666 | Line 2900 | public class ConcurrentHashMapV8<K, V>
2900       * @throws RuntimeException or Error if the remappingFunction does so,
2901       *         in which case the mapping is unchanged
2902       */
2903 <    public V computeIfPresent(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2903 >    @SuppressWarnings("unchecked") public V computeIfPresent
2904 >        (K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2905          if (key == null || remappingFunction == null)
2906              throw new NullPointerException();
2907          return (V)internalCompute(key, true, remappingFunction);
# Line 2712 | Line 2947 | public class ConcurrentHashMapV8<K, V>
2947       * @throws RuntimeException or Error if the remappingFunction does so,
2948       *         in which case the mapping is unchanged
2949       */
2950 <    //    @SuppressWarnings("unchecked")
2951 <    public V compute(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2950 >    @SuppressWarnings("unchecked") public V compute
2951 >        (K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2952          if (key == null || remappingFunction == null)
2953              throw new NullPointerException();
2954          return (V)internalCompute(key, false, remappingFunction);
# Line 2744 | Line 2979 | public class ConcurrentHashMapV8<K, V>
2979       * so the computation should be short and simple, and must not
2980       * attempt to update any other mappings of this Map.
2981       */
2982 <    //    @SuppressWarnings("unchecked")
2983 <    public V merge(K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) {
2982 >    @SuppressWarnings("unchecked") public V merge
2983 >        (K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) {
2984          if (key == null || value == null || remappingFunction == null)
2985              throw new NullPointerException();
2986          return (V)internalMerge(key, value, remappingFunction);
# Line 2760 | Line 2995 | public class ConcurrentHashMapV8<K, V>
2995       *         {@code null} if there was no mapping for {@code key}
2996       * @throws NullPointerException if the specified key is null
2997       */
2998 <    @SuppressWarnings("unchecked")
2764 <        public V remove(Object key) {
2998 >    @SuppressWarnings("unchecked") public V remove(Object key) {
2999          if (key == null)
3000              throw new NullPointerException();
3001          return (V)internalReplace(key, null, null);
# Line 2798 | Line 3032 | public class ConcurrentHashMapV8<K, V>
3032       *         or {@code null} if there was no mapping for the key
3033       * @throws NullPointerException if the specified key or value is null
3034       */
3035 <    @SuppressWarnings("unchecked")
2802 <        public V replace(K key, V value) {
3035 >    @SuppressWarnings("unchecked") public V replace(K key, V value) {
3036          if (key == null || value == null)
3037              throw new NullPointerException();
3038          return (V)internalReplace(key, value, null);
# Line 2815 | Line 3048 | public class ConcurrentHashMapV8<K, V>
3048      /**
3049       * Returns a {@link Set} view of the keys contained in this map.
3050       * The set is backed by the map, so changes to the map are
3051 <     * reflected in the set, and vice-versa.  The set supports element
2819 <     * removal, which removes the corresponding mapping from this map,
2820 <     * via the {@code Iterator.remove}, {@code Set.remove},
2821 <     * {@code removeAll}, {@code retainAll}, and {@code clear}
2822 <     * operations.  It does not support the {@code add} or
2823 <     * {@code addAll} operations.
3051 >     * reflected in the set, and vice-versa.
3052       *
3053 <     * <p>The view's {@code iterator} is a "weakly consistent" iterator
2826 <     * that will never throw {@link ConcurrentModificationException},
2827 <     * and guarantees to traverse elements as they existed upon
2828 <     * construction of the iterator, and may (but is not guaranteed to)
2829 <     * reflect any modifications subsequent to construction.
3053 >     * @return the set view
3054       */
3055 <    public Set<K> keySet() {
3056 <        KeySet<K,V> ks = keySet;
3057 <        return (ks != null) ? ks : (keySet = new KeySet<K,V>(this));
3055 >    public KeySetView<K,V> keySet() {
3056 >        KeySetView<K,V> ks = keySet;
3057 >        return (ks != null) ? ks : (keySet = new KeySetView<K,V>(this, null));
3058 >    }
3059 >
3060 >    /**
3061 >     * Returns a {@link Set} view of the keys in this map, using the
3062 >     * given common mapped value for any additions (i.e., {@link
3063 >     * Collection#add} and {@link Collection#addAll}). This is of
3064 >     * course only appropriate if it is acceptable to use the same
3065 >     * value for all additions from this view.
3066 >     *
3067 >     * @param mappedValue the mapped value to use for any
3068 >     * additions.
3069 >     * @return the set view
3070 >     * @throws NullPointerException if the mappedValue is null
3071 >     */
3072 >    public KeySetView<K,V> keySet(V mappedValue) {
3073 >        if (mappedValue == null)
3074 >            throw new NullPointerException();
3075 >        return new KeySetView<K,V>(this, mappedValue);
3076      }
3077  
3078      /**
# Line 3005 | Line 3247 | public class ConcurrentHashMapV8<K, V>
3247  
3248      /* ----------------Iterators -------------- */
3249  
3250 <    static final class KeyIterator<K,V> extends Traverser<K,V,Object>
3250 >    @SuppressWarnings("serial") static final class KeyIterator<K,V> extends Traverser<K,V,Object>
3251          implements Spliterator<K>, Enumeration<K> {
3252          KeyIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3253 <        KeyIterator(Traverser<K,V,Object> it, boolean split) {
3254 <            super(it, split);
3253 >        KeyIterator(Traverser<K,V,Object> it) {
3254 >            super(it);
3255          }
3256          public KeyIterator<K,V> split() {
3257 <            if (last != null || (next != null && nextVal == null))
3257 >            if (nextKey != null)
3258                  throw new IllegalStateException();
3259 <            return new KeyIterator<K,V>(this, true);
3259 >            return new KeyIterator<K,V>(this);
3260          }
3261 <        @SuppressWarnings("unchecked")
3020 <            public final K next() {
3261 >        @SuppressWarnings("unchecked") public final K next() {
3262              if (nextVal == null && advance() == null)
3263                  throw new NoSuchElementException();
3264              Object k = nextKey;
# Line 3028 | Line 3269 | public class ConcurrentHashMapV8<K, V>
3269          public final K nextElement() { return next(); }
3270      }
3271  
3272 <    static final class ValueIterator<K,V> extends Traverser<K,V,Object>
3272 >    @SuppressWarnings("serial") static final class ValueIterator<K,V> extends Traverser<K,V,Object>
3273          implements Spliterator<V>, Enumeration<V> {
3274          ValueIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3275 <        ValueIterator(Traverser<K,V,Object> it, boolean split) {
3276 <            super(it, split);
3275 >        ValueIterator(Traverser<K,V,Object> it) {
3276 >            super(it);
3277          }
3278          public ValueIterator<K,V> split() {
3279 <            if (last != null || (next != null && nextVal == null))
3279 >            if (nextKey != null)
3280                  throw new IllegalStateException();
3281 <            return new ValueIterator<K,V>(this, true);
3281 >            return new ValueIterator<K,V>(this);
3282          }
3283  
3284 <        @SuppressWarnings("unchecked")
3044 <            public final V next() {
3284 >        @SuppressWarnings("unchecked") public final V next() {
3285              Object v;
3286              if ((v = nextVal) == null && (v = advance()) == null)
3287                  throw new NoSuchElementException();
# Line 3052 | Line 3292 | public class ConcurrentHashMapV8<K, V>
3292          public final V nextElement() { return next(); }
3293      }
3294  
3295 <    static final class EntryIterator<K,V> extends Traverser<K,V,Object>
3295 >    @SuppressWarnings("serial") static final class EntryIterator<K,V> extends Traverser<K,V,Object>
3296          implements Spliterator<Map.Entry<K,V>> {
3297          EntryIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3298 <        EntryIterator(Traverser<K,V,Object> it, boolean split) {
3299 <            super(it, split);
3298 >        EntryIterator(Traverser<K,V,Object> it) {
3299 >            super(it);
3300          }
3301          public EntryIterator<K,V> split() {
3302 <            if (last != null || (next != null && nextVal == null))
3302 >            if (nextKey != null)
3303                  throw new IllegalStateException();
3304 <            return new EntryIterator<K,V>(this, true);
3304 >            return new EntryIterator<K,V>(this);
3305          }
3306  
3307 <        @SuppressWarnings("unchecked")
3068 <            public final Map.Entry<K,V> next() {
3307 >        @SuppressWarnings("unchecked") public final Map.Entry<K,V> next() {
3308              Object v;
3309              if ((v = nextVal) == null && (v = advance()) == null)
3310                  throw new NoSuchElementException();
# Line 3160 | Line 3399 | public class ConcurrentHashMapV8<K, V>
3399              return (i == n) ? r : Arrays.copyOf(r, i);
3400          }
3401  
3402 <        @SuppressWarnings("unchecked")
3164 <            public final <T> T[] toArray(T[] a) {
3402 >        @SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) {
3403              long sz = map.mappingCount();
3404              if (sz > (long)(MAX_ARRAY_SIZE))
3405                  throw new OutOfMemoryError(oomeMsg);
# Line 3249 | Line 3487 | public class ConcurrentHashMapV8<K, V>
3487  
3488      }
3489  
3252    static final class KeySet<K,V> extends CHMView<K,V> implements Set<K> {
3253        KeySet(ConcurrentHashMapV8<K, V> map)  {
3254            super(map);
3255        }
3256        public final boolean contains(Object o) { return map.containsKey(o); }
3257        public final boolean remove(Object o)   { return map.remove(o) != null; }
3258        public final Iterator<K> iterator() {
3259            return new KeyIterator<K,V>(map);
3260        }
3261        public final boolean add(K e) {
3262            throw new UnsupportedOperationException();
3263        }
3264        public final boolean addAll(Collection<? extends K> c) {
3265            throw new UnsupportedOperationException();
3266        }
3267        public boolean equals(Object o) {
3268            Set<?> c;
3269            return ((o instanceof Set) &&
3270                    ((c = (Set<?>)o) == this ||
3271                     (containsAll(c) && c.containsAll(this))));
3272        }
3273    }
3274
3275
3490      static final class Values<K,V> extends CHMView<K,V>
3491          implements Collection<V> {
3492          Values(ConcurrentHashMapV8<K, V> map)   { super(map); }
# Line 3357 | Line 3571 | public class ConcurrentHashMapV8<K, V>
3571       * for each key-value mapping, followed by a null pair.
3572       * The key-value mappings are emitted in no particular order.
3573       */
3574 <    @SuppressWarnings("unchecked")
3361 <        private void writeObject(java.io.ObjectOutputStream s)
3574 >    @SuppressWarnings("unchecked") private void writeObject(java.io.ObjectOutputStream s)
3575          throws java.io.IOException {
3576          if (segments == null) { // for serialization compatibility
3577              segments = (Segment<K,V>[])
# Line 3382 | Line 3595 | public class ConcurrentHashMapV8<K, V>
3595       * Reconstitutes the instance from a stream (that is, deserializes it).
3596       * @param s the stream
3597       */
3598 <    @SuppressWarnings("unchecked")
3386 <        private void readObject(java.io.ObjectInputStream s)
3598 >    @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s)
3599          throws java.io.IOException, ClassNotFoundException {
3600          s.defaultReadObject();
3601          this.segments = null; // unneeded
# Line 3504 | Line 3716 | public class ConcurrentHashMapV8<K, V>
3716      // -------------------------------------------------------
3717  
3718      /**
3719 <     * Returns an extended {@link Parallel} view of this map using the
3508 <     * given executor for bulk parallel operations.
3719 >     * Performs the given action for each (key, value).
3720       *
3721 <     * @param executor the executor
3511 <     * @return a parallel view
3721 >     * @param action the action
3722       */
3723 <    public Parallel parallel(ForkJoinPool executor)  {
3724 <        return new Parallel(executor);
3723 >    public void forEach(BiAction<K,V> action) {
3724 >        ForkJoinTasks.forEach
3725 >            (this, action).invoke();
3726      }
3727  
3728      /**
3729 <     * An extended view of a ConcurrentHashMap supporting bulk
3730 <     * parallel operations. These operations are designed to be
3731 <     * safely, and often sensibly, applied even with maps that are
3732 <     * being concurrently updated by other threads; for example, when
3733 <     * computing a snapshot summary of the values in a shared
3734 <     * registry.  There are three kinds of operation, each with four
3735 <     * forms, accepting functions with Keys, Values, Entries, and
3525 <     * (Key, Value) arguments and/or return values. Because the
3526 <     * elements of a ConcurrentHashMap are not ordered in any
3527 <     * particular way, and may be processed in different orders in
3528 <     * different parallel executions, the correctness of supplied
3529 <     * functions should not depend on any ordering, or on any other
3530 <     * objects or values that may transiently change while computation
3531 <     * is in progress; and except for forEach actions, should ideally
3532 <     * be side-effect-free.
3533 <     *
3534 <     * <ul>
3535 <     * <li> forEach: Perform a given action on each element.
3536 <     * A variant form applies a given transformation on each element
3537 <     * before performing the action.</li>
3538 <     *
3539 <     * <li> search: Return the first available non-null result of
3540 <     * applying a given function on each element; skipping further
3541 <     * search when a result is found.</li>
3542 <     *
3543 <     * <li> reduce: Accumulate each element.  The supplied reduction
3544 <     * function cannot rely on ordering (more formally, it should be
3545 <     * both associative and commutative).  There are five variants:
3546 <     *
3547 <     * <ul>
3548 <     *
3549 <     * <li> Plain reductions. (There is not a form of this method for
3550 <     * (key, value) function arguments since there is no corresponding
3551 <     * return type.)</li>
3552 <     *
3553 <     * <li> Mapped reductions that accumulate the results of a given
3554 <     * function applied to each element.</li>
3555 <     *
3556 <     * <li> Reductions to scalar doubles, longs, and ints, using a
3557 <     * given basis value.</li>
3558 <     *
3559 <     * </li>
3560 <     * </ul>
3561 <     * </ul>
3562 <     *
3563 <     * <p>The concurrency properties of the bulk operations follow
3564 <     * from those of ConcurrentHashMap: Any non-null result returned
3565 <     * from {@code get(key)} and related access methods bears a
3566 <     * happens-before relation with the associated insertion or
3567 <     * update.  The result of any bulk operation reflects the
3568 <     * composition of these per-element relations (but is not
3569 <     * necessarily atomic with respect to the map as a whole unless it
3570 <     * is somehow known to be quiescent).  Conversely, because keys
3571 <     * and values in the map are never null, null serves as a reliable
3572 <     * atomic indicator of the current lack of any result.  To
3573 <     * maintain this property, null serves as an implicit basis for
3574 <     * all non-scalar reduction operations. For the double, long, and
3575 <     * int versions, the basis should be one that, when combined with
3576 <     * any other value, returns that other value (more formally, it
3577 <     * should be the identity element for the reduction). Most common
3578 <     * reductions have these properties; for example, computing a sum
3579 <     * with basis 0 or a minimum with basis MAX_VALUE.
3580 <     *
3581 <     * <p>Search and transformation functions provided as arguments
3582 <     * should similarly return null to indicate the lack of any result
3583 <     * (in which case it is not used). In the case of mapped
3584 <     * reductions, this also enables transformations to serve as
3585 <     * filters, returning null (or, in the case of primitive
3586 <     * specializations, the identity basis) if the element should not
3587 <     * be combined. You can create compound transformations and
3588 <     * filterings by composing them yourself under this "null means
3589 <     * there is nothing there now" rule before using them in search or
3590 <     * reduce operations.
3591 <     *
3592 <     * <p>Methods accepting and/or returning Entry arguments maintain
3593 <     * key-value associations. They may be useful for example when
3594 <     * finding the key for the greatest value. Note that "plain" Entry
3595 <     * arguments can be supplied using {@code new
3596 <     * AbstractMap.SimpleEntry(k,v)}.
3597 <     *
3598 <     * <p> Bulk operations may complete abruptly, throwing an
3599 <     * exception encountered in the application of a supplied
3600 <     * function. Bear in mind when handling such exceptions that other
3601 <     * concurrently executing functions could also have thrown
3602 <     * exceptions, or would have done so if the first exception had
3603 <     * not occurred.
3604 <     *
3605 <     * <p>Parallel speedups compared to sequential processing are
3606 <     * common but not guaranteed.  Operations involving brief
3607 <     * functions on small maps may execute more slowly than sequential
3608 <     * loops if the underlying work to parallelize the computation is
3609 <     * more expensive than the computation itself. Similarly,
3610 <     * parallelization may not lead to much actual parallelism if all
3611 <     * processors are busy performing unrelated tasks.
3612 <     *
3613 <     * <p> All arguments to all task methods must be non-null.
3614 <     *
3615 <     * <p><em>jsr166e note: During transition, this class
3616 <     * uses nested functional interfaces with different names but the
3617 <     * same forms as those expected for JDK8.<em>
3729 >     * Performs the given action for each non-null transformation
3730 >     * of each (key, value).
3731 >     *
3732 >     * @param transformer a function returning the transformation
3733 >     * for an element, or null of there is no transformation (in
3734 >     * which case the action is not applied).
3735 >     * @param action the action
3736       */
3737 <    public class Parallel {
3738 <        final ForkJoinPool fjp;
3737 >    public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
3738 >                            Action<U> action) {
3739 >        ForkJoinTasks.forEach
3740 >            (this, transformer, action).invoke();
3741 >    }
3742  
3743 <        /**
3744 <         * Returns an extended view of this map using the given
3745 <         * executor for bulk parallel operations.
3746 <         *
3747 <         * @param executor the executor
3748 <         */
3749 <        public Parallel(ForkJoinPool executor)  {
3750 <            this.fjp = executor;
3751 <        }
3743 >    /**
3744 >     * Returns a non-null result from applying the given search
3745 >     * function on each (key, value), or null if none.  Upon
3746 >     * success, further element processing is suppressed and the
3747 >     * results of any other parallel invocations of the search
3748 >     * function are ignored.
3749 >     *
3750 >     * @param searchFunction a function returning a non-null
3751 >     * result on success, else null
3752 >     * @return a non-null result from applying the given search
3753 >     * function on each (key, value), or null if none
3754 >     */
3755 >    public <U> U search(BiFun<? super K, ? super V, ? extends U> searchFunction) {
3756 >        return ForkJoinTasks.search
3757 >            (this, searchFunction).invoke();
3758 >    }
3759  
3760 <        /**
3761 <         * Performs the given action for each (key, value).
3762 <         *
3763 <         * @param action the action
3764 <         */
3765 <        public void forEach(BiAction<K,V> action) {
3766 <            fjp.invoke(ForkJoinTasks.forEach
3767 <                       (ConcurrentHashMapV8.this, action));
3768 <        }
3760 >    /**
3761 >     * Returns the result of accumulating the given transformation
3762 >     * of all (key, value) pairs using the given reducer to
3763 >     * combine values, or null if none.
3764 >     *
3765 >     * @param transformer a function returning the transformation
3766 >     * for an element, or null of there is no transformation (in
3767 >     * which case it is not combined).
3768 >     * @param reducer a commutative associative combining function
3769 >     * @return the result of accumulating the given transformation
3770 >     * of all (key, value) pairs
3771 >     */
3772 >    public <U> U reduce(BiFun<? super K, ? super V, ? extends U> transformer,
3773 >                        BiFun<? super U, ? super U, ? extends U> reducer) {
3774 >        return ForkJoinTasks.reduce
3775 >            (this, transformer, reducer).invoke();
3776 >    }
3777  
3778 <        /**
3779 <         * Performs the given action for each non-null transformation
3780 <         * of each (key, value).
3781 <         *
3782 <         * @param transformer a function returning the transformation
3783 <         * for an element, or null of there is no transformation (in
3784 <         * which case the action is not applied).
3785 <         * @param action the action
3786 <         */
3787 <        public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
3788 <                                Action<U> action) {
3789 <            fjp.invoke(ForkJoinTasks.forEach
3790 <                       (ConcurrentHashMapV8.this, transformer, action));
3791 <        }
3778 >    /**
3779 >     * Returns the result of accumulating the given transformation
3780 >     * of all (key, value) pairs using the given reducer to
3781 >     * combine values, and the given basis as an identity value.
3782 >     *
3783 >     * @param transformer a function returning the transformation
3784 >     * for an element
3785 >     * @param basis the identity (initial default value) for the reduction
3786 >     * @param reducer a commutative associative combining function
3787 >     * @return the result of accumulating the given transformation
3788 >     * of all (key, value) pairs
3789 >     */
3790 >    public double reduceToDouble(ObjectByObjectToDouble<? super K, ? super V> transformer,
3791 >                                 double basis,
3792 >                                 DoubleByDoubleToDouble reducer) {
3793 >        return ForkJoinTasks.reduceToDouble
3794 >            (this, transformer, basis, reducer).invoke();
3795 >    }
3796  
3797 <        /**
3798 <         * Returns a non-null result from applying the given search
3799 <         * function on each (key, value), or null if none.  Further
3800 <         * element processing is suppressed upon success. However,
3801 <         * this method does not return until other in-progress
3802 <         * parallel invocations of the search function also complete.
3803 <         *
3804 <         * @param searchFunction a function returning a non-null
3805 <         * result on success, else null
3806 <         * @return a non-null result from applying the given search
3807 <         * function on each (key, value), or null if none
3808 <         */
3809 <        public <U> U search(BiFun<? super K, ? super V, ? extends U> searchFunction) {
3810 <            return fjp.invoke(ForkJoinTasks.search
3811 <                              (ConcurrentHashMapV8.this, searchFunction));
3812 <        }
3797 >    /**
3798 >     * Returns the result of accumulating the given transformation
3799 >     * of all (key, value) pairs using the given reducer to
3800 >     * combine values, and the given basis as an identity value.
3801 >     *
3802 >     * @param transformer a function returning the transformation
3803 >     * for an element
3804 >     * @param basis the identity (initial default value) for the reduction
3805 >     * @param reducer a commutative associative combining function
3806 >     * @return the result of accumulating the given transformation
3807 >     * of all (key, value) pairs
3808 >     */
3809 >    public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer,
3810 >                             long basis,
3811 >                             LongByLongToLong reducer) {
3812 >        return ForkJoinTasks.reduceToLong
3813 >            (this, transformer, basis, reducer).invoke();
3814 >    }
3815  
3816 <        /**
3817 <         * Returns the result of accumulating the given transformation
3818 <         * of all (key, value) pairs using the given reducer to
3819 <         * combine values, or null if none.
3820 <         *
3821 <         * @param transformer a function returning the transformation
3822 <         * for an element, or null of there is no transformation (in
3823 <         * which case it is not combined).
3824 <         * @param reducer a commutative associative combining function
3825 <         * @return the result of accumulating the given transformation
3826 <         * of all (key, value) pairs
3827 <         */
3828 <        public <U> U reduce(BiFun<? super K, ? super V, ? extends U> transformer,
3816 >    /**
3817 >     * Returns the result of accumulating the given transformation
3818 >     * of all (key, value) pairs using the given reducer to
3819 >     * combine values, and the given basis as an identity value.
3820 >     *
3821 >     * @param transformer a function returning the transformation
3822 >     * for an element
3823 >     * @param basis the identity (initial default value) for the reduction
3824 >     * @param reducer a commutative associative combining function
3825 >     * @return the result of accumulating the given transformation
3826 >     * of all (key, value) pairs
3827 >     */
3828 >    public int reduceToInt(ObjectByObjectToInt<? super K, ? super V> transformer,
3829 >                           int basis,
3830 >                           IntByIntToInt reducer) {
3831 >        return ForkJoinTasks.reduceToInt
3832 >            (this, transformer, basis, reducer).invoke();
3833 >    }
3834 >
3835 >    /**
3836 >     * Performs the given action for each key.
3837 >     *
3838 >     * @param action the action
3839 >     */
3840 >    public void forEachKey(Action<K> action) {
3841 >        ForkJoinTasks.forEachKey
3842 >            (this, action).invoke();
3843 >    }
3844 >
3845 >    /**
3846 >     * Performs the given action for each non-null transformation
3847 >     * of each key.
3848 >     *
3849 >     * @param transformer a function returning the transformation
3850 >     * for an element, or null of there is no transformation (in
3851 >     * which case the action is not applied).
3852 >     * @param action the action
3853 >     */
3854 >    public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
3855 >                               Action<U> action) {
3856 >        ForkJoinTasks.forEachKey
3857 >            (this, transformer, action).invoke();
3858 >    }
3859 >
3860 >    /**
3861 >     * Returns a non-null result from applying the given search
3862 >     * function on each key, or null if none. Upon success,
3863 >     * further element processing is suppressed and the results of
3864 >     * any other parallel invocations of the search function are
3865 >     * ignored.
3866 >     *
3867 >     * @param searchFunction a function returning a non-null
3868 >     * result on success, else null
3869 >     * @return a non-null result from applying the given search
3870 >     * function on each key, or null if none
3871 >     */
3872 >    public <U> U searchKeys(Fun<? super K, ? extends U> searchFunction) {
3873 >        return ForkJoinTasks.searchKeys
3874 >            (this, searchFunction).invoke();
3875 >    }
3876 >
3877 >    /**
3878 >     * Returns the result of accumulating all keys using the given
3879 >     * reducer to combine values, or null if none.
3880 >     *
3881 >     * @param reducer a commutative associative combining function
3882 >     * @return the result of accumulating all keys using the given
3883 >     * reducer to combine values, or null if none
3884 >     */
3885 >    public K reduceKeys(BiFun<? super K, ? super K, ? extends K> reducer) {
3886 >        return ForkJoinTasks.reduceKeys
3887 >            (this, reducer).invoke();
3888 >    }
3889 >
3890 >    /**
3891 >     * Returns the result of accumulating the given transformation
3892 >     * of all keys using the given reducer to combine values, or
3893 >     * null if none.
3894 >     *
3895 >     * @param transformer a function returning the transformation
3896 >     * for an element, or null of there is no transformation (in
3897 >     * which case it is not combined).
3898 >     * @param reducer a commutative associative combining function
3899 >     * @return the result of accumulating the given transformation
3900 >     * of all keys
3901 >     */
3902 >    public <U> U reduceKeys(Fun<? super K, ? extends U> transformer,
3903                              BiFun<? super U, ? super U, ? extends U> reducer) {
3904 <            return fjp.invoke(ForkJoinTasks.reduce
3905 <                              (ConcurrentHashMapV8.this, transformer, reducer));
3906 <        }
3904 >        return ForkJoinTasks.reduceKeys
3905 >            (this, transformer, reducer).invoke();
3906 >    }
3907  
3908 <        /**
3909 <         * Returns the result of accumulating the given transformation
3910 <         * of all (key, value) pairs using the given reducer to
3911 <         * combine values, and the given basis as an identity value.
3912 <         *
3913 <         * @param transformer a function returning the transformation
3914 <         * for an element
3915 <         * @param basis the identity (initial default value) for the reduction
3916 <         * @param reducer a commutative associative combining function
3917 <         * @return the result of accumulating the given transformation
3918 <         * of all (key, value) pairs
3919 <         */
3920 <        public double reduceToDouble(ObjectByObjectToDouble<? super K, ? super V> transformer,
3908 >    /**
3909 >     * Returns the result of accumulating the given transformation
3910 >     * of all keys using the given reducer to combine values, and
3911 >     * the given basis as an identity value.
3912 >     *
3913 >     * @param transformer a function returning the transformation
3914 >     * for an element
3915 >     * @param basis the identity (initial default value) for the reduction
3916 >     * @param reducer a commutative associative combining function
3917 >     * @return  the result of accumulating the given transformation
3918 >     * of all keys
3919 >     */
3920 >    public double reduceKeysToDouble(ObjectToDouble<? super K> transformer,
3921                                       double basis,
3922                                       DoubleByDoubleToDouble reducer) {
3923 <            return fjp.invoke(ForkJoinTasks.reduceToDouble
3924 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3925 <        }
3923 >        return ForkJoinTasks.reduceKeysToDouble
3924 >            (this, transformer, basis, reducer).invoke();
3925 >    }
3926  
3927 <        /**
3928 <         * Returns the result of accumulating the given transformation
3929 <         * of all (key, value) pairs using the given reducer to
3930 <         * combine values, and the given basis as an identity value.
3931 <         *
3932 <         * @param transformer a function returning the transformation
3933 <         * for an element
3934 <         * @param basis the identity (initial default value) for the reduction
3935 <         * @param reducer a commutative associative combining function
3936 <         * @return the result of accumulating the given transformation
3937 <         * of all (key, value) pairs using the given reducer to
3938 <         * combine values, and the given basis as an identity value.
3939 <         */
3724 <        public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer,
3927 >    /**
3928 >     * Returns the result of accumulating the given transformation
3929 >     * of all keys using the given reducer to combine values, and
3930 >     * the given basis as an identity value.
3931 >     *
3932 >     * @param transformer a function returning the transformation
3933 >     * for an element
3934 >     * @param basis the identity (initial default value) for the reduction
3935 >     * @param reducer a commutative associative combining function
3936 >     * @return the result of accumulating the given transformation
3937 >     * of all keys
3938 >     */
3939 >    public long reduceKeysToLong(ObjectToLong<? super K> transformer,
3940                                   long basis,
3941                                   LongByLongToLong reducer) {
3942 <            return fjp.invoke(ForkJoinTasks.reduceToLong
3943 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3944 <        }
3942 >        return ForkJoinTasks.reduceKeysToLong
3943 >            (this, transformer, basis, reducer).invoke();
3944 >    }
3945  
3946 <        /**
3947 <         * Returns the result of accumulating the given transformation
3948 <         * of all (key, value) pairs using the given reducer to
3949 <         * combine values, and the given basis as an identity value.
3950 <         *
3951 <         * @param transformer a function returning the transformation
3952 <         * for an element
3953 <         * @param basis the identity (initial default value) for the reduction
3954 <         * @param reducer a commutative associative combining function
3955 <         * @return the result of accumulating the given transformation
3956 <         * of all (key, value) pairs
3957 <         */
3958 <        public int reduceToInt(ObjectByObjectToInt<? super K, ? super V> transformer,
3946 >    /**
3947 >     * Returns the result of accumulating the given transformation
3948 >     * of all keys using the given reducer to combine values, and
3949 >     * the given basis as an identity value.
3950 >     *
3951 >     * @param transformer a function returning the transformation
3952 >     * for an element
3953 >     * @param basis the identity (initial default value) for the reduction
3954 >     * @param reducer a commutative associative combining function
3955 >     * @return the result of accumulating the given transformation
3956 >     * of all keys
3957 >     */
3958 >    public int reduceKeysToInt(ObjectToInt<? super K> transformer,
3959                                 int basis,
3960                                 IntByIntToInt reducer) {
3961 <            return fjp.invoke(ForkJoinTasks.reduceToInt
3962 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3963 <        }
3749 <
3750 <        /**
3751 <         * Performs the given action for each key.
3752 <         *
3753 <         * @param action the action
3754 <         */
3755 <        public void forEachKey(Action<K> action) {
3756 <            fjp.invoke(ForkJoinTasks.forEachKey
3757 <                       (ConcurrentHashMapV8.this, action));
3758 <        }
3759 <
3760 <        /**
3761 <         * Performs the given action for each non-null transformation
3762 <         * of each key.
3763 <         *
3764 <         * @param transformer a function returning the transformation
3765 <         * for an element, or null of there is no transformation (in
3766 <         * which case the action is not applied).
3767 <         * @param action the action
3768 <         */
3769 <        public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
3770 <                                   Action<U> action) {
3771 <            fjp.invoke(ForkJoinTasks.forEachKey
3772 <                       (ConcurrentHashMapV8.this, transformer, action));
3773 <        }
3774 <
3775 <        /**
3776 <         * Returns a non-null result from applying the given search
3777 <         * function on each key, or null if none.  Further element
3778 <         * processing is suppressed upon success. However, this method
3779 <         * does not return until other in-progress parallel
3780 <         * invocations of the search function also complete.
3781 <         *
3782 <         * @param searchFunction a function returning a non-null
3783 <         * result on success, else null
3784 <         * @return a non-null result from applying the given search
3785 <         * function on each key, or null if none
3786 <         */
3787 <        public <U> U searchKeys(Fun<? super K, ? extends U> searchFunction) {
3788 <            return fjp.invoke(ForkJoinTasks.searchKeys
3789 <                              (ConcurrentHashMapV8.this, searchFunction));
3790 <        }
3791 <
3792 <        /**
3793 <         * Returns the result of accumulating all keys using the given
3794 <         * reducer to combine values, or null if none.
3795 <         *
3796 <         * @param reducer a commutative associative combining function
3797 <         * @return the result of accumulating all keys using the given
3798 <         * reducer to combine values, or null if none
3799 <         */
3800 <        public K reduceKeys(BiFun<? super K, ? super K, ? extends K> reducer) {
3801 <            return fjp.invoke(ForkJoinTasks.reduceKeys
3802 <                              (ConcurrentHashMapV8.this, reducer));
3803 <        }
3804 <
3805 <        /**
3806 <         * Returns the result of accumulating the given transformation
3807 <         * of all keys using the given reducer to combine values, or
3808 <         * null if none.
3809 <         *
3810 <         * @param transformer a function returning the transformation
3811 <         * for an element, or null of there is no transformation (in
3812 <         * which case it is not combined).
3813 <         * @param reducer a commutative associative combining function
3814 <         * @return the result of accumulating the given transformation
3815 <         * of all keys
3816 <         */
3817 <        public <U> U reduceKeys(Fun<? super K, ? extends U> transformer,
3818 <                                BiFun<? super U, ? super U, ? extends U> reducer) {
3819 <            return fjp.invoke(ForkJoinTasks.reduceKeys
3820 <                              (ConcurrentHashMapV8.this, transformer, reducer));
3821 <        }
3822 <
3823 <        /**
3824 <         * Returns the result of accumulating the given transformation
3825 <         * of all keys using the given reducer to combine values, and
3826 <         * the given basis as an identity value.
3827 <         *
3828 <         * @param transformer a function returning the transformation
3829 <         * for an element
3830 <         * @param basis the identity (initial default value) for the reduction
3831 <         * @param reducer a commutative associative combining function
3832 <         * @return  the result of accumulating the given transformation
3833 <         * of all keys
3834 <         */
3835 <        public double reduceKeysToDouble(ObjectToDouble<? super K> transformer,
3836 <                                         double basis,
3837 <                                         DoubleByDoubleToDouble reducer) {
3838 <            return fjp.invoke(ForkJoinTasks.reduceKeysToDouble
3839 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3840 <        }
3841 <
3842 <        /**
3843 <         * Returns the result of accumulating the given transformation
3844 <         * of all keys using the given reducer to combine values, and
3845 <         * the given basis as an identity value.
3846 <         *
3847 <         * @param transformer a function returning the transformation
3848 <         * for an element
3849 <         * @param basis the identity (initial default value) for the reduction
3850 <         * @param reducer a commutative associative combining function
3851 <         * @return the result of accumulating the given transformation
3852 <         * of all keys
3853 <         */
3854 <        public long reduceKeysToLong(ObjectToLong<? super K> transformer,
3855 <                                     long basis,
3856 <                                     LongByLongToLong reducer) {
3857 <            return fjp.invoke(ForkJoinTasks.reduceKeysToLong
3858 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3859 <        }
3860 <
3861 <        /**
3862 <         * Returns the result of accumulating the given transformation
3863 <         * of all keys using the given reducer to combine values, and
3864 <         * the given basis as an identity value.
3865 <         *
3866 <         * @param transformer a function returning the transformation
3867 <         * for an element
3868 <         * @param basis the identity (initial default value) for the reduction
3869 <         * @param reducer a commutative associative combining function
3870 <         * @return the result of accumulating the given transformation
3871 <         * of all keys
3872 <         */
3873 <        public int reduceKeysToInt(ObjectToInt<? super K> transformer,
3874 <                                   int basis,
3875 <                                   IntByIntToInt reducer) {
3876 <            return fjp.invoke(ForkJoinTasks.reduceKeysToInt
3877 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3878 <        }
3961 >        return ForkJoinTasks.reduceKeysToInt
3962 >            (this, transformer, basis, reducer).invoke();
3963 >    }
3964  
3965 <        /**
3966 <         * Performs the given action for each value.
3967 <         *
3968 <         * @param action the action
3969 <         */
3970 <        public void forEachValue(Action<V> action) {
3971 <            fjp.invoke(ForkJoinTasks.forEachValue
3972 <                       (ConcurrentHashMapV8.this, action));
3973 <        }
3965 >    /**
3966 >     * Performs the given action for each value.
3967 >     *
3968 >     * @param action the action
3969 >     */
3970 >    public void forEachValue(Action<V> action) {
3971 >        ForkJoinTasks.forEachValue
3972 >            (this, action).invoke();
3973 >    }
3974  
3975 <        /**
3976 <         * Performs the given action for each non-null transformation
3977 <         * of each value.
3978 <         *
3979 <         * @param transformer a function returning the transformation
3980 <         * for an element, or null of there is no transformation (in
3981 <         * which case the action is not applied).
3982 <         */
3983 <        public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3984 <                                     Action<U> action) {
3985 <            fjp.invoke(ForkJoinTasks.forEachValue
3986 <                       (ConcurrentHashMapV8.this, transformer, action));
3987 <        }
3975 >    /**
3976 >     * Performs the given action for each non-null transformation
3977 >     * of each value.
3978 >     *
3979 >     * @param transformer a function returning the transformation
3980 >     * for an element, or null of there is no transformation (in
3981 >     * which case the action is not applied).
3982 >     */
3983 >    public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3984 >                                 Action<U> action) {
3985 >        ForkJoinTasks.forEachValue
3986 >            (this, transformer, action).invoke();
3987 >    }
3988  
3989 <        /**
3990 <         * Returns a non-null result from applying the given search
3991 <         * function on each value, or null if none.  Further element
3992 <         * processing is suppressed upon success. However, this method
3993 <         * does not return until other in-progress parallel
3994 <         * invocations of the search function also complete.
3995 <         *
3996 <         * @param searchFunction a function returning a non-null
3997 <         * result on success, else null
3998 <         * @return a non-null result from applying the given search
3999 <         * function on each value, or null if none
4000 <         *
4001 <         */
4002 <        public <U> U searchValues(Fun<? super V, ? extends U> searchFunction) {
4003 <            return fjp.invoke(ForkJoinTasks.searchValues
4004 <                              (ConcurrentHashMapV8.this, searchFunction));
4005 <        }
3989 >    /**
3990 >     * Returns a non-null result from applying the given search
3991 >     * function on each value, or null if none.  Upon success,
3992 >     * further element processing is suppressed and the results of
3993 >     * any other parallel invocations of the search function are
3994 >     * ignored.
3995 >     *
3996 >     * @param searchFunction a function returning a non-null
3997 >     * result on success, else null
3998 >     * @return a non-null result from applying the given search
3999 >     * function on each value, or null if none
4000 >     *
4001 >     */
4002 >    public <U> U searchValues(Fun<? super V, ? extends U> searchFunction) {
4003 >        return ForkJoinTasks.searchValues
4004 >            (this, searchFunction).invoke();
4005 >    }
4006  
4007 <        /**
4008 <         * Returns the result of accumulating all values using the
4009 <         * given reducer to combine values, or null if none.
4010 <         *
4011 <         * @param reducer a commutative associative combining function
4012 <         * @return  the result of accumulating all values
4013 <         */
4014 <        public V reduceValues(BiFun<? super V, ? super V, ? extends V> reducer) {
4015 <            return fjp.invoke(ForkJoinTasks.reduceValues
4016 <                              (ConcurrentHashMapV8.this, reducer));
4017 <        }
4007 >    /**
4008 >     * Returns the result of accumulating all values using the
4009 >     * given reducer to combine values, or null if none.
4010 >     *
4011 >     * @param reducer a commutative associative combining function
4012 >     * @return  the result of accumulating all values
4013 >     */
4014 >    public V reduceValues(BiFun<? super V, ? super V, ? extends V> reducer) {
4015 >        return ForkJoinTasks.reduceValues
4016 >            (this, reducer).invoke();
4017 >    }
4018  
4019 <        /**
4020 <         * Returns the result of accumulating the given transformation
4021 <         * of all values using the given reducer to combine values, or
4022 <         * null if none.
4023 <         *
4024 <         * @param transformer a function returning the transformation
4025 <         * for an element, or null of there is no transformation (in
4026 <         * which case it is not combined).
4027 <         * @param reducer a commutative associative combining function
4028 <         * @return the result of accumulating the given transformation
4029 <         * of all values
4030 <         */
4031 <        public <U> U reduceValues(Fun<? super V, ? extends U> transformer,
4032 <                                  BiFun<? super U, ? super U, ? extends U> reducer) {
4033 <            return fjp.invoke(ForkJoinTasks.reduceValues
4034 <                              (ConcurrentHashMapV8.this, transformer, reducer));
4035 <        }
4019 >    /**
4020 >     * Returns the result of accumulating the given transformation
4021 >     * of all values using the given reducer to combine values, or
4022 >     * null if none.
4023 >     *
4024 >     * @param transformer a function returning the transformation
4025 >     * for an element, or null of there is no transformation (in
4026 >     * which case it is not combined).
4027 >     * @param reducer a commutative associative combining function
4028 >     * @return the result of accumulating the given transformation
4029 >     * of all values
4030 >     */
4031 >    public <U> U reduceValues(Fun<? super V, ? extends U> transformer,
4032 >                              BiFun<? super U, ? super U, ? extends U> reducer) {
4033 >        return ForkJoinTasks.reduceValues
4034 >            (this, transformer, reducer).invoke();
4035 >    }
4036  
4037 <        /**
4038 <         * Returns the result of accumulating the given transformation
4039 <         * of all values using the given reducer to combine values,
4040 <         * and the given basis as an identity value.
4041 <         *
4042 <         * @param transformer a function returning the transformation
4043 <         * for an element
4044 <         * @param basis the identity (initial default value) for the reduction
4045 <         * @param reducer a commutative associative combining function
4046 <         * @return the result of accumulating the given transformation
4047 <         * of all values
4048 <         */
4049 <        public double reduceValuesToDouble(ObjectToDouble<? super V> transformer,
4050 <                                           double basis,
4051 <                                           DoubleByDoubleToDouble reducer) {
4052 <            return fjp.invoke(ForkJoinTasks.reduceValuesToDouble
4053 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4054 <        }
4037 >    /**
4038 >     * Returns the result of accumulating the given transformation
4039 >     * of all values using the given reducer to combine values,
4040 >     * and the given basis as an identity value.
4041 >     *
4042 >     * @param transformer a function returning the transformation
4043 >     * for an element
4044 >     * @param basis the identity (initial default value) for the reduction
4045 >     * @param reducer a commutative associative combining function
4046 >     * @return the result of accumulating the given transformation
4047 >     * of all values
4048 >     */
4049 >    public double reduceValuesToDouble(ObjectToDouble<? super V> transformer,
4050 >                                       double basis,
4051 >                                       DoubleByDoubleToDouble reducer) {
4052 >        return ForkJoinTasks.reduceValuesToDouble
4053 >            (this, transformer, basis, reducer).invoke();
4054 >    }
4055  
4056 <        /**
4057 <         * Returns the result of accumulating the given transformation
4058 <         * of all values using the given reducer to combine values,
4059 <         * and the given basis as an identity value.
4060 <         *
4061 <         * @param transformer a function returning the transformation
4062 <         * for an element
4063 <         * @param basis the identity (initial default value) for the reduction
4064 <         * @param reducer a commutative associative combining function
4065 <         * @return the result of accumulating the given transformation
4066 <         * of all values
4067 <         */
4068 <        public long reduceValuesToLong(ObjectToLong<? super V> transformer,
4069 <                                       long basis,
4070 <                                       LongByLongToLong reducer) {
4071 <            return fjp.invoke(ForkJoinTasks.reduceValuesToLong
4072 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4073 <        }
4056 >    /**
4057 >     * Returns the result of accumulating the given transformation
4058 >     * of all values using the given reducer to combine values,
4059 >     * and the given basis as an identity value.
4060 >     *
4061 >     * @param transformer a function returning the transformation
4062 >     * for an element
4063 >     * @param basis the identity (initial default value) for the reduction
4064 >     * @param reducer a commutative associative combining function
4065 >     * @return the result of accumulating the given transformation
4066 >     * of all values
4067 >     */
4068 >    public long reduceValuesToLong(ObjectToLong<? super V> transformer,
4069 >                                   long basis,
4070 >                                   LongByLongToLong reducer) {
4071 >        return ForkJoinTasks.reduceValuesToLong
4072 >            (this, transformer, basis, reducer).invoke();
4073 >    }
4074  
4075 <        /**
4076 <         * Returns the result of accumulating the given transformation
4077 <         * of all values using the given reducer to combine values,
4078 <         * and the given basis as an identity value.
4079 <         *
4080 <         * @param transformer a function returning the transformation
4081 <         * for an element
4082 <         * @param basis the identity (initial default value) for the reduction
4083 <         * @param reducer a commutative associative combining function
4084 <         * @return the result of accumulating the given transformation
4085 <         * of all values
4086 <         */
4087 <        public int reduceValuesToInt(ObjectToInt<? super V> transformer,
4088 <                                     int basis,
4089 <                                     IntByIntToInt reducer) {
4090 <            return fjp.invoke(ForkJoinTasks.reduceValuesToInt
4091 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4092 <        }
4075 >    /**
4076 >     * Returns the result of accumulating the given transformation
4077 >     * of all values using the given reducer to combine values,
4078 >     * and the given basis as an identity value.
4079 >     *
4080 >     * @param transformer a function returning the transformation
4081 >     * for an element
4082 >     * @param basis the identity (initial default value) for the reduction
4083 >     * @param reducer a commutative associative combining function
4084 >     * @return the result of accumulating the given transformation
4085 >     * of all values
4086 >     */
4087 >    public int reduceValuesToInt(ObjectToInt<? super V> transformer,
4088 >                                 int basis,
4089 >                                 IntByIntToInt reducer) {
4090 >        return ForkJoinTasks.reduceValuesToInt
4091 >            (this, transformer, basis, reducer).invoke();
4092 >    }
4093  
4094 <        /**
4095 <         * Performs the given action for each entry.
4096 <         *
4097 <         * @param action the action
4098 <         */
4099 <        public void forEachEntry(Action<Map.Entry<K,V>> action) {
4100 <            fjp.invoke(ForkJoinTasks.forEachEntry
4101 <                       (ConcurrentHashMapV8.this, action));
4102 <        }
4094 >    /**
4095 >     * Performs the given action for each entry.
4096 >     *
4097 >     * @param action the action
4098 >     */
4099 >    public void forEachEntry(Action<Map.Entry<K,V>> action) {
4100 >        ForkJoinTasks.forEachEntry
4101 >            (this, action).invoke();
4102 >    }
4103  
4104 <        /**
4105 <         * Performs the given action for each non-null transformation
4106 <         * of each entry.
4107 <         *
4108 <         * @param transformer a function returning the transformation
4109 <         * for an element, or null of there is no transformation (in
4110 <         * which case the action is not applied).
4111 <         * @param action the action
4112 <         */
4113 <        public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
4114 <                                     Action<U> action) {
4115 <            fjp.invoke(ForkJoinTasks.forEachEntry
4116 <                       (ConcurrentHashMapV8.this, transformer, action));
4117 <        }
4104 >    /**
4105 >     * Performs the given action for each non-null transformation
4106 >     * of each entry.
4107 >     *
4108 >     * @param transformer a function returning the transformation
4109 >     * for an element, or null of there is no transformation (in
4110 >     * which case the action is not applied).
4111 >     * @param action the action
4112 >     */
4113 >    public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
4114 >                                 Action<U> action) {
4115 >        ForkJoinTasks.forEachEntry
4116 >            (this, transformer, action).invoke();
4117 >    }
4118  
4119 <        /**
4120 <         * Returns a non-null result from applying the given search
4121 <         * function on each entry, or null if none.  Further element
4122 <         * processing is suppressed upon success. However, this method
4123 <         * does not return until other in-progress parallel
4124 <         * invocations of the search function also complete.
4125 <         *
4126 <         * @param searchFunction a function returning a non-null
4127 <         * result on success, else null
4128 <         * @return a non-null result from applying the given search
4129 <         * function on each entry, or null if none
4130 <         */
4131 <        public <U> U searchEntries(Fun<Map.Entry<K,V>, ? extends U> searchFunction) {
4132 <            return fjp.invoke(ForkJoinTasks.searchEntries
4133 <                              (ConcurrentHashMapV8.this, searchFunction));
4134 <        }
4119 >    /**
4120 >     * Returns a non-null result from applying the given search
4121 >     * function on each entry, or null if none.  Upon success,
4122 >     * further element processing is suppressed and the results of
4123 >     * any other parallel invocations of the search function are
4124 >     * ignored.
4125 >     *
4126 >     * @param searchFunction a function returning a non-null
4127 >     * result on success, else null
4128 >     * @return a non-null result from applying the given search
4129 >     * function on each entry, or null if none
4130 >     */
4131 >    public <U> U searchEntries(Fun<Map.Entry<K,V>, ? extends U> searchFunction) {
4132 >        return ForkJoinTasks.searchEntries
4133 >            (this, searchFunction).invoke();
4134 >    }
4135  
4136 <        /**
4137 <         * Returns the result of accumulating all entries using the
4138 <         * given reducer to combine values, or null if none.
4139 <         *
4140 <         * @param reducer a commutative associative combining function
4141 <         * @return the result of accumulating all entries
4142 <         */
4143 <        public Map.Entry<K,V> reduceEntries(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
4144 <            return fjp.invoke(ForkJoinTasks.reduceEntries
4145 <                              (ConcurrentHashMapV8.this, reducer));
4146 <        }
4136 >    /**
4137 >     * Returns the result of accumulating all entries using the
4138 >     * given reducer to combine values, or null if none.
4139 >     *
4140 >     * @param reducer a commutative associative combining function
4141 >     * @return the result of accumulating all entries
4142 >     */
4143 >    public Map.Entry<K,V> reduceEntries(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
4144 >        return ForkJoinTasks.reduceEntries
4145 >            (this, reducer).invoke();
4146 >    }
4147  
4148 <        /**
4149 <         * Returns the result of accumulating the given transformation
4150 <         * of all entries using the given reducer to combine values,
4151 <         * or null if none.
4152 <         *
4153 <         * @param transformer a function returning the transformation
4154 <         * for an element, or null of there is no transformation (in
4155 <         * which case it is not combined).
4156 <         * @param reducer a commutative associative combining function
4157 <         * @return the result of accumulating the given transformation
4158 <         * of all entries
4159 <         */
4160 <        public <U> U reduceEntries(Fun<Map.Entry<K,V>, ? extends U> transformer,
4161 <                                   BiFun<? super U, ? super U, ? extends U> reducer) {
4162 <            return fjp.invoke(ForkJoinTasks.reduceEntries
4163 <                              (ConcurrentHashMapV8.this, transformer, reducer));
4164 <        }
4148 >    /**
4149 >     * Returns the result of accumulating the given transformation
4150 >     * of all entries using the given reducer to combine values,
4151 >     * or null if none.
4152 >     *
4153 >     * @param transformer a function returning the transformation
4154 >     * for an element, or null of there is no transformation (in
4155 >     * which case it is not combined).
4156 >     * @param reducer a commutative associative combining function
4157 >     * @return the result of accumulating the given transformation
4158 >     * of all entries
4159 >     */
4160 >    public <U> U reduceEntries(Fun<Map.Entry<K,V>, ? extends U> transformer,
4161 >                               BiFun<? super U, ? super U, ? extends U> reducer) {
4162 >        return ForkJoinTasks.reduceEntries
4163 >            (this, transformer, reducer).invoke();
4164 >    }
4165  
4166 <        /**
4167 <         * Returns the result of accumulating the given transformation
4168 <         * of all entries using the given reducer to combine values,
4169 <         * and the given basis as an identity value.
4170 <         *
4171 <         * @param transformer a function returning the transformation
4172 <         * for an element
4173 <         * @param basis the identity (initial default value) for the reduction
4174 <         * @param reducer a commutative associative combining function
4175 <         * @return the result of accumulating the given transformation
4176 <         * of all entries
4177 <         */
4178 <        public double reduceEntriesToDouble(ObjectToDouble<Map.Entry<K,V>> transformer,
4179 <                                            double basis,
4180 <                                            DoubleByDoubleToDouble reducer) {
4181 <            return fjp.invoke(ForkJoinTasks.reduceEntriesToDouble
4182 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4183 <        }
4166 >    /**
4167 >     * Returns the result of accumulating the given transformation
4168 >     * of all entries using the given reducer to combine values,
4169 >     * and the given basis as an identity value.
4170 >     *
4171 >     * @param transformer a function returning the transformation
4172 >     * for an element
4173 >     * @param basis the identity (initial default value) for the reduction
4174 >     * @param reducer a commutative associative combining function
4175 >     * @return the result of accumulating the given transformation
4176 >     * of all entries
4177 >     */
4178 >    public double reduceEntriesToDouble(ObjectToDouble<Map.Entry<K,V>> transformer,
4179 >                                        double basis,
4180 >                                        DoubleByDoubleToDouble reducer) {
4181 >        return ForkJoinTasks.reduceEntriesToDouble
4182 >            (this, transformer, basis, reducer).invoke();
4183 >    }
4184  
4185 <        /**
4186 <         * Returns the result of accumulating the given transformation
4187 <         * of all entries using the given reducer to combine values,
4188 <         * and the given basis as an identity value.
4189 <         *
4190 <         * @param transformer a function returning the transformation
4191 <         * for an element
4192 <         * @param basis the identity (initial default value) for the reduction
4193 <         * @param reducer a commutative associative combining function
4194 <         * @return  the result of accumulating the given transformation
4195 <         * of all entries
4196 <         */
4197 <        public long reduceEntriesToLong(ObjectToLong<Map.Entry<K,V>> transformer,
4198 <                                        long basis,
4199 <                                        LongByLongToLong reducer) {
4200 <            return fjp.invoke(ForkJoinTasks.reduceEntriesToLong
4201 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4202 <        }
4185 >    /**
4186 >     * Returns the result of accumulating the given transformation
4187 >     * of all entries using the given reducer to combine values,
4188 >     * and the given basis as an identity value.
4189 >     *
4190 >     * @param transformer a function returning the transformation
4191 >     * for an element
4192 >     * @param basis the identity (initial default value) for the reduction
4193 >     * @param reducer a commutative associative combining function
4194 >     * @return  the result of accumulating the given transformation
4195 >     * of all entries
4196 >     */
4197 >    public long reduceEntriesToLong(ObjectToLong<Map.Entry<K,V>> transformer,
4198 >                                    long basis,
4199 >                                    LongByLongToLong reducer) {
4200 >        return ForkJoinTasks.reduceEntriesToLong
4201 >            (this, transformer, basis, reducer).invoke();
4202 >    }
4203  
4204 <        /**
4205 <         * Returns the result of accumulating the given transformation
4206 <         * of all entries using the given reducer to combine values,
4207 <         * and the given basis as an identity value.
4208 <         *
4209 <         * @param transformer a function returning the transformation
4210 <         * for an element
4211 <         * @param basis the identity (initial default value) for the reduction
4212 <         * @param reducer a commutative associative combining function
4213 <         * @return the result of accumulating the given transformation
4214 <         * of all entries
4215 <         */
4216 <        public int reduceEntriesToInt(ObjectToInt<Map.Entry<K,V>> transformer,
4217 <                                      int basis,
4218 <                                      IntByIntToInt reducer) {
4219 <            return fjp.invoke(ForkJoinTasks.reduceEntriesToInt
4220 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4136 <        }
4204 >    /**
4205 >     * Returns the result of accumulating the given transformation
4206 >     * of all entries using the given reducer to combine values,
4207 >     * and the given basis as an identity value.
4208 >     *
4209 >     * @param transformer a function returning the transformation
4210 >     * for an element
4211 >     * @param basis the identity (initial default value) for the reduction
4212 >     * @param reducer a commutative associative combining function
4213 >     * @return the result of accumulating the given transformation
4214 >     * of all entries
4215 >     */
4216 >    public int reduceEntriesToInt(ObjectToInt<Map.Entry<K,V>> transformer,
4217 >                                  int basis,
4218 >                                  IntByIntToInt reducer) {
4219 >        return ForkJoinTasks.reduceEntriesToInt
4220 >            (this, transformer, basis, reducer).invoke();
4221      }
4222  
4223      // ---------------------------------------------------------------------
4224  
4225      /**
4226       * Predefined tasks for performing bulk parallel operations on
4227 <     * ConcurrentHashMaps. These tasks follow the forms and rules used
4228 <     * in class {@link Parallel}. Each method has the same name, but
4229 <     * returns a task rather than invoking it. These methods may be
4230 <     * useful in custom applications such as submitting a task without
4231 <     * waiting for completion, or combining with other tasks.
4227 >     * ConcurrentHashMapV8s. These tasks follow the forms and rules used
4228 >     * for bulk operations. Each method has the same name, but returns
4229 >     * a task rather than invoking it. These methods may be useful in
4230 >     * custom applications such as submitting a task without waiting
4231 >     * for completion, using a custom pool, or combining with other
4232 >     * tasks.
4233       */
4234      public static class ForkJoinTasks {
4235          private ForkJoinTasks() {}
# Line 4161 | Line 4246 | public class ConcurrentHashMapV8<K, V>
4246              (ConcurrentHashMapV8<K,V> map,
4247               BiAction<K,V> action) {
4248              if (action == null) throw new NullPointerException();
4249 <            return new ForEachMappingTask<K,V>(map, action);
4249 >            return new ForEachMappingTask<K,V>(map, null, -1, null, action);
4250          }
4251  
4252          /**
# Line 4170 | Line 4255 | public class ConcurrentHashMapV8<K, V>
4255           *
4256           * @param map the map
4257           * @param transformer a function returning the transformation
4258 <         * for an element, or null of there is no transformation (in
4259 <         * which case the action is not applied).
4258 >         * for an element, or null if there is no transformation (in
4259 >         * which case the action is not applied)
4260           * @param action the action
4261           * @return the task
4262           */
# Line 4182 | Line 4267 | public class ConcurrentHashMapV8<K, V>
4267              if (transformer == null || action == null)
4268                  throw new NullPointerException();
4269              return new ForEachTransformedMappingTask<K,V,U>
4270 <                (map, transformer, action);
4270 >                (map, null, -1, null, transformer, action);
4271          }
4272  
4273          /**
4274 <         * Returns a task that when invoked, returns a non-null
4275 <         * result from applying the given search function on each
4276 <         * (key, value), or null if none.  Further element processing
4277 <         * is suppressed upon success. However, this method does not
4278 <         * return until other in-progress parallel invocations of the
4194 <         * search function also complete.
4274 >         * Returns a task that when invoked, returns a non-null result
4275 >         * from applying the given search function on each (key,
4276 >         * value), or null if none. Upon success, further element
4277 >         * processing is suppressed and the results of any other
4278 >         * parallel invocations of the search function are ignored.
4279           *
4280           * @param map the map
4281           * @param searchFunction a function returning a non-null
# Line 4203 | Line 4287 | public class ConcurrentHashMapV8<K, V>
4287               BiFun<? super K, ? super V, ? extends U> searchFunction) {
4288              if (searchFunction == null) throw new NullPointerException();
4289              return new SearchMappingsTask<K,V,U>
4290 <                (map, searchFunction,
4290 >                (map, null, -1, null, searchFunction,
4291                   new AtomicReference<U>());
4292          }
4293  
# Line 4214 | Line 4298 | public class ConcurrentHashMapV8<K, V>
4298           *
4299           * @param map the map
4300           * @param transformer a function returning the transformation
4301 <         * for an element, or null of there is no transformation (in
4301 >         * for an element, or null if there is no transformation (in
4302           * which case it is not combined).
4303           * @param reducer a commutative associative combining function
4304           * @return the task
# Line 4226 | Line 4310 | public class ConcurrentHashMapV8<K, V>
4310              if (transformer == null || reducer == null)
4311                  throw new NullPointerException();
4312              return new MapReduceMappingsTask<K,V,U>
4313 <                (map, transformer, reducer);
4313 >                (map, null, -1, null, transformer, reducer);
4314          }
4315  
4316          /**
# Line 4250 | Line 4334 | public class ConcurrentHashMapV8<K, V>
4334              if (transformer == null || reducer == null)
4335                  throw new NullPointerException();
4336              return new MapReduceMappingsToDoubleTask<K,V>
4337 <                (map, transformer, basis, reducer);
4337 >                (map, null, -1, null, transformer, basis, reducer);
4338          }
4339  
4340          /**
# Line 4274 | Line 4358 | public class ConcurrentHashMapV8<K, V>
4358              if (transformer == null || reducer == null)
4359                  throw new NullPointerException();
4360              return new MapReduceMappingsToLongTask<K,V>
4361 <                (map, transformer, basis, reducer);
4361 >                (map, null, -1, null, transformer, basis, reducer);
4362          }
4363  
4364          /**
# Line 4297 | Line 4381 | public class ConcurrentHashMapV8<K, V>
4381              if (transformer == null || reducer == null)
4382                  throw new NullPointerException();
4383              return new MapReduceMappingsToIntTask<K,V>
4384 <                (map, transformer, basis, reducer);
4384 >                (map, null, -1, null, transformer, basis, reducer);
4385          }
4386  
4387          /**
# Line 4312 | Line 4396 | public class ConcurrentHashMapV8<K, V>
4396              (ConcurrentHashMapV8<K,V> map,
4397               Action<K> action) {
4398              if (action == null) throw new NullPointerException();
4399 <            return new ForEachKeyTask<K,V>(map, action);
4399 >            return new ForEachKeyTask<K,V>(map, null, -1, null, action);
4400          }
4401  
4402          /**
# Line 4321 | 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
4409 <         * which case the action is not applied).
4408 >         * for an element, or null if there is no transformation (in
4409 >         * which case the action is not applied)
4410           * @param action the action
4411           * @return the task
4412           */
# Line 4333 | Line 4417 | public class ConcurrentHashMapV8<K, V>
4417              if (transformer == null || action == null)
4418                  throw new NullPointerException();
4419              return new ForEachTransformedKeyTask<K,V,U>
4420 <                (map, transformer, action);
4420 >                (map, null, -1, null, transformer, action);
4421          }
4422  
4423          /**
4424           * Returns a task that when invoked, returns a non-null result
4425           * from applying the given search function on each key, or
4426 <         * null if none.  Further element processing is suppressed
4427 <         * upon success. However, this method does not return until
4428 <         * other in-progress parallel invocations of the search
4345 <         * function also complete.
4426 >         * null if none.  Upon success, further element processing is
4427 >         * suppressed and the results of any other parallel
4428 >         * invocations of the search function are ignored.
4429           *
4430           * @param map the map
4431           * @param searchFunction a function returning a non-null
# Line 4354 | Line 4437 | public class ConcurrentHashMapV8<K, V>
4437               Fun<? super K, ? extends U> searchFunction) {
4438              if (searchFunction == null) throw new NullPointerException();
4439              return new SearchKeysTask<K,V,U>
4440 <                (map, searchFunction,
4440 >                (map, null, -1, null, searchFunction,
4441                   new AtomicReference<U>());
4442          }
4443  
# Line 4372 | Line 4455 | public class ConcurrentHashMapV8<K, V>
4455               BiFun<? super K, ? super K, ? extends K> reducer) {
4456              if (reducer == null) throw new NullPointerException();
4457              return new ReduceKeysTask<K,V>
4458 <                (map, reducer);
4458 >                (map, null, -1, null, reducer);
4459          }
4460 +
4461          /**
4462           * Returns a task that when invoked, returns the result of
4463           * accumulating the given transformation of all keys using the given
# Line 4381 | Line 4465 | public class ConcurrentHashMapV8<K, V>
4465           *
4466           * @param map the map
4467           * @param transformer a function returning the transformation
4468 <         * for an element, or null of there is no transformation (in
4468 >         * for an element, or null if there is no transformation (in
4469           * which case it is not combined).
4470           * @param reducer a commutative associative combining function
4471           * @return the task
# Line 4393 | Line 4477 | public class ConcurrentHashMapV8<K, V>
4477              if (transformer == null || reducer == null)
4478                  throw new NullPointerException();
4479              return new MapReduceKeysTask<K,V,U>
4480 <                (map, transformer, reducer);
4480 >                (map, null, -1, null, transformer, reducer);
4481          }
4482  
4483          /**
# Line 4417 | Line 4501 | public class ConcurrentHashMapV8<K, V>
4501              if (transformer == null || reducer == null)
4502                  throw new NullPointerException();
4503              return new MapReduceKeysToDoubleTask<K,V>
4504 <                (map, transformer, basis, reducer);
4504 >                (map, null, -1, null, transformer, basis, reducer);
4505          }
4506  
4507          /**
# Line 4441 | Line 4525 | public class ConcurrentHashMapV8<K, V>
4525              if (transformer == null || reducer == null)
4526                  throw new NullPointerException();
4527              return new MapReduceKeysToLongTask<K,V>
4528 <                (map, transformer, basis, reducer);
4528 >                (map, null, -1, null, transformer, basis, reducer);
4529          }
4530  
4531          /**
# Line 4465 | Line 4549 | public class ConcurrentHashMapV8<K, V>
4549              if (transformer == null || reducer == null)
4550                  throw new NullPointerException();
4551              return new MapReduceKeysToIntTask<K,V>
4552 <                (map, transformer, basis, reducer);
4552 >                (map, null, -1, null, transformer, basis, reducer);
4553          }
4554  
4555          /**
# Line 4479 | Line 4563 | public class ConcurrentHashMapV8<K, V>
4563              (ConcurrentHashMapV8<K,V> map,
4564               Action<V> action) {
4565              if (action == null) throw new NullPointerException();
4566 <            return new ForEachValueTask<K,V>(map, action);
4566 >            return new ForEachValueTask<K,V>(map, null, -1, null, action);
4567          }
4568  
4569          /**
# Line 4488 | Line 4572 | public class ConcurrentHashMapV8<K, V>
4572           *
4573           * @param map the map
4574           * @param transformer a function returning the transformation
4575 <         * for an element, or null of there is no transformation (in
4576 <         * which case the action is not applied).
4575 >         * for an element, or null if there is no transformation (in
4576 >         * which case the action is not applied)
4577           * @param action the action
4578           */
4579          public static <K,V,U> ForkJoinTask<Void> forEachValue
# Line 4499 | Line 4583 | public class ConcurrentHashMapV8<K, V>
4583              if (transformer == null || action == null)
4584                  throw new NullPointerException();
4585              return new ForEachTransformedValueTask<K,V,U>
4586 <                (map, transformer, action);
4586 >                (map, null, -1, null, transformer, action);
4587          }
4588  
4589          /**
4590           * Returns a task that when invoked, returns a non-null result
4591           * from applying the given search function on each value, or
4592 <         * null if none.  Further element processing is suppressed
4593 <         * upon success. However, this method does not return until
4594 <         * other in-progress parallel invocations of the search
4511 <         * function also complete.
4592 >         * null if none.  Upon success, further element processing is
4593 >         * suppressed and the results of any other parallel
4594 >         * invocations of the search function are ignored.
4595           *
4596           * @param map the map
4597           * @param searchFunction a function returning a non-null
4598           * result on success, else null
4599           * @return the task
4517         *
4600           */
4601          public static <K,V,U> ForkJoinTask<U> searchValues
4602              (ConcurrentHashMapV8<K,V> map,
4603               Fun<? super V, ? extends U> searchFunction) {
4604              if (searchFunction == null) throw new NullPointerException();
4605              return new SearchValuesTask<K,V,U>
4606 <                (map, searchFunction,
4606 >                (map, null, -1, null, searchFunction,
4607                   new AtomicReference<U>());
4608          }
4609  
# Line 4539 | Line 4621 | public class ConcurrentHashMapV8<K, V>
4621               BiFun<? super V, ? super V, ? extends V> reducer) {
4622              if (reducer == null) throw new NullPointerException();
4623              return new ReduceValuesTask<K,V>
4624 <                (map, reducer);
4624 >                (map, null, -1, null, reducer);
4625          }
4626  
4627          /**
# Line 4549 | Line 4631 | public class ConcurrentHashMapV8<K, V>
4631           *
4632           * @param map the map
4633           * @param transformer a function returning the transformation
4634 <         * for an element, or null of there is no transformation (in
4634 >         * for an element, or null if there is no transformation (in
4635           * which case it is not combined).
4636           * @param reducer a commutative associative combining function
4637           * @return the task
# Line 4561 | Line 4643 | public class ConcurrentHashMapV8<K, V>
4643              if (transformer == null || reducer == null)
4644                  throw new NullPointerException();
4645              return new MapReduceValuesTask<K,V,U>
4646 <                (map, transformer, reducer);
4646 >                (map, null, -1, null, transformer, reducer);
4647          }
4648  
4649          /**
# Line 4585 | Line 4667 | public class ConcurrentHashMapV8<K, V>
4667              if (transformer == null || reducer == null)
4668                  throw new NullPointerException();
4669              return new MapReduceValuesToDoubleTask<K,V>
4670 <                (map, transformer, basis, reducer);
4670 >                (map, null, -1, null, transformer, basis, reducer);
4671          }
4672  
4673          /**
# Line 4609 | Line 4691 | public class ConcurrentHashMapV8<K, V>
4691              if (transformer == null || reducer == null)
4692                  throw new NullPointerException();
4693              return new MapReduceValuesToLongTask<K,V>
4694 <                (map, transformer, basis, reducer);
4694 >                (map, null, -1, null, transformer, basis, reducer);
4695          }
4696  
4697          /**
# Line 4633 | Line 4715 | public class ConcurrentHashMapV8<K, V>
4715              if (transformer == null || reducer == null)
4716                  throw new NullPointerException();
4717              return new MapReduceValuesToIntTask<K,V>
4718 <                (map, transformer, basis, reducer);
4718 >                (map, null, -1, null, transformer, basis, reducer);
4719          }
4720  
4721          /**
# Line 4647 | Line 4729 | public class ConcurrentHashMapV8<K, V>
4729              (ConcurrentHashMapV8<K,V> map,
4730               Action<Map.Entry<K,V>> action) {
4731              if (action == null) throw new NullPointerException();
4732 <            return new ForEachEntryTask<K,V>(map, action);
4732 >            return new ForEachEntryTask<K,V>(map, null, -1, null, action);
4733          }
4734  
4735          /**
# Line 4656 | Line 4738 | public class ConcurrentHashMapV8<K, V>
4738           *
4739           * @param map the map
4740           * @param transformer a function returning the transformation
4741 <         * for an element, or null of there is no transformation (in
4742 <         * which case the action is not applied).
4741 >         * for an element, or null if there is no transformation (in
4742 >         * which case the action is not applied)
4743           * @param action the action
4744           */
4745          public static <K,V,U> ForkJoinTask<Void> forEachEntry
# Line 4667 | Line 4749 | public class ConcurrentHashMapV8<K, V>
4749              if (transformer == null || action == null)
4750                  throw new NullPointerException();
4751              return new ForEachTransformedEntryTask<K,V,U>
4752 <                (map, transformer, action);
4752 >                (map, null, -1, null, transformer, action);
4753          }
4754  
4755          /**
4756           * Returns a task that when invoked, returns a non-null result
4757           * from applying the given search function on each entry, or
4758 <         * null if none.  Further element processing is suppressed
4759 <         * upon success. However, this method does not return until
4760 <         * other in-progress parallel invocations of the search
4679 <         * function also complete.
4758 >         * null if none.  Upon success, further element processing is
4759 >         * suppressed and the results of any other parallel
4760 >         * invocations of the search function are ignored.
4761           *
4762           * @param map the map
4763           * @param searchFunction a function returning a non-null
4764           * result on success, else null
4765           * @return the task
4685         *
4766           */
4767          public static <K,V,U> ForkJoinTask<U> searchEntries
4768              (ConcurrentHashMapV8<K,V> map,
4769               Fun<Map.Entry<K,V>, ? extends U> searchFunction) {
4770              if (searchFunction == null) throw new NullPointerException();
4771              return new SearchEntriesTask<K,V,U>
4772 <                (map, searchFunction,
4772 >                (map, null, -1, null, searchFunction,
4773                   new AtomicReference<U>());
4774          }
4775  
# Line 4707 | Line 4787 | public class ConcurrentHashMapV8<K, V>
4787               BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
4788              if (reducer == null) throw new NullPointerException();
4789              return new ReduceEntriesTask<K,V>
4790 <                (map, reducer);
4790 >                (map, null, -1, null, reducer);
4791          }
4792  
4793          /**
# Line 4717 | Line 4797 | public class ConcurrentHashMapV8<K, V>
4797           *
4798           * @param map the map
4799           * @param transformer a function returning the transformation
4800 <         * for an element, or null of there is no transformation (in
4800 >         * for an element, or null if there is no transformation (in
4801           * which case it is not combined).
4802           * @param reducer a commutative associative combining function
4803           * @return the task
# Line 4729 | Line 4809 | public class ConcurrentHashMapV8<K, V>
4809              if (transformer == null || reducer == null)
4810                  throw new NullPointerException();
4811              return new MapReduceEntriesTask<K,V,U>
4812 <                (map, transformer, reducer);
4812 >                (map, null, -1, null, transformer, reducer);
4813          }
4814  
4815          /**
# Line 4753 | Line 4833 | public class ConcurrentHashMapV8<K, V>
4833              if (transformer == null || reducer == null)
4834                  throw new NullPointerException();
4835              return new MapReduceEntriesToDoubleTask<K,V>
4836 <                (map, transformer, basis, reducer);
4836 >                (map, null, -1, null, transformer, basis, reducer);
4837          }
4838  
4839          /**
# Line 4777 | Line 4857 | public class ConcurrentHashMapV8<K, V>
4857              if (transformer == null || reducer == null)
4858                  throw new NullPointerException();
4859              return new MapReduceEntriesToLongTask<K,V>
4860 <                (map, transformer, basis, reducer);
4860 >                (map, null, -1, null, transformer, basis, reducer);
4861          }
4862  
4863          /**
# Line 4801 | Line 4881 | public class ConcurrentHashMapV8<K, V>
4881              if (transformer == null || reducer == null)
4882                  throw new NullPointerException();
4883              return new MapReduceEntriesToIntTask<K,V>
4884 <                (map, transformer, basis, reducer);
4884 >                (map, null, -1, null, transformer, basis, reducer);
4885          }
4886      }
4887  
# Line 4818 | Line 4898 | public class ConcurrentHashMapV8<K, V>
4898       * exceptions are handled in a simpler manner, by just trying to
4899       * complete root task exceptionally.
4900       */
4901 <    static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> {
4901 >    @SuppressWarnings("serial") static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> {
4902          final BulkTask<K,V,?> parent;  // completion target
4903 <        int batch;                     // split control
4903 >        int batch;                     // split control; -1 for unknown
4904          int pending;                   // completion control
4905  
4906 <        /** Constructor for root tasks */
4907 <        BulkTask(ConcurrentHashMapV8<K,V> map) {
4906 >        BulkTask(ConcurrentHashMapV8<K,V> map, BulkTask<K,V,?> parent,
4907 >                 int batch) {
4908              super(map);
4829            this.parent = null;
4830            this.batch = -1; // force call to batch() on execution
4831        }
4832
4833        /** Constructor for subtasks */
4834        BulkTask(BulkTask<K,V,?> parent, int batch, boolean split) {
4835            super(parent, split);
4909              this.parent = parent;
4910              this.batch = batch;
4911 <        }
4912 <
4913 <        // FJ methods
4914 <
4915 <        /**
4916 <         * Propagates completion. Note that all reduce actions
4917 <         * bypass this method to combine while completing.
4918 <         */
4919 <        final void tryComplete() {
4920 <            BulkTask<K,V,?> a = this, s = a;
4848 <            for (int c;;) {
4849 <                if ((c = a.pending) == 0) {
4850 <                    if ((a = (s = a).parent) == null) {
4851 <                        s.quietlyComplete();
4852 <                        break;
4853 <                    }
4854 <                }
4855 <                else if (U.compareAndSwapInt(a, PENDING, c, c - 1))
4856 <                    break;
4911 >            if (parent != null && map != null) { // split parent
4912 >                Node[] t;
4913 >                if ((t = parent.tab) == null &&
4914 >                    (t = parent.tab = map.table) != null)
4915 >                    parent.baseLimit = parent.baseSize = t.length;
4916 >                this.tab = t;
4917 >                this.baseSize = parent.baseSize;
4918 >                int hi = this.baseLimit = parent.baseLimit;
4919 >                parent.baseLimit = this.index = this.baseIndex =
4920 >                    (hi + parent.baseIndex + 1) >>> 1;
4921              }
4922          }
4923  
4924          /**
4925 <         * Forces root task to throw exception unless already complete.
4925 >         * Forces root task to complete.
4926 >         * @param ex if null, complete normally, else exceptionally
4927 >         * @return false to simplify use
4928           */
4929 <        final void tryAbortComputation(Throwable ex) {
4929 >        final boolean tryCompleteComputation(Throwable ex) {
4930              for (BulkTask<K,V,?> a = this;;) {
4931                  BulkTask<K,V,?> p = a.parent;
4932                  if (p == null) {
4933 <                    a.completeExceptionally(ex);
4934 <                    break;
4933 >                    if (ex != null)
4934 >                        a.completeExceptionally(ex);
4935 >                    else
4936 >                        a.quietlyComplete();
4937 >                    return false;
4938                  }
4939                  a = p;
4940              }
4941          }
4942  
4943 <        public final boolean exec() {
4944 <            try {
4945 <                compute();
4946 <            }
4947 <            catch (Throwable ex) {
4879 <                tryAbortComputation(ex);
4880 <            }
4881 <            return false;
4943 >        /**
4944 >         * Version of tryCompleteComputation for function screening checks
4945 >         */
4946 >        final boolean abortOnNullFunction() {
4947 >            return tryCompleteComputation(new Error("Unexpected null function"));
4948          }
4949  
4884        public abstract void compute();
4885
4950          // utilities
4951  
4952          /** CompareAndSet pending count */
# Line 4898 | Line 4962 | public class ConcurrentHashMapV8<K, V>
4962           * dividing by two anyway.
4963           */
4964          final int batch() {
4965 <            int b = batch;
4966 <            if (b < 0) {
4967 <                long n = map.counter.sum();
4968 <                int sp = getPool().getParallelism() << 3; // slack of 8
4969 <                b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp;
4965 >            ConcurrentHashMapV8<K, V> m; int b; Node[] t;  ForkJoinPool pool;
4966 >            if ((b = batch) < 0 && (m = map) != null) { // force initialization
4967 >                if ((t = tab) == null && (t = tab = m.table) != null)
4968 >                    baseLimit = baseSize = t.length;
4969 >                if (t != null) {
4970 >                    long n = m.counter.sum();
4971 >                    int par = ((pool = getPool()) == null) ?
4972 >                        ForkJoinPool.getCommonPoolParallelism() :
4973 >                        pool.getParallelism();
4974 >                    int sp = par << 3; // slack of 8
4975 >                    b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp;
4976 >                }
4977              }
4978              return b;
4979          }
4980  
4981          /**
4911         * Error message for hoisted null checks of functions
4912         */
4913        static final String NullFunctionMessage =
4914            "Unexpected null function";
4915
4916        /**
4982           * Returns exportable snapshot entry.
4983           */
4984          static <K,V> AbstractMap.SimpleEntry<K,V> entryFor(K k, V v) {
4985 <            return new AbstractMap.SimpleEntry(k, v);
4985 >            return new AbstractMap.SimpleEntry<K,V>(k, v);
4986          }
4987  
4988          // Unsafe mechanics
# Line 4925 | Line 4990 | public class ConcurrentHashMapV8<K, V>
4990          private static final long PENDING;
4991          static {
4992              try {
4993 <                U = sun.misc.Unsafe.getUnsafe();
4993 >                U = getUnsafe();
4994                  PENDING = U.objectFieldOffset
4995                      (BulkTask.class.getDeclaredField("pending"));
4996              } catch (Exception e) {
# Line 4934 | Line 4999 | public class ConcurrentHashMapV8<K, V>
4999          }
5000      }
5001  
5002 +    /**
5003 +     * Base class for non-reductive actions
5004 +     */
5005 +    @SuppressWarnings("serial") static abstract class BulkAction<K,V,R> extends BulkTask<K,V,R> {
5006 +        BulkAction<K,V,?> nextTask;
5007 +        BulkAction(ConcurrentHashMapV8<K,V> map, BulkTask<K,V,?> parent,
5008 +                   int batch, BulkAction<K,V,?> nextTask) {
5009 +            super(map, parent, batch);
5010 +            this.nextTask = nextTask;
5011 +        }
5012 +
5013 +        /**
5014 +         * Try to complete task and upward parents. Upon hitting
5015 +         * non-completed parent, if a non-FJ task, try to help out the
5016 +         * computation.
5017 +         */
5018 +        final void tryComplete(BulkAction<K,V,?> subtasks) {
5019 +            BulkTask<K,V,?> a = this, s = a;
5020 +            for (int c;;) {
5021 +                if ((c = a.pending) == 0) {
5022 +                    if ((a = (s = a).parent) == null) {
5023 +                        s.quietlyComplete();
5024 +                        break;
5025 +                    }
5026 +                }
5027 +                else if (a.casPending(c, c - 1)) {
5028 +                    if (subtasks != null && !inForkJoinPool()) {
5029 +                        while ((s = a.parent) != null)
5030 +                            a = s;
5031 +                        while (!a.isDone()) {
5032 +                            BulkAction<K,V,?> next = subtasks.nextTask;
5033 +                            if (subtasks.tryUnfork())
5034 +                                subtasks.exec();
5035 +                            if ((subtasks = next) == null)
5036 +                                break;
5037 +                        }
5038 +                    }
5039 +                    break;
5040 +                }
5041 +            }
5042 +        }
5043 +
5044 +    }
5045 +
5046      /*
5047       * Task classes. Coded in a regular but ugly format/style to
5048       * simplify checks that each variant differs in the right way from
5049       * others.
5050       */
5051  
5052 <    static final class ForEachKeyTask<K,V>
5053 <        extends BulkTask<K,V,Void> {
5052 >    @SuppressWarnings("serial") static final class ForEachKeyTask<K,V>
5053 >        extends BulkAction<K,V,Void> {
5054          final Action<K> action;
5055          ForEachKeyTask
5056 <            (ConcurrentHashMapV8<K,V> m,
5057 <             Action<K> action) {
4949 <            super(m);
4950 <            this.action = action;
4951 <        }
4952 <        ForEachKeyTask
4953 <            (BulkTask<K,V,?> p, int b, boolean split,
5056 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5057 >             ForEachKeyTask<K,V> nextTask,
5058               Action<K> action) {
5059 <            super(p, b, split);
5059 >            super(m, p, b, nextTask);
5060              this.action = action;
5061          }
5062 <        public final void compute() {
5062 >        @SuppressWarnings("unchecked") public final boolean exec() {
5063              final Action<K> action = this.action;
5064              if (action == null)
5065 <                throw new Error(NullFunctionMessage);
5066 <            int b = batch(), c;
5067 <            while (b > 1 && baseIndex != baseLimit) {
5068 <                do {} while (!casPending(c = pending, c+1));
5069 <                new ForEachKeyTask<K,V>(this, b >>>= 1, true, action).fork();
5065 >                return abortOnNullFunction();
5066 >            ForEachKeyTask<K,V> subtasks = null;
5067 >            try {
5068 >                int b = batch(), c;
5069 >                while (b > 1 && baseIndex != baseLimit) {
5070 >                    do {} while (!casPending(c = pending, c+1));
5071 >                    (subtasks = new ForEachKeyTask<K,V>
5072 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5073 >                }
5074 >                while (advance() != null)
5075 >                    action.apply((K)nextKey);
5076 >            } catch (Throwable ex) {
5077 >                return tryCompleteComputation(ex);
5078              }
5079 <            while (advance() != null)
5080 <                action.apply((K)nextKey);
4969 <            tryComplete();
5079 >            tryComplete(subtasks);
5080 >            return false;
5081          }
5082      }
5083  
5084 <    static final class ForEachValueTask<K,V>
5085 <        extends BulkTask<K,V,Void> {
5084 >    @SuppressWarnings("serial") static final class ForEachValueTask<K,V>
5085 >        extends BulkAction<K,V,Void> {
5086          final Action<V> action;
5087          ForEachValueTask
5088 <            (ConcurrentHashMapV8<K,V> m,
5089 <             Action<V> action) {
4979 <            super(m);
4980 <            this.action = action;
4981 <        }
4982 <        ForEachValueTask
4983 <            (BulkTask<K,V,?> p, int b, boolean split,
5088 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5089 >             ForEachValueTask<K,V> nextTask,
5090               Action<V> action) {
5091 <            super(p, b, split);
5091 >            super(m, p, b, nextTask);
5092              this.action = action;
5093          }
5094 <        public final void compute() {
5094 >        @SuppressWarnings("unchecked") public final boolean exec() {
5095              final Action<V> action = this.action;
5096              if (action == null)
5097 <                throw new Error(NullFunctionMessage);
5098 <            int b = batch(), c;
5099 <            while (b > 1 && baseIndex != baseLimit) {
5100 <                do {} while (!casPending(c = pending, c+1));
5101 <                new ForEachValueTask<K,V>(this, b >>>= 1, true, action).fork();
5097 >                return abortOnNullFunction();
5098 >            ForEachValueTask<K,V> subtasks = null;
5099 >            try {
5100 >                int b = batch(), c;
5101 >                while (b > 1 && baseIndex != baseLimit) {
5102 >                    do {} while (!casPending(c = pending, c+1));
5103 >                    (subtasks = new ForEachValueTask<K,V>
5104 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5105 >                }
5106 >                Object v;
5107 >                while ((v = advance()) != null)
5108 >                    action.apply((V)v);
5109 >            } catch (Throwable ex) {
5110 >                return tryCompleteComputation(ex);
5111              }
5112 <            Object v;
5113 <            while ((v = advance()) != null)
4999 <                action.apply((V)v);
5000 <            tryComplete();
5112 >            tryComplete(subtasks);
5113 >            return false;
5114          }
5115      }
5116  
5117 <    static final class ForEachEntryTask<K,V>
5118 <        extends BulkTask<K,V,Void> {
5117 >    @SuppressWarnings("serial") static final class ForEachEntryTask<K,V>
5118 >        extends BulkAction<K,V,Void> {
5119          final Action<Entry<K,V>> action;
5120          ForEachEntryTask
5121 <            (ConcurrentHashMapV8<K,V> m,
5122 <             Action<Entry<K,V>> action) {
5010 <            super(m);
5011 <            this.action = action;
5012 <        }
5013 <        ForEachEntryTask
5014 <            (BulkTask<K,V,?> p, int b, boolean split,
5121 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5122 >             ForEachEntryTask<K,V> nextTask,
5123               Action<Entry<K,V>> action) {
5124 <            super(p, b, split);
5124 >            super(m, p, b, nextTask);
5125              this.action = action;
5126          }
5127 <        public final void compute() {
5127 >        @SuppressWarnings("unchecked") public final boolean exec() {
5128              final Action<Entry<K,V>> action = this.action;
5129              if (action == null)
5130 <                throw new Error(NullFunctionMessage);
5131 <            int b = batch(), c;
5132 <            while (b > 1 && baseIndex != baseLimit) {
5133 <                do {} while (!casPending(c = pending, c+1));
5134 <                new ForEachEntryTask<K,V>(this, b >>>= 1, true, action).fork();
5130 >                return abortOnNullFunction();
5131 >            ForEachEntryTask<K,V> subtasks = null;
5132 >            try {
5133 >                int b = batch(), c;
5134 >                while (b > 1 && baseIndex != baseLimit) {
5135 >                    do {} while (!casPending(c = pending, c+1));
5136 >                    (subtasks = new ForEachEntryTask<K,V>
5137 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5138 >                }
5139 >                Object v;
5140 >                while ((v = advance()) != null)
5141 >                    action.apply(entryFor((K)nextKey, (V)v));
5142 >            } catch (Throwable ex) {
5143 >                return tryCompleteComputation(ex);
5144              }
5145 <            Object v;
5146 <            while ((v = advance()) != null)
5030 <                action.apply(entryFor((K)nextKey, (V)v));
5031 <            tryComplete();
5145 >            tryComplete(subtasks);
5146 >            return false;
5147          }
5148      }
5149  
5150 <    static final class ForEachMappingTask<K,V>
5151 <        extends BulkTask<K,V,Void> {
5150 >    @SuppressWarnings("serial") static final class ForEachMappingTask<K,V>
5151 >        extends BulkAction<K,V,Void> {
5152          final BiAction<K,V> action;
5153          ForEachMappingTask
5154 <            (ConcurrentHashMapV8<K,V> m,
5155 <             BiAction<K,V> action) {
5041 <            super(m);
5042 <            this.action = action;
5043 <        }
5044 <        ForEachMappingTask
5045 <            (BulkTask<K,V,?> p, int b, boolean split,
5154 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5155 >             ForEachMappingTask<K,V> nextTask,
5156               BiAction<K,V> action) {
5157 <            super(p, b, split);
5157 >            super(m, p, b, nextTask);
5158              this.action = action;
5159          }
5160 <
5051 <        public final void compute() {
5160 >        @SuppressWarnings("unchecked") public final boolean exec() {
5161              final BiAction<K,V> action = this.action;
5162              if (action == null)
5163 <                throw new Error(NullFunctionMessage);
5164 <            int b = batch(), c;
5165 <            while (b > 1 && baseIndex != baseLimit) {
5166 <                do {} while (!casPending(c = pending, c+1));
5167 <                new ForEachMappingTask<K,V>(this, b >>>= 1, true,
5168 <                                            action).fork();
5163 >                return abortOnNullFunction();
5164 >            ForEachMappingTask<K,V> subtasks = null;
5165 >            try {
5166 >                int b = batch(), c;
5167 >                while (b > 1 && baseIndex != baseLimit) {
5168 >                    do {} while (!casPending(c = pending, c+1));
5169 >                    (subtasks = new ForEachMappingTask<K,V>
5170 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5171 >                }
5172 >                Object v;
5173 >                while ((v = advance()) != null)
5174 >                    action.apply((K)nextKey, (V)v);
5175 >            } catch (Throwable ex) {
5176 >                return tryCompleteComputation(ex);
5177              }
5178 <            Object v;
5179 <            while ((v = advance()) != null)
5063 <                action.apply((K)nextKey, (V)v);
5064 <            tryComplete();
5178 >            tryComplete(subtasks);
5179 >            return false;
5180          }
5181      }
5182  
5183 <    static final class ForEachTransformedKeyTask<K,V,U>
5184 <        extends BulkTask<K,V,Void> {
5183 >    @SuppressWarnings("serial") static final class ForEachTransformedKeyTask<K,V,U>
5184 >        extends BulkAction<K,V,Void> {
5185          final Fun<? super K, ? extends U> transformer;
5186          final Action<U> action;
5187          ForEachTransformedKeyTask
5188 <            (ConcurrentHashMapV8<K,V> m,
5188 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5189 >             ForEachTransformedKeyTask<K,V,U> nextTask,
5190               Fun<? super K, ? extends U> transformer,
5191               Action<U> action) {
5192 <            super(m);
5192 >            super(m, p, b, nextTask);
5193              this.transformer = transformer;
5194              this.action = action;
5195  
5196          }
5197 <        ForEachTransformedKeyTask
5082 <            (BulkTask<K,V,?> p, int b, boolean split,
5083 <             Fun<? super K, ? extends U> transformer,
5084 <             Action<U> action) {
5085 <            super(p, b, split);
5086 <            this.transformer = transformer;
5087 <            this.action = action;
5088 <        }
5089 <        public final void compute() {
5197 >        @SuppressWarnings("unchecked") public final boolean exec() {
5198              final Fun<? super K, ? extends U> transformer =
5199                  this.transformer;
5200              final Action<U> action = this.action;
5201              if (transformer == null || action == null)
5202 <                throw new Error(NullFunctionMessage);
5203 <            int b = batch(), c;
5204 <            while (b > 1 && baseIndex != baseLimit) {
5205 <                do {} while (!casPending(c = pending, c+1));
5206 <                new ForEachTransformedKeyTask<K,V,U>
5207 <                    (this, b >>>= 1, true, transformer, action).fork();
5208 <            }
5209 <            U u;
5210 <            while (advance() != null) {
5211 <                if ((u = transformer.apply((K)nextKey)) != null)
5212 <                    action.apply(u);
5202 >                return abortOnNullFunction();
5203 >            ForEachTransformedKeyTask<K,V,U> subtasks = null;
5204 >            try {
5205 >                int b = batch(), c;
5206 >                while (b > 1 && baseIndex != baseLimit) {
5207 >                    do {} while (!casPending(c = pending, c+1));
5208 >                    (subtasks = new ForEachTransformedKeyTask<K,V,U>
5209 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5210 >                }
5211 >                U u;
5212 >                while (advance() != null) {
5213 >                    if ((u = transformer.apply((K)nextKey)) != null)
5214 >                        action.apply(u);
5215 >                }
5216 >            } catch (Throwable ex) {
5217 >                return tryCompleteComputation(ex);
5218              }
5219 <            tryComplete();
5219 >            tryComplete(subtasks);
5220 >            return false;
5221          }
5222      }
5223  
5224 <    static final class ForEachTransformedValueTask<K,V,U>
5225 <        extends BulkTask<K,V,Void> {
5224 >    @SuppressWarnings("serial") static final class ForEachTransformedValueTask<K,V,U>
5225 >        extends BulkAction<K,V,Void> {
5226          final Fun<? super V, ? extends U> transformer;
5227          final Action<U> action;
5228          ForEachTransformedValueTask
5229 <            (ConcurrentHashMapV8<K,V> m,
5229 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5230 >             ForEachTransformedValueTask<K,V,U> nextTask,
5231               Fun<? super V, ? extends U> transformer,
5232               Action<U> action) {
5233 <            super(m);
5233 >            super(m, p, b, nextTask);
5234              this.transformer = transformer;
5235              this.action = action;
5236  
5237          }
5238 <        ForEachTransformedValueTask
5124 <            (BulkTask<K,V,?> p, int b, boolean split,
5125 <             Fun<? super V, ? extends U> transformer,
5126 <             Action<U> action) {
5127 <            super(p, b, split);
5128 <            this.transformer = transformer;
5129 <            this.action = action;
5130 <        }
5131 <        public final void compute() {
5238 >        @SuppressWarnings("unchecked") public final boolean exec() {
5239              final Fun<? super V, ? extends U> transformer =
5240                  this.transformer;
5241              final Action<U> action = this.action;
5242              if (transformer == null || action == null)
5243 <                throw new Error(NullFunctionMessage);
5244 <            int b = batch(), c;
5245 <            while (b > 1 && baseIndex != baseLimit) {
5246 <                do {} while (!casPending(c = pending, c+1));
5247 <                new ForEachTransformedValueTask<K,V,U>
5248 <                    (this, b >>>= 1, true, transformer, action).fork();
5249 <            }
5250 <            Object v; U u;
5251 <            while ((v = advance()) != null) {
5252 <                if ((u = transformer.apply((V)v)) != null)
5253 <                    action.apply(u);
5243 >                return abortOnNullFunction();
5244 >            ForEachTransformedValueTask<K,V,U> subtasks = null;
5245 >            try {
5246 >                int b = batch(), c;
5247 >                while (b > 1 && baseIndex != baseLimit) {
5248 >                    do {} while (!casPending(c = pending, c+1));
5249 >                    (subtasks = new ForEachTransformedValueTask<K,V,U>
5250 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5251 >                }
5252 >                Object v; U u;
5253 >                while ((v = advance()) != null) {
5254 >                    if ((u = transformer.apply((V)v)) != null)
5255 >                        action.apply(u);
5256 >                }
5257 >            } catch (Throwable ex) {
5258 >                return tryCompleteComputation(ex);
5259              }
5260 <            tryComplete();
5260 >            tryComplete(subtasks);
5261 >            return false;
5262          }
5263      }
5264  
5265 <    static final class ForEachTransformedEntryTask<K,V,U>
5266 <        extends BulkTask<K,V,Void> {
5265 >    @SuppressWarnings("serial") static final class ForEachTransformedEntryTask<K,V,U>
5266 >        extends BulkAction<K,V,Void> {
5267          final Fun<Map.Entry<K,V>, ? extends U> transformer;
5268          final Action<U> action;
5269          ForEachTransformedEntryTask
5270 <            (ConcurrentHashMapV8<K,V> m,
5270 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5271 >             ForEachTransformedEntryTask<K,V,U> nextTask,
5272               Fun<Map.Entry<K,V>, ? extends U> transformer,
5273               Action<U> action) {
5274 <            super(m);
5274 >            super(m, p, b, nextTask);
5275              this.transformer = transformer;
5276              this.action = action;
5277  
5278          }
5279 <        ForEachTransformedEntryTask
5166 <            (BulkTask<K,V,?> p, int b, boolean split,
5167 <             Fun<Map.Entry<K,V>, ? extends U> transformer,
5168 <             Action<U> action) {
5169 <            super(p, b, split);
5170 <            this.transformer = transformer;
5171 <            this.action = action;
5172 <        }
5173 <        public final void compute() {
5279 >        @SuppressWarnings("unchecked") public final boolean exec() {
5280              final Fun<Map.Entry<K,V>, ? extends U> transformer =
5281                  this.transformer;
5282              final Action<U> action = this.action;
5283              if (transformer == null || action == null)
5284 <                throw new Error(NullFunctionMessage);
5285 <            int b = batch(), c;
5286 <            while (b > 1 && baseIndex != baseLimit) {
5287 <                do {} while (!casPending(c = pending, c+1));
5288 <                new ForEachTransformedEntryTask<K,V,U>
5289 <                    (this, b >>>= 1, true, transformer, action).fork();
5290 <            }
5291 <            Object v; U u;
5292 <            while ((v = advance()) != null) {
5293 <                if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5294 <                    action.apply(u);
5284 >                return abortOnNullFunction();
5285 >            ForEachTransformedEntryTask<K,V,U> subtasks = null;
5286 >            try {
5287 >                int b = batch(), c;
5288 >                while (b > 1 && baseIndex != baseLimit) {
5289 >                    do {} while (!casPending(c = pending, c+1));
5290 >                    (subtasks = new ForEachTransformedEntryTask<K,V,U>
5291 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5292 >                }
5293 >                Object v; U u;
5294 >                while ((v = advance()) != null) {
5295 >                    if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5296 >                        action.apply(u);
5297 >                }
5298 >            } catch (Throwable ex) {
5299 >                return tryCompleteComputation(ex);
5300              }
5301 <            tryComplete();
5301 >            tryComplete(subtasks);
5302 >            return false;
5303          }
5304      }
5305  
5306 <    static final class ForEachTransformedMappingTask<K,V,U>
5307 <        extends BulkTask<K,V,Void> {
5306 >    @SuppressWarnings("serial") static final class ForEachTransformedMappingTask<K,V,U>
5307 >        extends BulkAction<K,V,Void> {
5308          final BiFun<? super K, ? super V, ? extends U> transformer;
5309          final Action<U> action;
5310          ForEachTransformedMappingTask
5311 <            (ConcurrentHashMapV8<K,V> m,
5311 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5312 >             ForEachTransformedMappingTask<K,V,U> nextTask,
5313               BiFun<? super K, ? super V, ? extends U> transformer,
5314               Action<U> action) {
5315 <            super(m);
5315 >            super(m, p, b, nextTask);
5316              this.transformer = transformer;
5317              this.action = action;
5318  
5319          }
5320 <        ForEachTransformedMappingTask
5208 <            (BulkTask<K,V,?> p, int b, boolean split,
5209 <             BiFun<? super K, ? super V, ? extends U> transformer,
5210 <             Action<U> action) {
5211 <            super(p, b, split);
5212 <            this.transformer = transformer;
5213 <            this.action = action;
5214 <        }
5215 <        public final void compute() {
5320 >        @SuppressWarnings("unchecked") public final boolean exec() {
5321              final BiFun<? super K, ? super V, ? extends U> transformer =
5322                  this.transformer;
5323              final Action<U> action = this.action;
5324              if (transformer == null || action == null)
5325 <                throw new Error(NullFunctionMessage);
5326 <            int b = batch(), c;
5327 <            while (b > 1 && baseIndex != baseLimit) {
5328 <                do {} while (!casPending(c = pending, c+1));
5329 <                new ForEachTransformedMappingTask<K,V,U>
5330 <                    (this, b >>>= 1, true, transformer, action).fork();
5331 <            }
5332 <            Object v; U u;
5333 <            while ((v = advance()) != null) {
5334 <                if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5335 <                    action.apply(u);
5325 >                return abortOnNullFunction();
5326 >            ForEachTransformedMappingTask<K,V,U> subtasks = null;
5327 >            try {
5328 >                int b = batch(), c;
5329 >                while (b > 1 && baseIndex != baseLimit) {
5330 >                    do {} while (!casPending(c = pending, c+1));
5331 >                    (subtasks = new ForEachTransformedMappingTask<K,V,U>
5332 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5333 >                }
5334 >                Object v; U u;
5335 >                while ((v = advance()) != null) {
5336 >                    if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5337 >                        action.apply(u);
5338 >                }
5339 >            } catch (Throwable ex) {
5340 >                return tryCompleteComputation(ex);
5341              }
5342 <            tryComplete();
5342 >            tryComplete(subtasks);
5343 >            return false;
5344          }
5345      }
5346  
5347 <    static final class SearchKeysTask<K,V,U>
5348 <        extends BulkTask<K,V,U> {
5347 >    @SuppressWarnings("serial") static final class SearchKeysTask<K,V,U>
5348 >        extends BulkAction<K,V,U> {
5349          final Fun<? super K, ? extends U> searchFunction;
5350          final AtomicReference<U> result;
5351          SearchKeysTask
5352 <            (ConcurrentHashMapV8<K,V> m,
5353 <             Fun<? super K, ? extends U> searchFunction,
5243 <             AtomicReference<U> result) {
5244 <            super(m);
5245 <            this.searchFunction = searchFunction; this.result = result;
5246 <        }
5247 <        SearchKeysTask
5248 <            (BulkTask<K,V,?> p, int b, boolean split,
5352 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5353 >             SearchKeysTask<K,V,U> nextTask,
5354               Fun<? super K, ? extends U> searchFunction,
5355               AtomicReference<U> result) {
5356 <            super(p, b, split);
5356 >            super(m, p, b, nextTask);
5357              this.searchFunction = searchFunction; this.result = result;
5358          }
5359 <        public final void compute() {
5359 >        @SuppressWarnings("unchecked") public final boolean exec() {
5360              AtomicReference<U> result = this.result;
5361              final Fun<? super K, ? extends U> searchFunction =
5362                  this.searchFunction;
5363              if (searchFunction == null || result == null)
5364 <                throw new Error(NullFunctionMessage);
5365 <            int b = batch(), c;
5366 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5367 <                do {} while (!casPending(c = pending, c+1));
5368 <                new SearchKeysTask<K,V,U>(this, b >>>= 1, true,
5369 <                                          searchFunction, result).fork();
5370 <            }
5371 <            U u;
5372 <            while (result.get() == null && advance() != null) {
5373 <                if ((u = searchFunction.apply((K)nextKey)) != null) {
5374 <                    result.compareAndSet(null, u);
5375 <                    break;
5364 >                return abortOnNullFunction();
5365 >            SearchKeysTask<K,V,U> subtasks = null;
5366 >            try {
5367 >                int b = batch(), c;
5368 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5369 >                    do {} while (!casPending(c = pending, c+1));
5370 >                    (subtasks = new SearchKeysTask<K,V,U>
5371 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5372 >                }
5373 >                U u;
5374 >                while (result.get() == null && advance() != null) {
5375 >                    if ((u = searchFunction.apply((K)nextKey)) != null) {
5376 >                        if (result.compareAndSet(null, u))
5377 >                            tryCompleteComputation(null);
5378 >                        break;
5379 >                    }
5380                  }
5381 +            } catch (Throwable ex) {
5382 +                return tryCompleteComputation(ex);
5383              }
5384 <            tryComplete();
5384 >            tryComplete(subtasks);
5385 >            return false;
5386          }
5387          public final U getRawResult() { return result.get(); }
5388      }
5389  
5390 <    static final class SearchValuesTask<K,V,U>
5391 <        extends BulkTask<K,V,U> {
5390 >    @SuppressWarnings("serial") static final class SearchValuesTask<K,V,U>
5391 >        extends BulkAction<K,V,U> {
5392          final Fun<? super V, ? extends U> searchFunction;
5393          final AtomicReference<U> result;
5394          SearchValuesTask
5395 <            (ConcurrentHashMapV8<K,V> m,
5395 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5396 >             SearchValuesTask<K,V,U> nextTask,
5397               Fun<? super V, ? extends U> searchFunction,
5398               AtomicReference<U> result) {
5399 <            super(m);
5399 >            super(m, p, b, nextTask);
5400              this.searchFunction = searchFunction; this.result = result;
5401          }
5402 <        SearchValuesTask
5290 <            (BulkTask<K,V,?> p, int b, boolean split,
5291 <             Fun<? super V, ? extends U> searchFunction,
5292 <             AtomicReference<U> result) {
5293 <            super(p, b, split);
5294 <            this.searchFunction = searchFunction; this.result = result;
5295 <        }
5296 <        public final void compute() {
5402 >        @SuppressWarnings("unchecked") public final boolean exec() {
5403              AtomicReference<U> result = this.result;
5404              final Fun<? super V, ? extends U> searchFunction =
5405                  this.searchFunction;
5406              if (searchFunction == null || result == null)
5407 <                throw new Error(NullFunctionMessage);
5408 <            int b = batch(), c;
5409 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5410 <                do {} while (!casPending(c = pending, c+1));
5411 <                new SearchValuesTask<K,V,U>(this, b >>>= 1, true,
5412 <                                            searchFunction, result).fork();
5413 <            }
5414 <            Object v; U u;
5415 <            while (result.get() == null && (v = advance()) != null) {
5416 <                if ((u = searchFunction.apply((V)v)) != null) {
5417 <                    result.compareAndSet(null, u);
5418 <                    break;
5407 >                return abortOnNullFunction();
5408 >            SearchValuesTask<K,V,U> subtasks = null;
5409 >            try {
5410 >                int b = batch(), c;
5411 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5412 >                    do {} while (!casPending(c = pending, c+1));
5413 >                    (subtasks = new SearchValuesTask<K,V,U>
5414 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5415 >                }
5416 >                Object v; U u;
5417 >                while (result.get() == null && (v = advance()) != null) {
5418 >                    if ((u = searchFunction.apply((V)v)) != null) {
5419 >                        if (result.compareAndSet(null, u))
5420 >                            tryCompleteComputation(null);
5421 >                        break;
5422 >                    }
5423                  }
5424 +            } catch (Throwable ex) {
5425 +                return tryCompleteComputation(ex);
5426              }
5427 <            tryComplete();
5427 >            tryComplete(subtasks);
5428 >            return false;
5429          }
5430          public final U getRawResult() { return result.get(); }
5431      }
5432  
5433 <    static final class SearchEntriesTask<K,V,U>
5434 <        extends BulkTask<K,V,U> {
5433 >    @SuppressWarnings("serial") static final class SearchEntriesTask<K,V,U>
5434 >        extends BulkAction<K,V,U> {
5435          final Fun<Entry<K,V>, ? extends U> searchFunction;
5436          final AtomicReference<U> result;
5437          SearchEntriesTask
5438 <            (ConcurrentHashMapV8<K,V> m,
5439 <             Fun<Entry<K,V>, ? extends U> searchFunction,
5327 <             AtomicReference<U> result) {
5328 <            super(m);
5329 <            this.searchFunction = searchFunction; this.result = result;
5330 <        }
5331 <        SearchEntriesTask
5332 <            (BulkTask<K,V,?> p, int b, boolean split,
5438 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5439 >             SearchEntriesTask<K,V,U> nextTask,
5440               Fun<Entry<K,V>, ? extends U> searchFunction,
5441               AtomicReference<U> result) {
5442 <            super(p, b, split);
5442 >            super(m, p, b, nextTask);
5443              this.searchFunction = searchFunction; this.result = result;
5444          }
5445 <        public final void compute() {
5445 >        @SuppressWarnings("unchecked") public final boolean exec() {
5446              AtomicReference<U> result = this.result;
5447              final Fun<Entry<K,V>, ? extends U> searchFunction =
5448                  this.searchFunction;
5449              if (searchFunction == null || result == null)
5450 <                throw new Error(NullFunctionMessage);
5451 <            int b = batch(), c;
5452 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5453 <                do {} while (!casPending(c = pending, c+1));
5454 <                new SearchEntriesTask<K,V,U>(this, b >>>= 1, true,
5455 <                                             searchFunction, result).fork();
5456 <            }
5457 <            Object v; U u;
5458 <            while (result.get() == null && (v = advance()) != null) {
5459 <                if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) {
5460 <                    result.compareAndSet(null, u);
5461 <                    break;
5450 >                return abortOnNullFunction();
5451 >            SearchEntriesTask<K,V,U> subtasks = null;
5452 >            try {
5453 >                int b = batch(), c;
5454 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5455 >                    do {} while (!casPending(c = pending, c+1));
5456 >                    (subtasks = new SearchEntriesTask<K,V,U>
5457 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5458 >                }
5459 >                Object v; U u;
5460 >                while (result.get() == null && (v = advance()) != null) {
5461 >                    if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) {
5462 >                        if (result.compareAndSet(null, u))
5463 >                            tryCompleteComputation(null);
5464 >                        break;
5465 >                    }
5466                  }
5467 +            } catch (Throwable ex) {
5468 +                return tryCompleteComputation(ex);
5469              }
5470 <            tryComplete();
5470 >            tryComplete(subtasks);
5471 >            return false;
5472          }
5473          public final U getRawResult() { return result.get(); }
5474      }
5475  
5476 <    static final class SearchMappingsTask<K,V,U>
5477 <        extends BulkTask<K,V,U> {
5476 >    @SuppressWarnings("serial") static final class SearchMappingsTask<K,V,U>
5477 >        extends BulkAction<K,V,U> {
5478          final BiFun<? super K, ? super V, ? extends U> searchFunction;
5479          final AtomicReference<U> result;
5480          SearchMappingsTask
5481 <            (ConcurrentHashMapV8<K,V> m,
5481 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5482 >             SearchMappingsTask<K,V,U> nextTask,
5483               BiFun<? super K, ? super V, ? extends U> searchFunction,
5484               AtomicReference<U> result) {
5485 <            super(m);
5485 >            super(m, p, b, nextTask);
5486              this.searchFunction = searchFunction; this.result = result;
5487          }
5488 <        SearchMappingsTask
5374 <            (BulkTask<K,V,?> p, int b, boolean split,
5375 <             BiFun<? super K, ? super V, ? extends U> searchFunction,
5376 <             AtomicReference<U> result) {
5377 <            super(p, b, split);
5378 <            this.searchFunction = searchFunction; this.result = result;
5379 <        }
5380 <        public final void compute() {
5488 >        @SuppressWarnings("unchecked") public final boolean exec() {
5489              AtomicReference<U> result = this.result;
5490              final BiFun<? super K, ? super V, ? extends U> searchFunction =
5491                  this.searchFunction;
5492              if (searchFunction == null || result == null)
5493 <                throw new Error(NullFunctionMessage);
5494 <            int b = batch(), c;
5495 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5496 <                do {} while (!casPending(c = pending, c+1));
5497 <                new SearchMappingsTask<K,V,U>(this, b >>>= 1, true,
5498 <                                              searchFunction, result).fork();
5499 <            }
5500 <            Object v; U u;
5501 <            while (result.get() == null && (v = advance()) != null) {
5502 <                if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) {
5503 <                    result.compareAndSet(null, u);
5504 <                    break;
5493 >                return abortOnNullFunction();
5494 >            SearchMappingsTask<K,V,U> subtasks = null;
5495 >            try {
5496 >                int b = batch(), c;
5497 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5498 >                    do {} while (!casPending(c = pending, c+1));
5499 >                    (subtasks = new SearchMappingsTask<K,V,U>
5500 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5501 >                }
5502 >                Object v; U u;
5503 >                while (result.get() == null && (v = advance()) != null) {
5504 >                    if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) {
5505 >                        if (result.compareAndSet(null, u))
5506 >                            tryCompleteComputation(null);
5507 >                        break;
5508 >                    }
5509                  }
5510 +            } catch (Throwable ex) {
5511 +                return tryCompleteComputation(ex);
5512              }
5513 <            tryComplete();
5513 >            tryComplete(subtasks);
5514 >            return false;
5515          }
5516          public final U getRawResult() { return result.get(); }
5517      }
5518  
5519 <    static final class ReduceKeysTask<K,V>
5519 >    @SuppressWarnings("serial") static final class ReduceKeysTask<K,V>
5520          extends BulkTask<K,V,K> {
5521          final BiFun<? super K, ? super K, ? extends K> reducer;
5522          K result;
5523 <        ReduceKeysTask<K,V> sibling;
5523 >        ReduceKeysTask<K,V> rights, nextRight;
5524          ReduceKeysTask
5525 <            (ConcurrentHashMapV8<K,V> m,
5525 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5526 >             ReduceKeysTask<K,V> nextRight,
5527               BiFun<? super K, ? super K, ? extends K> reducer) {
5528 <            super(m);
5528 >            super(m, p, b); this.nextRight = nextRight;
5529              this.reducer = reducer;
5530          }
5531 <        ReduceKeysTask
5416 <            (BulkTask<K,V,?> p, int b, boolean split,
5417 <             BiFun<? super K, ? super K, ? extends K> reducer) {
5418 <            super(p, b, split);
5419 <            this.reducer = reducer;
5420 <        }
5421 <
5422 <        public final void compute() {
5423 <            ReduceKeysTask<K,V> t = this;
5531 >        @SuppressWarnings("unchecked") public final boolean exec() {
5532              final BiFun<? super K, ? super K, ? extends K> reducer =
5533                  this.reducer;
5534              if (reducer == null)
5535 <                throw new Error(NullFunctionMessage);
5536 <            int b = batch();
5537 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5538 <                b >>>= 1;
5539 <                t.pending = 1;
5540 <                ReduceKeysTask<K,V> rt =
5541 <                    new ReduceKeysTask<K,V>
5542 <                    (t, b, true, reducer);
5543 <                t = new ReduceKeysTask<K,V>
5544 <                    (t, b, false, reducer);
5545 <                t.sibling = rt;
5438 <                rt.sibling = t;
5439 <                rt.fork();
5440 <            }
5441 <            K r = null;
5442 <            while (t.advance() != null) {
5443 <                K u = (K)t.nextKey;
5444 <                r = (r == null) ? u : reducer.apply(r, u);
5445 <            }
5446 <            t.result = r;
5447 <            for (;;) {
5448 <                int c; BulkTask<K,V,?> par; ReduceKeysTask<K,V> s, p; K u;
5449 <                if ((par = t.parent) == null ||
5450 <                    !(par instanceof ReduceKeysTask)) {
5451 <                    t.quietlyComplete();
5452 <                    break;
5535 >                return abortOnNullFunction();
5536 >            try {
5537 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5538 >                    do {} while (!casPending(c = pending, c+1));
5539 >                    (rights = new ReduceKeysTask<K,V>
5540 >                     (map, this, b >>>= 1, rights, reducer)).fork();
5541 >                }
5542 >                K r = null;
5543 >                while (advance() != null) {
5544 >                    K u = (K)nextKey;
5545 >                    r = (r == null) ? u : reducer.apply(r, u);
5546                  }
5547 <                else if ((c = (p = (ReduceKeysTask<K,V>)par).pending) == 0) {
5548 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5549 <                        r = (r == null) ? u : reducer.apply(r, u);
5550 <                    (t = p).result = r;
5547 >                result = r;
5548 >                for (ReduceKeysTask<K,V> t = this, s;;) {
5549 >                    int c; BulkTask<K,V,?> par; K tr, sr;
5550 >                    if ((c = t.pending) == 0) {
5551 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5552 >                            if ((sr = s.result) != null)
5553 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5554 >                        }
5555 >                        if ((par = t.parent) == null ||
5556 >                            !(par instanceof ReduceKeysTask)) {
5557 >                            t.quietlyComplete();
5558 >                            break;
5559 >                        }
5560 >                        t = (ReduceKeysTask<K,V>)par;
5561 >                    }
5562 >                    else if (t.casPending(c, c - 1))
5563 >                        break;
5564                  }
5565 <                else if (p.casPending(c, 0))
5566 <                    break;
5565 >            } catch (Throwable ex) {
5566 >                return tryCompleteComputation(ex);
5567              }
5568 +            ReduceKeysTask<K,V> s = rights;
5569 +            if (s != null && !inForkJoinPool()) {
5570 +                do  {
5571 +                    if (s.tryUnfork())
5572 +                        s.exec();
5573 +                } while ((s = s.nextRight) != null);
5574 +            }
5575 +            return false;
5576          }
5577          public final K getRawResult() { return result; }
5578      }
5579  
5580 <    static final class ReduceValuesTask<K,V>
5580 >    @SuppressWarnings("serial") static final class ReduceValuesTask<K,V>
5581          extends BulkTask<K,V,V> {
5582          final BiFun<? super V, ? super V, ? extends V> reducer;
5583          V result;
5584 <        ReduceValuesTask<K,V> sibling;
5471 <        ReduceValuesTask
5472 <            (ConcurrentHashMapV8<K,V> m,
5473 <             BiFun<? super V, ? super V, ? extends V> reducer) {
5474 <            super(m);
5475 <            this.reducer = reducer;
5476 <        }
5584 >        ReduceValuesTask<K,V> rights, nextRight;
5585          ReduceValuesTask
5586 <            (BulkTask<K,V,?> p, int b, boolean split,
5586 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5587 >             ReduceValuesTask<K,V> nextRight,
5588               BiFun<? super V, ? super V, ? extends V> reducer) {
5589 <            super(p, b, split);
5589 >            super(m, p, b); this.nextRight = nextRight;
5590              this.reducer = reducer;
5591          }
5592 <
5484 <        public final void compute() {
5485 <            ReduceValuesTask<K,V> t = this;
5592 >        @SuppressWarnings("unchecked") public final boolean exec() {
5593              final BiFun<? super V, ? super V, ? extends V> reducer =
5594                  this.reducer;
5595              if (reducer == null)
5596 <                throw new Error(NullFunctionMessage);
5597 <            int b = batch();
5598 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5599 <                b >>>= 1;
5600 <                t.pending = 1;
5601 <                ReduceValuesTask<K,V> rt =
5602 <                    new ReduceValuesTask<K,V>
5603 <                    (t, b, true, reducer);
5604 <                t = new ReduceValuesTask<K,V>
5605 <                    (t, b, false, reducer);
5606 <                t.sibling = rt;
5607 <                rt.sibling = t;
5501 <                rt.fork();
5502 <            }
5503 <            V r = null;
5504 <            Object v;
5505 <            while ((v = t.advance()) != null) {
5506 <                V u = (V)v;
5507 <                r = (r == null) ? u : reducer.apply(r, u);
5508 <            }
5509 <            t.result = r;
5510 <            for (;;) {
5511 <                int c; BulkTask<K,V,?> par; ReduceValuesTask<K,V> s, p; V u;
5512 <                if ((par = t.parent) == null ||
5513 <                    !(par instanceof ReduceValuesTask)) {
5514 <                    t.quietlyComplete();
5515 <                    break;
5596 >                return abortOnNullFunction();
5597 >            try {
5598 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5599 >                    do {} while (!casPending(c = pending, c+1));
5600 >                    (rights = new ReduceValuesTask<K,V>
5601 >                     (map, this, b >>>= 1, rights, reducer)).fork();
5602 >                }
5603 >                V r = null;
5604 >                Object v;
5605 >                while ((v = advance()) != null) {
5606 >                    V u = (V)v;
5607 >                    r = (r == null) ? u : reducer.apply(r, u);
5608                  }
5609 <                else if ((c = (p = (ReduceValuesTask<K,V>)par).pending) == 0) {
5610 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5611 <                        r = (r == null) ? u : reducer.apply(r, u);
5612 <                    (t = p).result = r;
5609 >                result = r;
5610 >                for (ReduceValuesTask<K,V> t = this, s;;) {
5611 >                    int c; BulkTask<K,V,?> par; V tr, sr;
5612 >                    if ((c = t.pending) == 0) {
5613 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5614 >                            if ((sr = s.result) != null)
5615 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5616 >                        }
5617 >                        if ((par = t.parent) == null ||
5618 >                            !(par instanceof ReduceValuesTask)) {
5619 >                            t.quietlyComplete();
5620 >                            break;
5621 >                        }
5622 >                        t = (ReduceValuesTask<K,V>)par;
5623 >                    }
5624 >                    else if (t.casPending(c, c - 1))
5625 >                        break;
5626                  }
5627 <                else if (p.casPending(c, 0))
5628 <                    break;
5627 >            } catch (Throwable ex) {
5628 >                return tryCompleteComputation(ex);
5629              }
5630 +            ReduceValuesTask<K,V> s = rights;
5631 +            if (s != null && !inForkJoinPool()) {
5632 +                do  {
5633 +                    if (s.tryUnfork())
5634 +                        s.exec();
5635 +                } while ((s = s.nextRight) != null);
5636 +            }
5637 +            return false;
5638          }
5639          public final V getRawResult() { return result; }
5640      }
5641  
5642 <    static final class ReduceEntriesTask<K,V>
5642 >    @SuppressWarnings("serial") static final class ReduceEntriesTask<K,V>
5643          extends BulkTask<K,V,Map.Entry<K,V>> {
5644          final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer;
5645          Map.Entry<K,V> result;
5646 <        ReduceEntriesTask<K,V> sibling;
5646 >        ReduceEntriesTask<K,V> rights, nextRight;
5647          ReduceEntriesTask
5648 <            (ConcurrentHashMapV8<K,V> m,
5648 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5649 >             ReduceEntriesTask<K,V> nextRight,
5650               BiFun<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5651 <            super(m);
5538 <            this.reducer = reducer;
5539 <        }
5540 <        ReduceEntriesTask
5541 <            (BulkTask<K,V,?> p, int b, boolean split,
5542 <             BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5543 <            super(p, b, split);
5651 >            super(m, p, b); this.nextRight = nextRight;
5652              this.reducer = reducer;
5653          }
5654 <
5547 <        public final void compute() {
5548 <            ReduceEntriesTask<K,V> t = this;
5654 >        @SuppressWarnings("unchecked") public final boolean exec() {
5655              final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer =
5656                  this.reducer;
5657              if (reducer == null)
5658 <                throw new Error(NullFunctionMessage);
5659 <            int b = batch();
5660 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5661 <                b >>>= 1;
5662 <                t.pending = 1;
5663 <                ReduceEntriesTask<K,V> rt =
5664 <                    new ReduceEntriesTask<K,V>
5665 <                    (t, b, true, reducer);
5666 <                t = new ReduceEntriesTask<K,V>
5667 <                    (t, b, false, reducer);
5668 <                t.sibling = rt;
5669 <                rt.sibling = t;
5564 <                rt.fork();
5565 <            }
5566 <            Map.Entry<K,V> r = null;
5567 <            Object v;
5568 <            while ((v = t.advance()) != null) {
5569 <                Map.Entry<K,V> u = entryFor((K)t.nextKey, (V)v);
5570 <                r = (r == null) ? u : reducer.apply(r, u);
5571 <            }
5572 <            t.result = r;
5573 <            for (;;) {
5574 <                int c; BulkTask<K,V,?> par; ReduceEntriesTask<K,V> s, p;
5575 <                Map.Entry<K,V> u;
5576 <                if ((par = t.parent) == null ||
5577 <                    !(par instanceof ReduceEntriesTask)) {
5578 <                    t.quietlyComplete();
5579 <                    break;
5658 >                return abortOnNullFunction();
5659 >            try {
5660 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5661 >                    do {} while (!casPending(c = pending, c+1));
5662 >                    (rights = new ReduceEntriesTask<K,V>
5663 >                     (map, this, b >>>= 1, rights, reducer)).fork();
5664 >                }
5665 >                Map.Entry<K,V> r = null;
5666 >                Object v;
5667 >                while ((v = advance()) != null) {
5668 >                    Map.Entry<K,V> u = entryFor((K)nextKey, (V)v);
5669 >                    r = (r == null) ? u : reducer.apply(r, u);
5670                  }
5671 <                else if ((c = (p = (ReduceEntriesTask<K,V>)par).pending) == 0) {
5672 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5673 <                        r = (r == null) ? u : reducer.apply(r, u);
5674 <                    (t = p).result = r;
5671 >                result = r;
5672 >                for (ReduceEntriesTask<K,V> t = this, s;;) {
5673 >                    int c; BulkTask<K,V,?> par; Map.Entry<K,V> tr, sr;
5674 >                    if ((c = t.pending) == 0) {
5675 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5676 >                            if ((sr = s.result) != null)
5677 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5678 >                        }
5679 >                        if ((par = t.parent) == null ||
5680 >                            !(par instanceof ReduceEntriesTask)) {
5681 >                            t.quietlyComplete();
5682 >                            break;
5683 >                        }
5684 >                        t = (ReduceEntriesTask<K,V>)par;
5685 >                    }
5686 >                    else if (t.casPending(c, c - 1))
5687 >                        break;
5688                  }
5689 <                else if (p.casPending(c, 0))
5690 <                    break;
5689 >            } catch (Throwable ex) {
5690 >                return tryCompleteComputation(ex);
5691              }
5692 +            ReduceEntriesTask<K,V> s = rights;
5693 +            if (s != null && !inForkJoinPool()) {
5694 +                do  {
5695 +                    if (s.tryUnfork())
5696 +                        s.exec();
5697 +                } while ((s = s.nextRight) != null);
5698 +            }
5699 +            return false;
5700          }
5701          public final Map.Entry<K,V> getRawResult() { return result; }
5702      }
5703  
5704 <    static final class MapReduceKeysTask<K,V,U>
5704 >    @SuppressWarnings("serial") static final class MapReduceKeysTask<K,V,U>
5705          extends BulkTask<K,V,U> {
5706          final Fun<? super K, ? extends U> transformer;
5707          final BiFun<? super U, ? super U, ? extends U> reducer;
5708          U result;
5709 <        MapReduceKeysTask<K,V,U> sibling;
5599 <        MapReduceKeysTask
5600 <            (ConcurrentHashMapV8<K,V> m,
5601 <             Fun<? super K, ? extends U> transformer,
5602 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5603 <            super(m);
5604 <            this.transformer = transformer;
5605 <            this.reducer = reducer;
5606 <        }
5709 >        MapReduceKeysTask<K,V,U> rights, nextRight;
5710          MapReduceKeysTask
5711 <            (BulkTask<K,V,?> p, int b, boolean split,
5711 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5712 >             MapReduceKeysTask<K,V,U> nextRight,
5713               Fun<? super K, ? extends U> transformer,
5714               BiFun<? super U, ? super U, ? extends U> reducer) {
5715 <            super(p, b, split);
5715 >            super(m, p, b); this.nextRight = nextRight;
5716              this.transformer = transformer;
5717              this.reducer = reducer;
5718          }
5719 <        public final void compute() {
5616 <            MapReduceKeysTask<K,V,U> t = this;
5719 >        @SuppressWarnings("unchecked") public final boolean exec() {
5720              final Fun<? super K, ? extends U> transformer =
5721                  this.transformer;
5722              final BiFun<? super U, ? super U, ? extends U> reducer =
5723                  this.reducer;
5724              if (transformer == null || reducer == null)
5725 <                throw new Error(NullFunctionMessage);
5726 <            int b = batch();
5727 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5728 <                b >>>= 1;
5729 <                t.pending = 1;
5730 <                MapReduceKeysTask<K,V,U> rt =
5731 <                    new MapReduceKeysTask<K,V,U>
5732 <                    (t, b, true, transformer, reducer);
5733 <                t = new MapReduceKeysTask<K,V,U>
5734 <                    (t, b, false, transformer, reducer);
5632 <                t.sibling = rt;
5633 <                rt.sibling = t;
5634 <                rt.fork();
5635 <            }
5636 <            U r = null, u;
5637 <            while (t.advance() != null) {
5638 <                if ((u = transformer.apply((K)t.nextKey)) != null)
5639 <                    r = (r == null) ? u : reducer.apply(r, u);
5640 <            }
5641 <            t.result = r;
5642 <            for (;;) {
5643 <                int c; BulkTask<K,V,?> par; MapReduceKeysTask<K,V,U> s, p;
5644 <                if ((par = t.parent) == null ||
5645 <                    !(par instanceof MapReduceKeysTask)) {
5646 <                    t.quietlyComplete();
5647 <                    break;
5648 <                }
5649 <                else if ((c = (p = (MapReduceKeysTask<K,V,U>)par).pending) == 0) {
5650 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5725 >                return abortOnNullFunction();
5726 >            try {
5727 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5728 >                    do {} while (!casPending(c = pending, c+1));
5729 >                    (rights = new MapReduceKeysTask<K,V,U>
5730 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5731 >                }
5732 >                U r = null, u;
5733 >                while (advance() != null) {
5734 >                    if ((u = transformer.apply((K)nextKey)) != null)
5735                          r = (r == null) ? u : reducer.apply(r, u);
5652                    (t = p).result = r;
5736                  }
5737 <                else if (p.casPending(c, 0))
5738 <                    break;
5737 >                result = r;
5738 >                for (MapReduceKeysTask<K,V,U> t = this, s;;) {
5739 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5740 >                    if ((c = t.pending) == 0) {
5741 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5742 >                            if ((sr = s.result) != null)
5743 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5744 >                        }
5745 >                        if ((par = t.parent) == null ||
5746 >                            !(par instanceof MapReduceKeysTask)) {
5747 >                            t.quietlyComplete();
5748 >                            break;
5749 >                        }
5750 >                        t = (MapReduceKeysTask<K,V,U>)par;
5751 >                    }
5752 >                    else if (t.casPending(c, c - 1))
5753 >                        break;
5754 >                }
5755 >            } catch (Throwable ex) {
5756 >                return tryCompleteComputation(ex);
5757 >            }
5758 >            MapReduceKeysTask<K,V,U> s = rights;
5759 >            if (s != null && !inForkJoinPool()) {
5760 >                do  {
5761 >                    if (s.tryUnfork())
5762 >                        s.exec();
5763 >                } while ((s = s.nextRight) != null);
5764              }
5765 +            return false;
5766          }
5767          public final U getRawResult() { return result; }
5768      }
5769  
5770 <    static final class MapReduceValuesTask<K,V,U>
5770 >    @SuppressWarnings("serial") static final class MapReduceValuesTask<K,V,U>
5771          extends BulkTask<K,V,U> {
5772          final Fun<? super V, ? extends U> transformer;
5773          final BiFun<? super U, ? super U, ? extends U> reducer;
5774          U result;
5775 <        MapReduceValuesTask<K,V,U> sibling;
5667 <        MapReduceValuesTask
5668 <            (ConcurrentHashMapV8<K,V> m,
5669 <             Fun<? super V, ? extends U> transformer,
5670 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5671 <            super(m);
5672 <            this.transformer = transformer;
5673 <            this.reducer = reducer;
5674 <        }
5775 >        MapReduceValuesTask<K,V,U> rights, nextRight;
5776          MapReduceValuesTask
5777 <            (BulkTask<K,V,?> p, int b, boolean split,
5777 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5778 >             MapReduceValuesTask<K,V,U> nextRight,
5779               Fun<? super V, ? extends U> transformer,
5780               BiFun<? super U, ? super U, ? extends U> reducer) {
5781 <            super(p, b, split);
5781 >            super(m, p, b); this.nextRight = nextRight;
5782              this.transformer = transformer;
5783              this.reducer = reducer;
5784          }
5785 <        public final void compute() {
5684 <            MapReduceValuesTask<K,V,U> t = this;
5785 >        @SuppressWarnings("unchecked") public final boolean exec() {
5786              final Fun<? super V, ? extends U> transformer =
5787                  this.transformer;
5788              final BiFun<? super U, ? super U, ? extends U> reducer =
5789                  this.reducer;
5790              if (transformer == null || reducer == null)
5791 <                throw new Error(NullFunctionMessage);
5792 <            int b = batch();
5793 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5794 <                b >>>= 1;
5795 <                t.pending = 1;
5796 <                MapReduceValuesTask<K,V,U> rt =
5797 <                    new MapReduceValuesTask<K,V,U>
5798 <                    (t, b, true, transformer, reducer);
5799 <                t = new MapReduceValuesTask<K,V,U>
5800 <                    (t, b, false, transformer, reducer);
5801 <                t.sibling = rt;
5701 <                rt.sibling = t;
5702 <                rt.fork();
5703 <            }
5704 <            U r = null, u;
5705 <            Object v;
5706 <            while ((v = t.advance()) != null) {
5707 <                if ((u = transformer.apply((V)v)) != null)
5708 <                    r = (r == null) ? u : reducer.apply(r, u);
5709 <            }
5710 <            t.result = r;
5711 <            for (;;) {
5712 <                int c; BulkTask<K,V,?> par; MapReduceValuesTask<K,V,U> s, p;
5713 <                if ((par = t.parent) == null ||
5714 <                    !(par instanceof MapReduceValuesTask)) {
5715 <                    t.quietlyComplete();
5716 <                    break;
5717 <                }
5718 <                else if ((c = (p = (MapReduceValuesTask<K,V,U>)par).pending) == 0) {
5719 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5791 >                return abortOnNullFunction();
5792 >            try {
5793 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5794 >                    do {} while (!casPending(c = pending, c+1));
5795 >                    (rights = new MapReduceValuesTask<K,V,U>
5796 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5797 >                }
5798 >                U r = null, u;
5799 >                Object v;
5800 >                while ((v = advance()) != null) {
5801 >                    if ((u = transformer.apply((V)v)) != null)
5802                          r = (r == null) ? u : reducer.apply(r, u);
5721                    (t = p).result = r;
5803                  }
5804 <                else if (p.casPending(c, 0))
5805 <                    break;
5804 >                result = r;
5805 >                for (MapReduceValuesTask<K,V,U> t = this, s;;) {
5806 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5807 >                    if ((c = t.pending) == 0) {
5808 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5809 >                            if ((sr = s.result) != null)
5810 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5811 >                        }
5812 >                        if ((par = t.parent) == null ||
5813 >                            !(par instanceof MapReduceValuesTask)) {
5814 >                            t.quietlyComplete();
5815 >                            break;
5816 >                        }
5817 >                        t = (MapReduceValuesTask<K,V,U>)par;
5818 >                    }
5819 >                    else if (t.casPending(c, c - 1))
5820 >                        break;
5821 >                }
5822 >            } catch (Throwable ex) {
5823 >                return tryCompleteComputation(ex);
5824 >            }
5825 >            MapReduceValuesTask<K,V,U> s = rights;
5826 >            if (s != null && !inForkJoinPool()) {
5827 >                do  {
5828 >                    if (s.tryUnfork())
5829 >                        s.exec();
5830 >                } while ((s = s.nextRight) != null);
5831              }
5832 +            return false;
5833          }
5834          public final U getRawResult() { return result; }
5835      }
5836  
5837 <    static final class MapReduceEntriesTask<K,V,U>
5837 >    @SuppressWarnings("serial") static final class MapReduceEntriesTask<K,V,U>
5838          extends BulkTask<K,V,U> {
5839          final Fun<Map.Entry<K,V>, ? extends U> transformer;
5840          final BiFun<? super U, ? super U, ? extends U> reducer;
5841          U result;
5842 <        MapReduceEntriesTask<K,V,U> sibling;
5736 <        MapReduceEntriesTask
5737 <            (ConcurrentHashMapV8<K,V> m,
5738 <             Fun<Map.Entry<K,V>, ? extends U> transformer,
5739 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5740 <            super(m);
5741 <            this.transformer = transformer;
5742 <            this.reducer = reducer;
5743 <        }
5842 >        MapReduceEntriesTask<K,V,U> rights, nextRight;
5843          MapReduceEntriesTask
5844 <            (BulkTask<K,V,?> p, int b, boolean split,
5844 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5845 >             MapReduceEntriesTask<K,V,U> nextRight,
5846               Fun<Map.Entry<K,V>, ? extends U> transformer,
5847               BiFun<? super U, ? super U, ? extends U> reducer) {
5848 <            super(p, b, split);
5848 >            super(m, p, b); this.nextRight = nextRight;
5849              this.transformer = transformer;
5850              this.reducer = reducer;
5851          }
5852 <        public final void compute() {
5753 <            MapReduceEntriesTask<K,V,U> t = this;
5852 >        @SuppressWarnings("unchecked") public final boolean exec() {
5853              final Fun<Map.Entry<K,V>, ? extends U> transformer =
5854                  this.transformer;
5855              final BiFun<? super U, ? super U, ? extends U> reducer =
5856                  this.reducer;
5857              if (transformer == null || reducer == null)
5858 <                throw new Error(NullFunctionMessage);
5859 <            int b = batch();
5860 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5861 <                b >>>= 1;
5862 <                t.pending = 1;
5863 <                MapReduceEntriesTask<K,V,U> rt =
5864 <                    new MapReduceEntriesTask<K,V,U>
5865 <                    (t, b, true, transformer, reducer);
5866 <                t = new MapReduceEntriesTask<K,V,U>
5867 <                    (t, b, false, transformer, reducer);
5868 <                t.sibling = rt;
5770 <                rt.sibling = t;
5771 <                rt.fork();
5772 <            }
5773 <            U r = null, u;
5774 <            Object v;
5775 <            while ((v = t.advance()) != null) {
5776 <                if ((u = transformer.apply(entryFor((K)t.nextKey, (V)v))) != null)
5777 <                    r = (r == null) ? u : reducer.apply(r, u);
5778 <            }
5779 <            t.result = r;
5780 <            for (;;) {
5781 <                int c; BulkTask<K,V,?> par; MapReduceEntriesTask<K,V,U> s, p;
5782 <                if ((par = t.parent) == null ||
5783 <                    !(par instanceof MapReduceEntriesTask)) {
5784 <                    t.quietlyComplete();
5785 <                    break;
5786 <                }
5787 <                else if ((c = (p = (MapReduceEntriesTask<K,V,U>)par).pending) == 0) {
5788 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5858 >                return abortOnNullFunction();
5859 >            try {
5860 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5861 >                    do {} while (!casPending(c = pending, c+1));
5862 >                    (rights = new MapReduceEntriesTask<K,V,U>
5863 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5864 >                }
5865 >                U r = null, u;
5866 >                Object v;
5867 >                while ((v = advance()) != null) {
5868 >                    if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5869                          r = (r == null) ? u : reducer.apply(r, u);
5790                    (t = p).result = r;
5870                  }
5871 <                else if (p.casPending(c, 0))
5872 <                    break;
5871 >                result = r;
5872 >                for (MapReduceEntriesTask<K,V,U> t = this, s;;) {
5873 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5874 >                    if ((c = t.pending) == 0) {
5875 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5876 >                            if ((sr = s.result) != null)
5877 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5878 >                        }
5879 >                        if ((par = t.parent) == null ||
5880 >                            !(par instanceof MapReduceEntriesTask)) {
5881 >                            t.quietlyComplete();
5882 >                            break;
5883 >                        }
5884 >                        t = (MapReduceEntriesTask<K,V,U>)par;
5885 >                    }
5886 >                    else if (t.casPending(c, c - 1))
5887 >                        break;
5888 >                }
5889 >            } catch (Throwable ex) {
5890 >                return tryCompleteComputation(ex);
5891 >            }
5892 >            MapReduceEntriesTask<K,V,U> s = rights;
5893 >            if (s != null && !inForkJoinPool()) {
5894 >                do  {
5895 >                    if (s.tryUnfork())
5896 >                        s.exec();
5897 >                } while ((s = s.nextRight) != null);
5898              }
5899 +            return false;
5900          }
5901          public final U getRawResult() { return result; }
5902      }
5903  
5904 <    static final class MapReduceMappingsTask<K,V,U>
5904 >    @SuppressWarnings("serial") static final class MapReduceMappingsTask<K,V,U>
5905          extends BulkTask<K,V,U> {
5906          final BiFun<? super K, ? super V, ? extends U> transformer;
5907          final BiFun<? super U, ? super U, ? extends U> reducer;
5908          U result;
5909 <        MapReduceMappingsTask<K,V,U> sibling;
5909 >        MapReduceMappingsTask<K,V,U> rights, nextRight;
5910          MapReduceMappingsTask
5911 <            (ConcurrentHashMapV8<K,V> m,
5911 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5912 >             MapReduceMappingsTask<K,V,U> nextRight,
5913               BiFun<? super K, ? super V, ? extends U> transformer,
5914               BiFun<? super U, ? super U, ? extends U> reducer) {
5915 <            super(m);
5915 >            super(m, p, b); this.nextRight = nextRight;
5916              this.transformer = transformer;
5917              this.reducer = reducer;
5918          }
5919 <        MapReduceMappingsTask
5814 <            (BulkTask<K,V,?> p, int b, boolean split,
5815 <             BiFun<? super K, ? super V, ? extends U> transformer,
5816 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5817 <            super(p, b, split);
5818 <            this.transformer = transformer;
5819 <            this.reducer = reducer;
5820 <        }
5821 <        public final void compute() {
5822 <            MapReduceMappingsTask<K,V,U> t = this;
5919 >        @SuppressWarnings("unchecked") public final boolean exec() {
5920              final BiFun<? super K, ? super V, ? extends U> transformer =
5921                  this.transformer;
5922              final BiFun<? super U, ? super U, ? extends U> reducer =
5923                  this.reducer;
5924              if (transformer == null || reducer == null)
5925 <                throw new Error(NullFunctionMessage);
5926 <            int b = batch();
5927 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5928 <                b >>>= 1;
5929 <                t.pending = 1;
5930 <                MapReduceMappingsTask<K,V,U> rt =
5931 <                    new MapReduceMappingsTask<K,V,U>
5932 <                    (t, b, true, transformer, reducer);
5933 <                t = new MapReduceMappingsTask<K,V,U>
5934 <                    (t, b, false, transformer, reducer);
5935 <                t.sibling = rt;
5839 <                rt.sibling = t;
5840 <                rt.fork();
5841 <            }
5842 <            U r = null, u;
5843 <            Object v;
5844 <            while ((v = t.advance()) != null) {
5845 <                if ((u = transformer.apply((K)t.nextKey, (V)v)) != null)
5846 <                    r = (r == null) ? u : reducer.apply(r, u);
5847 <            }
5848 <            for (;;) {
5849 <                int c; BulkTask<K,V,?> par; MapReduceMappingsTask<K,V,U> s, p;
5850 <                if ((par = t.parent) == null ||
5851 <                    !(par instanceof MapReduceMappingsTask)) {
5852 <                    t.quietlyComplete();
5853 <                    break;
5854 <                }
5855 <                else if ((c = (p = (MapReduceMappingsTask<K,V,U>)par).pending) == 0) {
5856 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5925 >                return abortOnNullFunction();
5926 >            try {
5927 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5928 >                    do {} while (!casPending(c = pending, c+1));
5929 >                    (rights = new MapReduceMappingsTask<K,V,U>
5930 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5931 >                }
5932 >                U r = null, u;
5933 >                Object v;
5934 >                while ((v = advance()) != null) {
5935 >                    if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5936                          r = (r == null) ? u : reducer.apply(r, u);
5858                    (t = p).result = r;
5937                  }
5938 <                else if (p.casPending(c, 0))
5939 <                    break;
5938 >                result = r;
5939 >                for (MapReduceMappingsTask<K,V,U> t = this, s;;) {
5940 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5941 >                    if ((c = t.pending) == 0) {
5942 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5943 >                            if ((sr = s.result) != null)
5944 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5945 >                        }
5946 >                        if ((par = t.parent) == null ||
5947 >                            !(par instanceof MapReduceMappingsTask)) {
5948 >                            t.quietlyComplete();
5949 >                            break;
5950 >                        }
5951 >                        t = (MapReduceMappingsTask<K,V,U>)par;
5952 >                    }
5953 >                    else if (t.casPending(c, c - 1))
5954 >                        break;
5955 >                }
5956 >            } catch (Throwable ex) {
5957 >                return tryCompleteComputation(ex);
5958              }
5959 +            MapReduceMappingsTask<K,V,U> s = rights;
5960 +            if (s != null && !inForkJoinPool()) {
5961 +                do  {
5962 +                    if (s.tryUnfork())
5963 +                        s.exec();
5964 +                } while ((s = s.nextRight) != null);
5965 +            }
5966 +            return false;
5967          }
5968          public final U getRawResult() { return result; }
5969      }
5970  
5971 <    static final class MapReduceKeysToDoubleTask<K,V>
5971 >    @SuppressWarnings("serial") static final class MapReduceKeysToDoubleTask<K,V>
5972          extends BulkTask<K,V,Double> {
5973          final ObjectToDouble<? super K> transformer;
5974          final DoubleByDoubleToDouble reducer;
5975          final double basis;
5976          double result;
5977 <        MapReduceKeysToDoubleTask<K,V> sibling;
5874 <        MapReduceKeysToDoubleTask
5875 <            (ConcurrentHashMapV8<K,V> m,
5876 <             ObjectToDouble<? super K> transformer,
5877 <             double basis,
5878 <             DoubleByDoubleToDouble reducer) {
5879 <            super(m);
5880 <            this.transformer = transformer;
5881 <            this.basis = basis; this.reducer = reducer;
5882 <        }
5977 >        MapReduceKeysToDoubleTask<K,V> rights, nextRight;
5978          MapReduceKeysToDoubleTask
5979 <            (BulkTask<K,V,?> p, int b, boolean split,
5979 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5980 >             MapReduceKeysToDoubleTask<K,V> nextRight,
5981               ObjectToDouble<? super K> transformer,
5982               double basis,
5983               DoubleByDoubleToDouble reducer) {
5984 <            super(p, b, split);
5984 >            super(m, p, b); this.nextRight = nextRight;
5985              this.transformer = transformer;
5986              this.basis = basis; this.reducer = reducer;
5987          }
5988 <        public final void compute() {
5893 <            MapReduceKeysToDoubleTask<K,V> t = this;
5988 >        @SuppressWarnings("unchecked") public final boolean exec() {
5989              final ObjectToDouble<? super K> transformer =
5990                  this.transformer;
5991              final DoubleByDoubleToDouble reducer = this.reducer;
5992              if (transformer == null || reducer == null)
5993 <                throw new Error(NullFunctionMessage);
5994 <            final double id = this.basis;
5995 <            int b = batch();
5996 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5997 <                b >>>= 1;
5998 <                t.pending = 1;
5999 <                MapReduceKeysToDoubleTask<K,V> rt =
6000 <                    new MapReduceKeysToDoubleTask<K,V>
6001 <                    (t, b, true, transformer, id, reducer);
6002 <                t = new MapReduceKeysToDoubleTask<K,V>
6003 <                    (t, b, false, transformer, id, reducer);
6004 <                t.sibling = rt;
6005 <                rt.sibling = t;
6006 <                rt.fork();
6007 <            }
6008 <            double r = id;
6009 <            while (t.advance() != null)
6010 <                r = reducer.apply(r, transformer.apply((K)t.nextKey));
6011 <            t.result = r;
6012 <            for (;;) {
6013 <                int c; BulkTask<K,V,?> par; MapReduceKeysToDoubleTask<K,V> s, p;
6014 <                if ((par = t.parent) == null ||
6015 <                    !(par instanceof MapReduceKeysToDoubleTask)) {
6016 <                    t.quietlyComplete();
6017 <                    break;
6018 <                }
6019 <                else if ((c = (p = (MapReduceKeysToDoubleTask<K,V>)par).pending) == 0) {
5925 <                    if ((s = t.sibling) != null)
5926 <                        r = reducer.apply(r, s.result);
5927 <                    (t = p).result = r;
5993 >                return abortOnNullFunction();
5994 >            try {
5995 >                final double id = this.basis;
5996 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5997 >                    do {} while (!casPending(c = pending, c+1));
5998 >                    (rights = new MapReduceKeysToDoubleTask<K,V>
5999 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6000 >                }
6001 >                double r = id;
6002 >                while (advance() != null)
6003 >                    r = reducer.apply(r, transformer.apply((K)nextKey));
6004 >                result = r;
6005 >                for (MapReduceKeysToDoubleTask<K,V> t = this, s;;) {
6006 >                    int c; BulkTask<K,V,?> par;
6007 >                    if ((c = t.pending) == 0) {
6008 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6009 >                            t.result = reducer.apply(t.result, s.result);
6010 >                        }
6011 >                        if ((par = t.parent) == null ||
6012 >                            !(par instanceof MapReduceKeysToDoubleTask)) {
6013 >                            t.quietlyComplete();
6014 >                            break;
6015 >                        }
6016 >                        t = (MapReduceKeysToDoubleTask<K,V>)par;
6017 >                    }
6018 >                    else if (t.casPending(c, c - 1))
6019 >                        break;
6020                  }
6021 <                else if (p.casPending(c, 0))
6022 <                    break;
6021 >            } catch (Throwable ex) {
6022 >                return tryCompleteComputation(ex);
6023              }
6024 +            MapReduceKeysToDoubleTask<K,V> s = rights;
6025 +            if (s != null && !inForkJoinPool()) {
6026 +                do  {
6027 +                    if (s.tryUnfork())
6028 +                        s.exec();
6029 +                } while ((s = s.nextRight) != null);
6030 +            }
6031 +            return false;
6032          }
6033          public final Double getRawResult() { return result; }
6034      }
6035  
6036 <    static final class MapReduceValuesToDoubleTask<K,V>
6036 >    @SuppressWarnings("serial") static final class MapReduceValuesToDoubleTask<K,V>
6037          extends BulkTask<K,V,Double> {
6038          final ObjectToDouble<? super V> transformer;
6039          final DoubleByDoubleToDouble reducer;
6040          final double basis;
6041          double result;
6042 <        MapReduceValuesToDoubleTask<K,V> sibling;
5943 <        MapReduceValuesToDoubleTask
5944 <            (ConcurrentHashMapV8<K,V> m,
5945 <             ObjectToDouble<? super V> transformer,
5946 <             double basis,
5947 <             DoubleByDoubleToDouble reducer) {
5948 <            super(m);
5949 <            this.transformer = transformer;
5950 <            this.basis = basis; this.reducer = reducer;
5951 <        }
6042 >        MapReduceValuesToDoubleTask<K,V> rights, nextRight;
6043          MapReduceValuesToDoubleTask
6044 <            (BulkTask<K,V,?> p, int b, boolean split,
6044 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6045 >             MapReduceValuesToDoubleTask<K,V> nextRight,
6046               ObjectToDouble<? super V> transformer,
6047               double basis,
6048               DoubleByDoubleToDouble reducer) {
6049 <            super(p, b, split);
6049 >            super(m, p, b); this.nextRight = nextRight;
6050              this.transformer = transformer;
6051              this.basis = basis; this.reducer = reducer;
6052          }
6053 <        public final void compute() {
5962 <            MapReduceValuesToDoubleTask<K,V> t = this;
6053 >        @SuppressWarnings("unchecked") public final boolean exec() {
6054              final ObjectToDouble<? super V> transformer =
6055                  this.transformer;
6056              final DoubleByDoubleToDouble reducer = this.reducer;
6057              if (transformer == null || reducer == null)
6058 <                throw new Error(NullFunctionMessage);
6059 <            final double id = this.basis;
6060 <            int b = batch();
6061 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6062 <                b >>>= 1;
6063 <                t.pending = 1;
6064 <                MapReduceValuesToDoubleTask<K,V> rt =
6065 <                    new MapReduceValuesToDoubleTask<K,V>
6066 <                    (t, b, true, transformer, id, reducer);
6067 <                t = new MapReduceValuesToDoubleTask<K,V>
6068 <                    (t, b, false, transformer, id, reducer);
6069 <                t.sibling = rt;
6070 <                rt.sibling = t;
6071 <                rt.fork();
6072 <            }
6073 <            double r = id;
6074 <            Object v;
6075 <            while ((v = t.advance()) != null)
6076 <                r = reducer.apply(r, transformer.apply((V)v));
6077 <            t.result = r;
6078 <            for (;;) {
6079 <                int c; BulkTask<K,V,?> par; MapReduceValuesToDoubleTask<K,V> s, p;
6080 <                if ((par = t.parent) == null ||
6081 <                    !(par instanceof MapReduceValuesToDoubleTask)) {
6082 <                    t.quietlyComplete();
6083 <                    break;
6084 <                }
6085 <                else if ((c = (p = (MapReduceValuesToDoubleTask<K,V>)par).pending) == 0) {
5995 <                    if ((s = t.sibling) != null)
5996 <                        r = reducer.apply(r, s.result);
5997 <                    (t = p).result = r;
6058 >                return abortOnNullFunction();
6059 >            try {
6060 >                final double id = this.basis;
6061 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6062 >                    do {} while (!casPending(c = pending, c+1));
6063 >                    (rights = new MapReduceValuesToDoubleTask<K,V>
6064 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6065 >                }
6066 >                double r = id;
6067 >                Object v;
6068 >                while ((v = advance()) != null)
6069 >                    r = reducer.apply(r, transformer.apply((V)v));
6070 >                result = r;
6071 >                for (MapReduceValuesToDoubleTask<K,V> t = this, s;;) {
6072 >                    int c; BulkTask<K,V,?> par;
6073 >                    if ((c = t.pending) == 0) {
6074 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6075 >                            t.result = reducer.apply(t.result, s.result);
6076 >                        }
6077 >                        if ((par = t.parent) == null ||
6078 >                            !(par instanceof MapReduceValuesToDoubleTask)) {
6079 >                            t.quietlyComplete();
6080 >                            break;
6081 >                        }
6082 >                        t = (MapReduceValuesToDoubleTask<K,V>)par;
6083 >                    }
6084 >                    else if (t.casPending(c, c - 1))
6085 >                        break;
6086                  }
6087 <                else if (p.casPending(c, 0))
6088 <                    break;
6087 >            } catch (Throwable ex) {
6088 >                return tryCompleteComputation(ex);
6089              }
6090 +            MapReduceValuesToDoubleTask<K,V> s = rights;
6091 +            if (s != null && !inForkJoinPool()) {
6092 +                do  {
6093 +                    if (s.tryUnfork())
6094 +                        s.exec();
6095 +                } while ((s = s.nextRight) != null);
6096 +            }
6097 +            return false;
6098          }
6099          public final Double getRawResult() { return result; }
6100      }
6101  
6102 <    static final class MapReduceEntriesToDoubleTask<K,V>
6102 >    @SuppressWarnings("serial") static final class MapReduceEntriesToDoubleTask<K,V>
6103          extends BulkTask<K,V,Double> {
6104          final ObjectToDouble<Map.Entry<K,V>> transformer;
6105          final DoubleByDoubleToDouble reducer;
6106          final double basis;
6107          double result;
6108 <        MapReduceEntriesToDoubleTask<K,V> sibling;
6013 <        MapReduceEntriesToDoubleTask
6014 <            (ConcurrentHashMapV8<K,V> m,
6015 <             ObjectToDouble<Map.Entry<K,V>> transformer,
6016 <             double basis,
6017 <             DoubleByDoubleToDouble reducer) {
6018 <            super(m);
6019 <            this.transformer = transformer;
6020 <            this.basis = basis; this.reducer = reducer;
6021 <        }
6108 >        MapReduceEntriesToDoubleTask<K,V> rights, nextRight;
6109          MapReduceEntriesToDoubleTask
6110 <            (BulkTask<K,V,?> p, int b, boolean split,
6110 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6111 >             MapReduceEntriesToDoubleTask<K,V> nextRight,
6112               ObjectToDouble<Map.Entry<K,V>> transformer,
6113               double basis,
6114               DoubleByDoubleToDouble reducer) {
6115 <            super(p, b, split);
6115 >            super(m, p, b); this.nextRight = nextRight;
6116              this.transformer = transformer;
6117              this.basis = basis; this.reducer = reducer;
6118          }
6119 <        public final void compute() {
6032 <            MapReduceEntriesToDoubleTask<K,V> t = this;
6119 >        @SuppressWarnings("unchecked") public final boolean exec() {
6120              final ObjectToDouble<Map.Entry<K,V>> transformer =
6121                  this.transformer;
6122              final DoubleByDoubleToDouble reducer = this.reducer;
6123              if (transformer == null || reducer == null)
6124 <                throw new Error(NullFunctionMessage);
6125 <            final double id = this.basis;
6126 <            int b = batch();
6127 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6128 <                b >>>= 1;
6129 <                t.pending = 1;
6130 <                MapReduceEntriesToDoubleTask<K,V> rt =
6131 <                    new MapReduceEntriesToDoubleTask<K,V>
6132 <                    (t, b, true, transformer, id, reducer);
6133 <                t = new MapReduceEntriesToDoubleTask<K,V>
6134 <                    (t, b, false, transformer, id, reducer);
6135 <                t.sibling = rt;
6136 <                rt.sibling = t;
6137 <                rt.fork();
6138 <            }
6139 <            double r = id;
6140 <            Object v;
6141 <            while ((v = t.advance()) != null)
6142 <                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6143 <            t.result = r;
6144 <            for (;;) {
6145 <                int c; BulkTask<K,V,?> par; MapReduceEntriesToDoubleTask<K,V> s, p;
6146 <                if ((par = t.parent) == null ||
6147 <                    !(par instanceof MapReduceEntriesToDoubleTask)) {
6148 <                    t.quietlyComplete();
6149 <                    break;
6150 <                }
6151 <                else if ((c = (p = (MapReduceEntriesToDoubleTask<K,V>)par).pending) == 0) {
6065 <                    if ((s = t.sibling) != null)
6066 <                        r = reducer.apply(r, s.result);
6067 <                    (t = p).result = r;
6124 >                return abortOnNullFunction();
6125 >            try {
6126 >                final double id = this.basis;
6127 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6128 >                    do {} while (!casPending(c = pending, c+1));
6129 >                    (rights = new MapReduceEntriesToDoubleTask<K,V>
6130 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6131 >                }
6132 >                double r = id;
6133 >                Object v;
6134 >                while ((v = advance()) != null)
6135 >                    r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v)));
6136 >                result = r;
6137 >                for (MapReduceEntriesToDoubleTask<K,V> t = this, s;;) {
6138 >                    int c; BulkTask<K,V,?> par;
6139 >                    if ((c = t.pending) == 0) {
6140 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6141 >                            t.result = reducer.apply(t.result, s.result);
6142 >                        }
6143 >                        if ((par = t.parent) == null ||
6144 >                            !(par instanceof MapReduceEntriesToDoubleTask)) {
6145 >                            t.quietlyComplete();
6146 >                            break;
6147 >                        }
6148 >                        t = (MapReduceEntriesToDoubleTask<K,V>)par;
6149 >                    }
6150 >                    else if (t.casPending(c, c - 1))
6151 >                        break;
6152                  }
6153 <                else if (p.casPending(c, 0))
6154 <                    break;
6153 >            } catch (Throwable ex) {
6154 >                return tryCompleteComputation(ex);
6155 >            }
6156 >            MapReduceEntriesToDoubleTask<K,V> s = rights;
6157 >            if (s != null && !inForkJoinPool()) {
6158 >                do  {
6159 >                    if (s.tryUnfork())
6160 >                        s.exec();
6161 >                } while ((s = s.nextRight) != null);
6162              }
6163 +            return false;
6164          }
6165          public final Double getRawResult() { return result; }
6166      }
6167  
6168 <    static final class MapReduceMappingsToDoubleTask<K,V>
6168 >    @SuppressWarnings("serial") static final class MapReduceMappingsToDoubleTask<K,V>
6169          extends BulkTask<K,V,Double> {
6170          final ObjectByObjectToDouble<? super K, ? super V> transformer;
6171          final DoubleByDoubleToDouble reducer;
6172          final double basis;
6173          double result;
6174 <        MapReduceMappingsToDoubleTask<K,V> sibling;
6083 <        MapReduceMappingsToDoubleTask
6084 <            (ConcurrentHashMapV8<K,V> m,
6085 <             ObjectByObjectToDouble<? super K, ? super V> transformer,
6086 <             double basis,
6087 <             DoubleByDoubleToDouble reducer) {
6088 <            super(m);
6089 <            this.transformer = transformer;
6090 <            this.basis = basis; this.reducer = reducer;
6091 <        }
6174 >        MapReduceMappingsToDoubleTask<K,V> rights, nextRight;
6175          MapReduceMappingsToDoubleTask
6176 <            (BulkTask<K,V,?> p, int b, boolean split,
6176 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6177 >             MapReduceMappingsToDoubleTask<K,V> nextRight,
6178               ObjectByObjectToDouble<? super K, ? super V> transformer,
6179               double basis,
6180               DoubleByDoubleToDouble reducer) {
6181 <            super(p, b, split);
6181 >            super(m, p, b); this.nextRight = nextRight;
6182              this.transformer = transformer;
6183              this.basis = basis; this.reducer = reducer;
6184          }
6185 <        public final void compute() {
6102 <            MapReduceMappingsToDoubleTask<K,V> t = this;
6185 >        @SuppressWarnings("unchecked") public final boolean exec() {
6186              final ObjectByObjectToDouble<? super K, ? super V> transformer =
6187                  this.transformer;
6188              final DoubleByDoubleToDouble reducer = this.reducer;
6189              if (transformer == null || reducer == null)
6190 <                throw new Error(NullFunctionMessage);
6191 <            final double id = this.basis;
6192 <            int b = batch();
6193 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6194 <                b >>>= 1;
6195 <                t.pending = 1;
6196 <                MapReduceMappingsToDoubleTask<K,V> rt =
6197 <                    new MapReduceMappingsToDoubleTask<K,V>
6198 <                    (t, b, true, transformer, id, reducer);
6199 <                t = new MapReduceMappingsToDoubleTask<K,V>
6200 <                    (t, b, false, transformer, id, reducer);
6201 <                t.sibling = rt;
6202 <                rt.sibling = t;
6203 <                rt.fork();
6204 <            }
6205 <            double r = id;
6206 <            Object v;
6207 <            while ((v = t.advance()) != null)
6208 <                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6209 <            t.result = r;
6210 <            for (;;) {
6211 <                int c; BulkTask<K,V,?> par; MapReduceMappingsToDoubleTask<K,V> s, p;
6212 <                if ((par = t.parent) == null ||
6213 <                    !(par instanceof MapReduceMappingsToDoubleTask)) {
6214 <                    t.quietlyComplete();
6215 <                    break;
6216 <                }
6217 <                else if ((c = (p = (MapReduceMappingsToDoubleTask<K,V>)par).pending) == 0) {
6135 <                    if ((s = t.sibling) != null)
6136 <                        r = reducer.apply(r, s.result);
6137 <                    (t = p).result = r;
6190 >                return abortOnNullFunction();
6191 >            try {
6192 >                final double id = this.basis;
6193 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6194 >                    do {} while (!casPending(c = pending, c+1));
6195 >                    (rights = new MapReduceMappingsToDoubleTask<K,V>
6196 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6197 >                }
6198 >                double r = id;
6199 >                Object v;
6200 >                while ((v = advance()) != null)
6201 >                    r = reducer.apply(r, transformer.apply((K)nextKey, (V)v));
6202 >                result = r;
6203 >                for (MapReduceMappingsToDoubleTask<K,V> t = this, s;;) {
6204 >                    int c; BulkTask<K,V,?> par;
6205 >                    if ((c = t.pending) == 0) {
6206 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6207 >                            t.result = reducer.apply(t.result, s.result);
6208 >                        }
6209 >                        if ((par = t.parent) == null ||
6210 >                            !(par instanceof MapReduceMappingsToDoubleTask)) {
6211 >                            t.quietlyComplete();
6212 >                            break;
6213 >                        }
6214 >                        t = (MapReduceMappingsToDoubleTask<K,V>)par;
6215 >                    }
6216 >                    else if (t.casPending(c, c - 1))
6217 >                        break;
6218                  }
6219 <                else if (p.casPending(c, 0))
6220 <                    break;
6219 >            } catch (Throwable ex) {
6220 >                return tryCompleteComputation(ex);
6221 >            }
6222 >            MapReduceMappingsToDoubleTask<K,V> s = rights;
6223 >            if (s != null && !inForkJoinPool()) {
6224 >                do  {
6225 >                    if (s.tryUnfork())
6226 >                        s.exec();
6227 >                } while ((s = s.nextRight) != null);
6228              }
6229 +            return false;
6230          }
6231          public final Double getRawResult() { return result; }
6232      }
6233  
6234 <    static final class MapReduceKeysToLongTask<K,V>
6234 >    @SuppressWarnings("serial") static final class MapReduceKeysToLongTask<K,V>
6235          extends BulkTask<K,V,Long> {
6236          final ObjectToLong<? super K> transformer;
6237          final LongByLongToLong reducer;
6238          final long basis;
6239          long result;
6240 <        MapReduceKeysToLongTask<K,V> sibling;
6153 <        MapReduceKeysToLongTask
6154 <            (ConcurrentHashMapV8<K,V> m,
6155 <             ObjectToLong<? super K> transformer,
6156 <             long basis,
6157 <             LongByLongToLong reducer) {
6158 <            super(m);
6159 <            this.transformer = transformer;
6160 <            this.basis = basis; this.reducer = reducer;
6161 <        }
6240 >        MapReduceKeysToLongTask<K,V> rights, nextRight;
6241          MapReduceKeysToLongTask
6242 <            (BulkTask<K,V,?> p, int b, boolean split,
6242 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6243 >             MapReduceKeysToLongTask<K,V> nextRight,
6244               ObjectToLong<? super K> transformer,
6245               long basis,
6246               LongByLongToLong reducer) {
6247 <            super(p, b, split);
6247 >            super(m, p, b); this.nextRight = nextRight;
6248              this.transformer = transformer;
6249              this.basis = basis; this.reducer = reducer;
6250          }
6251 <        public final void compute() {
6172 <            MapReduceKeysToLongTask<K,V> t = this;
6251 >        @SuppressWarnings("unchecked") public final boolean exec() {
6252              final ObjectToLong<? super K> transformer =
6253                  this.transformer;
6254              final LongByLongToLong reducer = this.reducer;
6255              if (transformer == null || reducer == null)
6256 <                throw new Error(NullFunctionMessage);
6257 <            final long id = this.basis;
6258 <            int b = batch();
6259 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6260 <                b >>>= 1;
6261 <                t.pending = 1;
6262 <                MapReduceKeysToLongTask<K,V> rt =
6263 <                    new MapReduceKeysToLongTask<K,V>
6264 <                    (t, b, true, transformer, id, reducer);
6265 <                t = new MapReduceKeysToLongTask<K,V>
6266 <                    (t, b, false, transformer, id, reducer);
6267 <                t.sibling = rt;
6268 <                rt.sibling = t;
6269 <                rt.fork();
6270 <            }
6271 <            long r = id;
6272 <            while (t.advance() != null)
6273 <                r = reducer.apply(r, transformer.apply((K)t.nextKey));
6274 <            t.result = r;
6275 <            for (;;) {
6276 <                int c; BulkTask<K,V,?> par; MapReduceKeysToLongTask<K,V> s, p;
6277 <                if ((par = t.parent) == null ||
6278 <                    !(par instanceof MapReduceKeysToLongTask)) {
6279 <                    t.quietlyComplete();
6280 <                    break;
6281 <                }
6282 <                else if ((c = (p = (MapReduceKeysToLongTask<K,V>)par).pending) == 0) {
6204 <                    if ((s = t.sibling) != null)
6205 <                        r = reducer.apply(r, s.result);
6206 <                    (t = p).result = r;
6256 >                return abortOnNullFunction();
6257 >            try {
6258 >                final long id = this.basis;
6259 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6260 >                    do {} while (!casPending(c = pending, c+1));
6261 >                    (rights = new MapReduceKeysToLongTask<K,V>
6262 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6263 >                }
6264 >                long r = id;
6265 >                while (advance() != null)
6266 >                    r = reducer.apply(r, transformer.apply((K)nextKey));
6267 >                result = r;
6268 >                for (MapReduceKeysToLongTask<K,V> t = this, s;;) {
6269 >                    int c; BulkTask<K,V,?> par;
6270 >                    if ((c = t.pending) == 0) {
6271 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6272 >                            t.result = reducer.apply(t.result, s.result);
6273 >                        }
6274 >                        if ((par = t.parent) == null ||
6275 >                            !(par instanceof MapReduceKeysToLongTask)) {
6276 >                            t.quietlyComplete();
6277 >                            break;
6278 >                        }
6279 >                        t = (MapReduceKeysToLongTask<K,V>)par;
6280 >                    }
6281 >                    else if (t.casPending(c, c - 1))
6282 >                        break;
6283                  }
6284 <                else if (p.casPending(c, 0))
6285 <                    break;
6284 >            } catch (Throwable ex) {
6285 >                return tryCompleteComputation(ex);
6286 >            }
6287 >            MapReduceKeysToLongTask<K,V> s = rights;
6288 >            if (s != null && !inForkJoinPool()) {
6289 >                do  {
6290 >                    if (s.tryUnfork())
6291 >                        s.exec();
6292 >                } while ((s = s.nextRight) != null);
6293              }
6294 +            return false;
6295          }
6296          public final Long getRawResult() { return result; }
6297      }
6298  
6299 <    static final class MapReduceValuesToLongTask<K,V>
6299 >    @SuppressWarnings("serial") static final class MapReduceValuesToLongTask<K,V>
6300          extends BulkTask<K,V,Long> {
6301          final ObjectToLong<? super V> transformer;
6302          final LongByLongToLong reducer;
6303          final long basis;
6304          long result;
6305 <        MapReduceValuesToLongTask<K,V> sibling;
6305 >        MapReduceValuesToLongTask<K,V> rights, nextRight;
6306          MapReduceValuesToLongTask
6307 <            (ConcurrentHashMapV8<K,V> m,
6307 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6308 >             MapReduceValuesToLongTask<K,V> nextRight,
6309               ObjectToLong<? super V> transformer,
6310               long basis,
6311               LongByLongToLong reducer) {
6312 <            super(m);
6312 >            super(m, p, b); this.nextRight = nextRight;
6313              this.transformer = transformer;
6314              this.basis = basis; this.reducer = reducer;
6315          }
6316 <        MapReduceValuesToLongTask
6232 <            (BulkTask<K,V,?> p, int b, boolean split,
6233 <             ObjectToLong<? super V> transformer,
6234 <             long basis,
6235 <             LongByLongToLong reducer) {
6236 <            super(p, b, split);
6237 <            this.transformer = transformer;
6238 <            this.basis = basis; this.reducer = reducer;
6239 <        }
6240 <        public final void compute() {
6241 <            MapReduceValuesToLongTask<K,V> t = this;
6316 >        @SuppressWarnings("unchecked") public final boolean exec() {
6317              final ObjectToLong<? super V> transformer =
6318                  this.transformer;
6319              final LongByLongToLong reducer = this.reducer;
6320              if (transformer == null || reducer == null)
6321 <                throw new Error(NullFunctionMessage);
6322 <            final long id = this.basis;
6323 <            int b = batch();
6324 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6325 <                b >>>= 1;
6326 <                t.pending = 1;
6327 <                MapReduceValuesToLongTask<K,V> rt =
6328 <                    new MapReduceValuesToLongTask<K,V>
6329 <                    (t, b, true, transformer, id, reducer);
6330 <                t = new MapReduceValuesToLongTask<K,V>
6331 <                    (t, b, false, transformer, id, reducer);
6332 <                t.sibling = rt;
6333 <                rt.sibling = t;
6334 <                rt.fork();
6335 <            }
6336 <            long r = id;
6337 <            Object v;
6338 <            while ((v = t.advance()) != null)
6339 <                r = reducer.apply(r, transformer.apply((V)v));
6340 <            t.result = r;
6341 <            for (;;) {
6342 <                int c; BulkTask<K,V,?> par; MapReduceValuesToLongTask<K,V> s, p;
6343 <                if ((par = t.parent) == null ||
6344 <                    !(par instanceof MapReduceValuesToLongTask)) {
6345 <                    t.quietlyComplete();
6346 <                    break;
6347 <                }
6348 <                else if ((c = (p = (MapReduceValuesToLongTask<K,V>)par).pending) == 0) {
6274 <                    if ((s = t.sibling) != null)
6275 <                        r = reducer.apply(r, s.result);
6276 <                    (t = p).result = r;
6321 >                return abortOnNullFunction();
6322 >            try {
6323 >                final long id = this.basis;
6324 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6325 >                    do {} while (!casPending(c = pending, c+1));
6326 >                    (rights = new MapReduceValuesToLongTask<K,V>
6327 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6328 >                }
6329 >                long r = id;
6330 >                Object v;
6331 >                while ((v = advance()) != null)
6332 >                    r = reducer.apply(r, transformer.apply((V)v));
6333 >                result = r;
6334 >                for (MapReduceValuesToLongTask<K,V> t = this, s;;) {
6335 >                    int c; BulkTask<K,V,?> par;
6336 >                    if ((c = t.pending) == 0) {
6337 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6338 >                            t.result = reducer.apply(t.result, s.result);
6339 >                        }
6340 >                        if ((par = t.parent) == null ||
6341 >                            !(par instanceof MapReduceValuesToLongTask)) {
6342 >                            t.quietlyComplete();
6343 >                            break;
6344 >                        }
6345 >                        t = (MapReduceValuesToLongTask<K,V>)par;
6346 >                    }
6347 >                    else if (t.casPending(c, c - 1))
6348 >                        break;
6349                  }
6350 <                else if (p.casPending(c, 0))
6351 <                    break;
6350 >            } catch (Throwable ex) {
6351 >                return tryCompleteComputation(ex);
6352              }
6353 +            MapReduceValuesToLongTask<K,V> s = rights;
6354 +            if (s != null && !inForkJoinPool()) {
6355 +                do  {
6356 +                    if (s.tryUnfork())
6357 +                        s.exec();
6358 +                } while ((s = s.nextRight) != null);
6359 +            }
6360 +            return false;
6361          }
6362          public final Long getRawResult() { return result; }
6363      }
6364  
6365 <    static final class MapReduceEntriesToLongTask<K,V>
6365 >    @SuppressWarnings("serial") static final class MapReduceEntriesToLongTask<K,V>
6366          extends BulkTask<K,V,Long> {
6367          final ObjectToLong<Map.Entry<K,V>> transformer;
6368          final LongByLongToLong reducer;
6369          final long basis;
6370          long result;
6371 <        MapReduceEntriesToLongTask<K,V> sibling;
6371 >        MapReduceEntriesToLongTask<K,V> rights, nextRight;
6372          MapReduceEntriesToLongTask
6373 <            (ConcurrentHashMapV8<K,V> m,
6373 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6374 >             MapReduceEntriesToLongTask<K,V> nextRight,
6375               ObjectToLong<Map.Entry<K,V>> transformer,
6376               long basis,
6377               LongByLongToLong reducer) {
6378 <            super(m);
6378 >            super(m, p, b); this.nextRight = nextRight;
6379              this.transformer = transformer;
6380              this.basis = basis; this.reducer = reducer;
6381          }
6382 <        MapReduceEntriesToLongTask
6302 <            (BulkTask<K,V,?> p, int b, boolean split,
6303 <             ObjectToLong<Map.Entry<K,V>> transformer,
6304 <             long basis,
6305 <             LongByLongToLong reducer) {
6306 <            super(p, b, split);
6307 <            this.transformer = transformer;
6308 <            this.basis = basis; this.reducer = reducer;
6309 <        }
6310 <        public final void compute() {
6311 <            MapReduceEntriesToLongTask<K,V> t = this;
6382 >        @SuppressWarnings("unchecked") public final boolean exec() {
6383              final ObjectToLong<Map.Entry<K,V>> transformer =
6384                  this.transformer;
6385              final LongByLongToLong reducer = this.reducer;
6386              if (transformer == null || reducer == null)
6387 <                throw new Error(NullFunctionMessage);
6388 <            final long id = this.basis;
6389 <            int b = batch();
6390 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6391 <                b >>>= 1;
6392 <                t.pending = 1;
6393 <                MapReduceEntriesToLongTask<K,V> rt =
6394 <                    new MapReduceEntriesToLongTask<K,V>
6395 <                    (t, b, true, transformer, id, reducer);
6396 <                t = new MapReduceEntriesToLongTask<K,V>
6397 <                    (t, b, false, transformer, id, reducer);
6398 <                t.sibling = rt;
6399 <                rt.sibling = t;
6400 <                rt.fork();
6401 <            }
6402 <            long r = id;
6403 <            Object v;
6404 <            while ((v = t.advance()) != null)
6405 <                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6406 <            t.result = r;
6407 <            for (;;) {
6408 <                int c; BulkTask<K,V,?> par; MapReduceEntriesToLongTask<K,V> s, p;
6409 <                if ((par = t.parent) == null ||
6410 <                    !(par instanceof MapReduceEntriesToLongTask)) {
6411 <                    t.quietlyComplete();
6412 <                    break;
6413 <                }
6414 <                else if ((c = (p = (MapReduceEntriesToLongTask<K,V>)par).pending) == 0) {
6344 <                    if ((s = t.sibling) != null)
6345 <                        r = reducer.apply(r, s.result);
6346 <                    (t = p).result = r;
6387 >                return abortOnNullFunction();
6388 >            try {
6389 >                final long id = this.basis;
6390 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6391 >                    do {} while (!casPending(c = pending, c+1));
6392 >                    (rights = new MapReduceEntriesToLongTask<K,V>
6393 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6394 >                }
6395 >                long r = id;
6396 >                Object v;
6397 >                while ((v = advance()) != null)
6398 >                    r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v)));
6399 >                result = r;
6400 >                for (MapReduceEntriesToLongTask<K,V> t = this, s;;) {
6401 >                    int c; BulkTask<K,V,?> par;
6402 >                    if ((c = t.pending) == 0) {
6403 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6404 >                            t.result = reducer.apply(t.result, s.result);
6405 >                        }
6406 >                        if ((par = t.parent) == null ||
6407 >                            !(par instanceof MapReduceEntriesToLongTask)) {
6408 >                            t.quietlyComplete();
6409 >                            break;
6410 >                        }
6411 >                        t = (MapReduceEntriesToLongTask<K,V>)par;
6412 >                    }
6413 >                    else if (t.casPending(c, c - 1))
6414 >                        break;
6415                  }
6416 <                else if (p.casPending(c, 0))
6417 <                    break;
6416 >            } catch (Throwable ex) {
6417 >                return tryCompleteComputation(ex);
6418              }
6419 +            MapReduceEntriesToLongTask<K,V> s = rights;
6420 +            if (s != null && !inForkJoinPool()) {
6421 +                do  {
6422 +                    if (s.tryUnfork())
6423 +                        s.exec();
6424 +                } while ((s = s.nextRight) != null);
6425 +            }
6426 +            return false;
6427          }
6428          public final Long getRawResult() { return result; }
6429      }
6430  
6431 <    static final class MapReduceMappingsToLongTask<K,V>
6431 >    @SuppressWarnings("serial") static final class MapReduceMappingsToLongTask<K,V>
6432          extends BulkTask<K,V,Long> {
6433          final ObjectByObjectToLong<? super K, ? super V> transformer;
6434          final LongByLongToLong reducer;
6435          final long basis;
6436          long result;
6437 <        MapReduceMappingsToLongTask<K,V> sibling;
6437 >        MapReduceMappingsToLongTask<K,V> rights, nextRight;
6438          MapReduceMappingsToLongTask
6439 <            (ConcurrentHashMapV8<K,V> m,
6439 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6440 >             MapReduceMappingsToLongTask<K,V> nextRight,
6441               ObjectByObjectToLong<? super K, ? super V> transformer,
6442               long basis,
6443               LongByLongToLong reducer) {
6444 <            super(m);
6444 >            super(m, p, b); this.nextRight = nextRight;
6445              this.transformer = transformer;
6446              this.basis = basis; this.reducer = reducer;
6447          }
6448 <        MapReduceMappingsToLongTask
6372 <            (BulkTask<K,V,?> p, int b, boolean split,
6373 <             ObjectByObjectToLong<? super K, ? super V> transformer,
6374 <             long basis,
6375 <             LongByLongToLong reducer) {
6376 <            super(p, b, split);
6377 <            this.transformer = transformer;
6378 <            this.basis = basis; this.reducer = reducer;
6379 <        }
6380 <        public final void compute() {
6381 <            MapReduceMappingsToLongTask<K,V> t = this;
6448 >        @SuppressWarnings("unchecked") public final boolean exec() {
6449              final ObjectByObjectToLong<? super K, ? super V> transformer =
6450                  this.transformer;
6451              final LongByLongToLong reducer = this.reducer;
6452              if (transformer == null || reducer == null)
6453 <                throw new Error(NullFunctionMessage);
6454 <            final long id = this.basis;
6455 <            int b = batch();
6456 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6457 <                b >>>= 1;
6458 <                t.pending = 1;
6459 <                MapReduceMappingsToLongTask<K,V> rt =
6460 <                    new MapReduceMappingsToLongTask<K,V>
6461 <                    (t, b, true, transformer, id, reducer);
6462 <                t = new MapReduceMappingsToLongTask<K,V>
6463 <                    (t, b, false, transformer, id, reducer);
6464 <                t.sibling = rt;
6465 <                rt.sibling = t;
6466 <                rt.fork();
6467 <            }
6468 <            long r = id;
6469 <            Object v;
6470 <            while ((v = t.advance()) != null)
6471 <                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6472 <            t.result = r;
6473 <            for (;;) {
6474 <                int c; BulkTask<K,V,?> par; MapReduceMappingsToLongTask<K,V> s, p;
6475 <                if ((par = t.parent) == null ||
6476 <                    !(par instanceof MapReduceMappingsToLongTask)) {
6477 <                    t.quietlyComplete();
6478 <                    break;
6479 <                }
6480 <                else if ((c = (p = (MapReduceMappingsToLongTask<K,V>)par).pending) == 0) {
6414 <                    if ((s = t.sibling) != null)
6415 <                        r = reducer.apply(r, s.result);
6416 <                    (t = p).result = r;
6453 >                return abortOnNullFunction();
6454 >            try {
6455 >                final long id = this.basis;
6456 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6457 >                    do {} while (!casPending(c = pending, c+1));
6458 >                    (rights = new MapReduceMappingsToLongTask<K,V>
6459 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6460 >                }
6461 >                long r = id;
6462 >                Object v;
6463 >                while ((v = advance()) != null)
6464 >                    r = reducer.apply(r, transformer.apply((K)nextKey, (V)v));
6465 >                result = r;
6466 >                for (MapReduceMappingsToLongTask<K,V> t = this, s;;) {
6467 >                    int c; BulkTask<K,V,?> par;
6468 >                    if ((c = t.pending) == 0) {
6469 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6470 >                            t.result = reducer.apply(t.result, s.result);
6471 >                        }
6472 >                        if ((par = t.parent) == null ||
6473 >                            !(par instanceof MapReduceMappingsToLongTask)) {
6474 >                            t.quietlyComplete();
6475 >                            break;
6476 >                        }
6477 >                        t = (MapReduceMappingsToLongTask<K,V>)par;
6478 >                    }
6479 >                    else if (t.casPending(c, c - 1))
6480 >                        break;
6481                  }
6482 <                else if (p.casPending(c, 0))
6483 <                    break;
6482 >            } catch (Throwable ex) {
6483 >                return tryCompleteComputation(ex);
6484              }
6485 +            MapReduceMappingsToLongTask<K,V> s = rights;
6486 +            if (s != null && !inForkJoinPool()) {
6487 +                do  {
6488 +                    if (s.tryUnfork())
6489 +                        s.exec();
6490 +                } while ((s = s.nextRight) != null);
6491 +            }
6492 +            return false;
6493          }
6494          public final Long getRawResult() { return result; }
6495      }
6496  
6497 <    static final class MapReduceKeysToIntTask<K,V>
6497 >    @SuppressWarnings("serial") static final class MapReduceKeysToIntTask<K,V>
6498          extends BulkTask<K,V,Integer> {
6499          final ObjectToInt<? super K> transformer;
6500          final IntByIntToInt reducer;
6501          final int basis;
6502          int result;
6503 <        MapReduceKeysToIntTask<K,V> sibling;
6503 >        MapReduceKeysToIntTask<K,V> rights, nextRight;
6504          MapReduceKeysToIntTask
6505 <            (ConcurrentHashMapV8<K,V> m,
6505 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6506 >             MapReduceKeysToIntTask<K,V> nextRight,
6507               ObjectToInt<? super K> transformer,
6508               int basis,
6509               IntByIntToInt reducer) {
6510 <            super(m);
6510 >            super(m, p, b); this.nextRight = nextRight;
6511              this.transformer = transformer;
6512              this.basis = basis; this.reducer = reducer;
6513          }
6514 <        MapReduceKeysToIntTask
6442 <            (BulkTask<K,V,?> p, int b, boolean split,
6443 <             ObjectToInt<? super K> transformer,
6444 <             int basis,
6445 <             IntByIntToInt reducer) {
6446 <            super(p, b, split);
6447 <            this.transformer = transformer;
6448 <            this.basis = basis; this.reducer = reducer;
6449 <        }
6450 <        public final void compute() {
6451 <            MapReduceKeysToIntTask<K,V> t = this;
6514 >        @SuppressWarnings("unchecked") public final boolean exec() {
6515              final ObjectToInt<? super K> transformer =
6516                  this.transformer;
6517              final IntByIntToInt reducer = this.reducer;
6518              if (transformer == null || reducer == null)
6519 <                throw new Error(NullFunctionMessage);
6520 <            final int id = this.basis;
6521 <            int b = batch();
6522 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6523 <                b >>>= 1;
6524 <                t.pending = 1;
6525 <                MapReduceKeysToIntTask<K,V> rt =
6526 <                    new MapReduceKeysToIntTask<K,V>
6527 <                    (t, b, true, transformer, id, reducer);
6528 <                t = new MapReduceKeysToIntTask<K,V>
6529 <                    (t, b, false, transformer, id, reducer);
6530 <                t.sibling = rt;
6531 <                rt.sibling = t;
6532 <                rt.fork();
6533 <            }
6534 <            int r = id;
6535 <            while (t.advance() != null)
6536 <                r = reducer.apply(r, transformer.apply((K)t.nextKey));
6537 <            t.result = r;
6538 <            for (;;) {
6539 <                int c; BulkTask<K,V,?> par; MapReduceKeysToIntTask<K,V> s, p;
6540 <                if ((par = t.parent) == null ||
6541 <                    !(par instanceof MapReduceKeysToIntTask)) {
6542 <                    t.quietlyComplete();
6543 <                    break;
6544 <                }
6545 <                else if ((c = (p = (MapReduceKeysToIntTask<K,V>)par).pending) == 0) {
6483 <                    if ((s = t.sibling) != null)
6484 <                        r = reducer.apply(r, s.result);
6485 <                    (t = p).result = r;
6519 >                return abortOnNullFunction();
6520 >            try {
6521 >                final int id = this.basis;
6522 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6523 >                    do {} while (!casPending(c = pending, c+1));
6524 >                    (rights = new MapReduceKeysToIntTask<K,V>
6525 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6526 >                }
6527 >                int r = id;
6528 >                while (advance() != null)
6529 >                    r = reducer.apply(r, transformer.apply((K)nextKey));
6530 >                result = r;
6531 >                for (MapReduceKeysToIntTask<K,V> t = this, s;;) {
6532 >                    int c; BulkTask<K,V,?> par;
6533 >                    if ((c = t.pending) == 0) {
6534 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6535 >                            t.result = reducer.apply(t.result, s.result);
6536 >                        }
6537 >                        if ((par = t.parent) == null ||
6538 >                            !(par instanceof MapReduceKeysToIntTask)) {
6539 >                            t.quietlyComplete();
6540 >                            break;
6541 >                        }
6542 >                        t = (MapReduceKeysToIntTask<K,V>)par;
6543 >                    }
6544 >                    else if (t.casPending(c, c - 1))
6545 >                        break;
6546                  }
6547 <                else if (p.casPending(c, 0))
6548 <                    break;
6547 >            } catch (Throwable ex) {
6548 >                return tryCompleteComputation(ex);
6549 >            }
6550 >            MapReduceKeysToIntTask<K,V> s = rights;
6551 >            if (s != null && !inForkJoinPool()) {
6552 >                do  {
6553 >                    if (s.tryUnfork())
6554 >                        s.exec();
6555 >                } while ((s = s.nextRight) != null);
6556              }
6557 +            return false;
6558          }
6559          public final Integer getRawResult() { return result; }
6560      }
6561  
6562 <    static final class MapReduceValuesToIntTask<K,V>
6562 >    @SuppressWarnings("serial") static final class MapReduceValuesToIntTask<K,V>
6563          extends BulkTask<K,V,Integer> {
6564          final ObjectToInt<? super V> transformer;
6565          final IntByIntToInt reducer;
6566          final int basis;
6567          int result;
6568 <        MapReduceValuesToIntTask<K,V> sibling;
6501 <        MapReduceValuesToIntTask
6502 <            (ConcurrentHashMapV8<K,V> m,
6503 <             ObjectToInt<? super V> transformer,
6504 <             int basis,
6505 <             IntByIntToInt reducer) {
6506 <            super(m);
6507 <            this.transformer = transformer;
6508 <            this.basis = basis; this.reducer = reducer;
6509 <        }
6568 >        MapReduceValuesToIntTask<K,V> rights, nextRight;
6569          MapReduceValuesToIntTask
6570 <            (BulkTask<K,V,?> p, int b, boolean split,
6570 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6571 >             MapReduceValuesToIntTask<K,V> nextRight,
6572               ObjectToInt<? super V> transformer,
6573               int basis,
6574               IntByIntToInt reducer) {
6575 <            super(p, b, split);
6575 >            super(m, p, b); this.nextRight = nextRight;
6576              this.transformer = transformer;
6577              this.basis = basis; this.reducer = reducer;
6578          }
6579 <        public final void compute() {
6520 <            MapReduceValuesToIntTask<K,V> t = this;
6579 >        @SuppressWarnings("unchecked") public final boolean exec() {
6580              final ObjectToInt<? super V> transformer =
6581                  this.transformer;
6582              final IntByIntToInt reducer = this.reducer;
6583              if (transformer == null || reducer == null)
6584 <                throw new Error(NullFunctionMessage);
6585 <            final int id = this.basis;
6586 <            int b = batch();
6587 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6588 <                b >>>= 1;
6589 <                t.pending = 1;
6590 <                MapReduceValuesToIntTask<K,V> rt =
6591 <                    new MapReduceValuesToIntTask<K,V>
6592 <                    (t, b, true, transformer, id, reducer);
6593 <                t = new MapReduceValuesToIntTask<K,V>
6594 <                    (t, b, false, transformer, id, reducer);
6595 <                t.sibling = rt;
6596 <                rt.sibling = t;
6597 <                rt.fork();
6598 <            }
6599 <            int r = id;
6600 <            Object v;
6601 <            while ((v = t.advance()) != null)
6602 <                r = reducer.apply(r, transformer.apply((V)v));
6603 <            t.result = r;
6604 <            for (;;) {
6605 <                int c; BulkTask<K,V,?> par; MapReduceValuesToIntTask<K,V> s, p;
6606 <                if ((par = t.parent) == null ||
6607 <                    !(par instanceof MapReduceValuesToIntTask)) {
6608 <                    t.quietlyComplete();
6609 <                    break;
6610 <                }
6611 <                else if ((c = (p = (MapReduceValuesToIntTask<K,V>)par).pending) == 0) {
6553 <                    if ((s = t.sibling) != null)
6554 <                        r = reducer.apply(r, s.result);
6555 <                    (t = p).result = r;
6584 >                return abortOnNullFunction();
6585 >            try {
6586 >                final int id = this.basis;
6587 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6588 >                    do {} while (!casPending(c = pending, c+1));
6589 >                    (rights = new MapReduceValuesToIntTask<K,V>
6590 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6591 >                }
6592 >                int r = id;
6593 >                Object v;
6594 >                while ((v = advance()) != null)
6595 >                    r = reducer.apply(r, transformer.apply((V)v));
6596 >                result = r;
6597 >                for (MapReduceValuesToIntTask<K,V> t = this, s;;) {
6598 >                    int c; BulkTask<K,V,?> par;
6599 >                    if ((c = t.pending) == 0) {
6600 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6601 >                            t.result = reducer.apply(t.result, s.result);
6602 >                        }
6603 >                        if ((par = t.parent) == null ||
6604 >                            !(par instanceof MapReduceValuesToIntTask)) {
6605 >                            t.quietlyComplete();
6606 >                            break;
6607 >                        }
6608 >                        t = (MapReduceValuesToIntTask<K,V>)par;
6609 >                    }
6610 >                    else if (t.casPending(c, c - 1))
6611 >                        break;
6612                  }
6613 <                else if (p.casPending(c, 0))
6614 <                    break;
6613 >            } catch (Throwable ex) {
6614 >                return tryCompleteComputation(ex);
6615 >            }
6616 >            MapReduceValuesToIntTask<K,V> s = rights;
6617 >            if (s != null && !inForkJoinPool()) {
6618 >                do  {
6619 >                    if (s.tryUnfork())
6620 >                        s.exec();
6621 >                } while ((s = s.nextRight) != null);
6622              }
6623 +            return false;
6624          }
6625          public final Integer getRawResult() { return result; }
6626      }
6627  
6628 <    static final class MapReduceEntriesToIntTask<K,V>
6628 >    @SuppressWarnings("serial") static final class MapReduceEntriesToIntTask<K,V>
6629          extends BulkTask<K,V,Integer> {
6630          final ObjectToInt<Map.Entry<K,V>> transformer;
6631          final IntByIntToInt reducer;
6632          final int basis;
6633          int result;
6634 <        MapReduceEntriesToIntTask<K,V> sibling;
6571 <        MapReduceEntriesToIntTask
6572 <            (ConcurrentHashMapV8<K,V> m,
6573 <             ObjectToInt<Map.Entry<K,V>> transformer,
6574 <             int basis,
6575 <             IntByIntToInt reducer) {
6576 <            super(m);
6577 <            this.transformer = transformer;
6578 <            this.basis = basis; this.reducer = reducer;
6579 <        }
6634 >        MapReduceEntriesToIntTask<K,V> rights, nextRight;
6635          MapReduceEntriesToIntTask
6636 <            (BulkTask<K,V,?> p, int b, boolean split,
6636 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6637 >             MapReduceEntriesToIntTask<K,V> nextRight,
6638               ObjectToInt<Map.Entry<K,V>> transformer,
6639               int basis,
6640               IntByIntToInt reducer) {
6641 <            super(p, b, split);
6641 >            super(m, p, b); this.nextRight = nextRight;
6642              this.transformer = transformer;
6643              this.basis = basis; this.reducer = reducer;
6644          }
6645 <        public final void compute() {
6590 <            MapReduceEntriesToIntTask<K,V> t = this;
6645 >        @SuppressWarnings("unchecked") public final boolean exec() {
6646              final ObjectToInt<Map.Entry<K,V>> transformer =
6647                  this.transformer;
6648              final IntByIntToInt reducer = this.reducer;
6649              if (transformer == null || reducer == null)
6650 <                throw new Error(NullFunctionMessage);
6651 <            final int id = this.basis;
6652 <            int b = batch();
6653 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6654 <                b >>>= 1;
6655 <                t.pending = 1;
6656 <                MapReduceEntriesToIntTask<K,V> rt =
6657 <                    new MapReduceEntriesToIntTask<K,V>
6658 <                    (t, b, true, transformer, id, reducer);
6659 <                t = new MapReduceEntriesToIntTask<K,V>
6660 <                    (t, b, false, transformer, id, reducer);
6661 <                t.sibling = rt;
6662 <                rt.sibling = t;
6663 <                rt.fork();
6664 <            }
6665 <            int r = id;
6666 <            Object v;
6667 <            while ((v = t.advance()) != null)
6668 <                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6669 <            t.result = r;
6670 <            for (;;) {
6671 <                int c; BulkTask<K,V,?> par; MapReduceEntriesToIntTask<K,V> s, p;
6672 <                if ((par = t.parent) == null ||
6673 <                    !(par instanceof MapReduceEntriesToIntTask)) {
6674 <                    t.quietlyComplete();
6675 <                    break;
6676 <                }
6677 <                else if ((c = (p = (MapReduceEntriesToIntTask<K,V>)par).pending) == 0) {
6623 <                    if ((s = t.sibling) != null)
6624 <                        r = reducer.apply(r, s.result);
6625 <                    (t = p).result = r;
6650 >                return abortOnNullFunction();
6651 >            try {
6652 >                final int id = this.basis;
6653 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6654 >                    do {} while (!casPending(c = pending, c+1));
6655 >                    (rights = new MapReduceEntriesToIntTask<K,V>
6656 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6657 >                }
6658 >                int r = id;
6659 >                Object v;
6660 >                while ((v = advance()) != null)
6661 >                    r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v)));
6662 >                result = r;
6663 >                for (MapReduceEntriesToIntTask<K,V> t = this, s;;) {
6664 >                    int c; BulkTask<K,V,?> par;
6665 >                    if ((c = t.pending) == 0) {
6666 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6667 >                            t.result = reducer.apply(t.result, s.result);
6668 >                        }
6669 >                        if ((par = t.parent) == null ||
6670 >                            !(par instanceof MapReduceEntriesToIntTask)) {
6671 >                            t.quietlyComplete();
6672 >                            break;
6673 >                        }
6674 >                        t = (MapReduceEntriesToIntTask<K,V>)par;
6675 >                    }
6676 >                    else if (t.casPending(c, c - 1))
6677 >                        break;
6678                  }
6679 <                else if (p.casPending(c, 0))
6680 <                    break;
6679 >            } catch (Throwable ex) {
6680 >                return tryCompleteComputation(ex);
6681 >            }
6682 >            MapReduceEntriesToIntTask<K,V> s = rights;
6683 >            if (s != null && !inForkJoinPool()) {
6684 >                do  {
6685 >                    if (s.tryUnfork())
6686 >                        s.exec();
6687 >                } while ((s = s.nextRight) != null);
6688              }
6689 +            return false;
6690          }
6691          public final Integer getRawResult() { return result; }
6692      }
6693  
6694 <    static final class MapReduceMappingsToIntTask<K,V>
6694 >    @SuppressWarnings("serial") static final class MapReduceMappingsToIntTask<K,V>
6695          extends BulkTask<K,V,Integer> {
6696          final ObjectByObjectToInt<? super K, ? super V> transformer;
6697          final IntByIntToInt reducer;
6698          final int basis;
6699          int result;
6700 <        MapReduceMappingsToIntTask<K,V> sibling;
6700 >        MapReduceMappingsToIntTask<K,V> rights, nextRight;
6701          MapReduceMappingsToIntTask
6702 <            (ConcurrentHashMapV8<K,V> m,
6702 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6703 >             MapReduceMappingsToIntTask<K,V> rights,
6704               ObjectByObjectToInt<? super K, ? super V> transformer,
6705               int basis,
6706               IntByIntToInt reducer) {
6707 <            super(m);
6707 >            super(m, p, b); this.nextRight = nextRight;
6708              this.transformer = transformer;
6709              this.basis = basis; this.reducer = reducer;
6710          }
6711 <        MapReduceMappingsToIntTask
6651 <            (BulkTask<K,V,?> p, int b, boolean split,
6652 <             ObjectByObjectToInt<? super K, ? super V> transformer,
6653 <             int basis,
6654 <             IntByIntToInt reducer) {
6655 <            super(p, b, split);
6656 <            this.transformer = transformer;
6657 <            this.basis = basis; this.reducer = reducer;
6658 <        }
6659 <        public final void compute() {
6660 <            MapReduceMappingsToIntTask<K,V> t = this;
6711 >        @SuppressWarnings("unchecked") public final boolean exec() {
6712              final ObjectByObjectToInt<? super K, ? super V> transformer =
6713                  this.transformer;
6714              final IntByIntToInt reducer = this.reducer;
6715              if (transformer == null || reducer == null)
6716 <                throw new Error(NullFunctionMessage);
6717 <            final int id = this.basis;
6718 <            int b = batch();
6719 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6720 <                b >>>= 1;
6721 <                t.pending = 1;
6722 <                MapReduceMappingsToIntTask<K,V> rt =
6723 <                    new MapReduceMappingsToIntTask<K,V>
6724 <                    (t, b, true, transformer, id, reducer);
6725 <                t = new MapReduceMappingsToIntTask<K,V>
6726 <                    (t, b, false, transformer, id, reducer);
6727 <                t.sibling = rt;
6728 <                rt.sibling = t;
6729 <                rt.fork();
6730 <            }
6731 <            int r = id;
6732 <            Object v;
6733 <            while ((v = t.advance()) != null)
6734 <                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6735 <            t.result = r;
6736 <            for (;;) {
6737 <                int c; BulkTask<K,V,?> par; MapReduceMappingsToIntTask<K,V> s, p;
6738 <                if ((par = t.parent) == null ||
6739 <                    !(par instanceof MapReduceMappingsToIntTask)) {
6740 <                    t.quietlyComplete();
6741 <                    break;
6742 <                }
6743 <                else if ((c = (p = (MapReduceMappingsToIntTask<K,V>)par).pending) == 0) {
6693 <                    if ((s = t.sibling) != null)
6694 <                        r = reducer.apply(r, s.result);
6695 <                    (t = p).result = r;
6716 >                return abortOnNullFunction();
6717 >            try {
6718 >                final int id = this.basis;
6719 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6720 >                    do {} while (!casPending(c = pending, c+1));
6721 >                    (rights = new MapReduceMappingsToIntTask<K,V>
6722 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6723 >                }
6724 >                int r = id;
6725 >                Object v;
6726 >                while ((v = advance()) != null)
6727 >                    r = reducer.apply(r, transformer.apply((K)nextKey, (V)v));
6728 >                result = r;
6729 >                for (MapReduceMappingsToIntTask<K,V> t = this, s;;) {
6730 >                    int c; BulkTask<K,V,?> par;
6731 >                    if ((c = t.pending) == 0) {
6732 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6733 >                            t.result = reducer.apply(t.result, s.result);
6734 >                        }
6735 >                        if ((par = t.parent) == null ||
6736 >                            !(par instanceof MapReduceMappingsToIntTask)) {
6737 >                            t.quietlyComplete();
6738 >                            break;
6739 >                        }
6740 >                        t = (MapReduceMappingsToIntTask<K,V>)par;
6741 >                    }
6742 >                    else if (t.casPending(c, c - 1))
6743 >                        break;
6744                  }
6745 <                else if (p.casPending(c, 0))
6746 <                    break;
6745 >            } catch (Throwable ex) {
6746 >                return tryCompleteComputation(ex);
6747 >            }
6748 >            MapReduceMappingsToIntTask<K,V> s = rights;
6749 >            if (s != null && !inForkJoinPool()) {
6750 >                do  {
6751 >                    if (s.tryUnfork())
6752 >                        s.exec();
6753 >                } while ((s = s.nextRight) != null);
6754              }
6755 +            return false;
6756          }
6757          public final Integer getRawResult() { return result; }
6758      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines