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.60 by dl, Thu Aug 16 12:24:58 2012 UTC vs.
Revision 1.70 by dl, Sun Oct 28 22:35:45 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines