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

Comparing jsr166/src/jsr166e/ConcurrentHashMapV8.java (file contents):
Revision 1.60 by dl, Thu Aug 16 12:24:58 2012 UTC vs.
Revision 1.61 by dl, Thu Sep 13 10:41:37 2012 UTC

# Line 540 | 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 718 | Line 722 | public class ConcurrentHashMapV8<K, V>
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 779 | 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 1550 | 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,
1555 <                                             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 1676 | Line 1679 | public class ConcurrentHashMapV8<K, V>
1679      }
1680  
1681      /** Implementation for merge */
1682 <    @SuppressWarnings("unchecked")
1683 <    private final Object internalMerge(K k, V v,
1681 <                                       BiFun<? super V, ? super V, ? extends V> mf) {
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 2008 | 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 2184 | 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 2207 | 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 2271 | Line 2277 | public class ConcurrentHashMapV8<K, V>
2277       * ForkJoinTask is Serializable, but iterators need not be, we
2278       * need to add warning suppressions.
2279       */
2280 <    @SuppressWarnings("serial")
2275 <    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 2291 | 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;
2300 <            int i;
2301 <            if (split) // adjust parent
2302 <                i = it.baseLimit = (lo + hi + 1) >>> 1;
2303 <            else       // clone parent
2304 <                i = lo;
2305 <            this.index = this.baseIndex = i;
2303 >            it.baseLimit = this.index = this.baseIndex =
2304 >                ((this.baseLimit = it.baseLimit) + it.baseIndex + 1) >>> 1;
2305          }
2306  
2307          /**
# Line 2488 | Line 2487 | public class ConcurrentHashMapV8<K, V>
2487       *
2488       * @throws NullPointerException if the specified key is null
2489       */
2490 <    @SuppressWarnings("unchecked")
2492 <    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 2564 | 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")
2568 <    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 2578 | 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")
2582 <    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 2635 | 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 2676 | 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 <    @SuppressWarnings("unchecked")
2676 <    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 2723 | 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 2755 | 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 2771 | 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")
2775 <        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 2809 | 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")
2813 <        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 3016 | Line 3010 | public class ConcurrentHashMapV8<K, V>
3010  
3011      /* ----------------Iterators -------------- */
3012  
3013 <    @SuppressWarnings("serial")
3020 <    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")
3032 <            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 3040 | Line 3032 | public class ConcurrentHashMapV8<K, V>
3032          public final K nextElement() { return next(); }
3033      }
3034  
3035 <    @SuppressWarnings("serial")
3044 <    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")
3057 <            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 3065 | Line 3055 | public class ConcurrentHashMapV8<K, V>
3055          public final V nextElement() { return next(); }
3056      }
3057  
3058 <    @SuppressWarnings("serial")
3069 <    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")
3082 <            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 3174 | Line 3162 | public class ConcurrentHashMapV8<K, V>
3162              return (i == n) ? r : Arrays.copyOf(r, i);
3163          }
3164  
3165 <        @SuppressWarnings("unchecked")
3178 <            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 3371 | 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")
3375 <        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 3396 | 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")
3400 <        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 4828 | 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 <    @SuppressWarnings("serial")
4832 <    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 4842 | 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 4869 | Line 4853 | public class ConcurrentHashMapV8<K, V>
4853          }
4854  
4855          /**
4856 <         * Forces 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) {
4890 <                tryAbortComputation(ex);
4891 <            }
4892 <            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  
4895        public abstract void compute();
4896
4881          // utilities
4882  
4883          /** CompareAndSet pending count */
# Line 4919 | Line 4903 | public class ConcurrentHashMapV8<K, V>
4903          }
4904  
4905          /**
4922         * Error message for hoisted null checks of functions
4923         */
4924        static final String NullFunctionMessage =
4925            "Unexpected null function";
4926
4927        /**
4906           * Returns exportable snapshot entry.
4907           */
4908          static <K,V> AbstractMap.SimpleEntry<K,V> entryFor(K k, V v) {
# Line 4951 | Line 4929 | public class ConcurrentHashMapV8<K, V>
4929       * others.
4930       */
4931  
4932 <    @SuppressWarnings("serial")
4955 <    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 4962 | 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 <        @SuppressWarnings("unchecked") 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)
4980 <                action.apply((K)nextKey);
4981 <            tryComplete();
4963 >            return false;
4964          }
4965      }
4966  
4967 <    @SuppressWarnings("serial")
4986 <    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 4993 | 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 <        @SuppressWarnings("unchecked") 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;
5011 <            while ((v = advance()) != null)
5012 <                action.apply((V)v);
5013 <            tryComplete();
4999 >            return false;
5000          }
5001      }
5002  
5003 <    @SuppressWarnings("serial")
5018 <    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 5025 | 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 <        @SuppressWarnings("unchecked") 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;
5043 <            while ((v = advance()) != null)
5044 <                action.apply(entryFor((K)nextKey, (V)v));
5045 <            tryComplete();
5035 >            return false;
5036          }
5037      }
5038  
5039 <    @SuppressWarnings("serial")
5050 <    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 5057 | 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 <        @SuppressWarnings("unchecked") 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;
5077 <            while ((v = advance()) != null)
5078 <                action.apply((K)nextKey, (V)v);
5079 <            tryComplete();
5073 >            return false;
5074          }
5075      }
5076  
5077 <    @SuppressWarnings("serial")
5084 <    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 5095 | 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 <        @SuppressWarnings("unchecked") 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 <    @SuppressWarnings("serial")
5127 <    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 5138 | 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 <        @SuppressWarnings("unchecked") 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 <    @SuppressWarnings("serial")
5170 <    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 5181 | 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 <        @SuppressWarnings("unchecked") 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 <    @SuppressWarnings("serial")
5213 <    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 5224 | 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 <        @SuppressWarnings("unchecked") 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 <    @SuppressWarnings("serial")
5256 <    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 5265 | 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 <        @SuppressWarnings("unchecked") 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 <            }
5295 <            U u;
5296 <            while (result.get() == null && advance() != null) {
5297 <                if ((u = searchFunction.apply((K)nextKey)) != null) {
5298 <                    if (result.compareAndSet(null, u)) {
5299 <                        for (BulkTask<K,V,?> a = this, p;;) {
5300 <                            if ((p = a.parent) == null) {
5301 <                                a.quietlyComplete();
5293 <                                break;
5294 <                            }
5295 <                            a = p;
5296 <                        }
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                      }
5298                    break;
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 <    @SuppressWarnings("serial")
5307 <    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 5316 | 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 <        @SuppressWarnings("unchecked") 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 <                    if (result.compareAndSet(null, u)) {
5347 <                        for (BulkTask<K,V,?> a = this, p;;) {
5348 <                            if ((p = a.parent) == null) {
5349 <                                a.quietlyComplete();
5344 <                                break;
5345 <                            }
5346 <                            a = p;
5347 <                        }
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                      }
5349                    break;
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 <    @SuppressWarnings("serial")
5358 <    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 5367 | 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 <        @SuppressWarnings("unchecked") 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 <                    if (result.compareAndSet(null, u)) {
5395 <                        for (BulkTask<K,V,?> a = this, p;;) {
5396 <                            if ((p = a.parent) == null) {
5397 <                                a.quietlyComplete();
5395 <                                break;
5396 <                            }
5397 <                            a = p;
5398 <                        }
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                      }
5400                    break;
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 <    @SuppressWarnings("serial")
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 5418 | 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 <        @SuppressWarnings("unchecked") 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 <                    if (result.compareAndSet(null, u)) {
5443 <                        for (BulkTask<K,V,?> a = this, p;;) {
5444 <                            if ((p = a.parent) == null) {
5445 <                                a.quietlyComplete();
5446 <                                break;
5447 <                            }
5448 <                            a = p;
5449 <                        }
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                      }
5451                    break;
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 <    @SuppressWarnings("serial")
5460 <    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 5469 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
5479 <            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;
5494 <                rt.sibling = t;
5495 <                rt.fork();
5496 <            }
5497 <            K r = null;
5498 <            while (t.advance() != null) {
5499 <                K u = (K)t.nextKey;
5500 <                r = (r == null) ? u : reducer.apply(r, u);
5501 <            }
5502 <            t.result = r;
5503 <            for (;;) {
5504 <                int c; BulkTask<K,V,?> par; ReduceKeysTask<K,V> s, p; K u;
5505 <                if ((par = t.parent) == null ||
5506 <                    !(par instanceof ReduceKeysTask)) {
5507 <                    t.quietlyComplete();
5508 <                    break;
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 <    @SuppressWarnings("serial")
5523 <    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 5532 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
5542 <            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;
5558 <                rt.fork();
5559 <            }
5560 <            V r = null;
5561 <            Object v;
5562 <            while ((v = t.advance()) != null) {
5563 <                V u = (V)v;
5564 <                r = (r == null) ? u : reducer.apply(r, u);
5565 <            }
5566 <            t.result = r;
5567 <            for (;;) {
5568 <                int c; BulkTask<K,V,?> par; ReduceValuesTask<K,V> s, p; V u;
5569 <                if ((par = t.parent) == null ||
5570 <                    !(par instanceof ReduceValuesTask)) {
5571 <                    t.quietlyComplete();
5572 <                    break;
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 <    @SuppressWarnings("serial")
5587 <    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 5596 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
5606 <            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;
5622 <                rt.fork();
5623 <            }
5624 <            Map.Entry<K,V> r = null;
5625 <            Object v;
5626 <            while ((v = t.advance()) != null) {
5627 <                Map.Entry<K,V> u = entryFor((K)t.nextKey, (V)v);
5628 <                r = (r == null) ? u : reducer.apply(r, u);
5629 <            }
5630 <            t.result = r;
5631 <            for (;;) {
5632 <                int c; BulkTask<K,V,?> par; ReduceEntriesTask<K,V> s, p;
5633 <                Map.Entry<K,V> u;
5634 <                if ((par = t.parent) == null ||
5635 <                    !(par instanceof ReduceEntriesTask)) {
5636 <                    t.quietlyComplete();
5637 <                    break;
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 <    @SuppressWarnings("serial")
5652 <    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 5664 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
5675 <            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);
5691 <                t.sibling = rt;
5692 <                rt.sibling = t;
5693 <                rt.fork();
5694 <            }
5695 <            U r = null, u;
5696 <            while (t.advance() != null) {
5697 <                if ((u = transformer.apply((K)t.nextKey)) != null)
5698 <                    r = (r == null) ? u : reducer.apply(r, u);
5699 <            }
5700 <            t.result = r;
5701 <            for (;;) {
5702 <                int c; BulkTask<K,V,?> par; MapReduceKeysTask<K,V,U> s, p;
5703 <                if ((par = t.parent) == null ||
5704 <                    !(par instanceof MapReduceKeysTask)) {
5705 <                    t.quietlyComplete();
5706 <                    break;
5707 <                }
5708 <                else if ((c = (p = (MapReduceKeysTask<K,V,U>)par).pending) == 0) {
5709 <                    if ((s = t.sibling) != null && (u = s.result) != null)
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);
5711                    (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 <    @SuppressWarnings("serial")
5721 <    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 5733 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
5744 <            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;
5761 <                rt.sibling = t;
5762 <                rt.fork();
5763 <            }
5764 <            U r = null, u;
5765 <            Object v;
5766 <            while ((v = t.advance()) != null) {
5767 <                if ((u = transformer.apply((V)v)) != null)
5768 <                    r = (r == null) ? u : reducer.apply(r, u);
5769 <            }
5770 <            t.result = r;
5771 <            for (;;) {
5772 <                int c; BulkTask<K,V,?> par; MapReduceValuesTask<K,V,U> s, p;
5773 <                if ((par = t.parent) == null ||
5774 <                    !(par instanceof MapReduceValuesTask)) {
5775 <                    t.quietlyComplete();
5776 <                    break;
5777 <                }
5778 <                else if ((c = (p = (MapReduceValuesTask<K,V,U>)par).pending) == 0) {
5779 <                    if ((s = t.sibling) != null && (u = s.result) != null)
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);
5781                    (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 <    @SuppressWarnings("serial")
5791 <    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 5803 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
5814 <            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;
5831 <                rt.sibling = t;
5832 <                rt.fork();
5833 <            }
5834 <            U r = null, u;
5835 <            Object v;
5836 <            while ((v = t.advance()) != null) {
5837 <                if ((u = transformer.apply(entryFor((K)t.nextKey, (V)v))) != null)
5838 <                    r = (r == null) ? u : reducer.apply(r, u);
5839 <            }
5840 <            t.result = r;
5841 <            for (;;) {
5842 <                int c; BulkTask<K,V,?> par; MapReduceEntriesTask<K,V,U> s, p;
5843 <                if ((par = t.parent) == null ||
5844 <                    !(par instanceof MapReduceEntriesTask)) {
5845 <                    t.quietlyComplete();
5846 <                    break;
5847 <                }
5848 <                else if ((c = (p = (MapReduceEntriesTask<K,V,U>)par).pending) == 0) {
5849 <                    if ((s = t.sibling) != null && (u = s.result) != null)
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);
5851                    (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 <    @SuppressWarnings("serial")
5861 <    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 5873 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
5884 <            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;
5901 <                rt.sibling = t;
5902 <                rt.fork();
5903 <            }
5904 <            U r = null, u;
5905 <            Object v;
5906 <            while ((v = t.advance()) != null) {
5907 <                if ((u = transformer.apply((K)t.nextKey, (V)v)) != null)
5908 <                    r = (r == null) ? u : reducer.apply(r, u);
5909 <            }
5910 <            for (;;) {
5911 <                int c; BulkTask<K,V,?> par; MapReduceMappingsTask<K,V,U> s, p;
5912 <                if ((par = t.parent) == null ||
5913 <                    !(par instanceof MapReduceMappingsTask)) {
5914 <                    t.quietlyComplete();
5915 <                    break;
5916 <                }
5917 <                else if ((c = (p = (MapReduceMappingsTask<K,V,U>)par).pending) == 0) {
5918 <                    if ((s = t.sibling) != null && (u = s.result) != null)
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);
5920                    (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 <    @SuppressWarnings("serial")
5930 <    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 5944 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
5956 <            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) {
5988 <                    if ((s = t.sibling) != null)
5989 <                        r = reducer.apply(r, s.result);
5990 <                    (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 <    @SuppressWarnings("serial")
6000 <    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 6014 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6026 <            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) {
6059 <                    if ((s = t.sibling) != null)
6060 <                        r = reducer.apply(r, s.result);
6061 <                    (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 <    @SuppressWarnings("serial")
6071 <    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 6085 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6097 <            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) {
6130 <                    if ((s = t.sibling) != null)
6131 <                        r = reducer.apply(r, s.result);
6132 <                    (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 <    @SuppressWarnings("serial")
6142 <    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 6156 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6168 <            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) {
6201 <                    if ((s = t.sibling) != null)
6202 <                        r = reducer.apply(r, s.result);
6203 <                    (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 <    @SuppressWarnings("serial")
6213 <    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 6227 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6239 <            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) {
6271 <                    if ((s = t.sibling) != null)
6272 <                        r = reducer.apply(r, s.result);
6273 <                    (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 <    @SuppressWarnings("serial")
6283 <    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 6297 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6309 <            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) {
6342 <                    if ((s = t.sibling) != null)
6343 <                        r = reducer.apply(r, s.result);
6344 <                    (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 <    @SuppressWarnings("serial")
6354 <    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 6368 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6380 <            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) {
6413 <                    if ((s = t.sibling) != null)
6414 <                        r = reducer.apply(r, s.result);
6415 <                    (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 <    @SuppressWarnings("serial")
6425 <    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 6439 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6451 <            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) {
6484 <                    if ((s = t.sibling) != null)
6485 <                        r = reducer.apply(r, s.result);
6486 <                    (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 <    @SuppressWarnings("serial")
6496 <    static final class MapReduceKeysToIntTask<K,V>
6455 >    @SuppressWarnings("serial") static final class MapReduceKeysToIntTask<K,V>
6456          extends BulkTask<K,V,Integer> {
6457          final ObjectToInt<? super K> transformer;
6458          final IntByIntToInt reducer;
6459          final int basis;
6460          int result;
6461 <        MapReduceKeysToIntTask<K,V> sibling;
6461 >        MapReduceKeysToIntTask<K,V> rights, nextRight;
6462          MapReduceKeysToIntTask
6463              (ConcurrentHashMapV8<K,V> m,
6464               ObjectToInt<? super K> transformer,
# Line 6510 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6522 <            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) {
6554 <                    if ((s = t.sibling) != null)
6555 <                        r = reducer.apply(r, s.result);
6556 <                    (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 <    @SuppressWarnings("serial")
6566 <    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 6580 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6592 <            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) {
6625 <                    if ((s = t.sibling) != null)
6626 <                        r = reducer.apply(r, s.result);
6627 <                    (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 <    @SuppressWarnings("serial")
6637 <    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 6651 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6663 <            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) {
6696 <                    if ((s = t.sibling) != null)
6697 <                        r = reducer.apply(r, s.result);
6698 <                    (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 <    @SuppressWarnings("serial")
6708 <    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 6722 | 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 <        @SuppressWarnings("unchecked") public final void compute() {
6734 <            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) {
6767 <                    if ((s = t.sibling) != null)
6768 <                        r = reducer.apply(r, s.result);
6769 <                    (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