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.55 by jsr166, Mon Aug 13 18:25:53 2012 UTC vs.
Revision 1.66 by jsr166, Sun Oct 21 03:26:47 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines