--- jsr166/src/jsr166e/ConcurrentHashMapV8.java 2012/08/13 15:52:33 1.52 +++ jsr166/src/jsr166e/ConcurrentHashMapV8.java 2012/08/14 13:16:50 1.59 @@ -47,19 +47,22 @@ import java.io.Serializable; * block, so may overlap with update operations (including {@code put} * and {@code remove}). Retrievals reflect the results of the most * recently completed update operations holding upon their - * onset. For aggregate operations such as {@code putAll} and {@code - * clear}, concurrent retrievals may reflect insertion or removal of - * only some entries. Similarly, Iterators and Enumerations return - * elements reflecting the state of the hash table at some point at or - * since the creation of the iterator/enumeration. They do - * not throw {@link ConcurrentModificationException}. - * However, iterators are designed to be used by only one thread at a - * time. Bear in mind that the results of aggregate status methods - * including {@code size}, {@code isEmpty}, and {@code containsValue} - * are typically useful only when a map is not undergoing concurrent - * updates in other threads. Otherwise the results of these methods - * reflect transient states that may be adequate for monitoring - * or estimation purposes, but not for program control. + * onset. (More formally, an update operation for a given key bears a + * happens-before relation with any (non-null) retrieval for + * that key reporting the updated value.) For aggregate operations + * such as {@code putAll} and {@code clear}, concurrent retrievals may + * reflect insertion or removal of only some entries. Similarly, + * Iterators and Enumerations return elements reflecting the state of + * the hash table at some point at or since the creation of the + * iterator/enumeration. They do not throw {@link + * ConcurrentModificationException}. However, iterators are designed + * to be used by only one thread at a time. Bear in mind that the + * results of aggregate status methods including {@code size}, {@code + * isEmpty}, and {@code containsValue} are typically useful only when + * a map is not undergoing concurrent updates in other threads. + * Otherwise the results of these methods reflect transient states + * that may be adequate for monitoring or estimation purposes, but not + * for program control. * *

The table is dynamically expanded when there are too many * collisions (i.e., keys that have distinct hash codes but fall into @@ -712,11 +715,11 @@ public class ConcurrentHashMapV8 } /** - * Return the TreeNode (or null if not found) for the given key + * Returns the TreeNode (or null if not found) for the given key * starting at given root. */ @SuppressWarnings("unchecked") // suppress Comparable cast warning - final TreeNode getTreeNode(int h, Object k, TreeNode p) { + final TreeNode getTreeNode(int h, Object k, TreeNode p) { Class c = k.getClass(); while (p != null) { int dir, ph; Object pk; Class pc; @@ -777,7 +780,7 @@ public class ConcurrentHashMapV8 * @return null if added */ @SuppressWarnings("unchecked") // suppress Comparable cast warning - final TreeNode putTreeNode(int h, Object k, Object v) { + final TreeNode putTreeNode(int h, Object k, Object v) { Class c = k.getClass(); TreeNode pp = root, p = null; int dir = 0; @@ -1204,7 +1207,7 @@ public class ConcurrentHashMapV8 } /* - * Internal versions of the five insertion methods, each a + * Internal versions of the six insertion methods, each a * little more complicated than the last. All have * the same basic structure as the first (internalPut): * 1. If table uninitialized, create @@ -1222,6 +1225,8 @@ public class ConcurrentHashMapV8 * returns from function call. * * compute uses the same function-call mechanics, but without * the prescans + * * merge acts as putIfAbsent in the absent case, but invokes the + * update function if present * * putAll attempts to pre-allocate enough table space * and more lazily performs count updates and checks. * @@ -1546,7 +1551,7 @@ public class ConcurrentHashMapV8 /** Implementation for compute */ @SuppressWarnings("unchecked") - private final Object internalCompute(K k, boolean onlyIfPresent, + private final Object internalCompute(K k, boolean onlyIfPresent, BiFun mf) { int h = spread(k.hashCode()); Object val = null; @@ -1670,6 +1675,8 @@ public class ConcurrentHashMapV8 return val; } + /** Implementation for merge */ + @SuppressWarnings("unchecked") private final Object internalMerge(K k, V v, BiFun mf) { int h = spread(k.hashCode()); @@ -2222,7 +2229,7 @@ public class ConcurrentHashMapV8 /** * Encapsulates traversal for methods such as containsValue; also - * serves as a base class for other iterators. + * serves as a base class for other iterators and bulk tasks. * * At each step, the iterator snapshots the key ("nextKey") and * value ("nextVal") of a valid node (i.e., one that, at point of @@ -2260,8 +2267,11 @@ public class ConcurrentHashMapV8 * This class extends ForkJoinTask to streamline parallel * iteration in bulk operations (see BulkTask). This adds only an * int of space overhead, which is close enough to negligible in - * cases where it is not needed to not worry about it. + * cases where it is not needed to not worry about it. Because + * ForkJoinTask is Serializable, but iterators need not be, we + * need to add warning suppressions. */ + @SuppressWarnings("serial") static class Traverser extends ForkJoinTask { final ConcurrentHashMapV8 map; Node next; // the next entry to use @@ -2327,7 +2337,7 @@ public class ConcurrentHashMapV8 } public final void remove() { - if (nextVal == null) + if (nextVal == null && last == null) advance(); Node e = last; if (e == null) @@ -2464,7 +2474,7 @@ public class ConcurrentHashMapV8 */ public long mappingCount() { long n = counter.sum(); - return (n < 0L) ? 0L : n; + return (n < 0L) ? 0L : n; // ignore transient negative values } /** @@ -2479,7 +2489,7 @@ public class ConcurrentHashMapV8 * @throws NullPointerException if the specified key is null */ @SuppressWarnings("unchecked") - public V get(Object key) { + public V get(Object key) { if (key == null) throw new NullPointerException(); return (V)internalGet(key); @@ -2555,7 +2565,7 @@ public class ConcurrentHashMapV8 * @throws NullPointerException if the specified key or value is null */ @SuppressWarnings("unchecked") - public V put(K key, V value) { + public V put(K key, V value) { if (key == null || value == null) throw new NullPointerException(); return (V)internalPut(key, value); @@ -2569,7 +2579,7 @@ public class ConcurrentHashMapV8 * @throws NullPointerException if the specified key or value is null */ @SuppressWarnings("unchecked") - public V putIfAbsent(K key, V value) { + public V putIfAbsent(K key, V value) { if (key == null || value == null) throw new NullPointerException(); return (V)internalPutIfAbsent(key, value); @@ -2626,7 +2636,7 @@ public class ConcurrentHashMapV8 * in which case the mapping is left unestablished */ @SuppressWarnings("unchecked") - public V computeIfAbsent(K key, Fun mappingFunction) { + public V computeIfAbsent(K key, Fun mappingFunction) { if (key == null || mappingFunction == null) throw new NullPointerException(); return (V)internalComputeIfAbsent(key, mappingFunction); @@ -2657,8 +2667,7 @@ public class ConcurrentHashMapV8 * * @param key key with which the specified value is to be associated * @param remappingFunction the function to compute a value - * @return the new value associated with - * the specified key, or null if none. + * @return the new value associated with the specified key, or null if none * @throws NullPointerException if the specified key or remappingFunction * is null * @throws IllegalStateException if the computation detectably @@ -2667,6 +2676,7 @@ public class ConcurrentHashMapV8 * @throws RuntimeException or Error if the remappingFunction does so, * in which case the mapping is unchanged */ + @SuppressWarnings("unchecked") public V computeIfPresent(K key, BiFun remappingFunction) { if (key == null || remappingFunction == null) throw new NullPointerException(); @@ -2704,8 +2714,7 @@ public class ConcurrentHashMapV8 * * @param key key with which the specified value is to be associated * @param remappingFunction the function to compute a value - * @return the new value associated with - * the specified key, or null if none. + * @return the new value associated with the specified key, or null if none * @throws NullPointerException if the specified key or remappingFunction * is null * @throws IllegalStateException if the computation detectably @@ -2714,7 +2723,7 @@ public class ConcurrentHashMapV8 * @throws RuntimeException or Error if the remappingFunction does so, * in which case the mapping is unchanged */ - // @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") public V compute(K key, BiFun remappingFunction) { if (key == null || remappingFunction == null) throw new NullPointerException(); @@ -2746,7 +2755,7 @@ public class ConcurrentHashMapV8 * so the computation should be short and simple, and must not * attempt to update any other mappings of this Map. */ - // @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") public V merge(K key, V value, BiFun remappingFunction) { if (key == null || value == null || remappingFunction == null) throw new NullPointerException(); @@ -2898,27 +2907,27 @@ public class ConcurrentHashMapV8 } /** - * Returns a partionable iterator of the keys in this map. + * Returns a partitionable iterator of the keys in this map. * - * @return a partionable iterator of the keys in this map + * @return a partitionable iterator of the keys in this map */ public Spliterator keySpliterator() { return new KeyIterator(this); } /** - * Returns a partionable iterator of the values in this map. + * Returns a partitionable iterator of the values in this map. * - * @return a partionable iterator of the values in this map + * @return a partitionable iterator of the values in this map */ public Spliterator valueSpliterator() { return new ValueIterator(this); } /** - * Returns a partionable iterator of the entries in this map. + * Returns a partitionable iterator of the entries in this map. * - * @return a partionable iterator of the entries in this map + * @return a partitionable iterator of the entries in this map */ public Spliterator> entrySpliterator() { return new EntryIterator(this); @@ -3007,6 +3016,7 @@ public class ConcurrentHashMapV8 /* ----------------Iterators -------------- */ + @SuppressWarnings("serial") static final class KeyIterator extends Traverser implements Spliterator, Enumeration { KeyIterator(ConcurrentHashMapV8 map) { super(map); } @@ -3030,6 +3040,7 @@ public class ConcurrentHashMapV8 public final K nextElement() { return next(); } } + @SuppressWarnings("serial") static final class ValueIterator extends Traverser implements Spliterator, Enumeration { ValueIterator(ConcurrentHashMapV8 map) { super(map); } @@ -3054,6 +3065,7 @@ public class ConcurrentHashMapV8 public final V nextElement() { return next(); } } + @SuppressWarnings("serial") static final class EntryIterator extends Traverser implements Spliterator> { EntryIterator(ConcurrentHashMapV8 map) { super(map); } @@ -3518,7 +3530,7 @@ public class ConcurrentHashMapV8 /** * An extended view of a ConcurrentHashMap supporting bulk - * parallel operations. These operations are designed to be be + * parallel operations. These operations are designed to be * safely, and often sensibly, applied even with maps that are * being concurrently updated by other threads; for example, when * computing a snapshot summary of the values in a shared @@ -3636,7 +3648,7 @@ public class ConcurrentHashMapV8 * * @param action the action */ - public void forEach(BiAction action) { + public void forEach(BiAction action) { fjp.invoke(ForkJoinTasks.forEach (ConcurrentHashMapV8.this, action)); } @@ -3650,7 +3662,7 @@ public class ConcurrentHashMapV8 * which case the action is not applied). * @param action the action */ - public void forEach(BiFun transformer, + public void forEach(BiFun transformer, Action action) { fjp.invoke(ForkJoinTasks.forEach (ConcurrentHashMapV8.this, transformer, action)); @@ -3658,10 +3670,10 @@ public class ConcurrentHashMapV8 /** * Returns a non-null result from applying the given search - * function on each (key, value), or null if none. Further - * element processing is suppressed upon success. However, - * this method does not return until other in-progress - * parallel invocations of the search function also complete. + * function on each (key, value), or null if none. Upon + * success, further element processing is suppressed and the + * results of any other parallel invocations of the search + * function are ignored. * * @param searchFunction a function returning a non-null * result on success, else null @@ -3720,8 +3732,7 @@ public class ConcurrentHashMapV8 * @param basis the identity (initial default value) for the reduction * @param reducer a commutative associative combining function * @return the result of accumulating the given transformation - * of all (key, value) pairs using the given reducer to - * combine values, and the given basis as an identity value. + * of all (key, value) pairs */ public long reduceToLong(ObjectByObjectToLong transformer, long basis, @@ -3750,25 +3761,25 @@ public class ConcurrentHashMapV8 } /** - * Performs the given action for each key + * Performs the given action for each key. * * @param action the action */ - public void forEachKey(Action action) { + public void forEachKey(Action action) { fjp.invoke(ForkJoinTasks.forEachKey (ConcurrentHashMapV8.this, action)); } /** * Performs the given action for each non-null transformation - * of each key + * of each key. * * @param transformer a function returning the transformation * for an element, or null of there is no transformation (in * which case the action is not applied). * @param action the action */ - public void forEachKey(Fun transformer, + public void forEachKey(Fun transformer, Action action) { fjp.invoke(ForkJoinTasks.forEachKey (ConcurrentHashMapV8.this, transformer, action)); @@ -3776,10 +3787,10 @@ public class ConcurrentHashMapV8 /** * Returns a non-null result from applying the given search - * function on each key, or null if none. Further element - * processing is suppressed upon success. However, this method - * does not return until other in-progress parallel - * invocations of the search function also complete. + * function on each key, or null if none. Upon success, + * further element processing is suppressed and the results of + * any other parallel invocations of the search function are + * ignored. * * @param searchFunction a function returning a non-null * result on success, else null @@ -3880,24 +3891,24 @@ public class ConcurrentHashMapV8 } /** - * Performs the given action for each value + * Performs the given action for each value. * * @param action the action */ - public void forEachValue(Action action) { + public void forEachValue(Action action) { fjp.invoke(ForkJoinTasks.forEachValue (ConcurrentHashMapV8.this, action)); } /** * Performs the given action for each non-null transformation - * of each value + * of each value. * * @param transformer a function returning the transformation * for an element, or null of there is no transformation (in * which case the action is not applied). */ - public void forEachValue(Fun transformer, + public void forEachValue(Fun transformer, Action action) { fjp.invoke(ForkJoinTasks.forEachValue (ConcurrentHashMapV8.this, transformer, action)); @@ -3905,10 +3916,10 @@ public class ConcurrentHashMapV8 /** * Returns a non-null result from applying the given search - * function on each value, or null if none. Further element - * processing is suppressed upon success. However, this method - * does not return until other in-progress parallel - * invocations of the search function also complete. + * function on each value, or null if none. Upon success, + * further element processing is suppressed and the results of + * any other parallel invocations of the search function are + * ignored. * * @param searchFunction a function returning a non-null * result on success, else null @@ -4009,25 +4020,25 @@ public class ConcurrentHashMapV8 } /** - * Perform the given action for each entry + * Performs the given action for each entry. * * @param action the action */ - public void forEachEntry(Action> action) { + public void forEachEntry(Action> action) { fjp.invoke(ForkJoinTasks.forEachEntry (ConcurrentHashMapV8.this, action)); } /** - * Perform the given action for each non-null transformation - * of each entry + * Performs the given action for each non-null transformation + * of each entry. * * @param transformer a function returning the transformation * for an element, or null of there is no transformation (in * which case the action is not applied). * @param action the action */ - public void forEachEntry(Fun, ? extends U> transformer, + public void forEachEntry(Fun, ? extends U> transformer, Action action) { fjp.invoke(ForkJoinTasks.forEachEntry (ConcurrentHashMapV8.this, transformer, action)); @@ -4035,10 +4046,10 @@ public class ConcurrentHashMapV8 /** * Returns a non-null result from applying the given search - * function on each entry, or null if none. Further element - * processing is suppressed upon success. However, this method - * does not return until other in-progress parallel - * invocations of the search function also complete. + * function on each entry, or null if none. Upon success, + * further element processing is suppressed and the results of + * any other parallel invocations of the search function are + * ignored. * * @param searchFunction a function returning a non-null * result on success, else null @@ -4159,7 +4170,7 @@ public class ConcurrentHashMapV8 * @param action the action * @return the task */ - public static ForkJoinTask forEach + public static ForkJoinTask forEach (ConcurrentHashMapV8 map, BiAction action) { if (action == null) throw new NullPointerException(); @@ -4177,7 +4188,7 @@ public class ConcurrentHashMapV8 * @param action the action * @return the task */ - public static ForkJoinTask forEach + public static ForkJoinTask forEach (ConcurrentHashMapV8 map, BiFun transformer, Action action) { @@ -4188,12 +4199,11 @@ public class ConcurrentHashMapV8 } /** - * Returns a task that when invoked, returns a non-null - * result from applying the given search function on each - * (key, value), or null if none. Further element processing - * is suppressed upon success. However, this method does not - * return until other in-progress parallel invocations of the - * search function also complete. + * Returns a task that when invoked, returns a non-null result + * from applying the given search function on each (key, + * value), or null if none. Upon success, further element + * processing is suppressed and the results of any other + * parallel invocations of the search function are ignored. * * @param map the map * @param searchFunction a function returning a non-null @@ -4304,13 +4314,13 @@ public class ConcurrentHashMapV8 /** * Returns a task that when invoked, performs the given action - * for each key + * for each key. * * @param map the map * @param action the action * @return the task */ - public static ForkJoinTask forEachKey + public static ForkJoinTask forEachKey (ConcurrentHashMapV8 map, Action action) { if (action == null) throw new NullPointerException(); @@ -4319,7 +4329,7 @@ public class ConcurrentHashMapV8 /** * Returns a task that when invoked, performs the given action - * for each non-null transformation of each key + * for each non-null transformation of each key. * * @param map the map * @param transformer a function returning the transformation @@ -4328,7 +4338,7 @@ public class ConcurrentHashMapV8 * @param action the action * @return the task */ - public static ForkJoinTask forEachKey + public static ForkJoinTask forEachKey (ConcurrentHashMapV8 map, Fun transformer, Action action) { @@ -4341,10 +4351,9 @@ public class ConcurrentHashMapV8 /** * Returns a task that when invoked, returns a non-null result * from applying the given search function on each key, or - * null if none. Further element processing is suppressed - * upon success. However, this method does not return until - * other in-progress parallel invocations of the search - * function also complete. + * null if none. Upon success, further element processing is + * suppressed and the results of any other parallel + * invocations of the search function are ignored. * * @param map the map * @param searchFunction a function returning a non-null @@ -4376,6 +4385,7 @@ public class ConcurrentHashMapV8 return new ReduceKeysTask (map, reducer); } + /** * Returns a task that when invoked, returns the result of * accumulating the given transformation of all keys using the given @@ -4472,12 +4482,12 @@ public class ConcurrentHashMapV8 /** * Returns a task that when invoked, performs the given action - * for each value + * for each value. * * @param map the map * @param action the action */ - public static ForkJoinTask forEachValue + public static ForkJoinTask forEachValue (ConcurrentHashMapV8 map, Action action) { if (action == null) throw new NullPointerException(); @@ -4486,7 +4496,7 @@ public class ConcurrentHashMapV8 /** * Returns a task that when invoked, performs the given action - * for each non-null transformation of each value + * for each non-null transformation of each value. * * @param map the map * @param transformer a function returning the transformation @@ -4494,7 +4504,7 @@ public class ConcurrentHashMapV8 * which case the action is not applied). * @param action the action */ - public static ForkJoinTask forEachValue + public static ForkJoinTask forEachValue (ConcurrentHashMapV8 map, Fun transformer, Action action) { @@ -4507,10 +4517,9 @@ public class ConcurrentHashMapV8 /** * Returns a task that when invoked, returns a non-null result * from applying the given search function on each value, or - * null if none. Further element processing is suppressed - * upon success. However, this method does not return until - * other in-progress parallel invocations of the search - * function also complete. + * null if none. Upon success, further element processing is + * suppressed and the results of any other parallel + * invocations of the search function are ignored. * * @param map the map * @param searchFunction a function returning a non-null @@ -4640,12 +4649,12 @@ public class ConcurrentHashMapV8 /** * Returns a task that when invoked, perform the given action - * for each entry + * for each entry. * * @param map the map * @param action the action */ - public static ForkJoinTask forEachEntry + public static ForkJoinTask forEachEntry (ConcurrentHashMapV8 map, Action> action) { if (action == null) throw new NullPointerException(); @@ -4654,7 +4663,7 @@ public class ConcurrentHashMapV8 /** * Returns a task that when invoked, perform the given action - * for each non-null transformation of each entry + * for each non-null transformation of each entry. * * @param map the map * @param transformer a function returning the transformation @@ -4662,7 +4671,7 @@ public class ConcurrentHashMapV8 * which case the action is not applied). * @param action the action */ - public static ForkJoinTask forEachEntry + public static ForkJoinTask forEachEntry (ConcurrentHashMapV8 map, Fun, ? extends U> transformer, Action action) { @@ -4675,10 +4684,9 @@ public class ConcurrentHashMapV8 /** * Returns a task that when invoked, returns a non-null result * from applying the given search function on each entry, or - * null if none. Further element processing is suppressed - * upon success. However, this method does not return until - * other in-progress parallel invocations of the search - * function also complete. + * null if none. Upon success, further element processing is + * suppressed and the results of any other parallel + * invocations of the search function are ignored. * * @param map the map * @param searchFunction a function returning a non-null @@ -4811,7 +4819,7 @@ public class ConcurrentHashMapV8 /** * Base for FJ tasks for bulk operations. This adds a variant of - * CountedCompleters and some split and merge bookeeping to + * CountedCompleters and some split and merge bookkeeping to * iterator functionality. The forEach and reduce methods are * similar to those illustrated in CountedCompleter documentation, * except that bottom-up reduction completions perform them within @@ -4820,6 +4828,7 @@ public class ConcurrentHashMapV8 * exceptions are handled in a simpler manner, by just trying to * complete root task exceptionally. */ + @SuppressWarnings("serial") static abstract class BulkTask extends Traverser { final BulkTask parent; // completion target int batch; // split control @@ -4842,7 +4851,7 @@ public class ConcurrentHashMapV8 // FJ methods /** - * Propagate completion. Note that all reduce actions + * Propagates completion. Note that all reduce actions * bypass this method to combine while completing. */ final void tryComplete() { @@ -4860,7 +4869,7 @@ public class ConcurrentHashMapV8 } /** - * Force root task to throw exception unless already complete. + * Forces root task to throw exception unless already complete. */ final void tryAbortComputation(Throwable ex) { for (BulkTask a = this;;) { @@ -4877,7 +4886,7 @@ public class ConcurrentHashMapV8 try { compute(); } - catch(Throwable ex) { + catch (Throwable ex) { tryAbortComputation(ex); } return false; @@ -4893,7 +4902,7 @@ public class ConcurrentHashMapV8 } /** - * Return approx exp2 of the number of times (minus one) to + * Returns approx exp2 of the number of times (minus one) to * split task by two before executing leaf action. This value * is faster to compute and more convenient to use as a guide * to splitting than is the depth, since it is used while @@ -4904,7 +4913,7 @@ public class ConcurrentHashMapV8 if (b < 0) { long n = map.counter.sum(); int sp = getPool().getParallelism() << 3; // slack of 8 - b = batch = (n <= 0L)? 0 : (n < (long)sp) ? (int)n : sp; + b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp; } return b; } @@ -4916,10 +4925,10 @@ public class ConcurrentHashMapV8 "Unexpected null function"; /** - * Return exportable snapshot entry + * Returns exportable snapshot entry. */ static AbstractMap.SimpleEntry entryFor(K k, V v) { - return new AbstractMap.SimpleEntry(k, v); + return new AbstractMap.SimpleEntry(k, v); } // Unsafe mechanics @@ -4927,7 +4936,7 @@ public class ConcurrentHashMapV8 private static final long PENDING; static { try { - U = sun.misc.Unsafe.getUnsafe(); + U = getUnsafe(); PENDING = U.objectFieldOffset (BulkTask.class.getDeclaredField("pending")); } catch (Exception e) { @@ -4942,6 +4951,7 @@ public class ConcurrentHashMapV8 * others. */ + @SuppressWarnings("serial") static final class ForEachKeyTask extends BulkTask { final Action action; @@ -4957,7 +4967,7 @@ public class ConcurrentHashMapV8 super(p, b, split); this.action = action; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { final Action action = this.action; if (action == null) throw new Error(NullFunctionMessage); @@ -4972,6 +4982,7 @@ public class ConcurrentHashMapV8 } } + @SuppressWarnings("serial") static final class ForEachValueTask extends BulkTask { final Action action; @@ -4987,7 +4998,7 @@ public class ConcurrentHashMapV8 super(p, b, split); this.action = action; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { final Action action = this.action; if (action == null) throw new Error(NullFunctionMessage); @@ -5003,6 +5014,7 @@ public class ConcurrentHashMapV8 } } + @SuppressWarnings("serial") static final class ForEachEntryTask extends BulkTask { final Action> action; @@ -5018,7 +5030,7 @@ public class ConcurrentHashMapV8 super(p, b, split); this.action = action; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { final Action> action = this.action; if (action == null) throw new Error(NullFunctionMessage); @@ -5034,6 +5046,7 @@ public class ConcurrentHashMapV8 } } + @SuppressWarnings("serial") static final class ForEachMappingTask extends BulkTask { final BiAction action; @@ -5050,7 +5063,7 @@ public class ConcurrentHashMapV8 this.action = action; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { final BiAction action = this.action; if (action == null) throw new Error(NullFunctionMessage); @@ -5067,6 +5080,7 @@ public class ConcurrentHashMapV8 } } + @SuppressWarnings("serial") static final class ForEachTransformedKeyTask extends BulkTask { final Fun transformer; @@ -5088,7 +5102,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.action = action; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { final Fun transformer = this.transformer; final Action action = this.action; @@ -5109,6 +5123,7 @@ public class ConcurrentHashMapV8 } } + @SuppressWarnings("serial") static final class ForEachTransformedValueTask extends BulkTask { final Fun transformer; @@ -5130,7 +5145,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.action = action; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { final Fun transformer = this.transformer; final Action action = this.action; @@ -5151,6 +5166,7 @@ public class ConcurrentHashMapV8 } } + @SuppressWarnings("serial") static final class ForEachTransformedEntryTask extends BulkTask { final Fun, ? extends U> transformer; @@ -5172,7 +5188,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.action = action; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { final Fun, ? extends U> transformer = this.transformer; final Action action = this.action; @@ -5193,6 +5209,7 @@ public class ConcurrentHashMapV8 } } + @SuppressWarnings("serial") static final class ForEachTransformedMappingTask extends BulkTask { final BiFun transformer; @@ -5214,7 +5231,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.action = action; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { final BiFun transformer = this.transformer; final Action action = this.action; @@ -5235,6 +5252,7 @@ public class ConcurrentHashMapV8 } } + @SuppressWarnings("serial") static final class SearchKeysTask extends BulkTask { final Fun searchFunction; @@ -5253,7 +5271,7 @@ public class ConcurrentHashMapV8 super(p, b, split); this.searchFunction = searchFunction; this.result = result; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { AtomicReference result = this.result; final Fun searchFunction = this.searchFunction; @@ -5268,7 +5286,15 @@ public class ConcurrentHashMapV8 U u; while (result.get() == null && advance() != null) { if ((u = searchFunction.apply((K)nextKey)) != null) { - result.compareAndSet(null, u); + if (result.compareAndSet(null, u)) { + for (BulkTask a = this, p;;) { + if ((p = a.parent) == null) { + a.quietlyComplete(); + break; + } + a = p; + } + } break; } } @@ -5277,6 +5303,7 @@ public class ConcurrentHashMapV8 public final U getRawResult() { return result.get(); } } + @SuppressWarnings("serial") static final class SearchValuesTask extends BulkTask { final Fun searchFunction; @@ -5295,7 +5322,7 @@ public class ConcurrentHashMapV8 super(p, b, split); this.searchFunction = searchFunction; this.result = result; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { AtomicReference result = this.result; final Fun searchFunction = this.searchFunction; @@ -5310,7 +5337,15 @@ public class ConcurrentHashMapV8 Object v; U u; while (result.get() == null && (v = advance()) != null) { if ((u = searchFunction.apply((V)v)) != null) { - result.compareAndSet(null, u); + if (result.compareAndSet(null, u)) { + for (BulkTask a = this, p;;) { + if ((p = a.parent) == null) { + a.quietlyComplete(); + break; + } + a = p; + } + } break; } } @@ -5319,6 +5354,7 @@ public class ConcurrentHashMapV8 public final U getRawResult() { return result.get(); } } + @SuppressWarnings("serial") static final class SearchEntriesTask extends BulkTask { final Fun, ? extends U> searchFunction; @@ -5337,7 +5373,7 @@ public class ConcurrentHashMapV8 super(p, b, split); this.searchFunction = searchFunction; this.result = result; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { AtomicReference result = this.result; final Fun, ? extends U> searchFunction = this.searchFunction; @@ -5352,7 +5388,15 @@ public class ConcurrentHashMapV8 Object v; U u; while (result.get() == null && (v = advance()) != null) { if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) { - result.compareAndSet(null, u); + if (result.compareAndSet(null, u)) { + for (BulkTask a = this, p;;) { + if ((p = a.parent) == null) { + a.quietlyComplete(); + break; + } + a = p; + } + } break; } } @@ -5361,6 +5405,7 @@ public class ConcurrentHashMapV8 public final U getRawResult() { return result.get(); } } + @SuppressWarnings("serial") static final class SearchMappingsTask extends BulkTask { final BiFun searchFunction; @@ -5379,7 +5424,7 @@ public class ConcurrentHashMapV8 super(p, b, split); this.searchFunction = searchFunction; this.result = result; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { AtomicReference result = this.result; final BiFun searchFunction = this.searchFunction; @@ -5394,7 +5439,15 @@ public class ConcurrentHashMapV8 Object v; U u; while (result.get() == null && (v = advance()) != null) { if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) { - result.compareAndSet(null, u); + if (result.compareAndSet(null, u)) { + for (BulkTask a = this, p;;) { + if ((p = a.parent) == null) { + a.quietlyComplete(); + break; + } + a = p; + } + } break; } } @@ -5403,6 +5456,7 @@ public class ConcurrentHashMapV8 public final U getRawResult() { return result.get(); } } + @SuppressWarnings("serial") static final class ReduceKeysTask extends BulkTask { final BiFun reducer; @@ -5421,7 +5475,7 @@ public class ConcurrentHashMapV8 this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { ReduceKeysTask t = this; final BiFun reducer = this.reducer; @@ -5465,6 +5519,7 @@ public class ConcurrentHashMapV8 public final K getRawResult() { return result; } } + @SuppressWarnings("serial") static final class ReduceValuesTask extends BulkTask { final BiFun reducer; @@ -5483,7 +5538,7 @@ public class ConcurrentHashMapV8 this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { ReduceValuesTask t = this; final BiFun reducer = this.reducer; @@ -5528,6 +5583,7 @@ public class ConcurrentHashMapV8 public final V getRawResult() { return result; } } + @SuppressWarnings("serial") static final class ReduceEntriesTask extends BulkTask> { final BiFun, Map.Entry, ? extends Map.Entry> reducer; @@ -5546,7 +5602,7 @@ public class ConcurrentHashMapV8 this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { ReduceEntriesTask t = this; final BiFun, Map.Entry, ? extends Map.Entry> reducer = this.reducer; @@ -5592,6 +5648,7 @@ public class ConcurrentHashMapV8 public final Map.Entry getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceKeysTask extends BulkTask { final Fun transformer; @@ -5614,7 +5671,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceKeysTask t = this; final Fun transformer = this.transformer; @@ -5660,6 +5717,7 @@ public class ConcurrentHashMapV8 public final U getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceValuesTask extends BulkTask { final Fun transformer; @@ -5682,7 +5740,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceValuesTask t = this; final Fun transformer = this.transformer; @@ -5729,6 +5787,7 @@ public class ConcurrentHashMapV8 public final U getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceEntriesTask extends BulkTask { final Fun, ? extends U> transformer; @@ -5751,7 +5810,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceEntriesTask t = this; final Fun, ? extends U> transformer = this.transformer; @@ -5798,6 +5857,7 @@ public class ConcurrentHashMapV8 public final U getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceMappingsTask extends BulkTask { final BiFun transformer; @@ -5820,7 +5880,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceMappingsTask t = this; final BiFun transformer = this.transformer; @@ -5866,6 +5926,7 @@ public class ConcurrentHashMapV8 public final U getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceKeysToDoubleTask extends BulkTask { final ObjectToDouble transformer; @@ -5891,7 +5952,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceKeysToDoubleTask t = this; final ObjectToDouble transformer = this.transformer; @@ -5935,6 +5996,7 @@ public class ConcurrentHashMapV8 public final Double getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceValuesToDoubleTask extends BulkTask { final ObjectToDouble transformer; @@ -5960,7 +6022,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceValuesToDoubleTask t = this; final ObjectToDouble transformer = this.transformer; @@ -6005,6 +6067,7 @@ public class ConcurrentHashMapV8 public final Double getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceEntriesToDoubleTask extends BulkTask { final ObjectToDouble> transformer; @@ -6030,7 +6093,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceEntriesToDoubleTask t = this; final ObjectToDouble> transformer = this.transformer; @@ -6075,6 +6138,7 @@ public class ConcurrentHashMapV8 public final Double getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceMappingsToDoubleTask extends BulkTask { final ObjectByObjectToDouble transformer; @@ -6100,7 +6164,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceMappingsToDoubleTask t = this; final ObjectByObjectToDouble transformer = this.transformer; @@ -6145,6 +6209,7 @@ public class ConcurrentHashMapV8 public final Double getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceKeysToLongTask extends BulkTask { final ObjectToLong transformer; @@ -6170,7 +6235,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceKeysToLongTask t = this; final ObjectToLong transformer = this.transformer; @@ -6214,6 +6279,7 @@ public class ConcurrentHashMapV8 public final Long getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceValuesToLongTask extends BulkTask { final ObjectToLong transformer; @@ -6239,7 +6305,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceValuesToLongTask t = this; final ObjectToLong transformer = this.transformer; @@ -6284,6 +6350,7 @@ public class ConcurrentHashMapV8 public final Long getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceEntriesToLongTask extends BulkTask { final ObjectToLong> transformer; @@ -6309,7 +6376,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceEntriesToLongTask t = this; final ObjectToLong> transformer = this.transformer; @@ -6354,6 +6421,7 @@ public class ConcurrentHashMapV8 public final Long getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceMappingsToLongTask extends BulkTask { final ObjectByObjectToLong transformer; @@ -6379,7 +6447,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceMappingsToLongTask t = this; final ObjectByObjectToLong transformer = this.transformer; @@ -6424,6 +6492,7 @@ public class ConcurrentHashMapV8 public final Long getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceKeysToIntTask extends BulkTask { final ObjectToInt transformer; @@ -6449,7 +6518,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceKeysToIntTask t = this; final ObjectToInt transformer = this.transformer; @@ -6493,6 +6562,7 @@ public class ConcurrentHashMapV8 public final Integer getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceValuesToIntTask extends BulkTask { final ObjectToInt transformer; @@ -6518,7 +6588,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceValuesToIntTask t = this; final ObjectToInt transformer = this.transformer; @@ -6563,6 +6633,7 @@ public class ConcurrentHashMapV8 public final Integer getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceEntriesToIntTask extends BulkTask { final ObjectToInt> transformer; @@ -6588,7 +6659,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceEntriesToIntTask t = this; final ObjectToInt> transformer = this.transformer; @@ -6633,6 +6704,7 @@ public class ConcurrentHashMapV8 public final Integer getRawResult() { return result; } } + @SuppressWarnings("serial") static final class MapReduceMappingsToIntTask extends BulkTask { final ObjectByObjectToInt transformer; @@ -6658,7 +6730,7 @@ public class ConcurrentHashMapV8 this.transformer = transformer; this.basis = basis; this.reducer = reducer; } - public final void compute() { + @SuppressWarnings("unchecked") public final void compute() { MapReduceMappingsToIntTask t = this; final ObjectByObjectToInt transformer = this.transformer;