ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/ForkJoinPool.java
(Generate patch)

Comparing jsr166/src/jsr166y/ForkJoinPool.java (file contents):
Revision 1.169 by jsr166, Wed Jan 2 07:43:50 2013 UTC vs.
Revision 1.175 by jsr166, Sat Jan 19 20:39:43 2013 UTC

# Line 1026 | Line 1026 | public class ForkJoinPool extends Abstra
1026          private static final int ABASE;
1027          private static final int ASHIFT;
1028          static {
1029            int s;
1029              try {
1030                  U = getUnsafe();
1031                  Class<?> k = WorkQueue.class;
# Line 1034 | Line 1033 | public class ForkJoinPool extends Abstra
1033                  QLOCK = U.objectFieldOffset
1034                      (k.getDeclaredField("qlock"));
1035                  ABASE = U.arrayBaseOffset(ak);
1036 <                s = U.arrayIndexScale(ak);
1036 >                int scale = U.arrayIndexScale(ak);
1037 >                if ((scale & (scale - 1)) != 0)
1038 >                    throw new Error("data type scale not a power of two");
1039 >                ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
1040              } catch (Exception e) {
1041                  throw new Error(e);
1042              }
1041            if ((s & (s-1)) != 0)
1042                throw new Error("data type scale not a power of two");
1043            ASHIFT = 31 - Integer.numberOfLeadingZeros(s);
1043          }
1044      }
1045  
# Line 1248 | Line 1247 | public class ForkJoinPool extends Abstra
1247      /*
1248       * Acquires the plock lock to protect worker array and related
1249       * updates. This method is called only if an initial CAS on plock
1250 <     * fails. This acts as a spinLock for normal cases, but falls back
1250 >     * fails. This acts as a spinlock for normal cases, but falls back
1251       * to builtin monitor to block when (rarely) needed. This would be
1252       * a terrible idea for a highly contended lock, but works fine as
1253       * a more conservative alternative to a pure spinlock.
# Line 2555 | Line 2554 | public class ForkJoinPool extends Abstra
2554       * ongoing processing are automatically terminated upon program
2555       * {@link System#exit}.  Any program that relies on asynchronous
2556       * task processing to complete before program termination should
2557 <     * invoke {@link #quiesceCommonPool}, or the timeout-based {@code
2558 <     * commonPool().}{@link #awaitQuiescence}, before exit.
2557 >     * invoke {@code commonPool().}{@link #awaitQuiescence}, before
2558 >     * exit.
2559       *
2560       * @return the common pool instance
2561 +     * @since 1.8
2562       */
2563      public static ForkJoinPool commonPool() {
2564          // assert common != null : "static init error";
# Line 2741 | Line 2741 | public class ForkJoinPool extends Abstra
2741       * Returns the targeted parallelism level of the common pool.
2742       *
2743       * @return the targeted parallelism level of the common pool
2744 +     * @since 1.8
2745       */
2746      public static int getCommonPoolParallelism() {
2747          return commonParallelism;
# Line 3001 | Line 3002 | public class ForkJoinPool extends Abstra
3002       * Possibly initiates an orderly shutdown in which previously
3003       * submitted tasks are executed, but no new tasks will be
3004       * accepted. Invocation has no effect on execution state if this
3005 <     * is the {@link #commonPool}, and no additional effect if
3005 >     * is the {@link #commonPool()}, and no additional effect if
3006       * already shut down.  Tasks that are in the process of being
3007       * submitted concurrently during the course of this method may or
3008       * may not be rejected.
# Line 3019 | Line 3020 | public class ForkJoinPool extends Abstra
3020      /**
3021       * Possibly attempts to cancel and/or stop all tasks, and reject
3022       * all subsequently submitted tasks.  Invocation has no effect on
3023 <     * execution state if this is the {@link #commonPool}, and no
3023 >     * execution state if this is the {@link #commonPool()}, and no
3024       * additional effect if already shut down. Otherwise, tasks that
3025       * are in the process of being submitted or executed concurrently
3026       * during the course of this method may or may not be
# Line 3171 | Line 3172 | public class ForkJoinPool extends Abstra
3172       * Waits and/or attempts to assist performing tasks indefinitely
3173       * until the {@link #commonPool()} {@link #isQuiescent}
3174       */
3175 <    public static void quiesceCommonPool() {
3175 >    static void quiesceCommonPool() {
3176          common.awaitQuiescence(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
3177      }
3178  
# Line 3328 | Line 3329 | public class ForkJoinPool extends Abstra
3329      private static final long QLOCK;
3330  
3331      static {
3332 <        int s; // initialize field offsets for CAS etc
3332 >        // initialize field offsets for CAS etc
3333          try {
3334              U = getUnsafe();
3335              Class<?> k = ForkJoinPool.class;
# Line 3348 | Line 3349 | public class ForkJoinPool extends Abstra
3349                  (wk.getDeclaredField("qlock"));
3350              Class<?> ak = ForkJoinTask[].class;
3351              ABASE = U.arrayBaseOffset(ak);
3352 <            s = U.arrayIndexScale(ak);
3353 <            ASHIFT = 31 - Integer.numberOfLeadingZeros(s);
3352 >            int scale = U.arrayIndexScale(ak);
3353 >            if ((scale & (scale - 1)) != 0)
3354 >                throw new Error("data type scale not a power of two");
3355 >            ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
3356          } catch (Exception e) {
3357              throw new Error(e);
3358          }
3356        if ((s & (s-1)) != 0)
3357            throw new Error("data type scale not a power of two");
3359  
3360          submitters = new ThreadLocal<Submitter>();
3361          ForkJoinWorkerThreadFactory fac = defaultForkJoinWorkerThreadFactory =
# Line 3408 | Line 3409 | public class ForkJoinPool extends Abstra
3409      private static sun.misc.Unsafe getUnsafe() {
3410          try {
3411              return sun.misc.Unsafe.getUnsafe();
3412 <        } catch (SecurityException se) {
3413 <            try {
3414 <                return java.security.AccessController.doPrivileged
3415 <                    (new java.security
3416 <                     .PrivilegedExceptionAction<sun.misc.Unsafe>() {
3417 <                        public sun.misc.Unsafe run() throws Exception {
3418 <                            java.lang.reflect.Field f = sun.misc
3419 <                                .Unsafe.class.getDeclaredField("theUnsafe");
3420 <                            f.setAccessible(true);
3421 <                            return (sun.misc.Unsafe) f.get(null);
3422 <                        }});
3423 <            } catch (java.security.PrivilegedActionException e) {
3424 <                throw new RuntimeException("Could not initialize intrinsics",
3425 <                                           e.getCause());
3426 <            }
3412 >        } catch (SecurityException tryReflectionInstead) {}
3413 >        try {
3414 >            return java.security.AccessController.doPrivileged
3415 >            (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
3416 >                public sun.misc.Unsafe run() throws Exception {
3417 >                    Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
3418 >                    for (java.lang.reflect.Field f : k.getDeclaredFields()) {
3419 >                        f.setAccessible(true);
3420 >                        Object x = f.get(null);
3421 >                        if (k.isInstance(x))
3422 >                            return k.cast(x);
3423 >                    }
3424 >                    throw new NoSuchFieldError("the Unsafe");
3425 >                }});
3426 >        } catch (java.security.PrivilegedActionException e) {
3427 >            throw new RuntimeException("Could not initialize intrinsics",
3428 >                                       e.getCause());
3429          }
3430      }
3428
3431   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines