--- jsr166/src/jsr166e/ConcurrentHashMapV8.java 2012/12/15 20:21:25 1.84 +++ jsr166/src/jsr166e/ConcurrentHashMapV8.java 2013/01/09 02:51:36 1.87 @@ -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(); @@ -3730,7 +3730,6 @@ public class ConcurrentHashMapV8 * result on success, else null * @return a non-null result from applying the given search * function on each value, or null if none - * */ public U searchValuesSequentially (Fun searchFunction) { @@ -4337,7 +4336,6 @@ public class ConcurrentHashMapV8 * result on success, else null * @return a non-null result from applying the given search * function on each value, or null if none - * */ public U searchValuesInParallel (Fun searchFunction) { @@ -6844,21 +6842,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()); } } }