--- jsr166/src/jsr166e/ConcurrentHashMapV8.java 2013/01/02 07:43:49 1.85 +++ jsr166/src/jsr166e/ConcurrentHashMapV8.java 2013/01/22 20:17:55 1.90 @@ -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; } } @@ -4577,7 +4579,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 +4595,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"; @@ -6804,7 +6806,6 @@ public class ConcurrentHashMapV8 private static final int ASHIFT; static { - int ss; try { U = getUnsafe(); Class k = ConcurrentHashMapV8.class; @@ -6823,13 +6824,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 +6843,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()); } } }