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.15 by jsr166, Wed Jul 22 20:55:22 2009 UTC vs.
Revision 1.21 by jsr166, Fri Jul 24 23:47:01 2009 UTC

# Line 9 | Line 9 | import java.util.*;
9   import java.util.concurrent.*;
10   import java.util.concurrent.locks.*;
11   import java.util.concurrent.atomic.*;
12 import sun.misc.Unsafe;
13 import java.lang.reflect.*;
12  
13   /**
14   * An {@link ExecutorService} for running {@link ForkJoinTask}s.  A
# Line 28 | Line 26 | import java.lang.reflect.*;
26   * most tasks spawn other subtasks (as do most ForkJoinTasks), as well
27   * as the mixed execution of some plain Runnable- or Callable- based
28   * activities along with ForkJoinTasks. When setting
29 < * <tt>setAsyncMode</tt>, a ForkJoinPools may also be appropriate for
29 > * {@code setAsyncMode}, a ForkJoinPools may also be appropriate for
30   * use with fine-grained tasks that are never joined. Otherwise, other
31   * ExecutorService implementations are typically more appropriate
32   * choices.
# Line 38 | Line 36 | import java.lang.reflect.*;
36   * adding, suspending, or resuming threads, even if some tasks are
37   * waiting to join others. However, no such adjustments are performed
38   * in the face of blocked IO or other unmanaged synchronization. The
39 < * nested <code>ManagedBlocker</code> interface enables extension of
39 > * nested {@code ManagedBlocker} interface enables extension of
40   * the kinds of synchronization accommodated.  The target parallelism
41 < * level may also be changed dynamically (<code>setParallelism</code>)
41 > * level may also be changed dynamically ({@code setParallelism})
42   * and thread construction can be limited using methods
43 < * <code>setMaximumPoolSize</code> and/or
44 < * <code>setMaintainsParallelism</code>.
43 > * {@code setMaximumPoolSize} and/or
44 > * {@code setMaintainsParallelism}.
45   *
46   * <p>In addition to execution and lifecycle control methods, this
47   * class provides status check methods (for example
48 < * <code>getStealCount</code>) that are intended to aid in developing,
48 > * {@code getStealCount}) that are intended to aid in developing,
49   * tuning, and monitoring fork/join applications. Also, method
50 < * <code>toString</code> returns indications of pool state in a
50 > * {@code toString} returns indications of pool state in a
51   * convenient form for informal monitoring.
52   *
53   * <p><b>Implementation notes</b>: This implementation restricts the
54   * maximum number of running threads to 32767. Attempts to create
55   * pools with greater than the maximum result in
56   * IllegalArgumentExceptions.
57 + *
58 + * @since 1.7
59 + * @author Doug Lea
60   */
61   public class ForkJoinPool extends AbstractExecutorService {
62  
# Line 81 | Line 82 | public class ForkJoinPool extends Abstra
82           * Returns a new worker thread operating in the given pool.
83           *
84           * @param pool the pool this thread works in
85 <         * @throws NullPointerException if pool is null;
85 >         * @throws NullPointerException if pool is null
86           */
87          public ForkJoinWorkerThread newThread(ForkJoinPool pool);
88      }
89  
90      /**
91 <     * Default ForkJoinWorkerThreadFactory implementation, creates a
91 >     * Default ForkJoinWorkerThreadFactory implementation; creates a
92       * new ForkJoinWorkerThread.
93       */
94      static class  DefaultForkJoinWorkerThreadFactory
# Line 153 | Line 154 | public class ForkJoinPool extends Abstra
154  
155      /**
156       * The uncaught exception handler used when any worker
157 <     * abrupty terminates
157 >     * abruptly terminates
158       */
159      private Thread.UncaughtExceptionHandler ueh;
160  
# Line 181 | Line 182 | public class ForkJoinPool extends Abstra
182      private final LinkedTransferQueue<ForkJoinTask<?>> submissionQueue;
183  
184      /**
185 <     * Head of Treiber stack for barrier sync. See below for explanation
185 >     * Head of Treiber stack for barrier sync. See below for explanation.
186       */
187      private volatile WaitQueueNode syncStack;
188  
# Line 217 | Line 218 | public class ForkJoinPool extends Abstra
218       * making decisions about creating and suspending spare
219       * threads. Updated only by CAS.  Note: CASes in
220       * updateRunningCount and preJoin assume that running active count
221 <     * is in low word, so need to be modified if this changes
221 >     * is in low word, so need to be modified if this changes.
222       */
223      private volatile int workerCounts;
224  
# Line 226 | Line 227 | public class ForkJoinPool extends Abstra
227      private static int workerCountsFor(int t, int r) { return (t << 16) + r; }
228  
229      /**
230 <     * Add delta (which may be negative) to running count.  This must
230 >     * Adds delta (which may be negative) to running count.  This must
231       * be called before (with negative arg) and after (with positive)
232 <     * any managed synchronization (i.e., mainly, joins)
232 >     * any managed synchronization (i.e., mainly, joins).
233 >     *
234       * @param delta the number to add
235       */
236      final void updateRunningCount(int delta) {
237          int s;
238 <        do;while (!casWorkerCounts(s = workerCounts, s + delta));
238 >        do {} while (!casWorkerCounts(s = workerCounts, s + delta));
239      }
240  
241      /**
242 <     * Add delta (which may be negative) to both total and running
242 >     * Adds delta (which may be negative) to both total and running
243       * count.  This must be called upon creation and termination of
244       * worker threads.
245 +     *
246       * @param delta the number to add
247       */
248      private void updateWorkerCount(int delta) {
249          int d = delta + (delta << 16); // add to both lo and hi parts
250          int s;
251 <        do;while (!casWorkerCounts(s = workerCounts, s + d));
251 >        do {} while (!casWorkerCounts(s = workerCounts, s + d));
252      }
253  
254      /**
# Line 271 | Line 274 | public class ForkJoinPool extends Abstra
274      private static int runControlFor(int r, int a)   { return (r << 16) + a; }
275  
276      /**
277 <     * Try incrementing active count; fail on contention. Called by
278 <     * workers before/during executing tasks.
279 <     * @return true on success;
277 >     * Tries incrementing active count; fails on contention.
278 >     * Called by workers before/during executing tasks.
279 >     *
280 >     * @return true on success
281       */
282      final boolean tryIncrementActiveCount() {
283          int c = runControl;
# Line 281 | Line 285 | public class ForkJoinPool extends Abstra
285      }
286  
287      /**
288 <     * Try decrementing active count; fail on contention.
289 <     * Possibly trigger termination on success
288 >     * Tries decrementing active count; fails on contention.
289 >     * Possibly triggers termination on success.
290       * Called by workers when they can't find tasks.
291 +     *
292       * @return true on success
293       */
294      final boolean tryDecrementActiveCount() {
# Line 297 | Line 302 | public class ForkJoinPool extends Abstra
302      }
303  
304      /**
305 <     * Return true if argument represents zero active count and
305 >     * Returns true if argument represents zero active count and
306       * nonzero runstate, which is the triggering condition for
307       * terminating on shutdown.
308       */
309      private static boolean canTerminateOnShutdown(int c) {
310 <        return ((c & -c) >>> 16) != 0; // i.e. least bit is nonzero runState bit
310 >        // i.e. least bit is nonzero runState bit
311 >        return ((c & -c) >>> 16) != 0;
312      }
313  
314      /**
# Line 328 | Line 334 | public class ForkJoinPool extends Abstra
334  
335      /**
336       * Creates a ForkJoinPool with a pool size equal to the number of
337 <     * processors available on the system and using the default
338 <     * ForkJoinWorkerThreadFactory,
337 >     * processors available on the system, using the default
338 >     * ForkJoinWorkerThreadFactory.
339 >     *
340       * @throws SecurityException if a security manager exists and
341       *         the caller is not permitted to modify threads
342       *         because it does not hold {@link
343 <     *         java.lang.RuntimePermission}<code>("modifyThread")</code>,
343 >     *         java.lang.RuntimePermission}{@code ("modifyThread")}
344       */
345      public ForkJoinPool() {
346          this(Runtime.getRuntime().availableProcessors(),
# Line 341 | Line 348 | public class ForkJoinPool extends Abstra
348      }
349  
350      /**
351 <     * Creates a ForkJoinPool with the indicated parellelism level
352 <     * threads, and using the default ForkJoinWorkerThreadFactory,
351 >     * Creates a ForkJoinPool with the indicated parallelism level
352 >     * threads and using the default ForkJoinWorkerThreadFactory.
353 >     *
354       * @param parallelism the number of worker threads
355       * @throws IllegalArgumentException if parallelism less than or
356       * equal to zero
357       * @throws SecurityException if a security manager exists and
358       *         the caller is not permitted to modify threads
359       *         because it does not hold {@link
360 <     *         java.lang.RuntimePermission}<code>("modifyThread")</code>,
360 >     *         java.lang.RuntimePermission}{@code ("modifyThread")}
361       */
362      public ForkJoinPool(int parallelism) {
363          this(parallelism, defaultForkJoinWorkerThreadFactory);
# Line 358 | Line 366 | public class ForkJoinPool extends Abstra
366      /**
367       * Creates a ForkJoinPool with parallelism equal to the number of
368       * processors available on the system and using the given
369 <     * ForkJoinWorkerThreadFactory,
369 >     * ForkJoinWorkerThreadFactory.
370 >     *
371       * @param factory the factory for creating new threads
372       * @throws NullPointerException if factory is null
373       * @throws SecurityException if a security manager exists and
374       *         the caller is not permitted to modify threads
375       *         because it does not hold {@link
376 <     *         java.lang.RuntimePermission}<code>("modifyThread")</code>,
376 >     *         java.lang.RuntimePermission}{@code ("modifyThread")}
377       */
378      public ForkJoinPool(ForkJoinWorkerThreadFactory factory) {
379          this(Runtime.getRuntime().availableProcessors(), factory);
# Line 376 | Line 385 | public class ForkJoinPool extends Abstra
385       * @param parallelism the targeted number of worker threads
386       * @param factory the factory for creating new threads
387       * @throws IllegalArgumentException if parallelism less than or
388 <     * equal to zero, or greater than implementation limit.
388 >     * equal to zero, or greater than implementation limit
389       * @throws NullPointerException if factory is null
390       * @throws SecurityException if a security manager exists and
391       *         the caller is not permitted to modify threads
392       *         because it does not hold {@link
393 <     *         java.lang.RuntimePermission}<code>("modifyThread")</code>,
393 >     *         java.lang.RuntimePermission}{@code ("modifyThread")}
394       */
395      public ForkJoinPool(int parallelism, ForkJoinWorkerThreadFactory factory) {
396          if (parallelism <= 0 || parallelism > MAX_THREADS)
# Line 402 | Line 411 | public class ForkJoinPool extends Abstra
411      }
412  
413      /**
414 <     * Create new worker using factory.
414 >     * Creates a new worker thread using factory.
415 >     *
416       * @param index the index to assign worker
417       * @return new worker, or null of factory failed
418       */
# Line 421 | Line 431 | public class ForkJoinPool extends Abstra
431      }
432  
433      /**
434 <     * Return a good size for worker array given pool size.
434 >     * Returns a good size for worker array given pool size.
435       * Currently requires size to be a power of two.
436       */
437 <    private static int arraySizeFor(int ps) {
438 <        return ps <= 1? 1 : (1 << (32 - Integer.numberOfLeadingZeros(ps-1)));
437 >    private static int arraySizeFor(int poolSize) {
438 >        return (poolSize <= 1) ? 1 :
439 >            (1 << (32 - Integer.numberOfLeadingZeros(poolSize-1)));
440      }
441  
442      /**
443 <     * Create or resize array if necessary to hold newLength.
444 <     * Call only under exclusion
443 >     * Creates or resizes array if necessary to hold newLength.
444 >     * Call only under exclusion.
445 >     *
446       * @return the array
447       */
448      private ForkJoinWorkerThread[] ensureWorkerArrayCapacity(int newLength) {
# Line 444 | Line 456 | public class ForkJoinPool extends Abstra
456      }
457  
458      /**
459 <     * Try to shrink workers into smaller array after one or more terminate
459 >     * Tries to shrink workers into smaller array after one or more terminate.
460       */
461      private void tryShrinkWorkerArray() {
462          ForkJoinWorkerThread[] ws = workers;
# Line 460 | Line 472 | public class ForkJoinPool extends Abstra
472      }
473  
474      /**
475 <     * Initialize workers if necessary
475 >     * Initializes workers if necessary.
476       */
477      final void ensureWorkerInitialization() {
478          ForkJoinWorkerThread[] ws = workers;
# Line 536 | Line 548 | public class ForkJoinPool extends Abstra
548      }
549  
550      /**
551 <     * Performs the given task; returning its result upon completion
551 >     * Performs the given task, returning its result upon completion.
552 >     *
553       * @param task the task
554       * @return the task's result
555       * @throws NullPointerException if task is null
# Line 549 | Line 562 | public class ForkJoinPool extends Abstra
562  
563      /**
564       * Arranges for (asynchronous) execution of the given task.
565 +     *
566       * @param task the task
567       * @throws NullPointerException if task is null
568       * @throws RejectedExecutionException if pool is shut down
# Line 583 | Line 597 | public class ForkJoinPool extends Abstra
597  
598      /**
599       * Adaptor for Runnables. This implements RunnableFuture
600 <     * to be compliant with AbstractExecutorService constraints
600 >     * to be compliant with AbstractExecutorService constraints.
601       */
602      static final class AdaptedRunnable<T> extends ForkJoinTask<T>
603          implements RunnableFuture<T> {
# Line 603 | Line 617 | public class ForkJoinPool extends Abstra
617              return true;
618          }
619          public void run() { invoke(); }
620 +        private static final long serialVersionUID = 5232453952276885070L;
621      }
622  
623      /**
# Line 631 | Line 646 | public class ForkJoinPool extends Abstra
646              }
647          }
648          public void run() { invoke(); }
649 +        private static final long serialVersionUID = 2838392045355241008L;
650      }
651  
652      public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) {
653 <        ArrayList<ForkJoinTask<T>> ts =
653 >        ArrayList<ForkJoinTask<T>> forkJoinTasks =
654              new ArrayList<ForkJoinTask<T>>(tasks.size());
655 <        for (Callable<T> c : tasks)
656 <            ts.add(new AdaptedCallable<T>(c));
657 <        invoke(new InvokeAll<T>(ts));
658 <        return (List<Future<T>>)(List)ts;
655 >        for (Callable<T> task : tasks)
656 >            forkJoinTasks.add(new AdaptedCallable<T>(task));
657 >        invoke(new InvokeAll<T>(forkJoinTasks));
658 >
659 >        @SuppressWarnings({"unchecked", "rawtypes"})
660 >        List<Future<T>> futures = (List<Future<T>>) (List) forkJoinTasks;
661 >        return futures;
662      }
663  
664      static final class InvokeAll<T> extends RecursiveAction {
665          final ArrayList<ForkJoinTask<T>> tasks;
666          InvokeAll(ArrayList<ForkJoinTask<T>> tasks) { this.tasks = tasks; }
667          public void compute() {
668 <            try { invokeAll(tasks); } catch(Exception ignore) {}
668 >            try { invokeAll(tasks); }
669 >            catch (Exception ignore) {}
670          }
671 +        private static final long serialVersionUID = -7914297376763021607L;
672      }
673  
674      // Configuration and status settings and queries
675  
676      /**
677 <     * Returns the factory used for constructing new workers
677 >     * Returns the factory used for constructing new workers.
678       *
679       * @return the factory used for constructing new workers
680       */
# Line 664 | Line 685 | public class ForkJoinPool extends Abstra
685      /**
686       * Returns the handler for internal worker threads that terminate
687       * due to unrecoverable errors encountered while executing tasks.
688 +     *
689       * @return the handler, or null if none
690       */
691      public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler() {
# Line 689 | Line 711 | public class ForkJoinPool extends Abstra
711       * @throws SecurityException if a security manager exists and
712       *         the caller is not permitted to modify threads
713       *         because it does not hold {@link
714 <     *         java.lang.RuntimePermission}<code>("modifyThread")</code>,
714 >     *         java.lang.RuntimePermission}{@code ("modifyThread")}
715       */
716      public Thread.UncaughtExceptionHandler
717          setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler h) {
# Line 716 | Line 738 | public class ForkJoinPool extends Abstra
738  
739  
740      /**
741 <     * Sets the target paralleism level of this pool.
741 >     * Sets the target parallelism level of this pool.
742 >     *
743       * @param parallelism the target parallelism
744       * @throws IllegalArgumentException if parallelism less than or
745 <     * equal to zero or greater than maximum size bounds.
745 >     * equal to zero or greater than maximum size bounds
746       * @throws SecurityException if a security manager exists and
747       *         the caller is not permitted to modify threads
748       *         because it does not hold {@link
749 <     *         java.lang.RuntimePermission}<code>("modifyThread")</code>,
749 >     *         java.lang.RuntimePermission}{@code ("modifyThread")}
750       */
751      public void setParallelism(int parallelism) {
752          checkPermission();
# Line 758 | Line 781 | public class ForkJoinPool extends Abstra
781      /**
782       * Returns the number of worker threads that have started but not
783       * yet terminated.  This result returned by this method may differ
784 <     * from <code>getParallelism</code> when threads are created to
784 >     * from {@code getParallelism} when threads are created to
785       * maintain parallelism when others are cooperatively blocked.
786       *
787       * @return the number of worker threads
# Line 770 | Line 793 | public class ForkJoinPool extends Abstra
793      /**
794       * Returns the maximum number of threads allowed to exist in the
795       * pool, even if there are insufficient unblocked running threads.
796 +     *
797       * @return the maximum
798       */
799      public int getMaximumPoolSize() {
# Line 781 | Line 805 | public class ForkJoinPool extends Abstra
805       * pool, even if there are insufficient unblocked running threads.
806       * Setting this value has no effect on current pool size. It
807       * controls construction of new threads.
808 +     *
809       * @throws IllegalArgumentException if negative or greater then
810 <     * internal implementation limit.
810 >     * internal implementation limit
811       */
812      public void setMaximumPoolSize(int newMax) {
813          if (newMax < 0 || newMax > MAX_THREADS)
# Line 795 | Line 820 | public class ForkJoinPool extends Abstra
820       * Returns true if this pool dynamically maintains its target
821       * parallelism level. If false, new threads are added only to
822       * avoid possible starvation.
823 <     * This setting is by default true;
823 >     * This setting is by default true.
824 >     *
825       * @return true if maintains parallelism
826       */
827      public boolean getMaintainsParallelism() {
# Line 806 | Line 832 | public class ForkJoinPool extends Abstra
832       * Sets whether this pool dynamically maintains its target
833       * parallelism level. If false, new threads are added only to
834       * avoid possible starvation.
835 +     *
836       * @param enable true to maintains parallelism
837       */
838      public void setMaintainsParallelism(boolean enable) {
# Line 819 | Line 846 | public class ForkJoinPool extends Abstra
846       * worker threads only process asynchronous tasks.  This method is
847       * designed to be invoked only when pool is quiescent, and
848       * typically only before any tasks are submitted. The effects of
849 <     * invocations at ather times may be unpredictable.
849 >     * invocations at other times may be unpredictable.
850       *
851       * @param async if true, use locally FIFO scheduling
852 <     * @return the previous mode.
852 >     * @return the previous mode
853       */
854      public boolean setAsyncMode(boolean async) {
855          boolean oldMode = locallyFifo;
# Line 840 | Line 867 | public class ForkJoinPool extends Abstra
867  
868      /**
869       * Returns true if this pool uses local first-in-first-out
870 <     * scheduling mode for forked tasks that are never joined.
870 >     * scheduling mode for forked tasks that are never joined.
871       *
872 <     * @return true if this pool uses async mode.
872 >     * @return true if this pool uses async mode
873       */
874      public boolean getAsyncMode() {
875          return locallyFifo;
# Line 863 | Line 890 | public class ForkJoinPool extends Abstra
890       * Returns an estimate of the number of threads that are currently
891       * stealing or executing tasks. This method may overestimate the
892       * number of active threads.
893 <     * @return the number of active threads.
893 >     *
894 >     * @return the number of active threads
895       */
896      public int getActiveThreadCount() {
897          return activeCountOf(runControl);
# Line 873 | Line 901 | public class ForkJoinPool extends Abstra
901       * Returns an estimate of the number of threads that are currently
902       * idle waiting for tasks. This method may underestimate the
903       * number of idle threads.
904 <     * @return the number of idle threads.
904 >     *
905 >     * @return the number of idle threads
906       */
907      final int getIdleThreadCount() {
908          int c = runningCountOf(workerCounts) - activeCountOf(runControl);
909 <        return (c <= 0)? 0 : c;
909 >        return (c <= 0) ? 0 : c;
910      }
911  
912      /**
913       * Returns true if all worker threads are currently idle. An idle
914       * worker is one that cannot obtain a task to execute because none
915       * are available to steal from other threads, and there are no
916 <     * pending submissions to the pool. This method is conservative:
917 <     * It might not return true immediately upon idleness of all
916 >     * pending submissions to the pool. This method is conservative;
917 >     * it might not return true immediately upon idleness of all
918       * threads, but will eventually become true if threads remain
919       * inactive.
920 +     *
921       * @return true if all threads are currently idle
922       */
923      public boolean isQuiescent() {
# Line 899 | Line 929 | public class ForkJoinPool extends Abstra
929       * one thread's work queue by another. The reported value
930       * underestimates the actual total number of steals when the pool
931       * is not quiescent. This value may be useful for monitoring and
932 <     * tuning fork/join programs: In general, steal counts should be
932 >     * tuning fork/join programs: in general, steal counts should be
933       * high enough to keep threads busy, but low enough to avoid
934       * overhead and contention across threads.
935 <     * @return the number of steals.
935 >     *
936 >     * @return the number of steals
937       */
938      public long getStealCount() {
939          return stealCount.get();
940      }
941  
942      /**
943 <     * Accumulate steal count from a worker. Call only
944 <     * when worker known to be idle.
943 >     * Accumulates steal count from a worker.
944 >     * Call only when worker known to be idle.
945       */
946      private void updateStealCount(ForkJoinWorkerThread w) {
947          int sc = w.getAndClearStealCount();
# Line 925 | Line 956 | public class ForkJoinPool extends Abstra
956       * an approximation, obtained by iterating across all threads in
957       * the pool. This method may be useful for tuning task
958       * granularities.
959 <     * @return the number of queued tasks.
959 >     *
960 >     * @return the number of queued tasks
961       */
962      public long getQueuedTaskCount() {
963          long count = 0;
# Line 944 | Line 976 | public class ForkJoinPool extends Abstra
976       * Returns an estimate of the number tasks submitted to this pool
977       * that have not yet begun executing. This method takes time
978       * proportional to the number of submissions.
979 <     * @return the number of queued submissions.
979 >     *
980 >     * @return the number of queued submissions
981       */
982      public int getQueuedSubmissionCount() {
983          return submissionQueue.size();
# Line 953 | Line 986 | public class ForkJoinPool extends Abstra
986      /**
987       * Returns true if there are any tasks submitted to this pool
988       * that have not yet begun executing.
989 <     * @return <code>true</code> if there are any queued submissions.
989 >     *
990 >     * @return {@code true} if there are any queued submissions
991       */
992      public boolean hasQueuedSubmissions() {
993          return !submissionQueue.isEmpty();
# Line 963 | Line 997 | public class ForkJoinPool extends Abstra
997       * Removes and returns the next unexecuted submission if one is
998       * available.  This method may be useful in extensions to this
999       * class that re-assign work in systems with multiple pools.
1000 +     *
1001       * @return the next submission, or null if none
1002       */
1003      protected ForkJoinTask<?> pollSubmission() {
# Line 973 | Line 1008 | public class ForkJoinPool extends Abstra
1008       * Removes all available unexecuted submitted and forked tasks
1009       * from scheduling queues and adds them to the given collection,
1010       * without altering their execution status. These may include
1011 <     * artifically generated or wrapped tasks. This method id designed
1011 >     * artificially generated or wrapped tasks. This method is designed
1012       * to be invoked only when the pool is known to be
1013       * quiescent. Invocations at other times may not remove all
1014       * tasks. A failure encountered while attempting to add elements
1015 <     * to collection <tt>c</tt> may result in elements being in
1015 >     * to collection {@code c} may result in elements being in
1016       * neither, either or both collections when the associated
1017       * exception is thrown.  The behavior of this operation is
1018       * undefined if the specified collection is modified while the
1019       * operation is in progress.
1020 +     *
1021       * @param c the collection to transfer elements into
1022       * @return the number of elements transferred
1023       */
# Line 1042 | Line 1078 | public class ForkJoinPool extends Abstra
1078       * Invocation has no additional effect if already shut down.
1079       * Tasks that are in the process of being submitted concurrently
1080       * during the course of this method may or may not be rejected.
1081 +     *
1082       * @throws SecurityException if a security manager exists and
1083       *         the caller is not permitted to modify threads
1084       *         because it does not hold {@link
1085 <     *         java.lang.RuntimePermission}<code>("modifyThread")</code>,
1085 >     *         java.lang.RuntimePermission}{@code ("modifyThread")}
1086       */
1087      public void shutdown() {
1088          checkPermission();
# Line 1061 | Line 1098 | public class ForkJoinPool extends Abstra
1098       * method may or may not be rejected. Unlike some other executors,
1099       * this method cancels rather than collects non-executed tasks
1100       * upon termination, so always returns an empty list. However, you
1101 <     * can use method <code>drainTasksTo</code> before invoking this
1101 >     * can use method {@code drainTasksTo} before invoking this
1102       * method to transfer unexecuted tasks to another collection.
1103 +     *
1104       * @return an empty list
1105       * @throws SecurityException if a security manager exists and
1106       *         the caller is not permitted to modify threads
1107       *         because it does not hold {@link
1108 <     *         java.lang.RuntimePermission}<code>("modifyThread")</code>,
1108 >     *         java.lang.RuntimePermission}{@code ("modifyThread")}
1109       */
1110      public List<Runnable> shutdownNow() {
1111          checkPermission();
# Line 1076 | Line 1114 | public class ForkJoinPool extends Abstra
1114      }
1115  
1116      /**
1117 <     * Returns <code>true</code> if all tasks have completed following shut down.
1117 >     * Returns {@code true} if all tasks have completed following shut down.
1118       *
1119 <     * @return <code>true</code> if all tasks have completed following shut down
1119 >     * @return {@code true} if all tasks have completed following shut down
1120       */
1121      public boolean isTerminated() {
1122          return runStateOf(runControl) == TERMINATED;
1123      }
1124  
1125      /**
1126 <     * Returns <code>true</code> if the process of termination has
1126 >     * Returns {@code true} if the process of termination has
1127       * commenced but possibly not yet completed.
1128       *
1129 <     * @return <code>true</code> if terminating
1129 >     * @return {@code true} if terminating
1130       */
1131      public boolean isTerminating() {
1132          return runStateOf(runControl) >= TERMINATING;
1133      }
1134  
1135      /**
1136 <     * Returns <code>true</code> if this pool has been shut down.
1136 >     * Returns {@code true} if this pool has been shut down.
1137       *
1138 <     * @return <code>true</code> if this pool has been shut down
1138 >     * @return {@code true} if this pool has been shut down
1139       */
1140      public boolean isShutdown() {
1141          return runStateOf(runControl) >= SHUTDOWN;
# Line 1110 | Line 1148 | public class ForkJoinPool extends Abstra
1148       *
1149       * @param timeout the maximum time to wait
1150       * @param unit the time unit of the timeout argument
1151 <     * @return <code>true</code> if this executor terminated and
1152 <     *         <code>false</code> if the timeout elapsed before termination
1151 >     * @return {@code true} if this executor terminated and
1152 >     *         {@code false} if the timeout elapsed before termination
1153       * @throws InterruptedException if interrupted while waiting
1154       */
1155      public boolean awaitTermination(long timeout, TimeUnit unit)
# Line 1135 | Line 1173 | public class ForkJoinPool extends Abstra
1173      // Shutdown and termination support
1174  
1175      /**
1176 <     * Callback from terminating worker. Null out the corresponding
1177 <     * workers slot, and if terminating, try to terminate, else try to
1178 <     * shrink workers array.
1176 >     * Callback from terminating worker. Nulls out the corresponding
1177 >     * workers slot, and if terminating, tries to terminate; else
1178 >     * tries to shrink workers array.
1179 >     *
1180       * @param w the worker
1181       */
1182      final void workerTerminated(ForkJoinWorkerThread w) {
# Line 1168 | Line 1207 | public class ForkJoinPool extends Abstra
1207      }
1208  
1209      /**
1210 <     * Initiate termination.
1210 >     * Initiates termination.
1211       */
1212      private void terminate() {
1213          if (transitionRunStateTo(TERMINATING)) {
# Line 1183 | Line 1222 | public class ForkJoinPool extends Abstra
1222      }
1223  
1224      /**
1225 <     * Possibly terminate when on shutdown state
1225 >     * Possibly terminates when on shutdown state.
1226       */
1227      private void terminateOnShutdown() {
1228          if (!hasQueuedSubmissions() && canTerminateOnShutdown(runControl))
# Line 1191 | Line 1230 | public class ForkJoinPool extends Abstra
1230      }
1231  
1232      /**
1233 <     * Clear out and cancel submissions
1233 >     * Clears out and cancels submissions.
1234       */
1235      private void cancelQueuedSubmissions() {
1236          ForkJoinTask<?> task;
# Line 1200 | Line 1239 | public class ForkJoinPool extends Abstra
1239      }
1240  
1241      /**
1242 <     * Clean out worker queues.
1242 >     * Cleans out worker queues.
1243       */
1244      private void cancelQueuedWorkerTasks() {
1245          final ReentrantLock lock = this.workerLock;
# Line 1220 | Line 1259 | public class ForkJoinPool extends Abstra
1259      }
1260  
1261      /**
1262 <     * Set each worker's status to terminating. Requires lock to avoid
1263 <     * conflicts with add/remove
1262 >     * Sets each worker's status to terminating. Requires lock to avoid
1263 >     * conflicts with add/remove.
1264       */
1265      private void stopAllWorkers() {
1266          final ReentrantLock lock = this.workerLock;
# Line 1241 | Line 1280 | public class ForkJoinPool extends Abstra
1280      }
1281  
1282      /**
1283 <     * Interrupt all unterminated workers.  This is not required for
1283 >     * Interrupts all unterminated workers.  This is not required for
1284       * sake of internal control, but may help unstick user code during
1285       * shutdown.
1286       */
# Line 1311 | Line 1350 | public class ForkJoinPool extends Abstra
1350          }
1351  
1352          /**
1353 <         * Wake up waiter, returning false if known to already
1353 >         * Wakes up waiter, returning false if known to already
1354           */
1355          boolean signal() {
1356              ForkJoinWorkerThread t = thread;
# Line 1323 | Line 1362 | public class ForkJoinPool extends Abstra
1362          }
1363  
1364          /**
1365 <         * Await release on sync
1365 >         * Awaits release on sync.
1366           */
1367          void awaitSyncRelease(ForkJoinPool p) {
1368              while (thread != null && !p.syncIsReleasable(this))
# Line 1331 | Line 1370 | public class ForkJoinPool extends Abstra
1370          }
1371  
1372          /**
1373 <         * Await resumption as spare
1373 >         * Awaits resumption as spare.
1374           */
1375          void awaitSpareRelease() {
1376              while (thread != null) {
# Line 1345 | Line 1384 | public class ForkJoinPool extends Abstra
1384       * Ensures that no thread is waiting for count to advance from the
1385       * current value of eventCount read on entry to this method, by
1386       * releasing waiting threads if necessary.
1387 +     *
1388       * @return the count
1389       */
1390      final long ensureSync() {
# Line 1366 | Line 1406 | public class ForkJoinPool extends Abstra
1406       */
1407      private void signalIdleWorkers() {
1408          long c;
1409 <        do;while (!casEventCount(c = eventCount, c+1));
1409 >        do {} while (!casEventCount(c = eventCount, c+1));
1410          ensureSync();
1411      }
1412  
1413      /**
1414 <     * Signal threads waiting to poll a task. Because method sync
1414 >     * Signals threads waiting to poll a task. Because method sync
1415       * rechecks availability, it is OK to only proceed if queue
1416       * appears to be non-empty, and OK to skip under contention to
1417       * increment count (since some other thread succeeded).
# Line 1390 | Line 1430 | public class ForkJoinPool extends Abstra
1430       * Waits until event count advances from last value held by
1431       * caller, or if excess threads, caller is resumed as spare, or
1432       * caller or pool is terminating. Updates caller's event on exit.
1433 +     *
1434       * @param w the calling worker thread
1435       */
1436      final void sync(ForkJoinWorkerThread w) {
# Line 1420 | Line 1461 | public class ForkJoinPool extends Abstra
1461       * Returns true if worker waiting on sync can proceed:
1462       *  - on signal (thread == null)
1463       *  - on event count advance (winning race to notify vs signaller)
1464 <     *  - on Interrupt
1464 >     *  - on interrupt
1465       *  - if the first queued node, we find work available
1466       * If node was not signalled and event count not advanced on exit,
1467       * then we also help advance event count.
1468 +     *
1469       * @return true if node can be released
1470       */
1471      final boolean syncIsReleasable(WaitQueueNode node) {
# Line 1458 | Line 1500 | public class ForkJoinPool extends Abstra
1500      //  Parallelism maintenance
1501  
1502      /**
1503 <     * Decrement running count; if too low, add spare.
1503 >     * Decrements running count; if too low, adds spare.
1504       *
1505       * Conceptually, all we need to do here is add or resume a
1506       * spare thread when one is about to block (and remove or
1507       * suspend it later when unblocked -- see suspendIfSpare).
1508       * However, implementing this idea requires coping with
1509 <     * several problems: We have imperfect information about the
1509 >     * several problems: we have imperfect information about the
1510       * states of threads. Some count updates can and usually do
1511       * lag run state changes, despite arrangements to keep them
1512       * accurate (for example, when possible, updating counts
# Line 1478 | Line 1520 | public class ForkJoinPool extends Abstra
1520       * only be suspended or removed when they are idle, not
1521       * immediately when they aren't needed. So adding threads will
1522       * raise parallelism level for longer than necessary.  Also,
1523 <     * FJ applications often enounter highly transient peaks when
1523 >     * FJ applications often encounter highly transient peaks when
1524       * many threads are blocked joining, but for less time than it
1525       * takes to create or resume spares.
1526       *
# Line 1487 | Line 1529 | public class ForkJoinPool extends Abstra
1529       * target counts, else create only to avoid starvation
1530       * @return true if joinMe known to be done
1531       */
1532 <    final boolean preJoin(ForkJoinTask<?> joinMe, boolean maintainParallelism) {
1532 >    final boolean preJoin(ForkJoinTask<?> joinMe,
1533 >                          boolean maintainParallelism) {
1534          maintainParallelism &= maintainsParallelism; // overrride
1535          boolean dec = false;  // true when running count decremented
1536          while (spareStack == null || !tryResumeSpare(dec)) {
1537              int counts = workerCounts;
1538 <            if (dec || (dec = casWorkerCounts(counts, --counts))) { // CAS cheat
1538 >            if (dec || (dec = casWorkerCounts(counts, --counts))) {
1539 >                // CAS cheat
1540                  if (!needSpare(counts, maintainParallelism))
1541                      break;
1542                  if (joinMe.status < 0)
# Line 1532 | Line 1576 | public class ForkJoinPool extends Abstra
1576       * there is apparently some work to do.  This self-limiting rule
1577       * means that the more threads that have already been added, the
1578       * less parallelism we will tolerate before adding another.
1579 +     *
1580       * @param counts current worker counts
1581       * @param maintainParallelism try to maintain parallelism
1582       */
# Line 1549 | Line 1594 | public class ForkJoinPool extends Abstra
1594      }
1595  
1596      /**
1597 <     * Add a spare worker if lock available and no more than the
1598 <     * expected numbers of threads exist
1597 >     * Adds a spare worker if lock available and no more than the
1598 >     * expected numbers of threads exist.
1599 >     *
1600       * @return true if successful
1601       */
1602      private boolean tryAddSpare(int expectedCounts) {
# Line 1583 | Line 1629 | public class ForkJoinPool extends Abstra
1629      }
1630  
1631      /**
1632 <     * Add the kth spare worker. On entry, pool coounts are already
1632 >     * Adds the kth spare worker. On entry, pool counts are already
1633       * adjusted to reflect addition.
1634       */
1635      private void createAndStartSpare(int k) {
# Line 1605 | Line 1651 | public class ForkJoinPool extends Abstra
1651      }
1652  
1653      /**
1654 <     * Suspend calling thread w if there are excess threads.  Called
1655 <     * only from sync.  Spares are enqueued in a Treiber stack
1656 <     * using the same WaitQueueNodes as barriers.  They are resumed
1657 <     * mainly in preJoin, but are also woken on pool events that
1658 <     * require all threads to check run state.
1654 >     * Suspends calling thread w if there are excess threads.  Called
1655 >     * only from sync.  Spares are enqueued in a Treiber stack using
1656 >     * the same WaitQueueNodes as barriers.  They are resumed mainly
1657 >     * in preJoin, but are also woken on pool events that require all
1658 >     * threads to check run state.
1659 >     *
1660       * @param w the caller
1661       */
1662      private boolean suspendIfSpare(ForkJoinWorkerThread w) {
# Line 1620 | Line 1667 | public class ForkJoinPool extends Abstra
1667                  node = new WaitQueueNode(0, w);
1668              if (casWorkerCounts(s, s-1)) { // representation-dependent
1669                  // push onto stack
1670 <                do;while (!casSpareStack(node.next = spareStack, node));
1670 >                do {} while (!casSpareStack(node.next = spareStack, node));
1671                  // block until released by resumeSpare
1672                  node.awaitSpareRelease();
1673                  return true;
# Line 1630 | Line 1677 | public class ForkJoinPool extends Abstra
1677      }
1678  
1679      /**
1680 <     * Try to pop and resume a spare thread.
1680 >     * Tries to pop and resume a spare thread.
1681 >     *
1682       * @param updateCount if true, increment running count on success
1683       * @return true if successful
1684       */
# Line 1648 | Line 1696 | public class ForkJoinPool extends Abstra
1696      }
1697  
1698      /**
1699 <     * Pop and resume all spare threads. Same idea as ensureSync.
1699 >     * Pops and resumes all spare threads. Same idea as ensureSync.
1700 >     *
1701       * @return true if any spares released
1702       */
1703      private boolean resumeAllSpares() {
# Line 1666 | Line 1715 | public class ForkJoinPool extends Abstra
1715      }
1716  
1717      /**
1718 <     * Pop and shutdown excessive spare threads. Call only while
1718 >     * Pops and shuts down excessive spare threads. Call only while
1719       * holding lock. This is not guaranteed to eliminate all excess
1720       * threads, only those suspended as spares, which are the ones
1721       * unlikely to be needed in the future.
# Line 1691 | Line 1740 | public class ForkJoinPool extends Abstra
1740      /**
1741       * Interface for extending managed parallelism for tasks running
1742       * in ForkJoinPools. A ManagedBlocker provides two methods.
1743 <     * Method <code>isReleasable</code> must return true if blocking is not
1744 <     * necessary. Method <code>block</code> blocks the current thread
1745 <     * if necessary (perhaps internally invoking isReleasable before
1746 <     * actually blocking.).
1743 >     * Method {@code isReleasable} must return true if blocking is not
1744 >     * necessary. Method {@code block} blocks the current thread if
1745 >     * necessary (perhaps internally invoking {@code isReleasable}
1746 >     * before actually blocking.).
1747 >     *
1748       * <p>For example, here is a ManagedBlocker based on a
1749       * ReentrantLock:
1750 <     * <pre>
1751 <     *   class ManagedLocker implements ManagedBlocker {
1752 <     *     final ReentrantLock lock;
1753 <     *     boolean hasLock = false;
1754 <     *     ManagedLocker(ReentrantLock lock) { this.lock = lock; }
1755 <     *     public boolean block() {
1756 <     *        if (!hasLock)
1757 <     *           lock.lock();
1758 <     *        return true;
1759 <     *     }
1760 <     *     public boolean isReleasable() {
1761 <     *        return hasLock || (hasLock = lock.tryLock());
1712 <     *     }
1750 >     *  <pre> {@code
1751 >     * class ManagedLocker implements ManagedBlocker {
1752 >     *   final ReentrantLock lock;
1753 >     *   boolean hasLock = false;
1754 >     *   ManagedLocker(ReentrantLock lock) { this.lock = lock; }
1755 >     *   public boolean block() {
1756 >     *     if (!hasLock)
1757 >     *       lock.lock();
1758 >     *     return true;
1759 >     *   }
1760 >     *   public boolean isReleasable() {
1761 >     *     return hasLock || (hasLock = lock.tryLock());
1762       *   }
1763 <     * </pre>
1763 >     * }}</pre>
1764       */
1765      public static interface ManagedBlocker {
1766          /**
1767           * Possibly blocks the current thread, for example waiting for
1768           * a lock or condition.
1769 +         *
1770           * @return true if no additional blocking is necessary (i.e.,
1771 <         * if isReleasable would return true).
1771 >         * if isReleasable would return true)
1772           * @throws InterruptedException if interrupted while waiting
1773 <         * (the method is not required to do so, but is allowe to).
1773 >         * (the method is not required to do so, but is allowed to)
1774           */
1775          boolean block() throws InterruptedException;
1776  
# Line 1735 | Line 1785 | public class ForkJoinPool extends Abstra
1785       * is a ForkJoinWorkerThread, this method possibly arranges for a
1786       * spare thread to be activated if necessary to ensure parallelism
1787       * while the current thread is blocked.  If
1788 <     * <code>maintainParallelism</code> is true and the pool supports
1788 >     * {@code maintainParallelism} is true and the pool supports
1789       * it ({@link #getMaintainsParallelism}), this method attempts to
1790 <     * maintain the pool's nominal parallelism. Otherwise if activates
1790 >     * maintain the pool's nominal parallelism. Otherwise it activates
1791       * a thread only if necessary to avoid complete starvation. This
1792       * option may be preferable when blockages use timeouts, or are
1793       * almost always brief.
1794       *
1795       * <p> If the caller is not a ForkJoinTask, this method is behaviorally
1796       * equivalent to
1797 <     * <pre>
1798 <     *   while (!blocker.isReleasable())
1799 <     *      if (blocker.block())
1800 <     *         return;
1801 <     * </pre>
1797 >     *  <pre> {@code
1798 >     * while (!blocker.isReleasable())
1799 >     *   if (blocker.block())
1800 >     *     return;
1801 >     * }</pre>
1802       * If the caller is a ForkJoinTask, then the pool may first
1803       * be expanded to ensure parallelism, and later adjusted.
1804       *
# Line 1757 | Line 1807 | public class ForkJoinPool extends Abstra
1807       * attempt to maintain the pool's nominal parallelism; otherwise
1808       * activate a thread only if necessary to avoid complete
1809       * starvation.
1810 <     * @throws InterruptedException if blocker.block did so.
1810 >     * @throws InterruptedException if blocker.block did so
1811       */
1812      public static void managedBlock(ManagedBlocker blocker,
1813                                      boolean maintainParallelism)
1814          throws InterruptedException {
1815          Thread t = Thread.currentThread();
1816 <        ForkJoinPool pool = (t instanceof ForkJoinWorkerThread?
1817 <                             ((ForkJoinWorkerThread)t).pool : null);
1816 >        ForkJoinPool pool = ((t instanceof ForkJoinWorkerThread) ?
1817 >                             ((ForkJoinWorkerThread) t).pool : null);
1818          if (!blocker.isReleasable()) {
1819              try {
1820                  if (pool == null ||
# Line 1779 | Line 1829 | public class ForkJoinPool extends Abstra
1829  
1830      private static void awaitBlocker(ManagedBlocker blocker)
1831          throws InterruptedException {
1832 <        do;while (!blocker.isReleasable() && !blocker.block());
1832 >        do {} while (!blocker.isReleasable() && !blocker.block());
1833      }
1834  
1835      // AbstractExecutorService overrides
1836  
1837      protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
1838 <        return new AdaptedRunnable(runnable, value);
1838 >        return new AdaptedRunnable<T>(runnable, value);
1839      }
1840  
1841      protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
1842 <        return new AdaptedCallable(callable);
1842 >        return new AdaptedCallable<T>(callable);
1843      }
1844  
1845  
1846 <    // Temporary Unsafe mechanics for preliminary release
1847 <    private static Unsafe getUnsafe() throws Throwable {
1846 >    // Unsafe mechanics for jsr166y 3rd party package.
1847 >    private static sun.misc.Unsafe getUnsafe() {
1848          try {
1849 <            return Unsafe.getUnsafe();
1849 >            return sun.misc.Unsafe.getUnsafe();
1850          } catch (SecurityException se) {
1851              try {
1852                  return java.security.AccessController.doPrivileged
1853 <                    (new java.security.PrivilegedExceptionAction<Unsafe>() {
1854 <                        public Unsafe run() throws Exception {
1855 <                            return getUnsafePrivileged();
1853 >                    (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
1854 >                        public sun.misc.Unsafe run() throws Exception {
1855 >                            return getUnsafeByReflection();
1856                          }});
1857              } catch (java.security.PrivilegedActionException e) {
1858 <                throw e.getCause();
1858 >                throw new RuntimeException("Could not initialize intrinsics",
1859 >                                           e.getCause());
1860              }
1861          }
1862      }
1863  
1864 <    private static Unsafe getUnsafePrivileged()
1864 >    private static sun.misc.Unsafe getUnsafeByReflection()
1865              throws NoSuchFieldException, IllegalAccessException {
1866 <        Field f = Unsafe.class.getDeclaredField("theUnsafe");
1866 >        java.lang.reflect.Field f =
1867 >            sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
1868          f.setAccessible(true);
1869 <        return (Unsafe) f.get(null);
1818 <    }
1819 <
1820 <    private static long fieldOffset(String fieldName)
1821 <            throws NoSuchFieldException {
1822 <        return _unsafe.objectFieldOffset
1823 <            (ForkJoinPool.class.getDeclaredField(fieldName));
1869 >        return (sun.misc.Unsafe) f.get(null);
1870      }
1871  
1872 <    static final Unsafe _unsafe;
1827 <    static final long eventCountOffset;
1828 <    static final long workerCountsOffset;
1829 <    static final long runControlOffset;
1830 <    static final long syncStackOffset;
1831 <    static final long spareStackOffset;
1832 <
1833 <    static {
1872 >    private static long fieldOffset(String fieldName, Class<?> klazz) {
1873          try {
1874 <            _unsafe = getUnsafe();
1875 <            eventCountOffset = fieldOffset("eventCount");
1876 <            workerCountsOffset = fieldOffset("workerCounts");
1877 <            runControlOffset = fieldOffset("runControl");
1878 <            syncStackOffset = fieldOffset("syncStack");
1879 <            spareStackOffset = fieldOffset("spareStack");
1841 <        } catch (Throwable e) {
1842 <            throw new RuntimeException("Could not initialize intrinsics", e);
1874 >            return UNSAFE.objectFieldOffset(klazz.getDeclaredField(fieldName));
1875 >        } catch (NoSuchFieldException e) {
1876 >            // Convert Exception to Error
1877 >            NoSuchFieldError error = new NoSuchFieldError(fieldName);
1878 >            error.initCause(e);
1879 >            throw error;
1880          }
1881      }
1882  
1883 +    private static final sun.misc.Unsafe UNSAFE = getUnsafe();
1884 +    static final long eventCountOffset =
1885 +        fieldOffset("eventCount", ForkJoinPool.class);
1886 +    static final long workerCountsOffset =
1887 +        fieldOffset("workerCounts", ForkJoinPool.class);
1888 +    static final long runControlOffset =
1889 +        fieldOffset("runControl", ForkJoinPool.class);
1890 +    static final long syncStackOffset =
1891 +        fieldOffset("syncStack",ForkJoinPool.class);
1892 +    static final long spareStackOffset =
1893 +        fieldOffset("spareStack", ForkJoinPool.class);
1894 +
1895      private boolean casEventCount(long cmp, long val) {
1896 <        return _unsafe.compareAndSwapLong(this, eventCountOffset, cmp, val);
1896 >        return UNSAFE.compareAndSwapLong(this, eventCountOffset, cmp, val);
1897      }
1898      private boolean casWorkerCounts(int cmp, int val) {
1899 <        return _unsafe.compareAndSwapInt(this, workerCountsOffset, cmp, val);
1899 >        return UNSAFE.compareAndSwapInt(this, workerCountsOffset, cmp, val);
1900      }
1901      private boolean casRunControl(int cmp, int val) {
1902 <        return _unsafe.compareAndSwapInt(this, runControlOffset, cmp, val);
1902 >        return UNSAFE.compareAndSwapInt(this, runControlOffset, cmp, val);
1903      }
1904      private boolean casSpareStack(WaitQueueNode cmp, WaitQueueNode val) {
1905 <        return _unsafe.compareAndSwapObject(this, spareStackOffset, cmp, val);
1905 >        return UNSAFE.compareAndSwapObject(this, spareStackOffset, cmp, val);
1906      }
1907      private boolean casBarrierStack(WaitQueueNode cmp, WaitQueueNode val) {
1908 <        return _unsafe.compareAndSwapObject(this, syncStackOffset, cmp, val);
1908 >        return UNSAFE.compareAndSwapObject(this, syncStackOffset, cmp, val);
1909      }
1910   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines