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.58 by jsr166, Tue Aug 14 05:55:08 2012 UTC vs.
Revision 1.59 by dl, Tue Aug 14 13:16:50 2012 UTC

# Line 47 | Line 47 | import java.io.Serializable;
47   * block, so may overlap with update operations (including {@code put}
48   * and {@code remove}). Retrievals reflect the results of the most
49   * recently <em>completed</em> update operations holding upon their
50 < * onset.  For aggregate operations such as {@code putAll} and {@code
51 < * clear}, concurrent retrievals may reflect insertion or removal of
52 < * only some entries.  Similarly, Iterators and Enumerations return
53 < * elements reflecting the state of the hash table at some point at or
54 < * since the creation of the iterator/enumeration.  They do
55 < * <em>not</em> throw {@link ConcurrentModificationException}.
56 < * However, iterators are designed to be used by only one thread at a
57 < * time.  Bear in mind that the results of aggregate status methods
58 < * including {@code size}, {@code isEmpty}, and {@code containsValue}
59 < * are typically useful only when a map is not undergoing concurrent
60 < * updates in other threads.  Otherwise the results of these methods
61 < * reflect transient states that may be adequate for monitoring
62 < * or estimation purposes, but not for program control.
50 > * onset. (More formally, an update operation for a given key bears a
51 > * <em>happens-before</em> relation with any (non-null) retrieval for
52 > * that key reporting the updated value.)  For aggregate operations
53 > * such as {@code putAll} and {@code clear}, concurrent retrievals may
54 > * reflect insertion or removal of only some entries.  Similarly,
55 > * Iterators and Enumerations return elements reflecting the state of
56 > * the hash table at some point at or since the creation of the
57 > * iterator/enumeration.  They do <em>not</em> throw {@link
58 > * ConcurrentModificationException}.  However, iterators are designed
59 > * to be used by only one thread at a time.  Bear in mind that the
60 > * results of aggregate status methods including {@code size}, {@code
61 > * isEmpty}, and {@code containsValue} are typically useful only when
62 > * a map is not undergoing concurrent updates in other threads.
63 > * Otherwise the results of these methods reflect transient states
64 > * that may be adequate for monitoring or estimation purposes, but not
65 > * for program control.
66   *
67   * <p> The table is dynamically expanded when there are too many
68   * collisions (i.e., keys that have distinct hash codes but fall into
# Line 716 | Line 719 | public class ConcurrentHashMapV8<K, V>
719           * starting at given root.
720           */
721          @SuppressWarnings("unchecked") // suppress Comparable cast warning
722 <            final TreeNode getTreeNode(int h, Object k, TreeNode p) {
722 >        final TreeNode getTreeNode(int h, Object k, TreeNode p) {
723              Class<?> c = k.getClass();
724              while (p != null) {
725                  int dir, ph;  Object pk; Class<?> pc;
# Line 777 | Line 780 | public class ConcurrentHashMapV8<K, V>
780           * @return null if added
781           */
782          @SuppressWarnings("unchecked") // suppress Comparable cast warning
783 <            final TreeNode putTreeNode(int h, Object k, Object v) {
783 >        final TreeNode putTreeNode(int h, Object k, Object v) {
784              Class<?> c = k.getClass();
785              TreeNode pp = root, p = null;
786              int dir = 0;
# Line 1204 | Line 1207 | public class ConcurrentHashMapV8<K, V>
1207      }
1208  
1209      /*
1210 <     * Internal versions of the five insertion methods, each a
1210 >     * Internal versions of the six insertion methods, each a
1211       * little more complicated than the last. All have
1212       * the same basic structure as the first (internalPut):
1213       *  1. If table uninitialized, create
# Line 1222 | Line 1225 | public class ConcurrentHashMapV8<K, V>
1225       *    returns from function call.
1226       *  * compute uses the same function-call mechanics, but without
1227       *    the prescans
1228 +     *  * merge acts as putIfAbsent in the absent case, but invokes the
1229 +     *    update function if present
1230       *  * putAll attempts to pre-allocate enough table space
1231       *    and more lazily performs count updates and checks.
1232       *
# Line 1546 | Line 1551 | public class ConcurrentHashMapV8<K, V>
1551  
1552      /** Implementation for compute */
1553      @SuppressWarnings("unchecked")
1554 <        private final Object internalCompute(K k, boolean onlyIfPresent,
1554 >    private final Object internalCompute(K k, boolean onlyIfPresent,
1555                                               BiFun<? super K, ? super V, ? extends V> mf) {
1556          int h = spread(k.hashCode());
1557          Object val = null;
# Line 1670 | Line 1675 | public class ConcurrentHashMapV8<K, V>
1675          return val;
1676      }
1677  
1678 +    /** Implementation for merge */
1679 +    @SuppressWarnings("unchecked")
1680      private final Object internalMerge(K k, V v,
1681                                         BiFun<? super V, ? super V, ? extends V> mf) {
1682          int h = spread(k.hashCode());
# Line 2222 | Line 2229 | public class ConcurrentHashMapV8<K, V>
2229  
2230      /**
2231       * Encapsulates traversal for methods such as containsValue; also
2232 <     * serves as a base class for other iterators.
2232 >     * serves as a base class for other iterators and bulk tasks.
2233       *
2234       * At each step, the iterator snapshots the key ("nextKey") and
2235       * value ("nextVal") of a valid node (i.e., one that, at point of
# Line 2260 | Line 2267 | public class ConcurrentHashMapV8<K, V>
2267       * This class extends ForkJoinTask to streamline parallel
2268       * iteration in bulk operations (see BulkTask). This adds only an
2269       * int of space overhead, which is close enough to negligible in
2270 <     * cases where it is not needed to not worry about it.
2270 >     * cases where it is not needed to not worry about it.  Because
2271 >     * ForkJoinTask is Serializable, but iterators need not be, we
2272 >     * need to add warning suppressions.
2273       */
2274 +    @SuppressWarnings("serial")
2275      static class Traverser<K,V,R> extends ForkJoinTask<R> {
2276          final ConcurrentHashMapV8<K, V> map;
2277          Node next;           // the next entry to use
# Line 2464 | Line 2474 | public class ConcurrentHashMapV8<K, V>
2474       */
2475      public long mappingCount() {
2476          long n = counter.sum();
2477 <        return (n < 0L) ? 0L : n;
2477 >        return (n < 0L) ? 0L : n; // ignore transient negative values
2478      }
2479  
2480      /**
# Line 2479 | Line 2489 | public class ConcurrentHashMapV8<K, V>
2489       * @throws NullPointerException if the specified key is null
2490       */
2491      @SuppressWarnings("unchecked")
2492 <        public V get(Object key) {
2492 >    public V get(Object key) {
2493          if (key == null)
2494              throw new NullPointerException();
2495          return (V)internalGet(key);
# Line 2555 | Line 2565 | public class ConcurrentHashMapV8<K, V>
2565       * @throws NullPointerException if the specified key or value is null
2566       */
2567      @SuppressWarnings("unchecked")
2568 <        public V put(K key, V value) {
2568 >    public V put(K key, V value) {
2569          if (key == null || value == null)
2570              throw new NullPointerException();
2571          return (V)internalPut(key, value);
# Line 2569 | Line 2579 | public class ConcurrentHashMapV8<K, V>
2579       * @throws NullPointerException if the specified key or value is null
2580       */
2581      @SuppressWarnings("unchecked")
2582 <        public V putIfAbsent(K key, V value) {
2582 >    public V putIfAbsent(K key, V value) {
2583          if (key == null || value == null)
2584              throw new NullPointerException();
2585          return (V)internalPutIfAbsent(key, value);
# Line 2626 | Line 2636 | public class ConcurrentHashMapV8<K, V>
2636       *         in which case the mapping is left unestablished
2637       */
2638      @SuppressWarnings("unchecked")
2639 <        public V computeIfAbsent(K key, Fun<? super K, ? extends V> mappingFunction) {
2639 >    public V computeIfAbsent(K key, Fun<? super K, ? extends V> mappingFunction) {
2640          if (key == null || mappingFunction == null)
2641              throw new NullPointerException();
2642          return (V)internalComputeIfAbsent(key, mappingFunction);
# Line 2666 | Line 2676 | public class ConcurrentHashMapV8<K, V>
2676       * @throws RuntimeException or Error if the remappingFunction does so,
2677       *         in which case the mapping is unchanged
2678       */
2679 +    @SuppressWarnings("unchecked")
2680      public V computeIfPresent(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2681          if (key == null || remappingFunction == null)
2682              throw new NullPointerException();
# Line 2712 | Line 2723 | public class ConcurrentHashMapV8<K, V>
2723       * @throws RuntimeException or Error if the remappingFunction does so,
2724       *         in which case the mapping is unchanged
2725       */
2726 <    //    @SuppressWarnings("unchecked")
2726 >    @SuppressWarnings("unchecked")
2727      public V compute(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2728          if (key == null || remappingFunction == null)
2729              throw new NullPointerException();
# Line 2744 | Line 2755 | public class ConcurrentHashMapV8<K, V>
2755       * so the computation should be short and simple, and must not
2756       * attempt to update any other mappings of this Map.
2757       */
2758 <    //    @SuppressWarnings("unchecked")
2758 >    @SuppressWarnings("unchecked")
2759      public V merge(K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) {
2760          if (key == null || value == null || remappingFunction == null)
2761              throw new NullPointerException();
# Line 3005 | Line 3016 | public class ConcurrentHashMapV8<K, V>
3016  
3017      /* ----------------Iterators -------------- */
3018  
3019 +    @SuppressWarnings("serial")
3020      static final class KeyIterator<K,V> extends Traverser<K,V,Object>
3021          implements Spliterator<K>, Enumeration<K> {
3022          KeyIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
# Line 3028 | Line 3040 | public class ConcurrentHashMapV8<K, V>
3040          public final K nextElement() { return next(); }
3041      }
3042  
3043 +    @SuppressWarnings("serial")
3044      static final class ValueIterator<K,V> extends Traverser<K,V,Object>
3045          implements Spliterator<V>, Enumeration<V> {
3046          ValueIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
# Line 3052 | Line 3065 | public class ConcurrentHashMapV8<K, V>
3065          public final V nextElement() { return next(); }
3066      }
3067  
3068 +    @SuppressWarnings("serial")
3069      static final class EntryIterator<K,V> extends Traverser<K,V,Object>
3070          implements Spliterator<Map.Entry<K,V>> {
3071          EntryIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
# Line 3656 | Line 3670 | public class ConcurrentHashMapV8<K, V>
3670  
3671          /**
3672           * Returns a non-null result from applying the given search
3673 <         * function on each (key, value), or null if none.  Further
3674 <         * element processing is suppressed upon success. However,
3675 <         * this method does not return until other in-progress
3676 <         * parallel invocations of the search function also complete.
3673 >         * function on each (key, value), or null if none.  Upon
3674 >         * success, further element processing is suppressed and the
3675 >         * results of any other parallel invocations of the search
3676 >         * function are ignored.
3677           *
3678           * @param searchFunction a function returning a non-null
3679           * result on success, else null
# Line 3718 | Line 3732 | public class ConcurrentHashMapV8<K, V>
3732           * @param basis the identity (initial default value) for the reduction
3733           * @param reducer a commutative associative combining function
3734           * @return the result of accumulating the given transformation
3735 <         * of all (key, value) pairs using the given reducer to
3722 <         * combine values, and the given basis as an identity value.
3735 >         * of all (key, value) pairs
3736           */
3737          public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer,
3738                                   long basis,
# Line 3774 | Line 3787 | public class ConcurrentHashMapV8<K, V>
3787  
3788          /**
3789           * Returns a non-null result from applying the given search
3790 <         * function on each key, or null if none.  Further element
3791 <         * processing is suppressed upon success. However, this method
3792 <         * does not return until other in-progress parallel
3793 <         * invocations of the search function also complete.
3790 >         * function on each key, or null if none. Upon success,
3791 >         * further element processing is suppressed and the results of
3792 >         * any other parallel invocations of the search function are
3793 >         * ignored.
3794           *
3795           * @param searchFunction a function returning a non-null
3796           * result on success, else null
# Line 3903 | Line 3916 | public class ConcurrentHashMapV8<K, V>
3916  
3917          /**
3918           * Returns a non-null result from applying the given search
3919 <         * function on each value, or null if none.  Further element
3920 <         * processing is suppressed upon success. However, this method
3921 <         * does not return until other in-progress parallel
3922 <         * invocations of the search function also complete.
3919 >         * function on each value, or null if none.  Upon success,
3920 >         * further element processing is suppressed and the results of
3921 >         * any other parallel invocations of the search function are
3922 >         * ignored.
3923           *
3924           * @param searchFunction a function returning a non-null
3925           * result on success, else null
# Line 4033 | Line 4046 | public class ConcurrentHashMapV8<K, V>
4046  
4047          /**
4048           * Returns a non-null result from applying the given search
4049 <         * function on each entry, or null if none.  Further element
4050 <         * processing is suppressed upon success. However, this method
4051 <         * does not return until other in-progress parallel
4052 <         * invocations of the search function also complete.
4049 >         * function on each entry, or null if none.  Upon success,
4050 >         * further element processing is suppressed and the results of
4051 >         * any other parallel invocations of the search function are
4052 >         * ignored.
4053           *
4054           * @param searchFunction a function returning a non-null
4055           * result on success, else null
# Line 4186 | Line 4199 | public class ConcurrentHashMapV8<K, V>
4199          }
4200  
4201          /**
4202 <         * Returns a task that when invoked, returns a non-null
4203 <         * result from applying the given search function on each
4204 <         * (key, value), or null if none.  Further element processing
4205 <         * is suppressed upon success. However, this method does not
4206 <         * return until other in-progress parallel invocations of the
4194 <         * search function also complete.
4202 >         * Returns a task that when invoked, returns a non-null result
4203 >         * from applying the given search function on each (key,
4204 >         * value), or null if none. Upon success, further element
4205 >         * processing is suppressed and the results of any other
4206 >         * parallel invocations of the search function are ignored.
4207           *
4208           * @param map the map
4209           * @param searchFunction a function returning a non-null
# Line 4339 | Line 4351 | public class ConcurrentHashMapV8<K, V>
4351          /**
4352           * Returns a task that when invoked, returns a non-null result
4353           * from applying the given search function on each key, or
4354 <         * null if none.  Further element processing is suppressed
4355 <         * upon success. However, this method does not return until
4356 <         * other in-progress parallel invocations of the search
4345 <         * function also complete.
4354 >         * null if none.  Upon success, further element processing is
4355 >         * suppressed and the results of any other parallel
4356 >         * invocations of the search function are ignored.
4357           *
4358           * @param map the map
4359           * @param searchFunction a function returning a non-null
# Line 4506 | Line 4517 | public class ConcurrentHashMapV8<K, V>
4517          /**
4518           * Returns a task that when invoked, returns a non-null result
4519           * from applying the given search function on each value, or
4520 <         * null if none.  Further element processing is suppressed
4521 <         * upon success. However, this method does not return until
4522 <         * other in-progress parallel invocations of the search
4512 <         * function also complete.
4520 >         * null if none.  Upon success, further element processing is
4521 >         * suppressed and the results of any other parallel
4522 >         * invocations of the search function are ignored.
4523           *
4524           * @param map the map
4525           * @param searchFunction a function returning a non-null
# Line 4674 | Line 4684 | public class ConcurrentHashMapV8<K, V>
4684          /**
4685           * Returns a task that when invoked, returns a non-null result
4686           * from applying the given search function on each entry, or
4687 <         * null if none.  Further element processing is suppressed
4688 <         * upon success. However, this method does not return until
4689 <         * other in-progress parallel invocations of the search
4680 <         * function also complete.
4687 >         * null if none.  Upon success, further element processing is
4688 >         * suppressed and the results of any other parallel
4689 >         * invocations of the search function are ignored.
4690           *
4691           * @param map the map
4692           * @param searchFunction a function returning a non-null
# Line 4819 | Line 4828 | public class ConcurrentHashMapV8<K, V>
4828       * exceptions are handled in a simpler manner, by just trying to
4829       * complete root task exceptionally.
4830       */
4831 +    @SuppressWarnings("serial")
4832      static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> {
4833          final BulkTask<K,V,?> parent;  // completion target
4834          int batch;                     // split control
# Line 4918 | Line 4928 | public class ConcurrentHashMapV8<K, V>
4928           * Returns exportable snapshot entry.
4929           */
4930          static <K,V> AbstractMap.SimpleEntry<K,V> entryFor(K k, V v) {
4931 <            return new AbstractMap.SimpleEntry(k, v);
4931 >            return new AbstractMap.SimpleEntry<K,V>(k, v);
4932          }
4933  
4934          // Unsafe mechanics
# Line 4926 | Line 4936 | public class ConcurrentHashMapV8<K, V>
4936          private static final long PENDING;
4937          static {
4938              try {
4939 <                U = sun.misc.Unsafe.getUnsafe();
4939 >                U = getUnsafe();
4940                  PENDING = U.objectFieldOffset
4941                      (BulkTask.class.getDeclaredField("pending"));
4942              } catch (Exception e) {
# Line 4941 | Line 4951 | public class ConcurrentHashMapV8<K, V>
4951       * others.
4952       */
4953  
4954 +    @SuppressWarnings("serial")
4955      static final class ForEachKeyTask<K,V>
4956          extends BulkTask<K,V,Void> {
4957          final Action<K> action;
# Line 4956 | Line 4967 | public class ConcurrentHashMapV8<K, V>
4967              super(p, b, split);
4968              this.action = action;
4969          }
4970 <        public final void compute() {
4970 >        @SuppressWarnings("unchecked") public final void compute() {
4971              final Action<K> action = this.action;
4972              if (action == null)
4973                  throw new Error(NullFunctionMessage);
# Line 4971 | Line 4982 | public class ConcurrentHashMapV8<K, V>
4982          }
4983      }
4984  
4985 +    @SuppressWarnings("serial")
4986      static final class ForEachValueTask<K,V>
4987          extends BulkTask<K,V,Void> {
4988          final Action<V> action;
# Line 4986 | Line 4998 | public class ConcurrentHashMapV8<K, V>
4998              super(p, b, split);
4999              this.action = action;
5000          }
5001 <        public final void compute() {
5001 >        @SuppressWarnings("unchecked") public final void compute() {
5002              final Action<V> action = this.action;
5003              if (action == null)
5004                  throw new Error(NullFunctionMessage);
# Line 5002 | Line 5014 | public class ConcurrentHashMapV8<K, V>
5014          }
5015      }
5016  
5017 +    @SuppressWarnings("serial")
5018      static final class ForEachEntryTask<K,V>
5019          extends BulkTask<K,V,Void> {
5020          final Action<Entry<K,V>> action;
# Line 5017 | Line 5030 | public class ConcurrentHashMapV8<K, V>
5030              super(p, b, split);
5031              this.action = action;
5032          }
5033 <        public final void compute() {
5033 >        @SuppressWarnings("unchecked") public final void compute() {
5034              final Action<Entry<K,V>> action = this.action;
5035              if (action == null)
5036                  throw new Error(NullFunctionMessage);
# Line 5033 | Line 5046 | public class ConcurrentHashMapV8<K, V>
5046          }
5047      }
5048  
5049 +    @SuppressWarnings("serial")
5050      static final class ForEachMappingTask<K,V>
5051          extends BulkTask<K,V,Void> {
5052          final BiAction<K,V> action;
# Line 5049 | Line 5063 | public class ConcurrentHashMapV8<K, V>
5063              this.action = action;
5064          }
5065  
5066 <        public final void compute() {
5066 >        @SuppressWarnings("unchecked") public final void compute() {
5067              final BiAction<K,V> action = this.action;
5068              if (action == null)
5069                  throw new Error(NullFunctionMessage);
# Line 5066 | Line 5080 | public class ConcurrentHashMapV8<K, V>
5080          }
5081      }
5082  
5083 +    @SuppressWarnings("serial")
5084      static final class ForEachTransformedKeyTask<K,V,U>
5085          extends BulkTask<K,V,Void> {
5086          final Fun<? super K, ? extends U> transformer;
# Line 5087 | Line 5102 | public class ConcurrentHashMapV8<K, V>
5102              this.transformer = transformer;
5103              this.action = action;
5104          }
5105 <        public final void compute() {
5105 >        @SuppressWarnings("unchecked") public final void compute() {
5106              final Fun<? super K, ? extends U> transformer =
5107                  this.transformer;
5108              final Action<U> action = this.action;
# Line 5108 | Line 5123 | public class ConcurrentHashMapV8<K, V>
5123          }
5124      }
5125  
5126 +    @SuppressWarnings("serial")
5127      static final class ForEachTransformedValueTask<K,V,U>
5128          extends BulkTask<K,V,Void> {
5129          final Fun<? super V, ? extends U> transformer;
# Line 5129 | Line 5145 | public class ConcurrentHashMapV8<K, V>
5145              this.transformer = transformer;
5146              this.action = action;
5147          }
5148 <        public final void compute() {
5148 >        @SuppressWarnings("unchecked") public final void compute() {
5149              final Fun<? super V, ? extends U> transformer =
5150                  this.transformer;
5151              final Action<U> action = this.action;
# Line 5150 | Line 5166 | public class ConcurrentHashMapV8<K, V>
5166          }
5167      }
5168  
5169 +    @SuppressWarnings("serial")
5170      static final class ForEachTransformedEntryTask<K,V,U>
5171          extends BulkTask<K,V,Void> {
5172          final Fun<Map.Entry<K,V>, ? extends U> transformer;
# Line 5171 | Line 5188 | public class ConcurrentHashMapV8<K, V>
5188              this.transformer = transformer;
5189              this.action = action;
5190          }
5191 <        public final void compute() {
5191 >        @SuppressWarnings("unchecked") public final void compute() {
5192              final Fun<Map.Entry<K,V>, ? extends U> transformer =
5193                  this.transformer;
5194              final Action<U> action = this.action;
# Line 5192 | Line 5209 | public class ConcurrentHashMapV8<K, V>
5209          }
5210      }
5211  
5212 +    @SuppressWarnings("serial")
5213      static final class ForEachTransformedMappingTask<K,V,U>
5214          extends BulkTask<K,V,Void> {
5215          final BiFun<? super K, ? super V, ? extends U> transformer;
# Line 5213 | Line 5231 | public class ConcurrentHashMapV8<K, V>
5231              this.transformer = transformer;
5232              this.action = action;
5233          }
5234 <        public final void compute() {
5234 >        @SuppressWarnings("unchecked") public final void compute() {
5235              final BiFun<? super K, ? super V, ? extends U> transformer =
5236                  this.transformer;
5237              final Action<U> action = this.action;
# Line 5234 | Line 5252 | public class ConcurrentHashMapV8<K, V>
5252          }
5253      }
5254  
5255 +    @SuppressWarnings("serial")
5256      static final class SearchKeysTask<K,V,U>
5257          extends BulkTask<K,V,U> {
5258          final Fun<? super K, ? extends U> searchFunction;
# Line 5252 | Line 5271 | public class ConcurrentHashMapV8<K, V>
5271              super(p, b, split);
5272              this.searchFunction = searchFunction; this.result = result;
5273          }
5274 <        public final void compute() {
5274 >        @SuppressWarnings("unchecked") public final void compute() {
5275              AtomicReference<U> result = this.result;
5276              final Fun<? super K, ? extends U> searchFunction =
5277                  this.searchFunction;
# Line 5267 | Line 5286 | public class ConcurrentHashMapV8<K, V>
5286              U u;
5287              while (result.get() == null && advance() != null) {
5288                  if ((u = searchFunction.apply((K)nextKey)) != null) {
5289 <                    result.compareAndSet(null, u);
5289 >                    if (result.compareAndSet(null, u)) {
5290 >                        for (BulkTask<K,V,?> a = this, p;;) {
5291 >                            if ((p = a.parent) == null) {
5292 >                                a.quietlyComplete();
5293 >                                break;
5294 >                            }
5295 >                            a = p;
5296 >                        }
5297 >                    }
5298                      break;
5299                  }
5300              }
# Line 5276 | Line 5303 | public class ConcurrentHashMapV8<K, V>
5303          public final U getRawResult() { return result.get(); }
5304      }
5305  
5306 +    @SuppressWarnings("serial")
5307      static final class SearchValuesTask<K,V,U>
5308          extends BulkTask<K,V,U> {
5309          final Fun<? super V, ? extends U> searchFunction;
# Line 5294 | Line 5322 | public class ConcurrentHashMapV8<K, V>
5322              super(p, b, split);
5323              this.searchFunction = searchFunction; this.result = result;
5324          }
5325 <        public final void compute() {
5325 >        @SuppressWarnings("unchecked") public final void compute() {
5326              AtomicReference<U> result = this.result;
5327              final Fun<? super V, ? extends U> searchFunction =
5328                  this.searchFunction;
# Line 5309 | Line 5337 | public class ConcurrentHashMapV8<K, V>
5337              Object v; U u;
5338              while (result.get() == null && (v = advance()) != null) {
5339                  if ((u = searchFunction.apply((V)v)) != null) {
5340 <                    result.compareAndSet(null, u);
5340 >                    if (result.compareAndSet(null, u)) {
5341 >                        for (BulkTask<K,V,?> a = this, p;;) {
5342 >                            if ((p = a.parent) == null) {
5343 >                                a.quietlyComplete();
5344 >                                break;
5345 >                            }
5346 >                            a = p;
5347 >                        }
5348 >                    }
5349                      break;
5350                  }
5351              }
# Line 5318 | Line 5354 | public class ConcurrentHashMapV8<K, V>
5354          public final U getRawResult() { return result.get(); }
5355      }
5356  
5357 +    @SuppressWarnings("serial")
5358      static final class SearchEntriesTask<K,V,U>
5359          extends BulkTask<K,V,U> {
5360          final Fun<Entry<K,V>, ? extends U> searchFunction;
# Line 5336 | Line 5373 | public class ConcurrentHashMapV8<K, V>
5373              super(p, b, split);
5374              this.searchFunction = searchFunction; this.result = result;
5375          }
5376 <        public final void compute() {
5376 >        @SuppressWarnings("unchecked") public final void compute() {
5377              AtomicReference<U> result = this.result;
5378              final Fun<Entry<K,V>, ? extends U> searchFunction =
5379                  this.searchFunction;
# Line 5351 | Line 5388 | public class ConcurrentHashMapV8<K, V>
5388              Object v; U u;
5389              while (result.get() == null && (v = advance()) != null) {
5390                  if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) {
5391 <                    result.compareAndSet(null, u);
5391 >                    if (result.compareAndSet(null, u)) {
5392 >                        for (BulkTask<K,V,?> a = this, p;;) {
5393 >                            if ((p = a.parent) == null) {
5394 >                                a.quietlyComplete();
5395 >                                break;
5396 >                            }
5397 >                            a = p;
5398 >                        }
5399 >                    }
5400                      break;
5401                  }
5402              }
# Line 5360 | Line 5405 | public class ConcurrentHashMapV8<K, V>
5405          public final U getRawResult() { return result.get(); }
5406      }
5407  
5408 +    @SuppressWarnings("serial")
5409      static final class SearchMappingsTask<K,V,U>
5410          extends BulkTask<K,V,U> {
5411          final BiFun<? super K, ? super V, ? extends U> searchFunction;
# Line 5378 | Line 5424 | public class ConcurrentHashMapV8<K, V>
5424              super(p, b, split);
5425              this.searchFunction = searchFunction; this.result = result;
5426          }
5427 <        public final void compute() {
5427 >        @SuppressWarnings("unchecked") public final void compute() {
5428              AtomicReference<U> result = this.result;
5429              final BiFun<? super K, ? super V, ? extends U> searchFunction =
5430                  this.searchFunction;
# Line 5393 | Line 5439 | public class ConcurrentHashMapV8<K, V>
5439              Object v; U u;
5440              while (result.get() == null && (v = advance()) != null) {
5441                  if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) {
5442 <                    result.compareAndSet(null, u);
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 >                        }
5450 >                    }
5451                      break;
5452                  }
5453              }
# Line 5402 | Line 5456 | public class ConcurrentHashMapV8<K, V>
5456          public final U getRawResult() { return result.get(); }
5457      }
5458  
5459 +    @SuppressWarnings("serial")
5460      static final class ReduceKeysTask<K,V>
5461          extends BulkTask<K,V,K> {
5462          final BiFun<? super K, ? super K, ? extends K> reducer;
# Line 5420 | Line 5475 | public class ConcurrentHashMapV8<K, V>
5475              this.reducer = reducer;
5476          }
5477  
5478 <        public final void compute() {
5478 >        @SuppressWarnings("unchecked") public final void compute() {
5479              ReduceKeysTask<K,V> t = this;
5480              final BiFun<? super K, ? super K, ? extends K> reducer =
5481                  this.reducer;
# Line 5464 | Line 5519 | public class ConcurrentHashMapV8<K, V>
5519          public final K getRawResult() { return result; }
5520      }
5521  
5522 +    @SuppressWarnings("serial")
5523      static final class ReduceValuesTask<K,V>
5524          extends BulkTask<K,V,V> {
5525          final BiFun<? super V, ? super V, ? extends V> reducer;
# Line 5482 | Line 5538 | public class ConcurrentHashMapV8<K, V>
5538              this.reducer = reducer;
5539          }
5540  
5541 <        public final void compute() {
5541 >        @SuppressWarnings("unchecked") public final void compute() {
5542              ReduceValuesTask<K,V> t = this;
5543              final BiFun<? super V, ? super V, ? extends V> reducer =
5544                  this.reducer;
# Line 5527 | Line 5583 | public class ConcurrentHashMapV8<K, V>
5583          public final V getRawResult() { return result; }
5584      }
5585  
5586 +    @SuppressWarnings("serial")
5587      static final class ReduceEntriesTask<K,V>
5588          extends BulkTask<K,V,Map.Entry<K,V>> {
5589          final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer;
# Line 5545 | Line 5602 | public class ConcurrentHashMapV8<K, V>
5602              this.reducer = reducer;
5603          }
5604  
5605 <        public final void compute() {
5605 >        @SuppressWarnings("unchecked") public final void compute() {
5606              ReduceEntriesTask<K,V> t = this;
5607              final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer =
5608                  this.reducer;
# Line 5591 | Line 5648 | public class ConcurrentHashMapV8<K, V>
5648          public final Map.Entry<K,V> getRawResult() { return result; }
5649      }
5650  
5651 +    @SuppressWarnings("serial")
5652      static final class MapReduceKeysTask<K,V,U>
5653          extends BulkTask<K,V,U> {
5654          final Fun<? super K, ? extends U> transformer;
# Line 5613 | Line 5671 | public class ConcurrentHashMapV8<K, V>
5671              this.transformer = transformer;
5672              this.reducer = reducer;
5673          }
5674 <        public final void compute() {
5674 >        @SuppressWarnings("unchecked") public final void compute() {
5675              MapReduceKeysTask<K,V,U> t = this;
5676              final Fun<? super K, ? extends U> transformer =
5677                  this.transformer;
# Line 5659 | Line 5717 | public class ConcurrentHashMapV8<K, V>
5717          public final U getRawResult() { return result; }
5718      }
5719  
5720 +    @SuppressWarnings("serial")
5721      static final class MapReduceValuesTask<K,V,U>
5722          extends BulkTask<K,V,U> {
5723          final Fun<? super V, ? extends U> transformer;
# Line 5681 | Line 5740 | public class ConcurrentHashMapV8<K, V>
5740              this.transformer = transformer;
5741              this.reducer = reducer;
5742          }
5743 <        public final void compute() {
5743 >        @SuppressWarnings("unchecked") public final void compute() {
5744              MapReduceValuesTask<K,V,U> t = this;
5745              final Fun<? super V, ? extends U> transformer =
5746                  this.transformer;
# Line 5728 | Line 5787 | public class ConcurrentHashMapV8<K, V>
5787          public final U getRawResult() { return result; }
5788      }
5789  
5790 +    @SuppressWarnings("serial")
5791      static final class MapReduceEntriesTask<K,V,U>
5792          extends BulkTask<K,V,U> {
5793          final Fun<Map.Entry<K,V>, ? extends U> transformer;
# Line 5750 | Line 5810 | public class ConcurrentHashMapV8<K, V>
5810              this.transformer = transformer;
5811              this.reducer = reducer;
5812          }
5813 <        public final void compute() {
5813 >        @SuppressWarnings("unchecked") public final void compute() {
5814              MapReduceEntriesTask<K,V,U> t = this;
5815              final Fun<Map.Entry<K,V>, ? extends U> transformer =
5816                  this.transformer;
# Line 5797 | Line 5857 | public class ConcurrentHashMapV8<K, V>
5857          public final U getRawResult() { return result; }
5858      }
5859  
5860 +    @SuppressWarnings("serial")
5861      static final class MapReduceMappingsTask<K,V,U>
5862          extends BulkTask<K,V,U> {
5863          final BiFun<? super K, ? super V, ? extends U> transformer;
# Line 5819 | Line 5880 | public class ConcurrentHashMapV8<K, V>
5880              this.transformer = transformer;
5881              this.reducer = reducer;
5882          }
5883 <        public final void compute() {
5883 >        @SuppressWarnings("unchecked") public final void compute() {
5884              MapReduceMappingsTask<K,V,U> t = this;
5885              final BiFun<? super K, ? super V, ? extends U> transformer =
5886                  this.transformer;
# Line 5865 | Line 5926 | public class ConcurrentHashMapV8<K, V>
5926          public final U getRawResult() { return result; }
5927      }
5928  
5929 +    @SuppressWarnings("serial")
5930      static final class MapReduceKeysToDoubleTask<K,V>
5931          extends BulkTask<K,V,Double> {
5932          final ObjectToDouble<? super K> transformer;
# Line 5890 | Line 5952 | public class ConcurrentHashMapV8<K, V>
5952              this.transformer = transformer;
5953              this.basis = basis; this.reducer = reducer;
5954          }
5955 <        public final void compute() {
5955 >        @SuppressWarnings("unchecked") public final void compute() {
5956              MapReduceKeysToDoubleTask<K,V> t = this;
5957              final ObjectToDouble<? super K> transformer =
5958                  this.transformer;
# Line 5934 | Line 5996 | public class ConcurrentHashMapV8<K, V>
5996          public final Double getRawResult() { return result; }
5997      }
5998  
5999 +    @SuppressWarnings("serial")
6000      static final class MapReduceValuesToDoubleTask<K,V>
6001          extends BulkTask<K,V,Double> {
6002          final ObjectToDouble<? super V> transformer;
# Line 5959 | Line 6022 | public class ConcurrentHashMapV8<K, V>
6022              this.transformer = transformer;
6023              this.basis = basis; this.reducer = reducer;
6024          }
6025 <        public final void compute() {
6025 >        @SuppressWarnings("unchecked") public final void compute() {
6026              MapReduceValuesToDoubleTask<K,V> t = this;
6027              final ObjectToDouble<? super V> transformer =
6028                  this.transformer;
# Line 6004 | Line 6067 | public class ConcurrentHashMapV8<K, V>
6067          public final Double getRawResult() { return result; }
6068      }
6069  
6070 +    @SuppressWarnings("serial")
6071      static final class MapReduceEntriesToDoubleTask<K,V>
6072          extends BulkTask<K,V,Double> {
6073          final ObjectToDouble<Map.Entry<K,V>> transformer;
# Line 6029 | Line 6093 | public class ConcurrentHashMapV8<K, V>
6093              this.transformer = transformer;
6094              this.basis = basis; this.reducer = reducer;
6095          }
6096 <        public final void compute() {
6096 >        @SuppressWarnings("unchecked") public final void compute() {
6097              MapReduceEntriesToDoubleTask<K,V> t = this;
6098              final ObjectToDouble<Map.Entry<K,V>> transformer =
6099                  this.transformer;
# Line 6074 | Line 6138 | public class ConcurrentHashMapV8<K, V>
6138          public final Double getRawResult() { return result; }
6139      }
6140  
6141 +    @SuppressWarnings("serial")
6142      static final class MapReduceMappingsToDoubleTask<K,V>
6143          extends BulkTask<K,V,Double> {
6144          final ObjectByObjectToDouble<? super K, ? super V> transformer;
# Line 6099 | Line 6164 | public class ConcurrentHashMapV8<K, V>
6164              this.transformer = transformer;
6165              this.basis = basis; this.reducer = reducer;
6166          }
6167 <        public final void compute() {
6167 >        @SuppressWarnings("unchecked") public final void compute() {
6168              MapReduceMappingsToDoubleTask<K,V> t = this;
6169              final ObjectByObjectToDouble<? super K, ? super V> transformer =
6170                  this.transformer;
# Line 6144 | Line 6209 | public class ConcurrentHashMapV8<K, V>
6209          public final Double getRawResult() { return result; }
6210      }
6211  
6212 +    @SuppressWarnings("serial")
6213      static final class MapReduceKeysToLongTask<K,V>
6214          extends BulkTask<K,V,Long> {
6215          final ObjectToLong<? super K> transformer;
# Line 6169 | Line 6235 | public class ConcurrentHashMapV8<K, V>
6235              this.transformer = transformer;
6236              this.basis = basis; this.reducer = reducer;
6237          }
6238 <        public final void compute() {
6238 >        @SuppressWarnings("unchecked") public final void compute() {
6239              MapReduceKeysToLongTask<K,V> t = this;
6240              final ObjectToLong<? super K> transformer =
6241                  this.transformer;
# Line 6213 | Line 6279 | public class ConcurrentHashMapV8<K, V>
6279          public final Long getRawResult() { return result; }
6280      }
6281  
6282 +    @SuppressWarnings("serial")
6283      static final class MapReduceValuesToLongTask<K,V>
6284          extends BulkTask<K,V,Long> {
6285          final ObjectToLong<? super V> transformer;
# Line 6238 | Line 6305 | public class ConcurrentHashMapV8<K, V>
6305              this.transformer = transformer;
6306              this.basis = basis; this.reducer = reducer;
6307          }
6308 <        public final void compute() {
6308 >        @SuppressWarnings("unchecked") public final void compute() {
6309              MapReduceValuesToLongTask<K,V> t = this;
6310              final ObjectToLong<? super V> transformer =
6311                  this.transformer;
# Line 6283 | Line 6350 | public class ConcurrentHashMapV8<K, V>
6350          public final Long getRawResult() { return result; }
6351      }
6352  
6353 +    @SuppressWarnings("serial")
6354      static final class MapReduceEntriesToLongTask<K,V>
6355          extends BulkTask<K,V,Long> {
6356          final ObjectToLong<Map.Entry<K,V>> transformer;
# Line 6308 | Line 6376 | public class ConcurrentHashMapV8<K, V>
6376              this.transformer = transformer;
6377              this.basis = basis; this.reducer = reducer;
6378          }
6379 <        public final void compute() {
6379 >        @SuppressWarnings("unchecked") public final void compute() {
6380              MapReduceEntriesToLongTask<K,V> t = this;
6381              final ObjectToLong<Map.Entry<K,V>> transformer =
6382                  this.transformer;
# Line 6353 | Line 6421 | public class ConcurrentHashMapV8<K, V>
6421          public final Long getRawResult() { return result; }
6422      }
6423  
6424 +    @SuppressWarnings("serial")
6425      static final class MapReduceMappingsToLongTask<K,V>
6426          extends BulkTask<K,V,Long> {
6427          final ObjectByObjectToLong<? super K, ? super V> transformer;
# Line 6378 | Line 6447 | public class ConcurrentHashMapV8<K, V>
6447              this.transformer = transformer;
6448              this.basis = basis; this.reducer = reducer;
6449          }
6450 <        public final void compute() {
6450 >        @SuppressWarnings("unchecked") public final void compute() {
6451              MapReduceMappingsToLongTask<K,V> t = this;
6452              final ObjectByObjectToLong<? super K, ? super V> transformer =
6453                  this.transformer;
# Line 6423 | Line 6492 | public class ConcurrentHashMapV8<K, V>
6492          public final Long getRawResult() { return result; }
6493      }
6494  
6495 +    @SuppressWarnings("serial")
6496      static final class MapReduceKeysToIntTask<K,V>
6497          extends BulkTask<K,V,Integer> {
6498          final ObjectToInt<? super K> transformer;
# Line 6448 | Line 6518 | public class ConcurrentHashMapV8<K, V>
6518              this.transformer = transformer;
6519              this.basis = basis; this.reducer = reducer;
6520          }
6521 <        public final void compute() {
6521 >        @SuppressWarnings("unchecked") public final void compute() {
6522              MapReduceKeysToIntTask<K,V> t = this;
6523              final ObjectToInt<? super K> transformer =
6524                  this.transformer;
# Line 6492 | Line 6562 | public class ConcurrentHashMapV8<K, V>
6562          public final Integer getRawResult() { return result; }
6563      }
6564  
6565 +    @SuppressWarnings("serial")
6566      static final class MapReduceValuesToIntTask<K,V>
6567          extends BulkTask<K,V,Integer> {
6568          final ObjectToInt<? super V> transformer;
# Line 6517 | Line 6588 | public class ConcurrentHashMapV8<K, V>
6588              this.transformer = transformer;
6589              this.basis = basis; this.reducer = reducer;
6590          }
6591 <        public final void compute() {
6591 >        @SuppressWarnings("unchecked") public final void compute() {
6592              MapReduceValuesToIntTask<K,V> t = this;
6593              final ObjectToInt<? super V> transformer =
6594                  this.transformer;
# Line 6562 | Line 6633 | public class ConcurrentHashMapV8<K, V>
6633          public final Integer getRawResult() { return result; }
6634      }
6635  
6636 +    @SuppressWarnings("serial")
6637      static final class MapReduceEntriesToIntTask<K,V>
6638          extends BulkTask<K,V,Integer> {
6639          final ObjectToInt<Map.Entry<K,V>> transformer;
# Line 6587 | Line 6659 | public class ConcurrentHashMapV8<K, V>
6659              this.transformer = transformer;
6660              this.basis = basis; this.reducer = reducer;
6661          }
6662 <        public final void compute() {
6662 >        @SuppressWarnings("unchecked") public final void compute() {
6663              MapReduceEntriesToIntTask<K,V> t = this;
6664              final ObjectToInt<Map.Entry<K,V>> transformer =
6665                  this.transformer;
# Line 6632 | Line 6704 | public class ConcurrentHashMapV8<K, V>
6704          public final Integer getRawResult() { return result; }
6705      }
6706  
6707 +    @SuppressWarnings("serial")
6708      static final class MapReduceMappingsToIntTask<K,V>
6709          extends BulkTask<K,V,Integer> {
6710          final ObjectByObjectToInt<? super K, ? super V> transformer;
# Line 6657 | Line 6730 | public class ConcurrentHashMapV8<K, V>
6730              this.transformer = transformer;
6731              this.basis = basis; this.reducer = reducer;
6732          }
6733 <        public final void compute() {
6733 >        @SuppressWarnings("unchecked") public final void compute() {
6734              MapReduceMappingsToIntTask<K,V> t = this;
6735              final ObjectByObjectToInt<? super K, ? super V> transformer =
6736                  this.transformer;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines