--- jsr166/src/jsr166e/ConcurrentHashMapV8.java 2013/01/18 04:23:27 1.88 +++ jsr166/src/jsr166e/ConcurrentHashMapV8.java 2013/02/18 03:15:10 1.100 @@ -212,8 +212,8 @@ import java.io.Serializable; * @param the type of keys maintained by this map * @param the type of mapped values */ -public class ConcurrentHashMapV8 - implements ConcurrentMap, Serializable { +public class ConcurrentHashMapV8 + implements ConcurrentMap, Serializable { private static final long serialVersionUID = 7249069246763182397L; /** @@ -1785,8 +1785,10 @@ public class ConcurrentHashMapV8 } } if (len != 0) { - if (len > 1) + if (len > 1) { addCount(delta, len); + delta = 0L; + } break; } } @@ -1975,7 +1977,7 @@ public class ConcurrentHashMapV8 } } - /* + /** * Moves and/or copies the nodes in each bin to new table. See * above for explanation. */ @@ -2277,7 +2279,7 @@ public class ConcurrentHashMapV8 */ @SuppressWarnings("serial") static class Traverser extends CountedCompleter { - final ConcurrentHashMapV8 map; + final ConcurrentHashMapV8 map; Node next; // the next entry to use Object nextKey; // cached key field of next V nextVal; // cached val field of next @@ -2289,7 +2291,7 @@ public class ConcurrentHashMapV8 int batch; // split control /** Creates iterator for all entries in the table. */ - Traverser(ConcurrentHashMapV8 map) { + Traverser(ConcurrentHashMapV8 map) { this.map = map; } @@ -2321,7 +2323,7 @@ public class ConcurrentHashMapV8 if (e != null) // advance past used/skipped node e = e.next; while (e == null) { // get to next non-null bin - ConcurrentHashMapV8 m; + ConcurrentHashMapV8 m; Node[] t; int b, i, n; Object ek; // must use locals if ((t = tab) != null) n = t.length; @@ -2374,7 +2376,7 @@ public class ConcurrentHashMapV8 * anyway. */ final int preSplit() { - ConcurrentHashMapV8 m; int b; Node[] t; ForkJoinPool pool; + ConcurrentHashMapV8 m; int b; Node[] t; ForkJoinPool pool; if ((b = batch) < 0 && (m = map) != null) { // force initialization if ((t = tab) == null && (t = tab = m.table) != null) baseLimit = baseSize = t.length; @@ -2571,7 +2573,7 @@ public class ConcurrentHashMapV8 /** * Tests if the specified object is a key in this table. * - * @param key possible key + * @param key possible key * @return {@code true} if and only if the specified object * is a key in this table, as determined by the * {@code equals} method; {@code false} otherwise @@ -2685,7 +2687,7 @@ public class ConcurrentHashMapV8 * memoized result, as in: * *
 {@code
-     * map.computeIfAbsent(key, new Fun() {
+     * map.computeIfAbsent(key, new Fun() {
      *   public V map(K k) { return new Value(f(k)); }});}
* * @param key key with which the specified value is to be associated @@ -2892,8 +2894,7 @@ public class ConcurrentHashMapV8 * course only appropriate if it is acceptable to use the same * value for all additions from this view. * - * @param mappedValue the mapped value to use for any - * additions. + * @param mappedValue the mapped value to use for any additions * @return the set view * @throws NullPointerException if the mappedValue is null */ @@ -3067,8 +3068,8 @@ public class ConcurrentHashMapV8 @SuppressWarnings("serial") static final class KeyIterator extends Traverser implements Spliterator, Enumeration { - KeyIterator(ConcurrentHashMapV8 map) { super(map); } - KeyIterator(ConcurrentHashMapV8 map, Traverser it) { + KeyIterator(ConcurrentHashMapV8 map) { super(map); } + KeyIterator(ConcurrentHashMapV8 map, Traverser it) { super(map, it, -1); } public KeyIterator split() { @@ -3090,8 +3091,8 @@ public class ConcurrentHashMapV8 @SuppressWarnings("serial") static final class ValueIterator extends Traverser implements Spliterator, Enumeration { - ValueIterator(ConcurrentHashMapV8 map) { super(map); } - ValueIterator(ConcurrentHashMapV8 map, Traverser it) { + ValueIterator(ConcurrentHashMapV8 map) { super(map); } + ValueIterator(ConcurrentHashMapV8 map, Traverser it) { super(map, it, -1); } public ValueIterator split() { @@ -3114,8 +3115,8 @@ public class ConcurrentHashMapV8 @SuppressWarnings("serial") static final class EntryIterator extends Traverser implements Spliterator> { - EntryIterator(ConcurrentHashMapV8 map) { super(map); } - EntryIterator(ConcurrentHashMapV8 map, Traverser it) { + EntryIterator(ConcurrentHashMapV8 map) { super(map); } + EntryIterator(ConcurrentHashMapV8 map, Traverser it) { super(map, it, -1); } public EntryIterator split() { @@ -3137,11 +3138,11 @@ public class ConcurrentHashMapV8 /** * Exported Entry for iterators */ - static final class MapEntry implements Map.Entry { + static final class MapEntry implements Map.Entry { final K key; // non-null V val; // non-null - final ConcurrentHashMapV8 map; - MapEntry(K key, V val, ConcurrentHashMapV8 map) { + final ConcurrentHashMapV8 map; + MapEntry(K key, V val, ConcurrentHashMapV8 map) { this.key = key; this.val = val; this.map = map; @@ -3371,8 +3372,8 @@ public class ConcurrentHashMapV8 * of each (key, 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). + * for an element, or null if there is no transformation (in + * which case the action is not applied) * @param action the action */ @SuppressWarnings("unchecked") public void forEachSequentially @@ -3415,8 +3416,8 @@ public class ConcurrentHashMapV8 * combine values, or null if none. * * @param transformer a function returning the transformation - * for an element, or null of there is no transformation (in - * which case it is not combined). + * for an element, or null if there is no transformation (in + * which case it is not combined) * @param reducer a commutative associative combining function * @return the result of accumulating the given transformation * of all (key, value) pairs @@ -3528,8 +3529,8 @@ public class ConcurrentHashMapV8 * 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). + * for an element, or null if there is no transformation (in + * which case the action is not applied) * @param action the action */ @SuppressWarnings("unchecked") public void forEachKeySequentially @@ -3593,8 +3594,8 @@ public class ConcurrentHashMapV8 * null if none. * * @param transformer a function returning the transformation - * for an element, or null of there is no transformation (in - * which case it is not combined). + * for an element, or null if there is no transformation (in + * which case it is not combined) * @param reducer a commutative associative combining function * @return the result of accumulating the given transformation * of all keys @@ -3706,8 +3707,8 @@ public class ConcurrentHashMapV8 * 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). + * for an element, or null if there is no transformation (in + * which case the action is not applied) */ public void forEachValueSequentially (Fun transformer, @@ -3766,8 +3767,8 @@ public class ConcurrentHashMapV8 * null if none. * * @param transformer a function returning the transformation - * for an element, or null of there is no transformation (in - * which case it is not combined). + * for an element, or null if there is no transformation (in + * which case it is not combined) * @param reducer a commutative associative combining function * @return the result of accumulating the given transformation * of all values @@ -3880,8 +3881,8 @@ public class ConcurrentHashMapV8 * 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). + * for an element, or null if there is no transformation (in + * which case the action is not applied) * @param action the action */ @SuppressWarnings("unchecked") public void forEachEntrySequentially @@ -3943,8 +3944,8 @@ public class ConcurrentHashMapV8 * or null if none. * * @param transformer a function returning the transformation - * for an element, or null of there is no transformation (in - * which case it is not combined). + * for an element, or null if there is no transformation (in + * which case it is not combined) * @param reducer a commutative associative combining function * @return the result of accumulating the given transformation * of all entries @@ -4055,8 +4056,8 @@ public class ConcurrentHashMapV8 * of each (key, 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). + * for an element, or null if there is no transformation (in + * which case the action is not applied) * @param action the action */ public void forEachInParallel @@ -4090,8 +4091,8 @@ public class ConcurrentHashMapV8 * combine values, or null if none. * * @param transformer a function returning the transformation - * for an element, or null of there is no transformation (in - * which case it is not combined). + * for an element, or null if there is no transformation (in + * which case it is not combined) * @param reducer a commutative associative combining function * @return the result of accumulating the given transformation * of all (key, value) pairs @@ -4178,8 +4179,8 @@ public class ConcurrentHashMapV8 * 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). + * for an element, or null if there is no transformation (in + * which case the action is not applied) * @param action the action */ public void forEachKeyInParallel @@ -4227,8 +4228,8 @@ public class ConcurrentHashMapV8 * null if none. * * @param transformer a function returning the transformation - * for an element, or null of there is no transformation (in - * which case it is not combined). + * for an element, or null if there is no transformation (in + * which case it is not combined) * @param reducer a commutative associative combining function * @return the result of accumulating the given transformation * of all keys @@ -4315,8 +4316,8 @@ public class ConcurrentHashMapV8 * 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). + * for an element, or null if there is no transformation (in + * which case the action is not applied) */ public void forEachValueInParallel (Fun transformer, @@ -4362,8 +4363,8 @@ public class ConcurrentHashMapV8 * null if none. * * @param transformer a function returning the transformation - * for an element, or null of there is no transformation (in - * which case it is not combined). + * for an element, or null if there is no transformation (in + * which case it is not combined) * @param reducer a commutative associative combining function * @return the result of accumulating the given transformation * of all values @@ -4450,8 +4451,8 @@ public class ConcurrentHashMapV8 * 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). + * for an element, or null if there is no transformation (in + * which case the action is not applied) * @param action the action */ public void forEachEntryInParallel @@ -4498,8 +4499,8 @@ public class ConcurrentHashMapV8 * or null if none. * * @param transformer a function returning the transformation - * for an element, or null of there is no transformation (in - * which case it is not combined). + * for an element, or null if there is no transformation (in + * which case it is not combined) * @param reducer a commutative associative combining function * @return the result of accumulating the given transformation * of all entries @@ -4577,9 +4578,9 @@ public class ConcurrentHashMapV8 /** * Base class for views. */ - abstract static class CHMView { - final ConcurrentHashMapV8 map; - CHMView(ConcurrentHashMapV8 map) { this.map = map; } + abstract static class CHMView { + final ConcurrentHashMapV8 map; + CHMView(ConcurrentHashMapV8 map) { this.map = map; } /** * Returns the map backing this view. @@ -4714,14 +4715,14 @@ public class ConcurrentHashMapV8 * A view of a ConcurrentHashMapV8 as a {@link Set} of keys, in * which additions may optionally be enabled by mapping to a * common value. This class cannot be directly instantiated. See - * {@link #keySet}, {@link #keySet(Object)}, {@link #newKeySet()}, + * {@link #keySet()}, {@link #keySet(Object)}, {@link #newKeySet()}, * {@link #newKeySet(int)}. */ public static class KeySetView extends CHMView implements Set, java.io.Serializable { private static final long serialVersionUID = 7249069246763182397L; private final V value; - KeySetView(ConcurrentHashMapV8 map, V value) { // non-public + KeySetView(ConcurrentHashMapV8 map, V value) { // non-public super(map); this.value = value; } @@ -4731,7 +4732,7 @@ public class ConcurrentHashMapV8 * or {@code null} if additions are not supported. * * @return the default mapped value for additions, or {@code null} - * if not supported. + * if not supported */ public V getMappedValue() { return value; } @@ -4755,8 +4756,6 @@ public class ConcurrentHashMapV8 V v; if ((v = value) == null) throw new UnsupportedOperationException(); - if (e == null) - throw new NullPointerException(); return map.internalPut(e, v, true) == null; } public boolean addAll(Collection c) { @@ -4765,8 +4764,6 @@ public class ConcurrentHashMapV8 if ((v = value) == null) throw new UnsupportedOperationException(); for (K e : c) { - if (e == null) - throw new NullPointerException(); if (map.internalPut(e, v, true) == null) added = true; } @@ -4783,7 +4780,7 @@ public class ConcurrentHashMapV8 /** * A view of a ConcurrentHashMapV8 as a {@link Collection} of * values, in which additions are disabled. This class cannot be - * directly instantiated. See {@link #values}, + * directly instantiated. See {@link #values()}. * *

The view's {@code iterator} is a "weakly consistent" iterator * that will never throw {@link ConcurrentModificationException}, @@ -4793,7 +4790,7 @@ public class ConcurrentHashMapV8 */ public static final class ValuesView extends CHMView implements Collection { - ValuesView(ConcurrentHashMapV8 map) { super(map); } + ValuesView(ConcurrentHashMapV8 map) { super(map); } public final boolean contains(Object o) { return map.containsValue(o); } public final boolean remove(Object o) { if (o != null) { @@ -4833,11 +4830,11 @@ public class ConcurrentHashMapV8 /** * A view of a ConcurrentHashMapV8 as a {@link Set} of (key, value) * entries. This class cannot be directly instantiated. See - * {@link #entrySet}. + * {@link #entrySet()}. */ public static final class EntrySetView extends CHMView implements Set> { - EntrySetView(ConcurrentHashMapV8 map) { super(map); } + EntrySetView(ConcurrentHashMapV8 map) { super(map); } public final boolean contains(Object o) { Object k, v, r; Map.Entry e; return ((o instanceof Map.Entry) && @@ -4869,11 +4866,7 @@ public class ConcurrentHashMapV8 } public final boolean add(Entry e) { - K key = e.getKey(); - V value = e.getValue(); - if (key == null || value == null) - throw new NullPointerException(); - return map.internalPut(key, value, false) == null; + return map.internalPut(e.getKey(), e.getValue(), false) == null; } public final boolean addAll(Collection> c) { boolean added = false; @@ -4970,7 +4963,7 @@ public class ConcurrentHashMapV8 * @param map the map * @param transformer a function returning the transformation * for an element, or null if there is no transformation (in - * which case it is not combined). + * which case it is not combined) * @param reducer a commutative associative combining function * @return the task */ @@ -5137,7 +5130,7 @@ public class ConcurrentHashMapV8 * @param map the map * @param transformer a function returning the transformation * for an element, or null if there is no transformation (in - * which case it is not combined). + * which case it is not combined) * @param reducer a commutative associative combining function * @return the task */ @@ -5303,7 +5296,7 @@ public class ConcurrentHashMapV8 * @param map the map * @param transformer a function returning the transformation * for an element, or null if there is no transformation (in - * which case it is not combined). + * which case it is not combined) * @param reducer a commutative associative combining function * @return the task */ @@ -5469,7 +5462,7 @@ public class ConcurrentHashMapV8 * @param map the map * @param transformer a function returning the transformation * for an element, or null if there is no transformation (in - * which case it is not combined). + * which case it is not combined) * @param reducer a commutative associative combining function * @return the task */ @@ -6804,7 +6797,6 @@ public class ConcurrentHashMapV8 private static final int ASHIFT; static { - int ss; try { U = getUnsafe(); Class k = ConcurrentHashMapV8.class; @@ -6823,13 +6815,13 @@ public class ConcurrentHashMapV8 (ck.getDeclaredField("value")); Class sc = Node[].class; ABASE = U.arrayBaseOffset(sc); - ss = U.arrayIndexScale(sc); - ASHIFT = 31 - Integer.numberOfLeadingZeros(ss); + int scale = U.arrayIndexScale(sc); + if ((scale & (scale - 1)) != 0) + throw new Error("data type scale not a power of two"); + ASHIFT = 31 - Integer.numberOfLeadingZeros(scale); } catch (Exception e) { throw new Error(e); } - if ((ss & (ss-1)) != 0) - throw new Error("data type scale not a power of two"); } /**