--- jsr166/src/jsr166e/ForkJoinPool.java 2013/01/01 15:10:32 1.40 +++ jsr166/src/jsr166e/ForkJoinPool.java 2013/01/09 02:51:36 1.45 @@ -1932,7 +1932,6 @@ public class ForkJoinPool extends Abstra * @param task the task to join * @param mode if shared, exit upon completing any task * if all workers are active - * */ private int helpComplete(ForkJoinTask task, int mode) { WorkQueue[] ws; WorkQueue q; int m, n, s, u; @@ -2556,10 +2555,11 @@ public class ForkJoinPool extends Abstra * ongoing processing are automatically terminated upon program * {@link System#exit}. Any program that relies on asynchronous * task processing to complete before program termination should - * invoke {@link #quiesceCommonPool}, or the timeout-based {@code - * commonPool().}{@link #awaitQuiescence}, before exit. + * invoke {@code commonPool().}{@link #awaitQuiescence}, before + * exit. * * @return the common pool instance + * @since 1.8 */ public static ForkJoinPool commonPool() { // assert common != null : "static init error"; @@ -2742,6 +2742,7 @@ public class ForkJoinPool extends Abstra * Returns the targeted parallelism level of the common pool. * * @return the targeted parallelism level of the common pool + * @since 1.8 */ public static int getCommonPoolParallelism() { return commonParallelism; @@ -3002,7 +3003,7 @@ public class ForkJoinPool extends Abstra * Possibly initiates an orderly shutdown in which previously * submitted tasks are executed, but no new tasks will be * accepted. Invocation has no effect on execution state if this - * is the {@link #commonPool}, and no additional effect if + * is the {@link #commonPool()}, and no additional effect if * already shut down. Tasks that are in the process of being * submitted concurrently during the course of this method may or * may not be rejected. @@ -3020,7 +3021,7 @@ public class ForkJoinPool extends Abstra /** * Possibly attempts to cancel and/or stop all tasks, and reject * all subsequently submitted tasks. Invocation has no effect on - * execution state if this is the {@link #commonPool}, and no + * execution state if this is the {@link #commonPool()}, and no * additional effect if already shut down. Otherwise, tasks that * are in the process of being submitted or executed concurrently * during the course of this method may or may not be @@ -3172,7 +3173,7 @@ public class ForkJoinPool extends Abstra * Waits and/or attempts to assist performing tasks indefinitely * until the {@link #commonPool()} {@link #isQuiescent} */ - public static void quiesceCommonPool() { + static void quiesceCommonPool() { common.awaitQuiescence(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } @@ -3409,22 +3410,23 @@ public class ForkJoinPool extends Abstra 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()); } } - }