--- jsr166/src/jsr166e/ConcurrentHashMapV8.java 2013/01/02 07:43:49 1.85 +++ jsr166/src/jsr166e/ConcurrentHashMapV8.java 2013/02/11 20:52:00 1.98 @@ -567,7 +567,7 @@ public class ConcurrentHashMapV8 static final int SEED_INCREMENT = 0x61c88647; /** - * Per-thread counter hash codes. Shared across all instances + * Per-thread counter hash codes. Shared across all instances. */ static final ThreadLocal threadCounterHashCode = new ThreadLocal(); @@ -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. */ @@ -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 */ @@ -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,7 +4578,7 @@ public class ConcurrentHashMapV8 /** * Base class for views. */ - static abstract class CHMView { + abstract static class CHMView { final ConcurrentHashMapV8 map; CHMView(ConcurrentHashMapV8 map) { this.map = map; } @@ -4593,9 +4594,9 @@ public class ConcurrentHashMapV8 public final void clear() { map.clear(); } // implementations below rely on concrete classes supplying these - abstract public Iterator iterator(); - abstract public boolean contains(Object o); - abstract public boolean remove(Object o); + public abstract Iterator iterator(); + public abstract boolean contains(Object o); + public abstract boolean remove(Object o); private static final String oomeMsg = "Required array size too large"; @@ -4714,7 +4715,7 @@ 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 @@ -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}, @@ -4833,7 +4830,7 @@ 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> { @@ -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"); } /** @@ -6842,21 +6834,23 @@ public class ConcurrentHashMapV8 private static sun.misc.Unsafe getUnsafe() { try { return sun.misc.Unsafe.getUnsafe(); - } catch (SecurityException se) { - try { - return java.security.AccessController.doPrivileged - (new java.security - .PrivilegedExceptionAction() { - public sun.misc.Unsafe run() throws Exception { - java.lang.reflect.Field f = sun.misc - .Unsafe.class.getDeclaredField("theUnsafe"); - f.setAccessible(true); - return (sun.misc.Unsafe) f.get(null); - }}); - } catch (java.security.PrivilegedActionException e) { - throw new RuntimeException("Could not initialize intrinsics", - e.getCause()); - } + } catch (SecurityException tryReflectionInstead) {} + try { + return java.security.AccessController.doPrivileged + (new java.security.PrivilegedExceptionAction() { + public sun.misc.Unsafe run() throws Exception { + Class k = sun.misc.Unsafe.class; + for (java.lang.reflect.Field f : k.getDeclaredFields()) { + f.setAccessible(true); + Object x = f.get(null); + if (k.isInstance(x)) + return k.cast(x); + } + throw new NoSuchFieldError("the Unsafe"); + }}); + } catch (java.security.PrivilegedActionException e) { + throw new RuntimeException("Could not initialize intrinsics", + e.getCause()); } } }