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.52 by dl, Mon Aug 13 15:52:33 2012 UTC vs.
Revision 1.61 by dl, Thu Sep 13 10:41:37 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 2281 | Line 2296 | public class ConcurrentHashMapV8<K, V>
2296          }
2297  
2298          /** Creates iterator for split() methods */
2299 <        Traverser(Traverser<K,V,?> it, boolean split) {
2299 >        Traverser(Traverser<K,V,?> it) {
2300              this.map = it.map;
2301              this.tab = it.tab;
2302              this.baseSize = it.baseSize;
2303 <            int lo = it.baseIndex;
2304 <            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;
2303 >            it.baseLimit = this.index = this.baseIndex =
2304 >                ((this.baseLimit = it.baseLimit) + it.baseIndex + 1) >>> 1;
2305          }
2306  
2307          /**
# Line 2327 | Line 2336 | public class ConcurrentHashMapV8<K, V>
2336          }
2337  
2338          public final void remove() {
2339 <            if (nextVal == null)
2339 >            if (nextVal == null && last == null)
2340                  advance();
2341              Node e = last;
2342              if (e == null)
# Line 2458 | Line 2467 | public class ConcurrentHashMapV8<K, V>
2467       * instead of {@link #size} because a ConcurrentHashMap may
2468       * contain more mappings than can be represented as an int. The
2469       * value returned is a snapshot; the actual count may differ if
2470 <     * there are ongoing concurrent insertions of removals.
2470 >     * there are ongoing concurrent insertions or removals.
2471       *
2472       * @return the number of mappings
2473       */
2474      public long mappingCount() {
2475          long n = counter.sum();
2476 <        return (n < 0L) ? 0L : n;
2476 >        return (n < 0L) ? 0L : n; // ignore transient negative values
2477      }
2478  
2479      /**
# Line 2478 | Line 2487 | public class ConcurrentHashMapV8<K, V>
2487       *
2488       * @throws NullPointerException if the specified key is null
2489       */
2490 <    @SuppressWarnings("unchecked")
2482 <        public V get(Object key) {
2490 >    @SuppressWarnings("unchecked") public V get(Object key) {
2491          if (key == null)
2492              throw new NullPointerException();
2493          return (V)internalGet(key);
# Line 2554 | Line 2562 | public class ConcurrentHashMapV8<K, V>
2562       *         {@code null} if there was no mapping for {@code key}
2563       * @throws NullPointerException if the specified key or value is null
2564       */
2565 <    @SuppressWarnings("unchecked")
2558 <        public V put(K key, V value) {
2565 >    @SuppressWarnings("unchecked") public V put(K key, V value) {
2566          if (key == null || value == null)
2567              throw new NullPointerException();
2568          return (V)internalPut(key, value);
# Line 2568 | Line 2575 | public class ConcurrentHashMapV8<K, V>
2575       *         or {@code null} if there was no mapping for the key
2576       * @throws NullPointerException if the specified key or value is null
2577       */
2578 <    @SuppressWarnings("unchecked")
2572 <        public V putIfAbsent(K key, V value) {
2578 >    @SuppressWarnings("unchecked") public V putIfAbsent(K key, V value) {
2579          if (key == null || value == null)
2580              throw new NullPointerException();
2581          return (V)internalPutIfAbsent(key, value);
# Line 2625 | Line 2631 | public class ConcurrentHashMapV8<K, V>
2631       * @throws RuntimeException or Error if the mappingFunction does so,
2632       *         in which case the mapping is left unestablished
2633       */
2634 <    @SuppressWarnings("unchecked")
2635 <        public V computeIfAbsent(K key, Fun<? super K, ? extends V> mappingFunction) {
2634 >    @SuppressWarnings("unchecked") public V computeIfAbsent
2635 >        (K key, Fun<? super K, ? extends V> mappingFunction) {
2636          if (key == null || mappingFunction == null)
2637              throw new NullPointerException();
2638          return (V)internalComputeIfAbsent(key, mappingFunction);
# Line 2657 | Line 2663 | public class ConcurrentHashMapV8<K, V>
2663       *
2664       * @param key key with which the specified value is to be associated
2665       * @param remappingFunction the function to compute a value
2666 <     * @return the new value associated with
2661 <     *         the specified key, or null if none.
2666 >     * @return the new value associated with the specified key, or null if none
2667       * @throws NullPointerException if the specified key or remappingFunction
2668       *         is null
2669       * @throws IllegalStateException if the computation detectably
# Line 2667 | Line 2672 | public class ConcurrentHashMapV8<K, V>
2672       * @throws RuntimeException or Error if the remappingFunction does so,
2673       *         in which case the mapping is unchanged
2674       */
2675 <    public V computeIfPresent(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2675 >    @SuppressWarnings("unchecked") public V computeIfPresent
2676 >        (K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2677          if (key == null || remappingFunction == null)
2678              throw new NullPointerException();
2679          return (V)internalCompute(key, true, remappingFunction);
# Line 2704 | Line 2710 | public class ConcurrentHashMapV8<K, V>
2710       *
2711       * @param key key with which the specified value is to be associated
2712       * @param remappingFunction the function to compute a value
2713 <     * @return the new value associated with
2708 <     *         the specified key, or null if none.
2713 >     * @return the new value associated with the specified key, or null if none
2714       * @throws NullPointerException if the specified key or remappingFunction
2715       *         is null
2716       * @throws IllegalStateException if the computation detectably
# Line 2714 | Line 2719 | public class ConcurrentHashMapV8<K, V>
2719       * @throws RuntimeException or Error if the remappingFunction does so,
2720       *         in which case the mapping is unchanged
2721       */
2722 <    //    @SuppressWarnings("unchecked")
2723 <    public V compute(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2722 >    @SuppressWarnings("unchecked") public V compute
2723 >        (K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2724          if (key == null || remappingFunction == null)
2725              throw new NullPointerException();
2726          return (V)internalCompute(key, false, remappingFunction);
# Line 2746 | Line 2751 | public class ConcurrentHashMapV8<K, V>
2751       * so the computation should be short and simple, and must not
2752       * attempt to update any other mappings of this Map.
2753       */
2754 <    //    @SuppressWarnings("unchecked")
2755 <    public V merge(K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) {
2754 >    @SuppressWarnings("unchecked") public V merge
2755 >        (K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) {
2756          if (key == null || value == null || remappingFunction == null)
2757              throw new NullPointerException();
2758          return (V)internalMerge(key, value, remappingFunction);
# Line 2762 | Line 2767 | public class ConcurrentHashMapV8<K, V>
2767       *         {@code null} if there was no mapping for {@code key}
2768       * @throws NullPointerException if the specified key is null
2769       */
2770 <    @SuppressWarnings("unchecked")
2766 <        public V remove(Object key) {
2770 >    @SuppressWarnings("unchecked") public V remove(Object key) {
2771          if (key == null)
2772              throw new NullPointerException();
2773          return (V)internalReplace(key, null, null);
# Line 2800 | Line 2804 | public class ConcurrentHashMapV8<K, V>
2804       *         or {@code null} if there was no mapping for the key
2805       * @throws NullPointerException if the specified key or value is null
2806       */
2807 <    @SuppressWarnings("unchecked")
2804 <        public V replace(K key, V value) {
2807 >    @SuppressWarnings("unchecked") public V replace(K key, V value) {
2808          if (key == null || value == null)
2809              throw new NullPointerException();
2810          return (V)internalReplace(key, value, null);
# Line 2898 | Line 2901 | public class ConcurrentHashMapV8<K, V>
2901      }
2902  
2903      /**
2904 <     * Returns a partionable iterator of the keys in this map.
2904 >     * Returns a partitionable iterator of the keys in this map.
2905       *
2906 <     * @return a partionable iterator of the keys in this map
2906 >     * @return a partitionable iterator of the keys in this map
2907       */
2908      public Spliterator<K> keySpliterator() {
2909          return new KeyIterator<K,V>(this);
2910      }
2911  
2912      /**
2913 <     * Returns a partionable iterator of the values in this map.
2913 >     * Returns a partitionable iterator of the values in this map.
2914       *
2915 <     * @return a partionable iterator of the values in this map
2915 >     * @return a partitionable iterator of the values in this map
2916       */
2917      public Spliterator<V> valueSpliterator() {
2918          return new ValueIterator<K,V>(this);
2919      }
2920  
2921      /**
2922 <     * Returns a partionable iterator of the entries in this map.
2922 >     * Returns a partitionable iterator of the entries in this map.
2923       *
2924 <     * @return a partionable iterator of the entries in this map
2924 >     * @return a partitionable iterator of the entries in this map
2925       */
2926      public Spliterator<Map.Entry<K,V>> entrySpliterator() {
2927          return new EntryIterator<K,V>(this);
# Line 3007 | Line 3010 | public class ConcurrentHashMapV8<K, V>
3010  
3011      /* ----------------Iterators -------------- */
3012  
3013 <    static final class KeyIterator<K,V> extends Traverser<K,V,Object>
3013 >    @SuppressWarnings("serial") static final class KeyIterator<K,V> extends Traverser<K,V,Object>
3014          implements Spliterator<K>, Enumeration<K> {
3015          KeyIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3016 <        KeyIterator(Traverser<K,V,Object> it, boolean split) {
3017 <            super(it, split);
3016 >        KeyIterator(Traverser<K,V,Object> it) {
3017 >            super(it);
3018          }
3019          public KeyIterator<K,V> split() {
3020              if (last != null || (next != null && nextVal == null))
3021                  throw new IllegalStateException();
3022 <            return new KeyIterator<K,V>(this, true);
3022 >            return new KeyIterator<K,V>(this);
3023          }
3024 <        @SuppressWarnings("unchecked")
3022 <            public final K next() {
3024 >        @SuppressWarnings("unchecked") public final K next() {
3025              if (nextVal == null && advance() == null)
3026                  throw new NoSuchElementException();
3027              Object k = nextKey;
# Line 3030 | Line 3032 | public class ConcurrentHashMapV8<K, V>
3032          public final K nextElement() { return next(); }
3033      }
3034  
3035 <    static final class ValueIterator<K,V> extends Traverser<K,V,Object>
3035 >    @SuppressWarnings("serial") static final class ValueIterator<K,V> extends Traverser<K,V,Object>
3036          implements Spliterator<V>, Enumeration<V> {
3037          ValueIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3038 <        ValueIterator(Traverser<K,V,Object> it, boolean split) {
3039 <            super(it, split);
3038 >        ValueIterator(Traverser<K,V,Object> it) {
3039 >            super(it);
3040          }
3041          public ValueIterator<K,V> split() {
3042              if (last != null || (next != null && nextVal == null))
3043                  throw new IllegalStateException();
3044 <            return new ValueIterator<K,V>(this, true);
3044 >            return new ValueIterator<K,V>(this);
3045          }
3046  
3047 <        @SuppressWarnings("unchecked")
3046 <            public final V next() {
3047 >        @SuppressWarnings("unchecked") public final V next() {
3048              Object v;
3049              if ((v = nextVal) == null && (v = advance()) == null)
3050                  throw new NoSuchElementException();
# Line 3054 | Line 3055 | public class ConcurrentHashMapV8<K, V>
3055          public final V nextElement() { return next(); }
3056      }
3057  
3058 <    static final class EntryIterator<K,V> extends Traverser<K,V,Object>
3058 >    @SuppressWarnings("serial") static final class EntryIterator<K,V> extends Traverser<K,V,Object>
3059          implements Spliterator<Map.Entry<K,V>> {
3060          EntryIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3061 <        EntryIterator(Traverser<K,V,Object> it, boolean split) {
3062 <            super(it, split);
3061 >        EntryIterator(Traverser<K,V,Object> it) {
3062 >            super(it);
3063          }
3064          public EntryIterator<K,V> split() {
3065              if (last != null || (next != null && nextVal == null))
3066                  throw new IllegalStateException();
3067 <            return new EntryIterator<K,V>(this, true);
3067 >            return new EntryIterator<K,V>(this);
3068          }
3069  
3070 <        @SuppressWarnings("unchecked")
3070 <            public final Map.Entry<K,V> next() {
3070 >        @SuppressWarnings("unchecked") public final Map.Entry<K,V> next() {
3071              Object v;
3072              if ((v = nextVal) == null && (v = advance()) == null)
3073                  throw new NoSuchElementException();
# Line 3162 | Line 3162 | public class ConcurrentHashMapV8<K, V>
3162              return (i == n) ? r : Arrays.copyOf(r, i);
3163          }
3164  
3165 <        @SuppressWarnings("unchecked")
3166 <            public final <T> T[] toArray(T[] a) {
3165 >        @SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) {
3166              long sz = map.mappingCount();
3167              if (sz > (long)(MAX_ARRAY_SIZE))
3168                  throw new OutOfMemoryError(oomeMsg);
# Line 3359 | Line 3358 | public class ConcurrentHashMapV8<K, V>
3358       * for each key-value mapping, followed by a null pair.
3359       * The key-value mappings are emitted in no particular order.
3360       */
3361 <    @SuppressWarnings("unchecked")
3363 <        private void writeObject(java.io.ObjectOutputStream s)
3361 >    @SuppressWarnings("unchecked") private void writeObject(java.io.ObjectOutputStream s)
3362          throws java.io.IOException {
3363          if (segments == null) { // for serialization compatibility
3364              segments = (Segment<K,V>[])
# Line 3384 | Line 3382 | public class ConcurrentHashMapV8<K, V>
3382       * Reconstitutes the instance from a stream (that is, deserializes it).
3383       * @param s the stream
3384       */
3385 <    @SuppressWarnings("unchecked")
3388 <        private void readObject(java.io.ObjectInputStream s)
3385 >    @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s)
3386          throws java.io.IOException, ClassNotFoundException {
3387          s.defaultReadObject();
3388          this.segments = null; // unneeded
# Line 3518 | Line 3515 | public class ConcurrentHashMapV8<K, V>
3515  
3516      /**
3517       * An extended view of a ConcurrentHashMap supporting bulk
3518 <     * parallel operations. These operations are designed to be be
3518 >     * parallel operations. These operations are designed to be
3519       * safely, and often sensibly, applied even with maps that are
3520       * being concurrently updated by other threads; for example, when
3521       * computing a snapshot summary of the values in a shared
# Line 3636 | Line 3633 | public class ConcurrentHashMapV8<K, V>
3633           *
3634           * @param action the action
3635           */
3636 <        public void forEach(BiAction<K,V> action) {
3636 >        public void forEach(BiAction<K,V> action) {
3637              fjp.invoke(ForkJoinTasks.forEach
3638                         (ConcurrentHashMapV8.this, action));
3639          }
# Line 3650 | Line 3647 | public class ConcurrentHashMapV8<K, V>
3647           * which case the action is not applied).
3648           * @param action the action
3649           */
3650 <        public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
3650 >        public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
3651                                  Action<U> action) {
3652              fjp.invoke(ForkJoinTasks.forEach
3653                         (ConcurrentHashMapV8.this, transformer, action));
# Line 3658 | Line 3655 | public class ConcurrentHashMapV8<K, V>
3655  
3656          /**
3657           * Returns a non-null result from applying the given search
3658 <         * function on each (key, value), or null if none.  Further
3659 <         * element processing is suppressed upon success. However,
3660 <         * this method does not return until other in-progress
3661 <         * parallel invocations of the search function also complete.
3658 >         * function on each (key, value), or null if none.  Upon
3659 >         * success, further element processing is suppressed and the
3660 >         * results of any other parallel invocations of the search
3661 >         * function are ignored.
3662           *
3663           * @param searchFunction a function returning a non-null
3664           * result on success, else null
# Line 3720 | Line 3717 | public class ConcurrentHashMapV8<K, V>
3717           * @param basis the identity (initial default value) for the reduction
3718           * @param reducer a commutative associative combining function
3719           * @return the result of accumulating the given transformation
3720 <         * of all (key, value) pairs using the given reducer to
3724 <         * combine values, and the given basis as an identity value.
3720 >         * of all (key, value) pairs
3721           */
3722          public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer,
3723                                   long basis,
# Line 3750 | Line 3746 | public class ConcurrentHashMapV8<K, V>
3746          }
3747  
3748          /**
3749 <         * Performs the given action for each key
3749 >         * Performs the given action for each key.
3750           *
3751           * @param action the action
3752           */
3753 <        public void forEachKey(Action<K> action) {
3753 >        public void forEachKey(Action<K> action) {
3754              fjp.invoke(ForkJoinTasks.forEachKey
3755                         (ConcurrentHashMapV8.this, action));
3756          }
3757  
3758          /**
3759           * Performs the given action for each non-null transformation
3760 <         * of each key
3760 >         * of each key.
3761           *
3762           * @param transformer a function returning the transformation
3763           * for an element, or null of there is no transformation (in
3764           * which case the action is not applied).
3765           * @param action the action
3766           */
3767 <        public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
3767 >        public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
3768                                     Action<U> action) {
3769              fjp.invoke(ForkJoinTasks.forEachKey
3770                         (ConcurrentHashMapV8.this, transformer, action));
# Line 3776 | Line 3772 | public class ConcurrentHashMapV8<K, V>
3772  
3773          /**
3774           * Returns a non-null result from applying the given search
3775 <         * function on each key, or null if none.  Further element
3776 <         * processing is suppressed upon success. However, this method
3777 <         * does not return until other in-progress parallel
3778 <         * invocations of the search function also complete.
3775 >         * function on each key, or null if none. Upon success,
3776 >         * further element processing is suppressed and the results of
3777 >         * any other parallel invocations of the search function are
3778 >         * ignored.
3779           *
3780           * @param searchFunction a function returning a non-null
3781           * result on success, else null
# Line 3880 | Line 3876 | public class ConcurrentHashMapV8<K, V>
3876          }
3877  
3878          /**
3879 <         * Performs the given action for each value
3879 >         * Performs the given action for each value.
3880           *
3881           * @param action the action
3882           */
3883 <        public void forEachValue(Action<V> action) {
3883 >        public void forEachValue(Action<V> action) {
3884              fjp.invoke(ForkJoinTasks.forEachValue
3885                         (ConcurrentHashMapV8.this, action));
3886          }
3887  
3888          /**
3889           * Performs the given action for each non-null transformation
3890 <         * of each value
3890 >         * of each value.
3891           *
3892           * @param transformer a function returning the transformation
3893           * for an element, or null of there is no transformation (in
3894           * which case the action is not applied).
3895           */
3896 <        public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3896 >        public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3897                                       Action<U> action) {
3898              fjp.invoke(ForkJoinTasks.forEachValue
3899                         (ConcurrentHashMapV8.this, transformer, action));
# Line 3905 | Line 3901 | public class ConcurrentHashMapV8<K, V>
3901  
3902          /**
3903           * Returns a non-null result from applying the given search
3904 <         * function on each value, or null if none.  Further element
3905 <         * processing is suppressed upon success. However, this method
3906 <         * does not return until other in-progress parallel
3907 <         * invocations of the search function also complete.
3904 >         * function on each value, or null if none.  Upon success,
3905 >         * further element processing is suppressed and the results of
3906 >         * any other parallel invocations of the search function are
3907 >         * ignored.
3908           *
3909           * @param searchFunction a function returning a non-null
3910           * result on success, else null
# Line 4009 | Line 4005 | public class ConcurrentHashMapV8<K, V>
4005          }
4006  
4007          /**
4008 <         * Perform the given action for each entry
4008 >         * Performs the given action for each entry.
4009           *
4010           * @param action the action
4011           */
4012 <        public void forEachEntry(Action<Map.Entry<K,V>> action) {
4012 >        public void forEachEntry(Action<Map.Entry<K,V>> action) {
4013              fjp.invoke(ForkJoinTasks.forEachEntry
4014                         (ConcurrentHashMapV8.this, action));
4015          }
4016  
4017          /**
4018 <         * Perform the given action for each non-null transformation
4019 <         * of each entry
4018 >         * Performs the given action for each non-null transformation
4019 >         * of each entry.
4020           *
4021           * @param transformer a function returning the transformation
4022           * for an element, or null of there is no transformation (in
4023           * which case the action is not applied).
4024           * @param action the action
4025           */
4026 <        public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
4026 >        public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
4027                                       Action<U> action) {
4028              fjp.invoke(ForkJoinTasks.forEachEntry
4029                         (ConcurrentHashMapV8.this, transformer, action));
# Line 4035 | Line 4031 | public class ConcurrentHashMapV8<K, V>
4031  
4032          /**
4033           * Returns a non-null result from applying the given search
4034 <         * function on each entry, or null if none.  Further element
4035 <         * processing is suppressed upon success. However, this method
4036 <         * does not return until other in-progress parallel
4037 <         * invocations of the search function also complete.
4034 >         * function on each entry, or null if none.  Upon success,
4035 >         * further element processing is suppressed and the results of
4036 >         * any other parallel invocations of the search function are
4037 >         * ignored.
4038           *
4039           * @param searchFunction a function returning a non-null
4040           * result on success, else null
# Line 4159 | Line 4155 | public class ConcurrentHashMapV8<K, V>
4155           * @param action the action
4156           * @return the task
4157           */
4158 <        public static <K,V> ForkJoinTask<Void> forEach
4158 >        public static <K,V> ForkJoinTask<Void> forEach
4159              (ConcurrentHashMapV8<K,V> map,
4160               BiAction<K,V> action) {
4161              if (action == null) throw new NullPointerException();
# Line 4177 | Line 4173 | public class ConcurrentHashMapV8<K, V>
4173           * @param action the action
4174           * @return the task
4175           */
4176 <        public static <K,V,U> ForkJoinTask<Void> forEach
4176 >        public static <K,V,U> ForkJoinTask<Void> forEach
4177              (ConcurrentHashMapV8<K,V> map,
4178               BiFun<? super K, ? super V, ? extends U> transformer,
4179               Action<U> action) {
# Line 4188 | Line 4184 | public class ConcurrentHashMapV8<K, V>
4184          }
4185  
4186          /**
4187 <         * Returns a task that when invoked, returns a non-null
4188 <         * result from applying the given search function on each
4189 <         * (key, value), or null if none.  Further element processing
4190 <         * is suppressed upon success. However, this method does not
4191 <         * return until other in-progress parallel invocations of the
4196 <         * search function also complete.
4187 >         * Returns a task that when invoked, returns a non-null result
4188 >         * from applying the given search function on each (key,
4189 >         * value), or null if none. Upon success, further element
4190 >         * processing is suppressed and the results of any other
4191 >         * parallel invocations of the search function are ignored.
4192           *
4193           * @param map the map
4194           * @param searchFunction a function returning a non-null
# Line 4304 | Line 4299 | public class ConcurrentHashMapV8<K, V>
4299  
4300          /**
4301           * Returns a task that when invoked, performs the given action
4302 <         * for each key
4302 >         * for each key.
4303           *
4304           * @param map the map
4305           * @param action the action
4306           * @return the task
4307           */
4308 <        public static <K,V> ForkJoinTask<Void> forEachKey
4308 >        public static <K,V> ForkJoinTask<Void> forEachKey
4309              (ConcurrentHashMapV8<K,V> map,
4310               Action<K> action) {
4311              if (action == null) throw new NullPointerException();
# Line 4319 | Line 4314 | public class ConcurrentHashMapV8<K, V>
4314  
4315          /**
4316           * Returns a task that when invoked, performs the given action
4317 <         * for each non-null transformation of each key
4317 >         * for each non-null transformation of each key.
4318           *
4319           * @param map the map
4320           * @param transformer a function returning the transformation
# Line 4328 | Line 4323 | public class ConcurrentHashMapV8<K, V>
4323           * @param action the action
4324           * @return the task
4325           */
4326 <        public static <K,V,U> ForkJoinTask<Void> forEachKey
4326 >        public static <K,V,U> ForkJoinTask<Void> forEachKey
4327              (ConcurrentHashMapV8<K,V> map,
4328               Fun<? super K, ? extends U> transformer,
4329               Action<U> action) {
# Line 4341 | Line 4336 | public class ConcurrentHashMapV8<K, V>
4336          /**
4337           * Returns a task that when invoked, returns a non-null result
4338           * from applying the given search function on each key, or
4339 <         * null if none.  Further element processing is suppressed
4340 <         * upon success. However, this method does not return until
4341 <         * other in-progress parallel invocations of the search
4347 <         * function also complete.
4339 >         * null if none.  Upon success, further element processing is
4340 >         * suppressed and the results of any other parallel
4341 >         * invocations of the search function are ignored.
4342           *
4343           * @param map the map
4344           * @param searchFunction a function returning a non-null
# Line 4376 | Line 4370 | public class ConcurrentHashMapV8<K, V>
4370              return new ReduceKeysTask<K,V>
4371                  (map, reducer);
4372          }
4373 +
4374          /**
4375           * Returns a task that when invoked, returns the result of
4376           * accumulating the given transformation of all keys using the given
# Line 4472 | Line 4467 | public class ConcurrentHashMapV8<K, V>
4467  
4468          /**
4469           * Returns a task that when invoked, performs the given action
4470 <         * for each value
4470 >         * for each value.
4471           *
4472           * @param map the map
4473           * @param action the action
4474           */
4475 <        public static <K,V> ForkJoinTask<Void> forEachValue
4475 >        public static <K,V> ForkJoinTask<Void> forEachValue
4476              (ConcurrentHashMapV8<K,V> map,
4477               Action<V> action) {
4478              if (action == null) throw new NullPointerException();
# Line 4486 | Line 4481 | public class ConcurrentHashMapV8<K, V>
4481  
4482          /**
4483           * Returns a task that when invoked, performs the given action
4484 <         * for each non-null transformation of each value
4484 >         * for each non-null transformation of each value.
4485           *
4486           * @param map the map
4487           * @param transformer a function returning the transformation
# Line 4494 | Line 4489 | public class ConcurrentHashMapV8<K, V>
4489           * which case the action is not applied).
4490           * @param action the action
4491           */
4492 <        public static <K,V,U> ForkJoinTask<Void> forEachValue
4492 >        public static <K,V,U> ForkJoinTask<Void> forEachValue
4493              (ConcurrentHashMapV8<K,V> map,
4494               Fun<? super V, ? extends U> transformer,
4495               Action<U> action) {
# Line 4507 | Line 4502 | public class ConcurrentHashMapV8<K, V>
4502          /**
4503           * Returns a task that when invoked, returns a non-null result
4504           * from applying the given search function on each value, or
4505 <         * null if none.  Further element processing is suppressed
4506 <         * upon success. However, this method does not return until
4507 <         * other in-progress parallel invocations of the search
4513 <         * function also complete.
4505 >         * null if none.  Upon success, further element processing is
4506 >         * suppressed and the results of any other parallel
4507 >         * invocations of the search function are ignored.
4508           *
4509           * @param map the map
4510           * @param searchFunction a function returning a non-null
# Line 4640 | Line 4634 | public class ConcurrentHashMapV8<K, V>
4634  
4635          /**
4636           * Returns a task that when invoked, perform the given action
4637 <         * for each entry
4637 >         * for each entry.
4638           *
4639           * @param map the map
4640           * @param action the action
4641           */
4642 <        public static <K,V> ForkJoinTask<Void> forEachEntry
4642 >        public static <K,V> ForkJoinTask<Void> forEachEntry
4643              (ConcurrentHashMapV8<K,V> map,
4644               Action<Map.Entry<K,V>> action) {
4645              if (action == null) throw new NullPointerException();
# Line 4654 | Line 4648 | public class ConcurrentHashMapV8<K, V>
4648  
4649          /**
4650           * Returns a task that when invoked, perform the given action
4651 <         * for each non-null transformation of each entry
4651 >         * for each non-null transformation of each entry.
4652           *
4653           * @param map the map
4654           * @param transformer a function returning the transformation
# Line 4662 | Line 4656 | public class ConcurrentHashMapV8<K, V>
4656           * which case the action is not applied).
4657           * @param action the action
4658           */
4659 <        public static <K,V,U> ForkJoinTask<Void> forEachEntry
4659 >        public static <K,V,U> ForkJoinTask<Void> forEachEntry
4660              (ConcurrentHashMapV8<K,V> map,
4661               Fun<Map.Entry<K,V>, ? extends U> transformer,
4662               Action<U> action) {
# Line 4675 | Line 4669 | public class ConcurrentHashMapV8<K, V>
4669          /**
4670           * Returns a task that when invoked, returns a non-null result
4671           * from applying the given search function on each entry, or
4672 <         * null if none.  Further element processing is suppressed
4673 <         * upon success. However, this method does not return until
4674 <         * other in-progress parallel invocations of the search
4681 <         * function also complete.
4672 >         * null if none.  Upon success, further element processing is
4673 >         * suppressed and the results of any other parallel
4674 >         * invocations of the search function are ignored.
4675           *
4676           * @param map the map
4677           * @param searchFunction a function returning a non-null
# Line 4811 | Line 4804 | public class ConcurrentHashMapV8<K, V>
4804  
4805      /**
4806       * Base for FJ tasks for bulk operations. This adds a variant of
4807 <     * CountedCompleters and some split and merge bookeeping to
4807 >     * CountedCompleters and some split and merge bookkeeping to
4808       * iterator functionality. The forEach and reduce methods are
4809       * similar to those illustrated in CountedCompleter documentation,
4810       * except that bottom-up reduction completions perform them within
# Line 4820 | Line 4813 | public class ConcurrentHashMapV8<K, V>
4813       * exceptions are handled in a simpler manner, by just trying to
4814       * complete root task exceptionally.
4815       */
4816 <    static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> {
4816 >    @SuppressWarnings("serial") static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> {
4817          final BulkTask<K,V,?> parent;  // completion target
4818          int batch;                     // split control
4819          int pending;                   // completion control
# Line 4833 | Line 4826 | public class ConcurrentHashMapV8<K, V>
4826          }
4827  
4828          /** Constructor for subtasks */
4829 <        BulkTask(BulkTask<K,V,?> parent, int batch, boolean split) {
4830 <            super(parent, split);
4829 >        BulkTask(BulkTask<K,V,?> parent, int batch) {
4830 >            super(parent);
4831              this.parent = parent;
4832              this.batch = batch;
4833          }
# Line 4842 | Line 4835 | public class ConcurrentHashMapV8<K, V>
4835          // FJ methods
4836  
4837          /**
4838 <         * Propagate completion. Note that all reduce actions
4838 >         * Propagates completion. Note that all reduce actions
4839           * bypass this method to combine while completing.
4840           */
4841          final void tryComplete() {
# Line 4860 | Line 4853 | public class ConcurrentHashMapV8<K, V>
4853          }
4854  
4855          /**
4856 <         * Force root task to throw exception unless already complete.
4856 >         * Forces root task to complete.
4857 >         * @param ex if null, complete normally, else exceptionally
4858 >         * @return false to simplify use
4859           */
4860 <        final void tryAbortComputation(Throwable ex) {
4860 >        final boolean tryCompleteComputation(Throwable ex) {
4861              for (BulkTask<K,V,?> a = this;;) {
4862                  BulkTask<K,V,?> p = a.parent;
4863                  if (p == null) {
4864 <                    a.completeExceptionally(ex);
4865 <                    break;
4864 >                    if (ex != null)
4865 >                        a.completeExceptionally(ex);
4866 >                    else
4867 >                        a.quietlyComplete();
4868 >                    return false;
4869                  }
4870                  a = p;
4871              }
4872          }
4873  
4874 <        public final boolean exec() {
4875 <            try {
4876 <                compute();
4877 <            }
4878 <            catch(Throwable ex) {
4881 <                tryAbortComputation(ex);
4882 <            }
4883 <            return false;
4874 >        /**
4875 >         * Version of tryCompleteComputation for function screening checks
4876 >         */
4877 >        final boolean abortOnNullFunction() {
4878 >            return tryCompleteComputation(new Error("Unexpected null function"));
4879          }
4880  
4886        public abstract void compute();
4887
4881          // utilities
4882  
4883          /** CompareAndSet pending count */
# Line 4893 | Line 4886 | public class ConcurrentHashMapV8<K, V>
4886          }
4887  
4888          /**
4889 <         * Return approx exp2 of the number of times (minus one) to
4889 >         * Returns approx exp2 of the number of times (minus one) to
4890           * split task by two before executing leaf action. This value
4891           * is faster to compute and more convenient to use as a guide
4892           * to splitting than is the depth, since it is used while
# Line 4904 | Line 4897 | public class ConcurrentHashMapV8<K, V>
4897              if (b < 0) {
4898                  long n = map.counter.sum();
4899                  int sp = getPool().getParallelism() << 3; // slack of 8
4900 <                b = batch = (n <= 0L)? 0 : (n < (long)sp) ? (int)n : sp;
4900 >                b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp;
4901              }
4902              return b;
4903          }
4904  
4905          /**
4906 <         * 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
4906 >         * Returns exportable snapshot entry.
4907           */
4908          static <K,V> AbstractMap.SimpleEntry<K,V> entryFor(K k, V v) {
4909 <            return new AbstractMap.SimpleEntry(k, v);
4909 >            return new AbstractMap.SimpleEntry<K,V>(k, v);
4910          }
4911  
4912          // Unsafe mechanics
# Line 4927 | Line 4914 | public class ConcurrentHashMapV8<K, V>
4914          private static final long PENDING;
4915          static {
4916              try {
4917 <                U = sun.misc.Unsafe.getUnsafe();
4917 >                U = getUnsafe();
4918                  PENDING = U.objectFieldOffset
4919                      (BulkTask.class.getDeclaredField("pending"));
4920              } catch (Exception e) {
# Line 4942 | Line 4929 | public class ConcurrentHashMapV8<K, V>
4929       * others.
4930       */
4931  
4932 <    static final class ForEachKeyTask<K,V>
4932 >    @SuppressWarnings("serial") static final class ForEachKeyTask<K,V>
4933          extends BulkTask<K,V,Void> {
4934          final Action<K> action;
4935          ForEachKeyTask
# Line 4952 | Line 4939 | public class ConcurrentHashMapV8<K, V>
4939              this.action = action;
4940          }
4941          ForEachKeyTask
4942 <            (BulkTask<K,V,?> p, int b, boolean split,
4942 >            (BulkTask<K,V,?> p, int b,
4943               Action<K> action) {
4944 <            super(p, b, split);
4944 >            super(p, b);
4945              this.action = action;
4946          }
4947 <        public final void compute() {
4947 >        @SuppressWarnings("unchecked") public final boolean exec() {
4948              final Action<K> action = this.action;
4949              if (action == null)
4950 <                throw new Error(NullFunctionMessage);
4951 <            int b = batch(), c;
4952 <            while (b > 1 && baseIndex != baseLimit) {
4953 <                do {} while (!casPending(c = pending, c+1));
4954 <                new ForEachKeyTask<K,V>(this, b >>>= 1, true, action).fork();
4950 >                return abortOnNullFunction();
4951 >            try {
4952 >                int b = batch(), c;
4953 >                while (b > 1 && baseIndex != baseLimit) {
4954 >                    do {} while (!casPending(c = pending, c+1));
4955 >                    new ForEachKeyTask<K,V>(this, b >>>= 1, action).fork();
4956 >                }
4957 >                while (advance() != null)
4958 >                    action.apply((K)nextKey);
4959 >                tryComplete();
4960 >            } catch (Throwable ex) {
4961 >                return tryCompleteComputation(ex);
4962              }
4963 <            while (advance() != null)
4970 <                action.apply((K)nextKey);
4971 <            tryComplete();
4963 >            return false;
4964          }
4965      }
4966  
4967 <    static final class ForEachValueTask<K,V>
4967 >    @SuppressWarnings("serial") static final class ForEachValueTask<K,V>
4968          extends BulkTask<K,V,Void> {
4969          final Action<V> action;
4970          ForEachValueTask
# Line 4982 | Line 4974 | public class ConcurrentHashMapV8<K, V>
4974              this.action = action;
4975          }
4976          ForEachValueTask
4977 <            (BulkTask<K,V,?> p, int b, boolean split,
4977 >            (BulkTask<K,V,?> p, int b,
4978               Action<V> action) {
4979 <            super(p, b, split);
4979 >            super(p, b);
4980              this.action = action;
4981          }
4982 <        public final void compute() {
4982 >        @SuppressWarnings("unchecked") public final boolean exec() {
4983              final Action<V> action = this.action;
4984              if (action == null)
4985 <                throw new Error(NullFunctionMessage);
4986 <            int b = batch(), c;
4987 <            while (b > 1 && baseIndex != baseLimit) {
4988 <                do {} while (!casPending(c = pending, c+1));
4989 <                new ForEachValueTask<K,V>(this, b >>>= 1, true, action).fork();
4985 >                return abortOnNullFunction();
4986 >            try {
4987 >                int b = batch(), c;
4988 >                while (b > 1 && baseIndex != baseLimit) {
4989 >                    do {} while (!casPending(c = pending, c+1));
4990 >                    new ForEachValueTask<K,V>(this, b >>>= 1, action).fork();
4991 >                }
4992 >                Object v;
4993 >                while ((v = advance()) != null)
4994 >                    action.apply((V)v);
4995 >                tryComplete();
4996 >            } catch (Throwable ex) {
4997 >                return tryCompleteComputation(ex);
4998              }
4999 <            Object v;
5000 <            while ((v = advance()) != null)
5001 <                action.apply((V)v);
5002 <            tryComplete();
4999 >            return false;
5000          }
5001      }
5002  
5003 <    static final class ForEachEntryTask<K,V>
5003 >    @SuppressWarnings("serial") static final class ForEachEntryTask<K,V>
5004          extends BulkTask<K,V,Void> {
5005          final Action<Entry<K,V>> action;
5006          ForEachEntryTask
# Line 5013 | Line 5010 | public class ConcurrentHashMapV8<K, V>
5010              this.action = action;
5011          }
5012          ForEachEntryTask
5013 <            (BulkTask<K,V,?> p, int b, boolean split,
5013 >            (BulkTask<K,V,?> p, int b,
5014               Action<Entry<K,V>> action) {
5015 <            super(p, b, split);
5015 >            super(p, b);
5016              this.action = action;
5017          }
5018 <        public final void compute() {
5018 >        @SuppressWarnings("unchecked") public final boolean exec() {
5019              final Action<Entry<K,V>> action = this.action;
5020              if (action == null)
5021 <                throw new Error(NullFunctionMessage);
5022 <            int b = batch(), c;
5023 <            while (b > 1 && baseIndex != baseLimit) {
5024 <                do {} while (!casPending(c = pending, c+1));
5025 <                new ForEachEntryTask<K,V>(this, b >>>= 1, true, action).fork();
5021 >                return abortOnNullFunction();
5022 >            try {
5023 >                int b = batch(), c;
5024 >                while (b > 1 && baseIndex != baseLimit) {
5025 >                    do {} while (!casPending(c = pending, c+1));
5026 >                    new ForEachEntryTask<K,V>(this, b >>>= 1, action).fork();
5027 >                }
5028 >                Object v;
5029 >                while ((v = advance()) != null)
5030 >                    action.apply(entryFor((K)nextKey, (V)v));
5031 >                tryComplete();
5032 >            } catch (Throwable ex) {
5033 >                return tryCompleteComputation(ex);
5034              }
5035 <            Object v;
5031 <            while ((v = advance()) != null)
5032 <                action.apply(entryFor((K)nextKey, (V)v));
5033 <            tryComplete();
5035 >            return false;
5036          }
5037      }
5038  
5039 <    static final class ForEachMappingTask<K,V>
5039 >    @SuppressWarnings("serial") static final class ForEachMappingTask<K,V>
5040          extends BulkTask<K,V,Void> {
5041          final BiAction<K,V> action;
5042          ForEachMappingTask
# Line 5044 | Line 5046 | public class ConcurrentHashMapV8<K, V>
5046              this.action = action;
5047          }
5048          ForEachMappingTask
5049 <            (BulkTask<K,V,?> p, int b, boolean split,
5049 >            (BulkTask<K,V,?> p, int b,
5050               BiAction<K,V> action) {
5051 <            super(p, b, split);
5051 >            super(p, b);
5052              this.action = action;
5053          }
5054  
5055 <        public final void compute() {
5055 >        @SuppressWarnings("unchecked") public final boolean exec() {
5056              final BiAction<K,V> action = this.action;
5057              if (action == null)
5058 <                throw new Error(NullFunctionMessage);
5059 <            int b = batch(), c;
5060 <            while (b > 1 && baseIndex != baseLimit) {
5061 <                do {} while (!casPending(c = pending, c+1));
5062 <                new ForEachMappingTask<K,V>(this, b >>>= 1, true,
5063 <                                            action).fork();
5058 >                return abortOnNullFunction();
5059 >            try {
5060 >                int b = batch(), c;
5061 >                while (b > 1 && baseIndex != baseLimit) {
5062 >                    do {} while (!casPending(c = pending, c+1));
5063 >                    new ForEachMappingTask<K,V>(this, b >>>= 1,
5064 >                                                action).fork();
5065 >                }
5066 >                Object v;
5067 >                while ((v = advance()) != null)
5068 >                    action.apply((K)nextKey, (V)v);
5069 >                tryComplete();
5070 >            } catch (Throwable ex) {
5071 >                return tryCompleteComputation(ex);
5072              }
5073 <            Object v;
5064 <            while ((v = advance()) != null)
5065 <                action.apply((K)nextKey, (V)v);
5066 <            tryComplete();
5073 >            return false;
5074          }
5075      }
5076  
5077 <    static final class ForEachTransformedKeyTask<K,V,U>
5077 >    @SuppressWarnings("serial") static final class ForEachTransformedKeyTask<K,V,U>
5078          extends BulkTask<K,V,Void> {
5079          final Fun<? super K, ? extends U> transformer;
5080          final Action<U> action;
# Line 5081 | Line 5088 | public class ConcurrentHashMapV8<K, V>
5088  
5089          }
5090          ForEachTransformedKeyTask
5091 <            (BulkTask<K,V,?> p, int b, boolean split,
5091 >            (BulkTask<K,V,?> p, int b,
5092               Fun<? super K, ? extends U> transformer,
5093               Action<U> action) {
5094 <            super(p, b, split);
5094 >            super(p, b);
5095              this.transformer = transformer;
5096              this.action = action;
5097          }
5098 <        public final void compute() {
5098 >        @SuppressWarnings("unchecked") public final boolean exec() {
5099              final Fun<? super K, ? extends U> transformer =
5100                  this.transformer;
5101              final Action<U> action = this.action;
5102              if (transformer == null || action == null)
5103 <                throw new Error(NullFunctionMessage);
5104 <            int b = batch(), c;
5105 <            while (b > 1 && baseIndex != baseLimit) {
5106 <                do {} while (!casPending(c = pending, c+1));
5107 <                new ForEachTransformedKeyTask<K,V,U>
5108 <                    (this, b >>>= 1, true, transformer, action).fork();
5109 <            }
5110 <            U u;
5111 <            while (advance() != null) {
5112 <                if ((u = transformer.apply((K)nextKey)) != null)
5113 <                    action.apply(u);
5103 >                return abortOnNullFunction();
5104 >            try {
5105 >                int b = batch(), c;
5106 >                while (b > 1 && baseIndex != baseLimit) {
5107 >                    do {} while (!casPending(c = pending, c+1));
5108 >                    new ForEachTransformedKeyTask<K,V,U>
5109 >                        (this, b >>>= 1, transformer, action).fork();
5110 >                }
5111 >                U u;
5112 >                while (advance() != null) {
5113 >                    if ((u = transformer.apply((K)nextKey)) != null)
5114 >                        action.apply(u);
5115 >                }
5116 >                tryComplete();
5117 >            } catch (Throwable ex) {
5118 >                return tryCompleteComputation(ex);
5119              }
5120 <            tryComplete();
5120 >            return false;
5121          }
5122      }
5123  
5124 <    static final class ForEachTransformedValueTask<K,V,U>
5124 >    @SuppressWarnings("serial") static final class ForEachTransformedValueTask<K,V,U>
5125          extends BulkTask<K,V,Void> {
5126          final Fun<? super V, ? extends U> transformer;
5127          final Action<U> action;
# Line 5123 | Line 5135 | public class ConcurrentHashMapV8<K, V>
5135  
5136          }
5137          ForEachTransformedValueTask
5138 <            (BulkTask<K,V,?> p, int b, boolean split,
5138 >            (BulkTask<K,V,?> p, int b,
5139               Fun<? super V, ? extends U> transformer,
5140               Action<U> action) {
5141 <            super(p, b, split);
5141 >            super(p, b);
5142              this.transformer = transformer;
5143              this.action = action;
5144          }
5145 <        public final void compute() {
5145 >        @SuppressWarnings("unchecked") public final boolean exec() {
5146              final Fun<? super V, ? extends U> transformer =
5147                  this.transformer;
5148              final Action<U> action = this.action;
5149              if (transformer == null || action == null)
5150 <                throw new Error(NullFunctionMessage);
5151 <            int b = batch(), c;
5152 <            while (b > 1 && baseIndex != baseLimit) {
5153 <                do {} while (!casPending(c = pending, c+1));
5154 <                new ForEachTransformedValueTask<K,V,U>
5155 <                    (this, b >>>= 1, true, transformer, action).fork();
5156 <            }
5157 <            Object v; U u;
5158 <            while ((v = advance()) != null) {
5159 <                if ((u = transformer.apply((V)v)) != null)
5160 <                    action.apply(u);
5150 >                return abortOnNullFunction();
5151 >            try {
5152 >                int b = batch(), c;
5153 >                while (b > 1 && baseIndex != baseLimit) {
5154 >                    do {} while (!casPending(c = pending, c+1));
5155 >                    new ForEachTransformedValueTask<K,V,U>
5156 >                        (this, b >>>= 1, transformer, action).fork();
5157 >                }
5158 >                Object v; U u;
5159 >                while ((v = advance()) != null) {
5160 >                    if ((u = transformer.apply((V)v)) != null)
5161 >                        action.apply(u);
5162 >                }
5163 >                tryComplete();
5164 >            } catch (Throwable ex) {
5165 >                return tryCompleteComputation(ex);
5166              }
5167 <            tryComplete();
5167 >            return false;
5168          }
5169      }
5170  
5171 <    static final class ForEachTransformedEntryTask<K,V,U>
5171 >    @SuppressWarnings("serial") static final class ForEachTransformedEntryTask<K,V,U>
5172          extends BulkTask<K,V,Void> {
5173          final Fun<Map.Entry<K,V>, ? extends U> transformer;
5174          final Action<U> action;
# Line 5165 | Line 5182 | public class ConcurrentHashMapV8<K, V>
5182  
5183          }
5184          ForEachTransformedEntryTask
5185 <            (BulkTask<K,V,?> p, int b, boolean split,
5185 >            (BulkTask<K,V,?> p, int b,
5186               Fun<Map.Entry<K,V>, ? extends U> transformer,
5187               Action<U> action) {
5188 <            super(p, b, split);
5188 >            super(p, b);
5189              this.transformer = transformer;
5190              this.action = action;
5191          }
5192 <        public final void compute() {
5192 >        @SuppressWarnings("unchecked") public final boolean exec() {
5193              final Fun<Map.Entry<K,V>, ? extends U> transformer =
5194                  this.transformer;
5195              final Action<U> action = this.action;
5196              if (transformer == null || action == null)
5197 <                throw new Error(NullFunctionMessage);
5198 <            int b = batch(), c;
5199 <            while (b > 1 && baseIndex != baseLimit) {
5200 <                do {} while (!casPending(c = pending, c+1));
5201 <                new ForEachTransformedEntryTask<K,V,U>
5202 <                    (this, b >>>= 1, true, transformer, action).fork();
5203 <            }
5204 <            Object v; U u;
5205 <            while ((v = advance()) != null) {
5206 <                if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5207 <                    action.apply(u);
5197 >                return abortOnNullFunction();
5198 >            try {
5199 >                int b = batch(), c;
5200 >                while (b > 1 && baseIndex != baseLimit) {
5201 >                    do {} while (!casPending(c = pending, c+1));
5202 >                    new ForEachTransformedEntryTask<K,V,U>
5203 >                        (this, b >>>= 1, transformer, action).fork();
5204 >                }
5205 >                Object v; U u;
5206 >                while ((v = advance()) != null) {
5207 >                    if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5208 >                        action.apply(u);
5209 >                }
5210 >                tryComplete();
5211 >            } catch (Throwable ex) {
5212 >                return tryCompleteComputation(ex);
5213              }
5214 <            tryComplete();
5214 >            return false;
5215          }
5216      }
5217  
5218 <    static final class ForEachTransformedMappingTask<K,V,U>
5218 >    @SuppressWarnings("serial") static final class ForEachTransformedMappingTask<K,V,U>
5219          extends BulkTask<K,V,Void> {
5220          final BiFun<? super K, ? super V, ? extends U> transformer;
5221          final Action<U> action;
# Line 5207 | Line 5229 | public class ConcurrentHashMapV8<K, V>
5229  
5230          }
5231          ForEachTransformedMappingTask
5232 <            (BulkTask<K,V,?> p, int b, boolean split,
5232 >            (BulkTask<K,V,?> p, int b,
5233               BiFun<? super K, ? super V, ? extends U> transformer,
5234               Action<U> action) {
5235 <            super(p, b, split);
5235 >            super(p, b);
5236              this.transformer = transformer;
5237              this.action = action;
5238          }
5239 <        public final void compute() {
5239 >        @SuppressWarnings("unchecked") public final boolean exec() {
5240              final BiFun<? super K, ? super V, ? extends U> transformer =
5241                  this.transformer;
5242              final Action<U> action = this.action;
5243              if (transformer == null || action == null)
5244 <                throw new Error(NullFunctionMessage);
5245 <            int b = batch(), c;
5246 <            while (b > 1 && baseIndex != baseLimit) {
5247 <                do {} while (!casPending(c = pending, c+1));
5248 <                new ForEachTransformedMappingTask<K,V,U>
5249 <                    (this, b >>>= 1, true, transformer, action).fork();
5250 <            }
5251 <            Object v; U u;
5252 <            while ((v = advance()) != null) {
5253 <                if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5254 <                    action.apply(u);
5244 >                return abortOnNullFunction();
5245 >            try {
5246 >                int b = batch(), c;
5247 >                while (b > 1 && baseIndex != baseLimit) {
5248 >                    do {} while (!casPending(c = pending, c+1));
5249 >                    new ForEachTransformedMappingTask<K,V,U>
5250 >                        (this, b >>>= 1, transformer, action).fork();
5251 >                }
5252 >                Object v; U u;
5253 >                while ((v = advance()) != null) {
5254 >                    if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5255 >                        action.apply(u);
5256 >                }
5257 >                tryComplete();
5258 >            } catch (Throwable ex) {
5259 >                return tryCompleteComputation(ex);
5260              }
5261 <            tryComplete();
5261 >            return false;
5262          }
5263      }
5264  
5265 <    static final class SearchKeysTask<K,V,U>
5265 >    @SuppressWarnings("serial") static final class SearchKeysTask<K,V,U>
5266          extends BulkTask<K,V,U> {
5267          final Fun<? super K, ? extends U> searchFunction;
5268          final AtomicReference<U> result;
# Line 5247 | Line 5274 | public class ConcurrentHashMapV8<K, V>
5274              this.searchFunction = searchFunction; this.result = result;
5275          }
5276          SearchKeysTask
5277 <            (BulkTask<K,V,?> p, int b, boolean split,
5277 >            (BulkTask<K,V,?> p, int b,
5278               Fun<? super K, ? extends U> searchFunction,
5279               AtomicReference<U> result) {
5280 <            super(p, b, split);
5280 >            super(p, b);
5281              this.searchFunction = searchFunction; this.result = result;
5282          }
5283 <        public final void compute() {
5283 >        @SuppressWarnings("unchecked") public final boolean exec() {
5284              AtomicReference<U> result = this.result;
5285              final Fun<? super K, ? extends U> searchFunction =
5286                  this.searchFunction;
5287              if (searchFunction == null || result == null)
5288 <                throw new Error(NullFunctionMessage);
5289 <            int b = batch(), c;
5290 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5291 <                do {} while (!casPending(c = pending, c+1));
5292 <                new SearchKeysTask<K,V,U>(this, b >>>= 1, true,
5293 <                                          searchFunction, result).fork();
5294 <            }
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;
5288 >                return abortOnNullFunction();
5289 >            try {
5290 >                int b = batch(), c;
5291 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5292 >                    do {} while (!casPending(c = pending, c+1));
5293 >                    new SearchKeysTask<K,V,U>(this, b >>>= 1,
5294 >                                              searchFunction, result).fork();
5295                  }
5296 +                U u;
5297 +                while (result.get() == null && advance() != null) {
5298 +                    if ((u = searchFunction.apply((K)nextKey)) != null) {
5299 +                        if (result.compareAndSet(null, u))
5300 +                            tryCompleteComputation(null);
5301 +                        break;
5302 +                    }
5303 +                }
5304 +                tryComplete();
5305 +            } catch (Throwable ex) {
5306 +                return tryCompleteComputation(ex);
5307              }
5308 <            tryComplete();
5308 >            return false;
5309          }
5310          public final U getRawResult() { return result.get(); }
5311      }
5312  
5313 <    static final class SearchValuesTask<K,V,U>
5313 >    @SuppressWarnings("serial") static final class SearchValuesTask<K,V,U>
5314          extends BulkTask<K,V,U> {
5315          final Fun<? super V, ? extends U> searchFunction;
5316          final AtomicReference<U> result;
# Line 5289 | Line 5322 | public class ConcurrentHashMapV8<K, V>
5322              this.searchFunction = searchFunction; this.result = result;
5323          }
5324          SearchValuesTask
5325 <            (BulkTask<K,V,?> p, int b, boolean split,
5325 >            (BulkTask<K,V,?> p, int b,
5326               Fun<? super V, ? extends U> searchFunction,
5327               AtomicReference<U> result) {
5328 <            super(p, b, split);
5328 >            super(p, b);
5329              this.searchFunction = searchFunction; this.result = result;
5330          }
5331 <        public final void compute() {
5331 >        @SuppressWarnings("unchecked") public final boolean exec() {
5332              AtomicReference<U> result = this.result;
5333              final Fun<? super V, ? extends U> searchFunction =
5334                  this.searchFunction;
5335              if (searchFunction == null || result == null)
5336 <                throw new Error(NullFunctionMessage);
5337 <            int b = batch(), c;
5338 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5339 <                do {} while (!casPending(c = pending, c+1));
5340 <                new SearchValuesTask<K,V,U>(this, b >>>= 1, true,
5341 <                                            searchFunction, result).fork();
5342 <            }
5343 <            Object v; U u;
5344 <            while (result.get() == null && (v = advance()) != null) {
5345 <                if ((u = searchFunction.apply((V)v)) != null) {
5346 <                    result.compareAndSet(null, u);
5347 <                    break;
5336 >                return abortOnNullFunction();
5337 >            try {
5338 >                int b = batch(), c;
5339 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5340 >                    do {} while (!casPending(c = pending, c+1));
5341 >                    new SearchValuesTask<K,V,U>(this, b >>>= 1,
5342 >                                                searchFunction, result).fork();
5343 >                }
5344 >                Object v; U u;
5345 >                while (result.get() == null && (v = advance()) != null) {
5346 >                    if ((u = searchFunction.apply((V)v)) != null) {
5347 >                        if (result.compareAndSet(null, u))
5348 >                            tryCompleteComputation(null);
5349 >                        break;
5350 >                    }
5351                  }
5352 +                tryComplete();
5353 +            } catch (Throwable ex) {
5354 +                return tryCompleteComputation(ex);
5355              }
5356 <            tryComplete();
5356 >            return false;
5357          }
5358          public final U getRawResult() { return result.get(); }
5359      }
5360  
5361 <    static final class SearchEntriesTask<K,V,U>
5361 >    @SuppressWarnings("serial") static final class SearchEntriesTask<K,V,U>
5362          extends BulkTask<K,V,U> {
5363          final Fun<Entry<K,V>, ? extends U> searchFunction;
5364          final AtomicReference<U> result;
# Line 5331 | Line 5370 | public class ConcurrentHashMapV8<K, V>
5370              this.searchFunction = searchFunction; this.result = result;
5371          }
5372          SearchEntriesTask
5373 <            (BulkTask<K,V,?> p, int b, boolean split,
5373 >            (BulkTask<K,V,?> p, int b,
5374               Fun<Entry<K,V>, ? extends U> searchFunction,
5375               AtomicReference<U> result) {
5376 <            super(p, b, split);
5376 >            super(p, b);
5377              this.searchFunction = searchFunction; this.result = result;
5378          }
5379 <        public final void compute() {
5379 >        @SuppressWarnings("unchecked") public final boolean exec() {
5380              AtomicReference<U> result = this.result;
5381              final Fun<Entry<K,V>, ? extends U> searchFunction =
5382                  this.searchFunction;
5383              if (searchFunction == null || result == null)
5384 <                throw new Error(NullFunctionMessage);
5385 <            int b = batch(), c;
5386 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5387 <                do {} while (!casPending(c = pending, c+1));
5388 <                new SearchEntriesTask<K,V,U>(this, b >>>= 1, true,
5389 <                                             searchFunction, result).fork();
5390 <            }
5391 <            Object v; U u;
5392 <            while (result.get() == null && (v = advance()) != null) {
5393 <                if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) {
5394 <                    result.compareAndSet(null, u);
5395 <                    break;
5384 >                return abortOnNullFunction();
5385 >            try {
5386 >                int b = batch(), c;
5387 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5388 >                    do {} while (!casPending(c = pending, c+1));
5389 >                    new SearchEntriesTask<K,V,U>(this, b >>>= 1,
5390 >                                                 searchFunction, result).fork();
5391 >                }
5392 >                Object v; U u;
5393 >                while (result.get() == null && (v = advance()) != null) {
5394 >                    if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) {
5395 >                        if (result.compareAndSet(null, u))
5396 >                            tryCompleteComputation(null);
5397 >                        break;
5398 >                    }
5399                  }
5400 +                tryComplete();
5401 +            } catch (Throwable ex) {
5402 +                return tryCompleteComputation(ex);
5403              }
5404 <            tryComplete();
5404 >            return false;
5405          }
5406          public final U getRawResult() { return result.get(); }
5407      }
5408  
5409 <    static final class SearchMappingsTask<K,V,U>
5409 >    @SuppressWarnings("serial") static final class SearchMappingsTask<K,V,U>
5410          extends BulkTask<K,V,U> {
5411          final BiFun<? super K, ? super V, ? extends U> searchFunction;
5412          final AtomicReference<U> result;
# Line 5373 | Line 5418 | public class ConcurrentHashMapV8<K, V>
5418              this.searchFunction = searchFunction; this.result = result;
5419          }
5420          SearchMappingsTask
5421 <            (BulkTask<K,V,?> p, int b, boolean split,
5421 >            (BulkTask<K,V,?> p, int b,
5422               BiFun<? super K, ? super V, ? extends U> searchFunction,
5423               AtomicReference<U> result) {
5424 <            super(p, b, split);
5424 >            super(p, b);
5425              this.searchFunction = searchFunction; this.result = result;
5426          }
5427 <        public final void compute() {
5427 >        @SuppressWarnings("unchecked") public final boolean exec() {
5428              AtomicReference<U> result = this.result;
5429              final BiFun<? super K, ? super V, ? extends U> searchFunction =
5430                  this.searchFunction;
5431              if (searchFunction == null || result == null)
5432 <                throw new Error(NullFunctionMessage);
5433 <            int b = batch(), c;
5434 <            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5435 <                do {} while (!casPending(c = pending, c+1));
5436 <                new SearchMappingsTask<K,V,U>(this, b >>>= 1, true,
5437 <                                              searchFunction, result).fork();
5438 <            }
5439 <            Object v; U u;
5440 <            while (result.get() == null && (v = advance()) != null) {
5441 <                if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) {
5442 <                    result.compareAndSet(null, u);
5443 <                    break;
5432 >                return abortOnNullFunction();
5433 >            try {
5434 >                int b = batch(), c;
5435 >                while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5436 >                    do {} while (!casPending(c = pending, c+1));
5437 >                    new SearchMappingsTask<K,V,U>(this, b >>>= 1,
5438 >                                                  searchFunction, result).fork();
5439 >                }
5440 >                Object v; U u;
5441 >                while (result.get() == null && (v = advance()) != null) {
5442 >                    if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) {
5443 >                        if (result.compareAndSet(null, u))
5444 >                            tryCompleteComputation(null);
5445 >                        break;
5446 >                    }
5447                  }
5448 +                tryComplete();
5449 +            } catch (Throwable ex) {
5450 +                return tryCompleteComputation(ex);
5451              }
5452 <            tryComplete();
5452 >            return false;
5453          }
5454          public final U getRawResult() { return result.get(); }
5455      }
5456  
5457 <    static final class ReduceKeysTask<K,V>
5457 >    @SuppressWarnings("serial") static final class ReduceKeysTask<K,V>
5458          extends BulkTask<K,V,K> {
5459          final BiFun<? super K, ? super K, ? extends K> reducer;
5460          K result;
5461 <        ReduceKeysTask<K,V> sibling;
5461 >        ReduceKeysTask<K,V> rights, nextRight;
5462          ReduceKeysTask
5463              (ConcurrentHashMapV8<K,V> m,
5464               BiFun<? super K, ? super K, ? extends K> reducer) {
# Line 5415 | Line 5466 | public class ConcurrentHashMapV8<K, V>
5466              this.reducer = reducer;
5467          }
5468          ReduceKeysTask
5469 <            (BulkTask<K,V,?> p, int b, boolean split,
5469 >            (BulkTask<K,V,?> p, int b,
5470 >             ReduceKeysTask<K,V> nextRight,
5471               BiFun<? super K, ? super K, ? extends K> reducer) {
5472 <            super(p, b, split);
5472 >            super(p, b); this.nextRight = nextRight;
5473              this.reducer = reducer;
5474          }
5475  
5476 <        public final void compute() {
5425 <            ReduceKeysTask<K,V> t = this;
5476 >        @SuppressWarnings("unchecked") public final boolean exec() {
5477              final BiFun<? super K, ? super K, ? extends K> reducer =
5478                  this.reducer;
5479              if (reducer == null)
5480 <                throw new Error(NullFunctionMessage);
5481 <            int b = batch();
5482 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5483 <                b >>>= 1;
5484 <                t.pending = 1;
5485 <                ReduceKeysTask<K,V> rt =
5486 <                    new ReduceKeysTask<K,V>
5487 <                    (t, b, true, reducer);
5488 <                t = new ReduceKeysTask<K,V>
5489 <                    (t, b, false, reducer);
5490 <                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;
5480 >                return abortOnNullFunction();
5481 >            try {
5482 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5483 >                    do {} while (!casPending(c = pending, c+1));
5484 >                    (rights = new ReduceKeysTask<K,V>
5485 >                     (this, b >>>= 1, rights, reducer)).fork();
5486 >                }
5487 >                K r = null;
5488 >                while (advance() != null) {
5489 >                    K u = (K)nextKey;
5490 >                    r = (r == null) ? u : reducer.apply(r, u);
5491                  }
5492 <                else if ((c = (p = (ReduceKeysTask<K,V>)par).pending) == 0) {
5493 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5494 <                        r = (r == null) ? u : reducer.apply(r, u);
5495 <                    (t = p).result = r;
5492 >                result = r;
5493 >                for (ReduceKeysTask<K,V> t = this, s;;) {
5494 >                    int c; BulkTask<K,V,?> par; K tr, sr;
5495 >                    if ((c = t.pending) == 0) {
5496 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5497 >                            if ((sr = s.result) != null)
5498 >                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5499 >                        }
5500 >                        if ((par = t.parent) == null ||
5501 >                            !(par instanceof ReduceKeysTask)) {
5502 >                            t.quietlyComplete();
5503 >                            break;
5504 >                        }
5505 >                        t = (ReduceKeysTask<K,V>)par;
5506 >                    }
5507 >                    else if (t.casPending(c, c - 1))
5508 >                        break;
5509                  }
5510 <                else if (p.casPending(c, 0))
5511 <                    break;
5510 >            } catch (Throwable ex) {
5511 >                return tryCompleteComputation(ex);
5512              }
5513 +            return false;
5514          }
5515          public final K getRawResult() { return result; }
5516      }
5517  
5518 <    static final class ReduceValuesTask<K,V>
5518 >    @SuppressWarnings("serial") static final class ReduceValuesTask<K,V>
5519          extends BulkTask<K,V,V> {
5520          final BiFun<? super V, ? super V, ? extends V> reducer;
5521          V result;
5522 <        ReduceValuesTask<K,V> sibling;
5522 >        ReduceValuesTask<K,V> rights, nextRight;
5523          ReduceValuesTask
5524              (ConcurrentHashMapV8<K,V> m,
5525               BiFun<? super V, ? super V, ? extends V> reducer) {
# Line 5477 | Line 5527 | public class ConcurrentHashMapV8<K, V>
5527              this.reducer = reducer;
5528          }
5529          ReduceValuesTask
5530 <            (BulkTask<K,V,?> p, int b, boolean split,
5530 >            (BulkTask<K,V,?> p, int b,
5531 >             ReduceValuesTask<K,V> nextRight,
5532               BiFun<? super V, ? super V, ? extends V> reducer) {
5533 <            super(p, b, split);
5533 >            super(p, b); this.nextRight = nextRight;
5534              this.reducer = reducer;
5535          }
5536  
5537 <        public final void compute() {
5487 <            ReduceValuesTask<K,V> t = this;
5537 >        @SuppressWarnings("unchecked") public final boolean exec() {
5538              final BiFun<? super V, ? super V, ? extends V> reducer =
5539                  this.reducer;
5540              if (reducer == null)
5541 <                throw new Error(NullFunctionMessage);
5542 <            int b = batch();
5543 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5544 <                b >>>= 1;
5545 <                t.pending = 1;
5546 <                ReduceValuesTask<K,V> rt =
5547 <                    new ReduceValuesTask<K,V>
5548 <                    (t, b, true, reducer);
5549 <                t = new ReduceValuesTask<K,V>
5550 <                    (t, b, false, reducer);
5551 <                t.sibling = rt;
5552 <                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;
5541 >                return abortOnNullFunction();
5542 >            try {
5543 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5544 >                    do {} while (!casPending(c = pending, c+1));
5545 >                    (rights = new ReduceValuesTask<K,V>
5546 >                     (this, b >>>= 1, rights, reducer)).fork();
5547 >                }
5548 >                V r = null;
5549 >                Object v;
5550 >                while ((v = advance()) != null) {
5551 >                    V u = (V)v;
5552 >                    r = (r == null) ? u : reducer.apply(r, u);
5553                  }
5554 <                else if ((c = (p = (ReduceValuesTask<K,V>)par).pending) == 0) {
5555 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5556 <                        r = (r == null) ? u : reducer.apply(r, u);
5557 <                    (t = p).result = r;
5554 >                result = r;
5555 >                for (ReduceValuesTask<K,V> t = this, s;;) {
5556 >                    int c; BulkTask<K,V,?> par; V tr, sr;
5557 >                    if ((c = t.pending) == 0) {
5558 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5559 >                            if ((sr = s.result) != null)
5560 >                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5561 >                        }
5562 >                        if ((par = t.parent) == null ||
5563 >                            !(par instanceof ReduceValuesTask)) {
5564 >                            t.quietlyComplete();
5565 >                            break;
5566 >                        }
5567 >                        t = (ReduceValuesTask<K,V>)par;
5568 >                    }
5569 >                    else if (t.casPending(c, c - 1))
5570 >                        break;
5571                  }
5572 <                else if (p.casPending(c, 0))
5573 <                    break;
5572 >            } catch (Throwable ex) {
5573 >                return tryCompleteComputation(ex);
5574              }
5575 +            return false;
5576          }
5577          public final V getRawResult() { return result; }
5578      }
5579  
5580 <    static final class ReduceEntriesTask<K,V>
5580 >    @SuppressWarnings("serial") static final class ReduceEntriesTask<K,V>
5581          extends BulkTask<K,V,Map.Entry<K,V>> {
5582          final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer;
5583          Map.Entry<K,V> result;
5584 <        ReduceEntriesTask<K,V> sibling;
5584 >        ReduceEntriesTask<K,V> rights, nextRight;
5585          ReduceEntriesTask
5586              (ConcurrentHashMapV8<K,V> m,
5587               BiFun<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
# Line 5540 | Line 5589 | public class ConcurrentHashMapV8<K, V>
5589              this.reducer = reducer;
5590          }
5591          ReduceEntriesTask
5592 <            (BulkTask<K,V,?> p, int b, boolean split,
5592 >            (BulkTask<K,V,?> p, int b,
5593 >             ReduceEntriesTask<K,V> nextRight,
5594               BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5595 <            super(p, b, split);
5595 >            super(p, b); this.nextRight = nextRight;
5596              this.reducer = reducer;
5597          }
5598  
5599 <        public final void compute() {
5550 <            ReduceEntriesTask<K,V> t = this;
5599 >        @SuppressWarnings("unchecked") public final boolean exec() {
5600              final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer =
5601                  this.reducer;
5602              if (reducer == null)
5603 <                throw new Error(NullFunctionMessage);
5604 <            int b = batch();
5605 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5606 <                b >>>= 1;
5607 <                t.pending = 1;
5608 <                ReduceEntriesTask<K,V> rt =
5609 <                    new ReduceEntriesTask<K,V>
5610 <                    (t, b, true, reducer);
5611 <                t = new ReduceEntriesTask<K,V>
5612 <                    (t, b, false, reducer);
5613 <                t.sibling = rt;
5614 <                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;
5603 >                return abortOnNullFunction();
5604 >            try {
5605 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5606 >                    do {} while (!casPending(c = pending, c+1));
5607 >                    (rights = new ReduceEntriesTask<K,V>
5608 >                     (this, b >>>= 1, rights, reducer)).fork();
5609 >                }
5610 >                Map.Entry<K,V> r = null;
5611 >                Object v;
5612 >                while ((v = advance()) != null) {
5613 >                    Map.Entry<K,V> u = entryFor((K)nextKey, (V)v);
5614 >                    r = (r == null) ? u : reducer.apply(r, u);
5615                  }
5616 <                else if ((c = (p = (ReduceEntriesTask<K,V>)par).pending) == 0) {
5617 <                    if ((s = t.sibling) != null && (u = s.result) != null)
5618 <                        r = (r == null) ? u : reducer.apply(r, u);
5619 <                    (t = p).result = r;
5616 >                result = r;
5617 >                for (ReduceEntriesTask<K,V> t = this, s;;) {
5618 >                    int c; BulkTask<K,V,?> par; Map.Entry<K,V> tr, sr;
5619 >                    if ((c = t.pending) == 0) {
5620 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5621 >                            if ((sr = s.result) != null)
5622 >                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5623 >                        }
5624 >                        if ((par = t.parent) == null ||
5625 >                            !(par instanceof ReduceEntriesTask)) {
5626 >                            t.quietlyComplete();
5627 >                            break;
5628 >                        }
5629 >                        t = (ReduceEntriesTask<K,V>)par;
5630 >                    }
5631 >                    else if (t.casPending(c, c - 1))
5632 >                        break;
5633                  }
5634 <                else if (p.casPending(c, 0))
5635 <                    break;
5634 >            } catch (Throwable ex) {
5635 >                return tryCompleteComputation(ex);
5636              }
5637 +            return false;
5638          }
5639          public final Map.Entry<K,V> getRawResult() { return result; }
5640      }
5641  
5642 <    static final class MapReduceKeysTask<K,V,U>
5642 >    @SuppressWarnings("serial") static final class MapReduceKeysTask<K,V,U>
5643          extends BulkTask<K,V,U> {
5644          final Fun<? super K, ? extends U> transformer;
5645          final BiFun<? super U, ? super U, ? extends U> reducer;
5646          U result;
5647 <        MapReduceKeysTask<K,V,U> sibling;
5647 >        MapReduceKeysTask<K,V,U> rights, nextRight;
5648          MapReduceKeysTask
5649              (ConcurrentHashMapV8<K,V> m,
5650               Fun<? super K, ? extends U> transformer,
# Line 5607 | Line 5654 | public class ConcurrentHashMapV8<K, V>
5654              this.reducer = reducer;
5655          }
5656          MapReduceKeysTask
5657 <            (BulkTask<K,V,?> p, int b, boolean split,
5657 >            (BulkTask<K,V,?> p, int b,
5658 >             MapReduceKeysTask<K,V,U> nextRight,
5659               Fun<? super K, ? extends U> transformer,
5660               BiFun<? super U, ? super U, ? extends U> reducer) {
5661 <            super(p, b, split);
5661 >            super(p, b); this.nextRight = nextRight;
5662              this.transformer = transformer;
5663              this.reducer = reducer;
5664          }
5665 <        public final void compute() {
5618 <            MapReduceKeysTask<K,V,U> t = this;
5665 >        @SuppressWarnings("unchecked") public final boolean exec() {
5666              final Fun<? super K, ? extends U> transformer =
5667                  this.transformer;
5668              final BiFun<? super U, ? super U, ? extends U> reducer =
5669                  this.reducer;
5670              if (transformer == null || reducer == null)
5671 <                throw new Error(NullFunctionMessage);
5672 <            int b = batch();
5673 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5674 <                b >>>= 1;
5675 <                t.pending = 1;
5676 <                MapReduceKeysTask<K,V,U> rt =
5677 <                    new MapReduceKeysTask<K,V,U>
5678 <                    (t, b, true, transformer, reducer);
5679 <                t = new MapReduceKeysTask<K,V,U>
5680 <                    (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)
5671 >                return abortOnNullFunction();
5672 >            try {
5673 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5674 >                    do {} while (!casPending(c = pending, c+1));
5675 >                    (rights = new MapReduceKeysTask<K,V,U>
5676 >                     (this, b >>>= 1, rights, transformer, reducer)).fork();
5677 >                }
5678 >                U r = null, u;
5679 >                while (advance() != null) {
5680 >                    if ((u = transformer.apply((K)nextKey)) != null)
5681                          r = (r == null) ? u : reducer.apply(r, u);
5654                    (t = p).result = r;
5682                  }
5683 <                else if (p.casPending(c, 0))
5684 <                    break;
5683 >                result = r;
5684 >                for (MapReduceKeysTask<K,V,U> t = this, s;;) {
5685 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5686 >                    if ((c = t.pending) == 0) {
5687 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5688 >                            if ((sr = s.result) != null)
5689 >                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5690 >                        }
5691 >                        if ((par = t.parent) == null ||
5692 >                            !(par instanceof MapReduceKeysTask)) {
5693 >                            t.quietlyComplete();
5694 >                            break;
5695 >                        }
5696 >                        t = (MapReduceKeysTask<K,V,U>)par;
5697 >                    }
5698 >                    else if (t.casPending(c, c - 1))
5699 >                        break;
5700 >                }
5701 >            } catch (Throwable ex) {
5702 >                return tryCompleteComputation(ex);
5703              }
5704 +            return false;
5705          }
5706          public final U getRawResult() { return result; }
5707      }
5708  
5709 <    static final class MapReduceValuesTask<K,V,U>
5709 >    @SuppressWarnings("serial") static final class MapReduceValuesTask<K,V,U>
5710          extends BulkTask<K,V,U> {
5711          final Fun<? super V, ? extends U> transformer;
5712          final BiFun<? super U, ? super U, ? extends U> reducer;
5713          U result;
5714 <        MapReduceValuesTask<K,V,U> sibling;
5714 >        MapReduceValuesTask<K,V,U> rights, nextRight;
5715          MapReduceValuesTask
5716              (ConcurrentHashMapV8<K,V> m,
5717               Fun<? super V, ? extends U> transformer,
# Line 5675 | Line 5721 | public class ConcurrentHashMapV8<K, V>
5721              this.reducer = reducer;
5722          }
5723          MapReduceValuesTask
5724 <            (BulkTask<K,V,?> p, int b, boolean split,
5724 >            (BulkTask<K,V,?> p, int b,
5725 >             MapReduceValuesTask<K,V,U> nextRight,
5726               Fun<? super V, ? extends U> transformer,
5727               BiFun<? super U, ? super U, ? extends U> reducer) {
5728 <            super(p, b, split);
5728 >            super(p, b); this.nextRight = nextRight;
5729              this.transformer = transformer;
5730              this.reducer = reducer;
5731          }
5732 <        public final void compute() {
5686 <            MapReduceValuesTask<K,V,U> t = this;
5732 >        @SuppressWarnings("unchecked") public final boolean exec() {
5733              final Fun<? super V, ? extends U> transformer =
5734                  this.transformer;
5735              final BiFun<? super U, ? super U, ? extends U> reducer =
5736                  this.reducer;
5737              if (transformer == null || reducer == null)
5738 <                throw new Error(NullFunctionMessage);
5739 <            int b = batch();
5740 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5741 <                b >>>= 1;
5742 <                t.pending = 1;
5743 <                MapReduceValuesTask<K,V,U> rt =
5744 <                    new MapReduceValuesTask<K,V,U>
5745 <                    (t, b, true, transformer, reducer);
5746 <                t = new MapReduceValuesTask<K,V,U>
5747 <                    (t, b, false, transformer, reducer);
5748 <                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)
5738 >                return abortOnNullFunction();
5739 >            try {
5740 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5741 >                    do {} while (!casPending(c = pending, c+1));
5742 >                    (rights = new MapReduceValuesTask<K,V,U>
5743 >                     (this, b >>>= 1, rights, transformer, reducer)).fork();
5744 >                }
5745 >                U r = null, u;
5746 >                Object v;
5747 >                while ((v = advance()) != null) {
5748 >                    if ((u = transformer.apply((V)v)) != null)
5749                          r = (r == null) ? u : reducer.apply(r, u);
5723                    (t = p).result = r;
5750                  }
5751 <                else if (p.casPending(c, 0))
5752 <                    break;
5751 >                result = r;
5752 >                for (MapReduceValuesTask<K,V,U> t = this, s;;) {
5753 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5754 >                    if ((c = t.pending) == 0) {
5755 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5756 >                            if ((sr = s.result) != null)
5757 >                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5758 >                        }
5759 >                        if ((par = t.parent) == null ||
5760 >                            !(par instanceof MapReduceValuesTask)) {
5761 >                            t.quietlyComplete();
5762 >                            break;
5763 >                        }
5764 >                        t = (MapReduceValuesTask<K,V,U>)par;
5765 >                    }
5766 >                    else if (t.casPending(c, c - 1))
5767 >                        break;
5768 >                }
5769 >            } catch (Throwable ex) {
5770 >                return tryCompleteComputation(ex);
5771              }
5772 +            return false;
5773          }
5774          public final U getRawResult() { return result; }
5775      }
5776  
5777 <    static final class MapReduceEntriesTask<K,V,U>
5777 >    @SuppressWarnings("serial") static final class MapReduceEntriesTask<K,V,U>
5778          extends BulkTask<K,V,U> {
5779          final Fun<Map.Entry<K,V>, ? extends U> transformer;
5780          final BiFun<? super U, ? super U, ? extends U> reducer;
5781          U result;
5782 <        MapReduceEntriesTask<K,V,U> sibling;
5782 >        MapReduceEntriesTask<K,V,U> rights, nextRight;
5783          MapReduceEntriesTask
5784              (ConcurrentHashMapV8<K,V> m,
5785               Fun<Map.Entry<K,V>, ? extends U> transformer,
# Line 5744 | Line 5789 | public class ConcurrentHashMapV8<K, V>
5789              this.reducer = reducer;
5790          }
5791          MapReduceEntriesTask
5792 <            (BulkTask<K,V,?> p, int b, boolean split,
5792 >            (BulkTask<K,V,?> p, int b,
5793 >             MapReduceEntriesTask<K,V,U> nextRight,
5794               Fun<Map.Entry<K,V>, ? extends U> transformer,
5795               BiFun<? super U, ? super U, ? extends U> reducer) {
5796 <            super(p, b, split);
5796 >            super(p, b); this.nextRight = nextRight;
5797              this.transformer = transformer;
5798              this.reducer = reducer;
5799          }
5800 <        public final void compute() {
5755 <            MapReduceEntriesTask<K,V,U> t = this;
5800 >        @SuppressWarnings("unchecked") public final boolean exec() {
5801              final Fun<Map.Entry<K,V>, ? extends U> transformer =
5802                  this.transformer;
5803              final BiFun<? super U, ? super U, ? extends U> reducer =
5804                  this.reducer;
5805              if (transformer == null || reducer == null)
5806 <                throw new Error(NullFunctionMessage);
5807 <            int b = batch();
5808 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5809 <                b >>>= 1;
5810 <                t.pending = 1;
5811 <                MapReduceEntriesTask<K,V,U> rt =
5812 <                    new MapReduceEntriesTask<K,V,U>
5813 <                    (t, b, true, transformer, reducer);
5814 <                t = new MapReduceEntriesTask<K,V,U>
5815 <                    (t, b, false, transformer, reducer);
5816 <                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)
5806 >                return abortOnNullFunction();
5807 >            try {
5808 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5809 >                    do {} while (!casPending(c = pending, c+1));
5810 >                    (rights = new MapReduceEntriesTask<K,V,U>
5811 >                     (this, b >>>= 1, rights, transformer, reducer)).fork();
5812 >                }
5813 >                U r = null, u;
5814 >                Object v;
5815 >                while ((v = advance()) != null) {
5816 >                    if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5817                          r = (r == null) ? u : reducer.apply(r, u);
5792                    (t = p).result = r;
5818                  }
5819 <                else if (p.casPending(c, 0))
5820 <                    break;
5819 >                result = r;
5820 >                for (MapReduceEntriesTask<K,V,U> t = this, s;;) {
5821 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5822 >                    if ((c = t.pending) == 0) {
5823 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5824 >                            if ((sr = s.result) != null)
5825 >                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5826 >                        }
5827 >                        if ((par = t.parent) == null ||
5828 >                            !(par instanceof MapReduceEntriesTask)) {
5829 >                            t.quietlyComplete();
5830 >                            break;
5831 >                        }
5832 >                        t = (MapReduceEntriesTask<K,V,U>)par;
5833 >                    }
5834 >                    else if (t.casPending(c, c - 1))
5835 >                        break;
5836 >                }
5837 >            } catch (Throwable ex) {
5838 >                return tryCompleteComputation(ex);
5839              }
5840 +            return false;
5841          }
5842          public final U getRawResult() { return result; }
5843      }
5844  
5845 <    static final class MapReduceMappingsTask<K,V,U>
5845 >    @SuppressWarnings("serial") static final class MapReduceMappingsTask<K,V,U>
5846          extends BulkTask<K,V,U> {
5847          final BiFun<? super K, ? super V, ? extends U> transformer;
5848          final BiFun<? super U, ? super U, ? extends U> reducer;
5849          U result;
5850 <        MapReduceMappingsTask<K,V,U> sibling;
5850 >        MapReduceMappingsTask<K,V,U> rights, nextRight;
5851          MapReduceMappingsTask
5852              (ConcurrentHashMapV8<K,V> m,
5853               BiFun<? super K, ? super V, ? extends U> transformer,
# Line 5813 | Line 5857 | public class ConcurrentHashMapV8<K, V>
5857              this.reducer = reducer;
5858          }
5859          MapReduceMappingsTask
5860 <            (BulkTask<K,V,?> p, int b, boolean split,
5860 >            (BulkTask<K,V,?> p, int b,
5861 >             MapReduceMappingsTask<K,V,U> nextRight,
5862               BiFun<? super K, ? super V, ? extends U> transformer,
5863               BiFun<? super U, ? super U, ? extends U> reducer) {
5864 <            super(p, b, split);
5864 >            super(p, b); this.nextRight = nextRight;
5865              this.transformer = transformer;
5866              this.reducer = reducer;
5867          }
5868 <        public final void compute() {
5824 <            MapReduceMappingsTask<K,V,U> t = this;
5868 >        @SuppressWarnings("unchecked") public final boolean exec() {
5869              final BiFun<? super K, ? super V, ? extends U> transformer =
5870                  this.transformer;
5871              final BiFun<? super U, ? super U, ? extends U> reducer =
5872                  this.reducer;
5873              if (transformer == null || reducer == null)
5874 <                throw new Error(NullFunctionMessage);
5875 <            int b = batch();
5876 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5877 <                b >>>= 1;
5878 <                t.pending = 1;
5879 <                MapReduceMappingsTask<K,V,U> rt =
5880 <                    new MapReduceMappingsTask<K,V,U>
5881 <                    (t, b, true, transformer, reducer);
5882 <                t = new MapReduceMappingsTask<K,V,U>
5883 <                    (t, b, false, transformer, reducer);
5884 <                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)
5874 >                return abortOnNullFunction();
5875 >            try {
5876 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5877 >                    do {} while (!casPending(c = pending, c+1));
5878 >                    (rights = new MapReduceMappingsTask<K,V,U>
5879 >                     (this, b >>>= 1, rights, transformer, reducer)).fork();
5880 >                }
5881 >                U r = null, u;
5882 >                Object v;
5883 >                while ((v = advance()) != null) {
5884 >                    if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5885                          r = (r == null) ? u : reducer.apply(r, u);
5860                    (t = p).result = r;
5886                  }
5887 <                else if (p.casPending(c, 0))
5888 <                    break;
5887 >                result = r;
5888 >                for (MapReduceMappingsTask<K,V,U> t = this, s;;) {
5889 >                    int c; BulkTask<K,V,?> par; U tr, sr;
5890 >                    if ((c = t.pending) == 0) {
5891 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5892 >                            if ((sr = s.result) != null)
5893 >                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5894 >                        }
5895 >                        if ((par = t.parent) == null ||
5896 >                            !(par instanceof MapReduceMappingsTask)) {
5897 >                            t.quietlyComplete();
5898 >                            break;
5899 >                        }
5900 >                        t = (MapReduceMappingsTask<K,V,U>)par;
5901 >                    }
5902 >                    else if (t.casPending(c, c - 1))
5903 >                        break;
5904 >                }
5905 >            } catch (Throwable ex) {
5906 >                return tryCompleteComputation(ex);
5907              }
5908 +            return false;
5909          }
5910          public final U getRawResult() { return result; }
5911      }
5912  
5913 <    static final class MapReduceKeysToDoubleTask<K,V>
5913 >    @SuppressWarnings("serial") static final class MapReduceKeysToDoubleTask<K,V>
5914          extends BulkTask<K,V,Double> {
5915          final ObjectToDouble<? super K> transformer;
5916          final DoubleByDoubleToDouble reducer;
5917          final double basis;
5918          double result;
5919 <        MapReduceKeysToDoubleTask<K,V> sibling;
5919 >        MapReduceKeysToDoubleTask<K,V> rights, nextRight;
5920          MapReduceKeysToDoubleTask
5921              (ConcurrentHashMapV8<K,V> m,
5922               ObjectToDouble<? super K> transformer,
# Line 5883 | Line 5927 | public class ConcurrentHashMapV8<K, V>
5927              this.basis = basis; this.reducer = reducer;
5928          }
5929          MapReduceKeysToDoubleTask
5930 <            (BulkTask<K,V,?> p, int b, boolean split,
5930 >            (BulkTask<K,V,?> p, int b,
5931 >             MapReduceKeysToDoubleTask<K,V> nextRight,
5932               ObjectToDouble<? super K> transformer,
5933               double basis,
5934               DoubleByDoubleToDouble reducer) {
5935 <            super(p, b, split);
5935 >            super(p, b); this.nextRight = nextRight;
5936              this.transformer = transformer;
5937              this.basis = basis; this.reducer = reducer;
5938          }
5939 <        public final void compute() {
5895 <            MapReduceKeysToDoubleTask<K,V> t = this;
5939 >        @SuppressWarnings("unchecked") public final boolean exec() {
5940              final ObjectToDouble<? super K> transformer =
5941                  this.transformer;
5942              final DoubleByDoubleToDouble reducer = this.reducer;
5943              if (transformer == null || reducer == null)
5944 <                throw new Error(NullFunctionMessage);
5945 <            final double id = this.basis;
5946 <            int b = batch();
5947 <            while (b > 1 && t.baseIndex != t.baseLimit) {
5948 <                b >>>= 1;
5949 <                t.pending = 1;
5950 <                MapReduceKeysToDoubleTask<K,V> rt =
5951 <                    new MapReduceKeysToDoubleTask<K,V>
5952 <                    (t, b, true, transformer, id, reducer);
5953 <                t = new MapReduceKeysToDoubleTask<K,V>
5954 <                    (t, b, false, transformer, id, reducer);
5955 <                t.sibling = rt;
5956 <                rt.sibling = t;
5957 <                rt.fork();
5958 <            }
5959 <            double r = id;
5960 <            while (t.advance() != null)
5961 <                r = reducer.apply(r, transformer.apply((K)t.nextKey));
5962 <            t.result = r;
5963 <            for (;;) {
5964 <                int c; BulkTask<K,V,?> par; MapReduceKeysToDoubleTask<K,V> s, p;
5965 <                if ((par = t.parent) == null ||
5966 <                    !(par instanceof MapReduceKeysToDoubleTask)) {
5967 <                    t.quietlyComplete();
5968 <                    break;
5969 <                }
5970 <                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;
5944 >                return abortOnNullFunction();
5945 >            try {
5946 >                final double id = this.basis;
5947 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5948 >                    do {} while (!casPending(c = pending, c+1));
5949 >                    (rights = new MapReduceKeysToDoubleTask<K,V>
5950 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
5951 >                }
5952 >                double r = id;
5953 >                while (advance() != null)
5954 >                    r = reducer.apply(r, transformer.apply((K)nextKey));
5955 >                result = r;
5956 >                for (MapReduceKeysToDoubleTask<K,V> t = this, s;;) {
5957 >                    int c; BulkTask<K,V,?> par;
5958 >                    if ((c = t.pending) == 0) {
5959 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5960 >                            t.result = reducer.apply(t.result, s.result);
5961 >                        }
5962 >                        if ((par = t.parent) == null ||
5963 >                            !(par instanceof MapReduceKeysToDoubleTask)) {
5964 >                            t.quietlyComplete();
5965 >                            break;
5966 >                        }
5967 >                        t = (MapReduceKeysToDoubleTask<K,V>)par;
5968 >                    }
5969 >                    else if (t.casPending(c, c - 1))
5970 >                        break;
5971                  }
5972 <                else if (p.casPending(c, 0))
5973 <                    break;
5972 >            } catch (Throwable ex) {
5973 >                return tryCompleteComputation(ex);
5974              }
5975 +            return false;
5976          }
5977          public final Double getRawResult() { return result; }
5978      }
5979  
5980 <    static final class MapReduceValuesToDoubleTask<K,V>
5980 >    @SuppressWarnings("serial") static final class MapReduceValuesToDoubleTask<K,V>
5981          extends BulkTask<K,V,Double> {
5982          final ObjectToDouble<? super V> transformer;
5983          final DoubleByDoubleToDouble reducer;
5984          final double basis;
5985          double result;
5986 <        MapReduceValuesToDoubleTask<K,V> sibling;
5986 >        MapReduceValuesToDoubleTask<K,V> rights, nextRight;
5987          MapReduceValuesToDoubleTask
5988              (ConcurrentHashMapV8<K,V> m,
5989               ObjectToDouble<? super V> transformer,
# Line 5952 | Line 5994 | public class ConcurrentHashMapV8<K, V>
5994              this.basis = basis; this.reducer = reducer;
5995          }
5996          MapReduceValuesToDoubleTask
5997 <            (BulkTask<K,V,?> p, int b, boolean split,
5997 >            (BulkTask<K,V,?> p, int b,
5998 >             MapReduceValuesToDoubleTask<K,V> nextRight,
5999               ObjectToDouble<? super V> transformer,
6000               double basis,
6001               DoubleByDoubleToDouble reducer) {
6002 <            super(p, b, split);
6002 >            super(p, b); this.nextRight = nextRight;
6003              this.transformer = transformer;
6004              this.basis = basis; this.reducer = reducer;
6005          }
6006 <        public final void compute() {
5964 <            MapReduceValuesToDoubleTask<K,V> t = this;
6006 >        @SuppressWarnings("unchecked") public final boolean exec() {
6007              final ObjectToDouble<? super V> transformer =
6008                  this.transformer;
6009              final DoubleByDoubleToDouble reducer = this.reducer;
6010              if (transformer == null || reducer == null)
6011 <                throw new Error(NullFunctionMessage);
6012 <            final double id = this.basis;
6013 <            int b = batch();
6014 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6015 <                b >>>= 1;
6016 <                t.pending = 1;
6017 <                MapReduceValuesToDoubleTask<K,V> rt =
6018 <                    new MapReduceValuesToDoubleTask<K,V>
6019 <                    (t, b, true, transformer, id, reducer);
6020 <                t = new MapReduceValuesToDoubleTask<K,V>
6021 <                    (t, b, false, transformer, id, reducer);
6022 <                t.sibling = rt;
6023 <                rt.sibling = t;
6024 <                rt.fork();
6025 <            }
6026 <            double r = id;
6027 <            Object v;
6028 <            while ((v = t.advance()) != null)
6029 <                r = reducer.apply(r, transformer.apply((V)v));
6030 <            t.result = r;
6031 <            for (;;) {
6032 <                int c; BulkTask<K,V,?> par; MapReduceValuesToDoubleTask<K,V> s, p;
6033 <                if ((par = t.parent) == null ||
6034 <                    !(par instanceof MapReduceValuesToDoubleTask)) {
6035 <                    t.quietlyComplete();
6036 <                    break;
6037 <                }
6038 <                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;
6011 >                return abortOnNullFunction();
6012 >            try {
6013 >                final double id = this.basis;
6014 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6015 >                    do {} while (!casPending(c = pending, c+1));
6016 >                    (rights = new MapReduceValuesToDoubleTask<K,V>
6017 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6018 >                }
6019 >                double r = id;
6020 >                Object v;
6021 >                while ((v = advance()) != null)
6022 >                    r = reducer.apply(r, transformer.apply((V)v));
6023 >                result = r;
6024 >                for (MapReduceValuesToDoubleTask<K,V> t = this, s;;) {
6025 >                    int c; BulkTask<K,V,?> par;
6026 >                    if ((c = t.pending) == 0) {
6027 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6028 >                            t.result = reducer.apply(t.result, s.result);
6029 >                        }
6030 >                        if ((par = t.parent) == null ||
6031 >                            !(par instanceof MapReduceValuesToDoubleTask)) {
6032 >                            t.quietlyComplete();
6033 >                            break;
6034 >                        }
6035 >                        t = (MapReduceValuesToDoubleTask<K,V>)par;
6036 >                    }
6037 >                    else if (t.casPending(c, c - 1))
6038 >                        break;
6039                  }
6040 <                else if (p.casPending(c, 0))
6041 <                    break;
6040 >            } catch (Throwable ex) {
6041 >                return tryCompleteComputation(ex);
6042              }
6043 +            return false;
6044          }
6045          public final Double getRawResult() { return result; }
6046      }
6047  
6048 <    static final class MapReduceEntriesToDoubleTask<K,V>
6048 >    @SuppressWarnings("serial") static final class MapReduceEntriesToDoubleTask<K,V>
6049          extends BulkTask<K,V,Double> {
6050          final ObjectToDouble<Map.Entry<K,V>> transformer;
6051          final DoubleByDoubleToDouble reducer;
6052          final double basis;
6053          double result;
6054 <        MapReduceEntriesToDoubleTask<K,V> sibling;
6054 >        MapReduceEntriesToDoubleTask<K,V> rights, nextRight;
6055          MapReduceEntriesToDoubleTask
6056              (ConcurrentHashMapV8<K,V> m,
6057               ObjectToDouble<Map.Entry<K,V>> transformer,
# Line 6022 | Line 6062 | public class ConcurrentHashMapV8<K, V>
6062              this.basis = basis; this.reducer = reducer;
6063          }
6064          MapReduceEntriesToDoubleTask
6065 <            (BulkTask<K,V,?> p, int b, boolean split,
6065 >            (BulkTask<K,V,?> p, int b,
6066 >             MapReduceEntriesToDoubleTask<K,V> nextRight,
6067               ObjectToDouble<Map.Entry<K,V>> transformer,
6068               double basis,
6069               DoubleByDoubleToDouble reducer) {
6070 <            super(p, b, split);
6070 >            super(p, b); this.nextRight = nextRight;
6071              this.transformer = transformer;
6072              this.basis = basis; this.reducer = reducer;
6073          }
6074 <        public final void compute() {
6034 <            MapReduceEntriesToDoubleTask<K,V> t = this;
6074 >        @SuppressWarnings("unchecked") public final boolean exec() {
6075              final ObjectToDouble<Map.Entry<K,V>> transformer =
6076                  this.transformer;
6077              final DoubleByDoubleToDouble reducer = this.reducer;
6078              if (transformer == null || reducer == null)
6079 <                throw new Error(NullFunctionMessage);
6080 <            final double id = this.basis;
6081 <            int b = batch();
6082 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6083 <                b >>>= 1;
6084 <                t.pending = 1;
6085 <                MapReduceEntriesToDoubleTask<K,V> rt =
6086 <                    new MapReduceEntriesToDoubleTask<K,V>
6087 <                    (t, b, true, transformer, id, reducer);
6088 <                t = new MapReduceEntriesToDoubleTask<K,V>
6089 <                    (t, b, false, transformer, id, reducer);
6090 <                t.sibling = rt;
6091 <                rt.sibling = t;
6092 <                rt.fork();
6093 <            }
6094 <            double r = id;
6095 <            Object v;
6096 <            while ((v = t.advance()) != null)
6097 <                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6098 <            t.result = r;
6099 <            for (;;) {
6100 <                int c; BulkTask<K,V,?> par; MapReduceEntriesToDoubleTask<K,V> s, p;
6101 <                if ((par = t.parent) == null ||
6102 <                    !(par instanceof MapReduceEntriesToDoubleTask)) {
6103 <                    t.quietlyComplete();
6104 <                    break;
6105 <                }
6106 <                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;
6079 >                return abortOnNullFunction();
6080 >            try {
6081 >                final double id = this.basis;
6082 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6083 >                    do {} while (!casPending(c = pending, c+1));
6084 >                    (rights = new MapReduceEntriesToDoubleTask<K,V>
6085 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6086 >                }
6087 >                double r = id;
6088 >                Object v;
6089 >                while ((v = advance()) != null)
6090 >                    r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v)));
6091 >                result = r;
6092 >                for (MapReduceEntriesToDoubleTask<K,V> t = this, s;;) {
6093 >                    int c; BulkTask<K,V,?> par;
6094 >                    if ((c = t.pending) == 0) {
6095 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6096 >                            t.result = reducer.apply(t.result, s.result);
6097 >                        }
6098 >                        if ((par = t.parent) == null ||
6099 >                            !(par instanceof MapReduceEntriesToDoubleTask)) {
6100 >                            t.quietlyComplete();
6101 >                            break;
6102 >                        }
6103 >                        t = (MapReduceEntriesToDoubleTask<K,V>)par;
6104 >                    }
6105 >                    else if (t.casPending(c, c - 1))
6106 >                        break;
6107                  }
6108 <                else if (p.casPending(c, 0))
6109 <                    break;
6108 >            } catch (Throwable ex) {
6109 >                return tryCompleteComputation(ex);
6110              }
6111 +            return false;
6112          }
6113          public final Double getRawResult() { return result; }
6114      }
6115  
6116 <    static final class MapReduceMappingsToDoubleTask<K,V>
6116 >    @SuppressWarnings("serial") static final class MapReduceMappingsToDoubleTask<K,V>
6117          extends BulkTask<K,V,Double> {
6118          final ObjectByObjectToDouble<? super K, ? super V> transformer;
6119          final DoubleByDoubleToDouble reducer;
6120          final double basis;
6121          double result;
6122 <        MapReduceMappingsToDoubleTask<K,V> sibling;
6122 >        MapReduceMappingsToDoubleTask<K,V> rights, nextRight;
6123          MapReduceMappingsToDoubleTask
6124              (ConcurrentHashMapV8<K,V> m,
6125               ObjectByObjectToDouble<? super K, ? super V> transformer,
# Line 6092 | Line 6130 | public class ConcurrentHashMapV8<K, V>
6130              this.basis = basis; this.reducer = reducer;
6131          }
6132          MapReduceMappingsToDoubleTask
6133 <            (BulkTask<K,V,?> p, int b, boolean split,
6133 >            (BulkTask<K,V,?> p, int b,
6134 >             MapReduceMappingsToDoubleTask<K,V> nextRight,
6135               ObjectByObjectToDouble<? super K, ? super V> transformer,
6136               double basis,
6137               DoubleByDoubleToDouble reducer) {
6138 <            super(p, b, split);
6138 >            super(p, b); this.nextRight = nextRight;
6139              this.transformer = transformer;
6140              this.basis = basis; this.reducer = reducer;
6141          }
6142 <        public final void compute() {
6104 <            MapReduceMappingsToDoubleTask<K,V> t = this;
6142 >        @SuppressWarnings("unchecked") public final boolean exec() {
6143              final ObjectByObjectToDouble<? super K, ? super V> transformer =
6144                  this.transformer;
6145              final DoubleByDoubleToDouble reducer = this.reducer;
6146              if (transformer == null || reducer == null)
6147 <                throw new Error(NullFunctionMessage);
6148 <            final double id = this.basis;
6149 <            int b = batch();
6150 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6151 <                b >>>= 1;
6152 <                t.pending = 1;
6153 <                MapReduceMappingsToDoubleTask<K,V> rt =
6154 <                    new MapReduceMappingsToDoubleTask<K,V>
6155 <                    (t, b, true, transformer, id, reducer);
6156 <                t = new MapReduceMappingsToDoubleTask<K,V>
6157 <                    (t, b, false, transformer, id, reducer);
6158 <                t.sibling = rt;
6159 <                rt.sibling = t;
6160 <                rt.fork();
6161 <            }
6162 <            double r = id;
6163 <            Object v;
6164 <            while ((v = t.advance()) != null)
6165 <                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6166 <            t.result = r;
6167 <            for (;;) {
6168 <                int c; BulkTask<K,V,?> par; MapReduceMappingsToDoubleTask<K,V> s, p;
6169 <                if ((par = t.parent) == null ||
6170 <                    !(par instanceof MapReduceMappingsToDoubleTask)) {
6171 <                    t.quietlyComplete();
6172 <                    break;
6173 <                }
6174 <                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;
6147 >                return abortOnNullFunction();
6148 >            try {
6149 >                final double id = this.basis;
6150 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6151 >                    do {} while (!casPending(c = pending, c+1));
6152 >                    (rights = new MapReduceMappingsToDoubleTask<K,V>
6153 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6154 >                }
6155 >                double r = id;
6156 >                Object v;
6157 >                while ((v = advance()) != null)
6158 >                    r = reducer.apply(r, transformer.apply((K)nextKey, (V)v));
6159 >                result = r;
6160 >                for (MapReduceMappingsToDoubleTask<K,V> t = this, s;;) {
6161 >                    int c; BulkTask<K,V,?> par;
6162 >                    if ((c = t.pending) == 0) {
6163 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6164 >                            t.result = reducer.apply(t.result, s.result);
6165 >                        }
6166 >                        if ((par = t.parent) == null ||
6167 >                            !(par instanceof MapReduceMappingsToDoubleTask)) {
6168 >                            t.quietlyComplete();
6169 >                            break;
6170 >                        }
6171 >                        t = (MapReduceMappingsToDoubleTask<K,V>)par;
6172 >                    }
6173 >                    else if (t.casPending(c, c - 1))
6174 >                        break;
6175                  }
6176 <                else if (p.casPending(c, 0))
6177 <                    break;
6176 >            } catch (Throwable ex) {
6177 >                return tryCompleteComputation(ex);
6178              }
6179 +            return false;
6180          }
6181          public final Double getRawResult() { return result; }
6182      }
6183  
6184 <    static final class MapReduceKeysToLongTask<K,V>
6184 >    @SuppressWarnings("serial") static final class MapReduceKeysToLongTask<K,V>
6185          extends BulkTask<K,V,Long> {
6186          final ObjectToLong<? super K> transformer;
6187          final LongByLongToLong reducer;
6188          final long basis;
6189          long result;
6190 <        MapReduceKeysToLongTask<K,V> sibling;
6190 >        MapReduceKeysToLongTask<K,V> rights, nextRight;
6191          MapReduceKeysToLongTask
6192              (ConcurrentHashMapV8<K,V> m,
6193               ObjectToLong<? super K> transformer,
# Line 6162 | Line 6198 | public class ConcurrentHashMapV8<K, V>
6198              this.basis = basis; this.reducer = reducer;
6199          }
6200          MapReduceKeysToLongTask
6201 <            (BulkTask<K,V,?> p, int b, boolean split,
6201 >            (BulkTask<K,V,?> p, int b,
6202 >             MapReduceKeysToLongTask<K,V> nextRight,
6203               ObjectToLong<? super K> transformer,
6204               long basis,
6205               LongByLongToLong reducer) {
6206 <            super(p, b, split);
6206 >            super(p, b); this.nextRight = nextRight;
6207              this.transformer = transformer;
6208              this.basis = basis; this.reducer = reducer;
6209          }
6210 <        public final void compute() {
6174 <            MapReduceKeysToLongTask<K,V> t = this;
6210 >        @SuppressWarnings("unchecked") public final boolean exec() {
6211              final ObjectToLong<? super K> transformer =
6212                  this.transformer;
6213              final LongByLongToLong reducer = this.reducer;
6214              if (transformer == null || reducer == null)
6215 <                throw new Error(NullFunctionMessage);
6216 <            final long id = this.basis;
6217 <            int b = batch();
6218 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6219 <                b >>>= 1;
6220 <                t.pending = 1;
6221 <                MapReduceKeysToLongTask<K,V> rt =
6222 <                    new MapReduceKeysToLongTask<K,V>
6223 <                    (t, b, true, transformer, id, reducer);
6224 <                t = new MapReduceKeysToLongTask<K,V>
6225 <                    (t, b, false, transformer, id, reducer);
6226 <                t.sibling = rt;
6227 <                rt.sibling = t;
6228 <                rt.fork();
6229 <            }
6230 <            long r = id;
6231 <            while (t.advance() != null)
6232 <                r = reducer.apply(r, transformer.apply((K)t.nextKey));
6233 <            t.result = r;
6234 <            for (;;) {
6235 <                int c; BulkTask<K,V,?> par; MapReduceKeysToLongTask<K,V> s, p;
6236 <                if ((par = t.parent) == null ||
6237 <                    !(par instanceof MapReduceKeysToLongTask)) {
6238 <                    t.quietlyComplete();
6239 <                    break;
6240 <                }
6241 <                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;
6215 >                return abortOnNullFunction();
6216 >            try {
6217 >                final long id = this.basis;
6218 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6219 >                    do {} while (!casPending(c = pending, c+1));
6220 >                    (rights = new MapReduceKeysToLongTask<K,V>
6221 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6222 >                }
6223 >                long r = id;
6224 >                while (advance() != null)
6225 >                    r = reducer.apply(r, transformer.apply((K)nextKey));
6226 >                result = r;
6227 >                for (MapReduceKeysToLongTask<K,V> t = this, s;;) {
6228 >                    int c; BulkTask<K,V,?> par;
6229 >                    if ((c = t.pending) == 0) {
6230 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6231 >                            t.result = reducer.apply(t.result, s.result);
6232 >                        }
6233 >                        if ((par = t.parent) == null ||
6234 >                            !(par instanceof MapReduceKeysToLongTask)) {
6235 >                            t.quietlyComplete();
6236 >                            break;
6237 >                        }
6238 >                        t = (MapReduceKeysToLongTask<K,V>)par;
6239 >                    }
6240 >                    else if (t.casPending(c, c - 1))
6241 >                        break;
6242                  }
6243 <                else if (p.casPending(c, 0))
6244 <                    break;
6243 >            } catch (Throwable ex) {
6244 >                return tryCompleteComputation(ex);
6245              }
6246 +            return false;
6247          }
6248          public final Long getRawResult() { return result; }
6249      }
6250  
6251 <    static final class MapReduceValuesToLongTask<K,V>
6251 >    @SuppressWarnings("serial") static final class MapReduceValuesToLongTask<K,V>
6252          extends BulkTask<K,V,Long> {
6253          final ObjectToLong<? super V> transformer;
6254          final LongByLongToLong reducer;
6255          final long basis;
6256          long result;
6257 <        MapReduceValuesToLongTask<K,V> sibling;
6257 >        MapReduceValuesToLongTask<K,V> rights, nextRight;
6258          MapReduceValuesToLongTask
6259              (ConcurrentHashMapV8<K,V> m,
6260               ObjectToLong<? super V> transformer,
# Line 6231 | Line 6265 | public class ConcurrentHashMapV8<K, V>
6265              this.basis = basis; this.reducer = reducer;
6266          }
6267          MapReduceValuesToLongTask
6268 <            (BulkTask<K,V,?> p, int b, boolean split,
6268 >            (BulkTask<K,V,?> p, int b,
6269 >             MapReduceValuesToLongTask<K,V> nextRight,
6270               ObjectToLong<? super V> transformer,
6271               long basis,
6272               LongByLongToLong reducer) {
6273 <            super(p, b, split);
6273 >            super(p, b); this.nextRight = nextRight;
6274              this.transformer = transformer;
6275              this.basis = basis; this.reducer = reducer;
6276          }
6277 <        public final void compute() {
6243 <            MapReduceValuesToLongTask<K,V> t = this;
6277 >        @SuppressWarnings("unchecked") public final boolean exec() {
6278              final ObjectToLong<? super V> transformer =
6279                  this.transformer;
6280              final LongByLongToLong reducer = this.reducer;
6281              if (transformer == null || reducer == null)
6282 <                throw new Error(NullFunctionMessage);
6283 <            final long id = this.basis;
6284 <            int b = batch();
6285 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6286 <                b >>>= 1;
6287 <                t.pending = 1;
6288 <                MapReduceValuesToLongTask<K,V> rt =
6289 <                    new MapReduceValuesToLongTask<K,V>
6290 <                    (t, b, true, transformer, id, reducer);
6291 <                t = new MapReduceValuesToLongTask<K,V>
6292 <                    (t, b, false, transformer, id, reducer);
6293 <                t.sibling = rt;
6294 <                rt.sibling = t;
6295 <                rt.fork();
6296 <            }
6297 <            long r = id;
6298 <            Object v;
6299 <            while ((v = t.advance()) != null)
6300 <                r = reducer.apply(r, transformer.apply((V)v));
6301 <            t.result = r;
6302 <            for (;;) {
6303 <                int c; BulkTask<K,V,?> par; MapReduceValuesToLongTask<K,V> s, p;
6304 <                if ((par = t.parent) == null ||
6305 <                    !(par instanceof MapReduceValuesToLongTask)) {
6306 <                    t.quietlyComplete();
6307 <                    break;
6308 <                }
6309 <                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;
6282 >                return abortOnNullFunction();
6283 >            try {
6284 >                final long id = this.basis;
6285 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6286 >                    do {} while (!casPending(c = pending, c+1));
6287 >                    (rights = new MapReduceValuesToLongTask<K,V>
6288 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6289 >                }
6290 >                long r = id;
6291 >                Object v;
6292 >                while ((v = advance()) != null)
6293 >                    r = reducer.apply(r, transformer.apply((V)v));
6294 >                result = r;
6295 >                for (MapReduceValuesToLongTask<K,V> t = this, s;;) {
6296 >                    int c; BulkTask<K,V,?> par;
6297 >                    if ((c = t.pending) == 0) {
6298 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6299 >                            t.result = reducer.apply(t.result, s.result);
6300 >                        }
6301 >                        if ((par = t.parent) == null ||
6302 >                            !(par instanceof MapReduceValuesToLongTask)) {
6303 >                            t.quietlyComplete();
6304 >                            break;
6305 >                        }
6306 >                        t = (MapReduceValuesToLongTask<K,V>)par;
6307 >                    }
6308 >                    else if (t.casPending(c, c - 1))
6309 >                        break;
6310                  }
6311 <                else if (p.casPending(c, 0))
6312 <                    break;
6311 >            } catch (Throwable ex) {
6312 >                return tryCompleteComputation(ex);
6313              }
6314 +            return false;
6315          }
6316          public final Long getRawResult() { return result; }
6317      }
6318  
6319 <    static final class MapReduceEntriesToLongTask<K,V>
6319 >    @SuppressWarnings("serial") static final class MapReduceEntriesToLongTask<K,V>
6320          extends BulkTask<K,V,Long> {
6321          final ObjectToLong<Map.Entry<K,V>> transformer;
6322          final LongByLongToLong reducer;
6323          final long basis;
6324          long result;
6325 <        MapReduceEntriesToLongTask<K,V> sibling;
6325 >        MapReduceEntriesToLongTask<K,V> rights, nextRight;
6326          MapReduceEntriesToLongTask
6327              (ConcurrentHashMapV8<K,V> m,
6328               ObjectToLong<Map.Entry<K,V>> transformer,
# Line 6301 | Line 6333 | public class ConcurrentHashMapV8<K, V>
6333              this.basis = basis; this.reducer = reducer;
6334          }
6335          MapReduceEntriesToLongTask
6336 <            (BulkTask<K,V,?> p, int b, boolean split,
6336 >            (BulkTask<K,V,?> p, int b,
6337 >             MapReduceEntriesToLongTask<K,V> nextRight,
6338               ObjectToLong<Map.Entry<K,V>> transformer,
6339               long basis,
6340               LongByLongToLong reducer) {
6341 <            super(p, b, split);
6341 >            super(p, b); this.nextRight = nextRight;
6342              this.transformer = transformer;
6343              this.basis = basis; this.reducer = reducer;
6344          }
6345 <        public final void compute() {
6313 <            MapReduceEntriesToLongTask<K,V> t = this;
6345 >        @SuppressWarnings("unchecked") public final boolean exec() {
6346              final ObjectToLong<Map.Entry<K,V>> transformer =
6347                  this.transformer;
6348              final LongByLongToLong reducer = this.reducer;
6349              if (transformer == null || reducer == null)
6350 <                throw new Error(NullFunctionMessage);
6351 <            final long id = this.basis;
6352 <            int b = batch();
6353 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6354 <                b >>>= 1;
6355 <                t.pending = 1;
6356 <                MapReduceEntriesToLongTask<K,V> rt =
6357 <                    new MapReduceEntriesToLongTask<K,V>
6358 <                    (t, b, true, transformer, id, reducer);
6359 <                t = new MapReduceEntriesToLongTask<K,V>
6360 <                    (t, b, false, transformer, id, reducer);
6361 <                t.sibling = rt;
6362 <                rt.sibling = t;
6363 <                rt.fork();
6364 <            }
6365 <            long r = id;
6366 <            Object v;
6367 <            while ((v = t.advance()) != null)
6368 <                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6369 <            t.result = r;
6370 <            for (;;) {
6371 <                int c; BulkTask<K,V,?> par; MapReduceEntriesToLongTask<K,V> s, p;
6372 <                if ((par = t.parent) == null ||
6373 <                    !(par instanceof MapReduceEntriesToLongTask)) {
6374 <                    t.quietlyComplete();
6375 <                    break;
6376 <                }
6377 <                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;
6350 >                return abortOnNullFunction();
6351 >            try {
6352 >                final long id = this.basis;
6353 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6354 >                    do {} while (!casPending(c = pending, c+1));
6355 >                    (rights = new MapReduceEntriesToLongTask<K,V>
6356 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6357 >                }
6358 >                long r = id;
6359 >                Object v;
6360 >                while ((v = advance()) != null)
6361 >                    r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v)));
6362 >                result = r;
6363 >                for (MapReduceEntriesToLongTask<K,V> t = this, s;;) {
6364 >                    int c; BulkTask<K,V,?> par;
6365 >                    if ((c = t.pending) == 0) {
6366 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6367 >                            t.result = reducer.apply(t.result, s.result);
6368 >                        }
6369 >                        if ((par = t.parent) == null ||
6370 >                            !(par instanceof MapReduceEntriesToLongTask)) {
6371 >                            t.quietlyComplete();
6372 >                            break;
6373 >                        }
6374 >                        t = (MapReduceEntriesToLongTask<K,V>)par;
6375 >                    }
6376 >                    else if (t.casPending(c, c - 1))
6377 >                        break;
6378                  }
6379 <                else if (p.casPending(c, 0))
6380 <                    break;
6379 >            } catch (Throwable ex) {
6380 >                return tryCompleteComputation(ex);
6381              }
6382 +            return false;
6383          }
6384          public final Long getRawResult() { return result; }
6385      }
6386  
6387 <    static final class MapReduceMappingsToLongTask<K,V>
6387 >    @SuppressWarnings("serial") static final class MapReduceMappingsToLongTask<K,V>
6388          extends BulkTask<K,V,Long> {
6389          final ObjectByObjectToLong<? super K, ? super V> transformer;
6390          final LongByLongToLong reducer;
6391          final long basis;
6392          long result;
6393 <        MapReduceMappingsToLongTask<K,V> sibling;
6393 >        MapReduceMappingsToLongTask<K,V> rights, nextRight;
6394          MapReduceMappingsToLongTask
6395              (ConcurrentHashMapV8<K,V> m,
6396               ObjectByObjectToLong<? super K, ? super V> transformer,
# Line 6371 | Line 6401 | public class ConcurrentHashMapV8<K, V>
6401              this.basis = basis; this.reducer = reducer;
6402          }
6403          MapReduceMappingsToLongTask
6404 <            (BulkTask<K,V,?> p, int b, boolean split,
6404 >            (BulkTask<K,V,?> p, int b,
6405 >             MapReduceMappingsToLongTask<K,V> nextRight,
6406               ObjectByObjectToLong<? super K, ? super V> transformer,
6407               long basis,
6408               LongByLongToLong reducer) {
6409 <            super(p, b, split);
6409 >            super(p, b); this.nextRight = nextRight;
6410              this.transformer = transformer;
6411              this.basis = basis; this.reducer = reducer;
6412          }
6413 <        public final void compute() {
6383 <            MapReduceMappingsToLongTask<K,V> t = this;
6413 >        @SuppressWarnings("unchecked") public final boolean exec() {
6414              final ObjectByObjectToLong<? super K, ? super V> transformer =
6415                  this.transformer;
6416              final LongByLongToLong reducer = this.reducer;
6417              if (transformer == null || reducer == null)
6418 <                throw new Error(NullFunctionMessage);
6419 <            final long id = this.basis;
6420 <            int b = batch();
6421 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6422 <                b >>>= 1;
6423 <                t.pending = 1;
6424 <                MapReduceMappingsToLongTask<K,V> rt =
6425 <                    new MapReduceMappingsToLongTask<K,V>
6426 <                    (t, b, true, transformer, id, reducer);
6427 <                t = new MapReduceMappingsToLongTask<K,V>
6428 <                    (t, b, false, transformer, id, reducer);
6429 <                t.sibling = rt;
6430 <                rt.sibling = t;
6431 <                rt.fork();
6432 <            }
6433 <            long r = id;
6434 <            Object v;
6435 <            while ((v = t.advance()) != null)
6436 <                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6437 <            t.result = r;
6438 <            for (;;) {
6439 <                int c; BulkTask<K,V,?> par; MapReduceMappingsToLongTask<K,V> s, p;
6440 <                if ((par = t.parent) == null ||
6441 <                    !(par instanceof MapReduceMappingsToLongTask)) {
6442 <                    t.quietlyComplete();
6443 <                    break;
6444 <                }
6445 <                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;
6418 >                return abortOnNullFunction();
6419 >            try {
6420 >                final long id = this.basis;
6421 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6422 >                    do {} while (!casPending(c = pending, c+1));
6423 >                    (rights = new MapReduceMappingsToLongTask<K,V>
6424 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6425 >                }
6426 >                long r = id;
6427 >                Object v;
6428 >                while ((v = advance()) != null)
6429 >                    r = reducer.apply(r, transformer.apply((K)nextKey, (V)v));
6430 >                result = r;
6431 >                for (MapReduceMappingsToLongTask<K,V> t = this, s;;) {
6432 >                    int c; BulkTask<K,V,?> par;
6433 >                    if ((c = t.pending) == 0) {
6434 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6435 >                            t.result = reducer.apply(t.result, s.result);
6436 >                        }
6437 >                        if ((par = t.parent) == null ||
6438 >                            !(par instanceof MapReduceMappingsToLongTask)) {
6439 >                            t.quietlyComplete();
6440 >                            break;
6441 >                        }
6442 >                        t = (MapReduceMappingsToLongTask<K,V>)par;
6443 >                    }
6444 >                    else if (t.casPending(c, c - 1))
6445 >                        break;
6446                  }
6447 <                else if (p.casPending(c, 0))
6448 <                    break;
6447 >            } catch (Throwable ex) {
6448 >                return tryCompleteComputation(ex);
6449              }
6450 +            return false;
6451          }
6452          public final Long getRawResult() { return result; }
6453      }
6454  
6455 <    static final class MapReduceKeysToIntTask<K,V>
6455 >    @SuppressWarnings("serial") static final class MapReduceKeysToIntTask<K,V>
6456          extends BulkTask<K,V,Integer> {
6457          final ObjectToInt<? super K> transformer;
6458          final IntByIntToInt reducer;
6459          final int basis;
6460          int result;
6461 <        MapReduceKeysToIntTask<K,V> sibling;
6461 >        MapReduceKeysToIntTask<K,V> rights, nextRight;
6462          MapReduceKeysToIntTask
6463              (ConcurrentHashMapV8<K,V> m,
6464               ObjectToInt<? super K> transformer,
# Line 6441 | Line 6469 | public class ConcurrentHashMapV8<K, V>
6469              this.basis = basis; this.reducer = reducer;
6470          }
6471          MapReduceKeysToIntTask
6472 <            (BulkTask<K,V,?> p, int b, boolean split,
6472 >            (BulkTask<K,V,?> p, int b,
6473 >             MapReduceKeysToIntTask<K,V> nextRight,
6474               ObjectToInt<? super K> transformer,
6475               int basis,
6476               IntByIntToInt reducer) {
6477 <            super(p, b, split);
6477 >            super(p, b); this.nextRight = nextRight;
6478              this.transformer = transformer;
6479              this.basis = basis; this.reducer = reducer;
6480          }
6481 <        public final void compute() {
6453 <            MapReduceKeysToIntTask<K,V> t = this;
6481 >        @SuppressWarnings("unchecked") public final boolean exec() {
6482              final ObjectToInt<? super K> transformer =
6483                  this.transformer;
6484              final IntByIntToInt reducer = this.reducer;
6485              if (transformer == null || reducer == null)
6486 <                throw new Error(NullFunctionMessage);
6487 <            final int id = this.basis;
6488 <            int b = batch();
6489 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6490 <                b >>>= 1;
6491 <                t.pending = 1;
6492 <                MapReduceKeysToIntTask<K,V> rt =
6493 <                    new MapReduceKeysToIntTask<K,V>
6494 <                    (t, b, true, transformer, id, reducer);
6495 <                t = new MapReduceKeysToIntTask<K,V>
6496 <                    (t, b, false, transformer, id, reducer);
6497 <                t.sibling = rt;
6498 <                rt.sibling = t;
6499 <                rt.fork();
6500 <            }
6501 <            int r = id;
6502 <            while (t.advance() != null)
6503 <                r = reducer.apply(r, transformer.apply((K)t.nextKey));
6504 <            t.result = r;
6505 <            for (;;) {
6506 <                int c; BulkTask<K,V,?> par; MapReduceKeysToIntTask<K,V> s, p;
6507 <                if ((par = t.parent) == null ||
6508 <                    !(par instanceof MapReduceKeysToIntTask)) {
6509 <                    t.quietlyComplete();
6510 <                    break;
6511 <                }
6512 <                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;
6486 >                return abortOnNullFunction();
6487 >            try {
6488 >                final int id = this.basis;
6489 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6490 >                    do {} while (!casPending(c = pending, c+1));
6491 >                    (rights = new MapReduceKeysToIntTask<K,V>
6492 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6493 >                }
6494 >                int r = id;
6495 >                while (advance() != null)
6496 >                    r = reducer.apply(r, transformer.apply((K)nextKey));
6497 >                result = r;
6498 >                for (MapReduceKeysToIntTask<K,V> t = this, s;;) {
6499 >                    int c; BulkTask<K,V,?> par;
6500 >                    if ((c = t.pending) == 0) {
6501 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6502 >                            t.result = reducer.apply(t.result, s.result);
6503 >                        }
6504 >                        if ((par = t.parent) == null ||
6505 >                            !(par instanceof MapReduceKeysToIntTask)) {
6506 >                            t.quietlyComplete();
6507 >                            break;
6508 >                        }
6509 >                        t = (MapReduceKeysToIntTask<K,V>)par;
6510 >                    }
6511 >                    else if (t.casPending(c, c - 1))
6512 >                        break;
6513                  }
6514 <                else if (p.casPending(c, 0))
6515 <                    break;
6514 >            } catch (Throwable ex) {
6515 >                return tryCompleteComputation(ex);
6516              }
6517 +            return false;
6518          }
6519          public final Integer getRawResult() { return result; }
6520      }
6521  
6522 <    static final class MapReduceValuesToIntTask<K,V>
6522 >    @SuppressWarnings("serial") static final class MapReduceValuesToIntTask<K,V>
6523          extends BulkTask<K,V,Integer> {
6524          final ObjectToInt<? super V> transformer;
6525          final IntByIntToInt reducer;
6526          final int basis;
6527          int result;
6528 <        MapReduceValuesToIntTask<K,V> sibling;
6528 >        MapReduceValuesToIntTask<K,V> rights, nextRight;
6529          MapReduceValuesToIntTask
6530              (ConcurrentHashMapV8<K,V> m,
6531               ObjectToInt<? super V> transformer,
# Line 6510 | Line 6536 | public class ConcurrentHashMapV8<K, V>
6536              this.basis = basis; this.reducer = reducer;
6537          }
6538          MapReduceValuesToIntTask
6539 <            (BulkTask<K,V,?> p, int b, boolean split,
6539 >            (BulkTask<K,V,?> p, int b,
6540 >             MapReduceValuesToIntTask<K,V> nextRight,
6541               ObjectToInt<? super V> transformer,
6542               int basis,
6543               IntByIntToInt reducer) {
6544 <            super(p, b, split);
6544 >            super(p, b); this.nextRight = nextRight;
6545              this.transformer = transformer;
6546              this.basis = basis; this.reducer = reducer;
6547          }
6548 <        public final void compute() {
6522 <            MapReduceValuesToIntTask<K,V> t = this;
6548 >        @SuppressWarnings("unchecked") public final boolean exec() {
6549              final ObjectToInt<? super V> transformer =
6550                  this.transformer;
6551              final IntByIntToInt reducer = this.reducer;
6552              if (transformer == null || reducer == null)
6553 <                throw new Error(NullFunctionMessage);
6554 <            final int id = this.basis;
6555 <            int b = batch();
6556 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6557 <                b >>>= 1;
6558 <                t.pending = 1;
6559 <                MapReduceValuesToIntTask<K,V> rt =
6560 <                    new MapReduceValuesToIntTask<K,V>
6561 <                    (t, b, true, transformer, id, reducer);
6562 <                t = new MapReduceValuesToIntTask<K,V>
6563 <                    (t, b, false, transformer, id, reducer);
6564 <                t.sibling = rt;
6565 <                rt.sibling = t;
6566 <                rt.fork();
6567 <            }
6568 <            int r = id;
6569 <            Object v;
6570 <            while ((v = t.advance()) != null)
6571 <                r = reducer.apply(r, transformer.apply((V)v));
6572 <            t.result = r;
6573 <            for (;;) {
6574 <                int c; BulkTask<K,V,?> par; MapReduceValuesToIntTask<K,V> s, p;
6575 <                if ((par = t.parent) == null ||
6576 <                    !(par instanceof MapReduceValuesToIntTask)) {
6577 <                    t.quietlyComplete();
6578 <                    break;
6579 <                }
6580 <                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;
6553 >                return abortOnNullFunction();
6554 >            try {
6555 >                final int id = this.basis;
6556 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6557 >                    do {} while (!casPending(c = pending, c+1));
6558 >                    (rights = new MapReduceValuesToIntTask<K,V>
6559 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6560 >                }
6561 >                int r = id;
6562 >                Object v;
6563 >                while ((v = advance()) != null)
6564 >                    r = reducer.apply(r, transformer.apply((V)v));
6565 >                result = r;
6566 >                for (MapReduceValuesToIntTask<K,V> t = this, s;;) {
6567 >                    int c; BulkTask<K,V,?> par;
6568 >                    if ((c = t.pending) == 0) {
6569 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6570 >                            t.result = reducer.apply(t.result, s.result);
6571 >                        }
6572 >                        if ((par = t.parent) == null ||
6573 >                            !(par instanceof MapReduceValuesToIntTask)) {
6574 >                            t.quietlyComplete();
6575 >                            break;
6576 >                        }
6577 >                        t = (MapReduceValuesToIntTask<K,V>)par;
6578 >                    }
6579 >                    else if (t.casPending(c, c - 1))
6580 >                        break;
6581                  }
6582 <                else if (p.casPending(c, 0))
6583 <                    break;
6582 >            } catch (Throwable ex) {
6583 >                return tryCompleteComputation(ex);
6584              }
6585 +            return false;
6586          }
6587          public final Integer getRawResult() { return result; }
6588      }
6589  
6590 <    static final class MapReduceEntriesToIntTask<K,V>
6590 >    @SuppressWarnings("serial") static final class MapReduceEntriesToIntTask<K,V>
6591          extends BulkTask<K,V,Integer> {
6592          final ObjectToInt<Map.Entry<K,V>> transformer;
6593          final IntByIntToInt reducer;
6594          final int basis;
6595          int result;
6596 <        MapReduceEntriesToIntTask<K,V> sibling;
6596 >        MapReduceEntriesToIntTask<K,V> rights, nextRight;
6597          MapReduceEntriesToIntTask
6598              (ConcurrentHashMapV8<K,V> m,
6599               ObjectToInt<Map.Entry<K,V>> transformer,
# Line 6580 | Line 6604 | public class ConcurrentHashMapV8<K, V>
6604              this.basis = basis; this.reducer = reducer;
6605          }
6606          MapReduceEntriesToIntTask
6607 <            (BulkTask<K,V,?> p, int b, boolean split,
6607 >            (BulkTask<K,V,?> p, int b,
6608 >             MapReduceEntriesToIntTask<K,V> nextRight,
6609               ObjectToInt<Map.Entry<K,V>> transformer,
6610               int basis,
6611               IntByIntToInt reducer) {
6612 <            super(p, b, split);
6612 >            super(p, b); this.nextRight = nextRight;
6613              this.transformer = transformer;
6614              this.basis = basis; this.reducer = reducer;
6615          }
6616 <        public final void compute() {
6592 <            MapReduceEntriesToIntTask<K,V> t = this;
6616 >        @SuppressWarnings("unchecked") public final boolean exec() {
6617              final ObjectToInt<Map.Entry<K,V>> transformer =
6618                  this.transformer;
6619              final IntByIntToInt reducer = this.reducer;
6620              if (transformer == null || reducer == null)
6621 <                throw new Error(NullFunctionMessage);
6622 <            final int id = this.basis;
6623 <            int b = batch();
6624 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6625 <                b >>>= 1;
6626 <                t.pending = 1;
6627 <                MapReduceEntriesToIntTask<K,V> rt =
6628 <                    new MapReduceEntriesToIntTask<K,V>
6629 <                    (t, b, true, transformer, id, reducer);
6630 <                t = new MapReduceEntriesToIntTask<K,V>
6631 <                    (t, b, false, transformer, id, reducer);
6632 <                t.sibling = rt;
6633 <                rt.sibling = t;
6634 <                rt.fork();
6635 <            }
6636 <            int r = id;
6637 <            Object v;
6638 <            while ((v = t.advance()) != null)
6639 <                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6640 <            t.result = r;
6641 <            for (;;) {
6642 <                int c; BulkTask<K,V,?> par; MapReduceEntriesToIntTask<K,V> s, p;
6643 <                if ((par = t.parent) == null ||
6644 <                    !(par instanceof MapReduceEntriesToIntTask)) {
6645 <                    t.quietlyComplete();
6646 <                    break;
6647 <                }
6648 <                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;
6621 >                return abortOnNullFunction();
6622 >            try {
6623 >                final int id = this.basis;
6624 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6625 >                    do {} while (!casPending(c = pending, c+1));
6626 >                    (rights = new MapReduceEntriesToIntTask<K,V>
6627 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6628 >                }
6629 >                int r = id;
6630 >                Object v;
6631 >                while ((v = advance()) != null)
6632 >                    r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v)));
6633 >                result = r;
6634 >                for (MapReduceEntriesToIntTask<K,V> t = this, s;;) {
6635 >                    int c; BulkTask<K,V,?> par;
6636 >                    if ((c = t.pending) == 0) {
6637 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6638 >                            t.result = reducer.apply(t.result, s.result);
6639 >                        }
6640 >                        if ((par = t.parent) == null ||
6641 >                            !(par instanceof MapReduceEntriesToIntTask)) {
6642 >                            t.quietlyComplete();
6643 >                            break;
6644 >                        }
6645 >                        t = (MapReduceEntriesToIntTask<K,V>)par;
6646 >                    }
6647 >                    else if (t.casPending(c, c - 1))
6648 >                        break;
6649                  }
6650 <                else if (p.casPending(c, 0))
6651 <                    break;
6650 >            } catch (Throwable ex) {
6651 >                return tryCompleteComputation(ex);
6652              }
6653 +            return false;
6654          }
6655          public final Integer getRawResult() { return result; }
6656      }
6657  
6658 <    static final class MapReduceMappingsToIntTask<K,V>
6658 >    @SuppressWarnings("serial") static final class MapReduceMappingsToIntTask<K,V>
6659          extends BulkTask<K,V,Integer> {
6660          final ObjectByObjectToInt<? super K, ? super V> transformer;
6661          final IntByIntToInt reducer;
6662          final int basis;
6663          int result;
6664 <        MapReduceMappingsToIntTask<K,V> sibling;
6664 >        MapReduceMappingsToIntTask<K,V> rights, nextRight;
6665          MapReduceMappingsToIntTask
6666              (ConcurrentHashMapV8<K,V> m,
6667               ObjectByObjectToInt<? super K, ? super V> transformer,
# Line 6650 | Line 6672 | public class ConcurrentHashMapV8<K, V>
6672              this.basis = basis; this.reducer = reducer;
6673          }
6674          MapReduceMappingsToIntTask
6675 <            (BulkTask<K,V,?> p, int b, boolean split,
6675 >            (BulkTask<K,V,?> p, int b,
6676 >             MapReduceMappingsToIntTask<K,V> nextRight,
6677               ObjectByObjectToInt<? super K, ? super V> transformer,
6678               int basis,
6679               IntByIntToInt reducer) {
6680 <            super(p, b, split);
6680 >            super(p, b); this.nextRight = nextRight;
6681              this.transformer = transformer;
6682              this.basis = basis; this.reducer = reducer;
6683          }
6684 <        public final void compute() {
6662 <            MapReduceMappingsToIntTask<K,V> t = this;
6684 >        @SuppressWarnings("unchecked") public final boolean exec() {
6685              final ObjectByObjectToInt<? super K, ? super V> transformer =
6686                  this.transformer;
6687              final IntByIntToInt reducer = this.reducer;
6688              if (transformer == null || reducer == null)
6689 <                throw new Error(NullFunctionMessage);
6690 <            final int id = this.basis;
6691 <            int b = batch();
6692 <            while (b > 1 && t.baseIndex != t.baseLimit) {
6693 <                b >>>= 1;
6694 <                t.pending = 1;
6695 <                MapReduceMappingsToIntTask<K,V> rt =
6696 <                    new MapReduceMappingsToIntTask<K,V>
6697 <                    (t, b, true, transformer, id, reducer);
6698 <                t = new MapReduceMappingsToIntTask<K,V>
6699 <                    (t, b, false, transformer, id, reducer);
6700 <                t.sibling = rt;
6701 <                rt.sibling = t;
6702 <                rt.fork();
6703 <            }
6704 <            int r = id;
6705 <            Object v;
6706 <            while ((v = t.advance()) != null)
6707 <                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6708 <            t.result = r;
6709 <            for (;;) {
6710 <                int c; BulkTask<K,V,?> par; MapReduceMappingsToIntTask<K,V> s, p;
6711 <                if ((par = t.parent) == null ||
6712 <                    !(par instanceof MapReduceMappingsToIntTask)) {
6713 <                    t.quietlyComplete();
6714 <                    break;
6715 <                }
6716 <                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;
6689 >                return abortOnNullFunction();
6690 >            try {
6691 >                final int id = this.basis;
6692 >                for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6693 >                    do {} while (!casPending(c = pending, c+1));
6694 >                    (rights = new MapReduceMappingsToIntTask<K,V>
6695 >                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6696 >                }
6697 >                int r = id;
6698 >                Object v;
6699 >                while ((v = advance()) != null)
6700 >                    r = reducer.apply(r, transformer.apply((K)nextKey, (V)v));
6701 >                result = r;
6702 >                for (MapReduceMappingsToIntTask<K,V> t = this, s;;) {
6703 >                    int c; BulkTask<K,V,?> par;
6704 >                    if ((c = t.pending) == 0) {
6705 >                        for (s = t.rights; s != null; s = t.rights = s.nextRight) {
6706 >                            t.result = reducer.apply(t.result, s.result);
6707 >                        }
6708 >                        if ((par = t.parent) == null ||
6709 >                            !(par instanceof MapReduceMappingsToIntTask)) {
6710 >                            t.quietlyComplete();
6711 >                            break;
6712 >                        }
6713 >                        t = (MapReduceMappingsToIntTask<K,V>)par;
6714 >                    }
6715 >                    else if (t.casPending(c, c - 1))
6716 >                        break;
6717                  }
6718 <                else if (p.casPending(c, 0))
6719 <                    break;
6718 >            } catch (Throwable ex) {
6719 >                return tryCompleteComputation(ex);
6720              }
6721 +            return false;
6722          }
6723          public final Integer getRawResult() { return result; }
6724      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines