--- jsr166/src/jsr166e/extra/AtomicDouble.java 2011/10/25 20:21:25 1.12 +++ jsr166/src/jsr166e/extra/AtomicDouble.java 2013/02/11 06:29:57 1.15 @@ -29,7 +29,7 @@ import static java.lang.Double.longBitsT * long xBits = Double.doubleToRawLongBits(x); * long yBits = Double.doubleToRawLongBits(y); * return xBits == yBits; - * }} + * }} * * @see jsr166e.DoubleAdder * @see jsr166e.DoubleMaxUpdater @@ -216,7 +216,7 @@ public class AtomicDouble extends Number * @serialData The current value is emitted (a {@code double}). */ private void writeObject(java.io.ObjectOutputStream s) - throws java.io.IOException{ + throws java.io.IOException { s.defaultWriteObject(); s.writeDouble(get()); @@ -253,21 +253,23 @@ public class AtomicDouble extends Number 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()); } } }