--- jsr166/src/jsr166y/CountedCompleter.java 2012/11/26 14:11:53 1.27 +++ jsr166/src/jsr166y/CountedCompleter.java 2013/01/10 07:54:22 1.30 @@ -224,7 +224,7 @@ package jsr166y; * public static E search(E[] array) { * return new Searcher(null, array, new AtomicReference(), 0, array.length).invoke(); * } - *}} + * }} * * In this example, as well as others in which tasks have no other * effects except to compareAndSet a common result, the trailing @@ -704,7 +704,7 @@ public abstract class CountedCompleter() { - 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()); } } }