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

Comparing jsr166/src/jsr166y/ForkJoinTask.java (file contents):
Revision 1.13 by dl, Wed Jul 22 19:04:11 2009 UTC vs.
Revision 1.33 by dl, Tue Aug 4 00:36:45 2009 UTC

# Line 5 | Line 5
5   */
6  
7   package jsr166y;
8 < import java.io.Serializable;
9 < import java.util.*;
8 >
9   import java.util.concurrent.*;
10 < import java.util.concurrent.atomic.*;
11 < import sun.misc.Unsafe;
12 < import java.lang.reflect.*;
10 >
11 > import java.io.Serializable;
12 > import java.util.Collection;
13 > import java.util.Collections;
14 > import java.util.List;
15 > import java.util.RandomAccess;
16 > import java.util.Map;
17 > import java.util.WeakHashMap;
18  
19   /**
20 < * Abstract base class for tasks that run within a {@link
21 < * ForkJoinPool}.  A ForkJoinTask is a thread-like entity that is much
20 > * Abstract base class for tasks that run within a {@link ForkJoinPool}.
21 > * A {@code ForkJoinTask} is a thread-like entity that is much
22   * lighter weight than a normal thread.  Huge numbers of tasks and
23   * subtasks may be hosted by a small number of actual threads in a
24   * ForkJoinPool, at the price of some usage limitations.
25   *
26 < * <p> A "main" ForkJoinTask begins execution when submitted to a
27 < * {@link ForkJoinPool}. Once started, it will usually in turn start
28 < * other subtasks.  As indicated by the name of this class, many
29 < * programs using ForkJoinTasks employ only methods {@code fork}
30 < * and {@code join}, or derivatives such as
31 < * {@code invokeAll}.  However, this class also provides a number
32 < * of other methods that can come into play in advanced usages, as
33 < * well as extension mechanics that allow support of new forms of
34 < * fork/join processing.
26 > * <p>A "main" {@code ForkJoinTask} begins execution when submitted
27 > * to a {@link ForkJoinPool}.  Once started, it will usually in turn
28 > * start other subtasks.  As indicated by the name of this class,
29 > * many programs using {@code ForkJoinTask} employ only methods
30 > * {@link #fork} and {@link #join}, or derivatives such as {@link
31 > * #invokeAll}.  However, this class also provides a number of other
32 > * methods that can come into play in advanced usages, as well as
33 > * extension mechanics that allow support of new forms of fork/join
34 > * processing.
35   *
36 < * <p>A ForkJoinTask is a lightweight form of {@link Future}.  The
37 < * efficiency of ForkJoinTasks stems from a set of restrictions (that
38 < * are only partially statically enforceable) reflecting their
39 < * intended use as computational tasks calculating pure functions or
40 < * operating on purely isolated objects.  The primary coordination
41 < * mechanisms are {@link #fork}, that arranges asynchronous execution,
42 < * and {@link #join}, that doesn't proceed until the task's result has
43 < * been computed.  Computations should avoid {@code synchronized}
44 < * methods or blocks, and should minimize other blocking
45 < * synchronization apart from joining other tasks or using
46 < * synchronizers such as Phasers that are advertised to cooperate with
47 < * fork/join scheduling. Tasks should also not perform blocking IO,
48 < * and should ideally access variables that are completely independent
49 < * of those accessed by other running tasks. Minor breaches of these
50 < * restrictions, for example using shared output streams, may be
51 < * tolerable in practice, but frequent use may result in poor
52 < * performance, and the potential to indefinitely stall if the number
53 < * of threads not waiting for IO or other external synchronization
54 < * becomes exhausted. This usage restriction is in part enforced by
55 < * not permitting checked exceptions such as {@code IOExceptions}
56 < * to be thrown. However, computations may still encounter unchecked
57 < * exceptions, that are rethrown to callers attempting join
58 < * them. These exceptions may additionally include
59 < * RejectedExecutionExceptions stemming from internal resource
60 < * exhaustion such as failure to allocate internal task queues.
36 > * <p>A {@code ForkJoinTask} is a lightweight form of {@link Future}.
37 > * The efficiency of {@code ForkJoinTask}s stems from a set of
38 > * restrictions (that are only partially statically enforceable)
39 > * reflecting their intended use as computational tasks calculating
40 > * pure functions or operating on purely isolated objects.  The
41 > * primary coordination mechanisms are {@link #fork}, that arranges
42 > * asynchronous execution, and {@link #join}, that doesn't proceed
43 > * until the task's result has been computed.  Computations should
44 > * avoid {@code synchronized} methods or blocks, and should minimize
45 > * other blocking synchronization apart from joining other tasks or
46 > * using synchronizers such as Phasers that are advertised to
47 > * cooperate with fork/join scheduling. Tasks should also not perform
48 > * blocking IO, and should ideally access variables that are
49 > * completely independent of those accessed by other running
50 > * tasks. Minor breaches of these restrictions, for example using
51 > * shared output streams, may be tolerable in practice, but frequent
52 > * use may result in poor performance, and the potential to
53 > * indefinitely stall if the number of threads not waiting for IO or
54 > * other external synchronization becomes exhausted. This usage
55 > * restriction is in part enforced by not permitting checked
56 > * exceptions such as {@code IOExceptions} to be thrown. However,
57 > * computations may still encounter unchecked exceptions, that are
58 > * rethrown to callers attempting to join them. These exceptions may
59 > * additionally include RejectedExecutionExceptions stemming from
60 > * internal resource exhaustion such as failure to allocate internal
61 > * task queues.
62   *
63   * <p>The primary method for awaiting completion and extracting
64   * results of a task is {@link #join}, but there are several variants:
# Line 72 | Line 77 | import java.lang.reflect.*;
77   * performs the most common form of parallel invocation: forking a set
78   * of tasks and joining them all.
79   *
80 < * <p> The ForkJoinTask class is not usually directly subclassed.
80 > * <p>The ForkJoinTask class is not usually directly subclassed.
81   * Instead, you subclass one of the abstract classes that support a
82 < * particular style of fork/join processing.  Normally, a concrete
82 > * particular style of fork/join processing, typically {@link
83 > * RecursiveAction} for computations that do not return results, or
84 > * {@link RecursiveTask} for those that do.  Normally, a concrete
85   * ForkJoinTask subclass declares fields comprising its parameters,
86   * established in a constructor, and then defines a {@code compute}
87   * method that somehow uses the control methods supplied by this base
88   * class. While these methods have {@code public} access (to allow
89 < * instances of different task subclasses to call each others
89 > * instances of different task subclasses to call each other's
90   * methods), some of them may only be called from within other
91   * ForkJoinTasks (as may be determined using method {@link
92   * #inForkJoinPool}).  Attempts to invoke them in other contexts
93 < * result in exceptions or errors possibly including
93 > * result in exceptions or errors, possibly including
94   * ClassCastException.
95   *
96 < * <p>Most base support methods are {@code final} because their
97 < * implementations are intrinsically tied to the underlying
98 < * lightweight task scheduling framework, and so cannot be overridden.
99 < * Developers creating new basic styles of fork/join processing should
100 < * minimally implement {@code protected} methods
101 < * {@code exec}, {@code setRawResult}, and
102 < * {@code getRawResult}, while also introducing an abstract
103 < * computational method that can be implemented in its subclasses,
104 < * possibly relying on other {@code protected} methods provided
98 < * by this class.
96 > * <p>Most base support methods are {@code final}, to prevent
97 > * overriding of implementations that are intrinsically tied to the
98 > * underlying lightweight task scheduling framework.  Developers
99 > * creating new basic styles of fork/join processing should minimally
100 > * implement {@code protected} methods {@link #exec}, {@link
101 > * #setRawResult}, and {@link #getRawResult}, while also introducing
102 > * an abstract computational method that can be implemented in its
103 > * subclasses, possibly relying on other {@code protected} methods
104 > * provided by this class.
105   *
106   * <p>ForkJoinTasks should perform relatively small amounts of
107 < * computations, otherwise splitting into smaller tasks. As a very
108 < * rough rule of thumb, a task should perform more than 100 and less
109 < * than 10000 basic computational steps. If tasks are too big, then
110 < * parallelism cannot improve throughput. If too small, then memory
111 < * and internal task maintenance overhead may overwhelm processing.
107 > * computation. Large tasks should be split into smaller subtasks,
108 > * usually via recursive decomposition. As a very rough rule of thumb,
109 > * a task should perform more than 100 and less than 10000 basic
110 > * computational steps. If tasks are too big, then parallelism cannot
111 > * improve throughput. If too small, then memory and internal task
112 > * maintenance overhead may overwhelm processing.
113 > *
114 > * <p>This class provides {@code adapt} methods for {@link
115 > * java.lang.Runnable} and {@link java.util.concurrent.Callable}, that
116 > * may be of use when mixing execution of ForkJoinTasks with other
117 > * kinds of tasks. When all tasks are of this form, consider using a
118 > * pool in {@link ForkJoinPool#setAsyncMode}.
119   *
120 < * <p>ForkJoinTasks are {@code Serializable}, which enables them
121 < * to be used in extensions such as remote execution frameworks. It is
122 < * in general sensible to serialize tasks only before or after, but
123 < * not during execution. Serialization is not relied on during
111 < * execution itself.
120 > * <p>ForkJoinTasks are {@code Serializable}, which enables them to be
121 > * used in extensions such as remote execution frameworks. It is
122 > * sensible to serialize tasks only before or after, but not during,
123 > * execution. Serialization is not relied on during execution itself.
124   *
125   * @since 1.7
126   * @author Doug Lea
# Line 162 | Line 174 | public abstract class ForkJoinTask<V> im
174       */
175      static ForkJoinWorkerThread getWorker() {
176          Thread t = Thread.currentThread();
177 <        return ((t instanceof ForkJoinWorkerThread)?
178 <                (ForkJoinWorkerThread)t : null);
177 >        return ((t instanceof ForkJoinWorkerThread) ?
178 >                (ForkJoinWorkerThread) t : null);
179      }
180  
181      final boolean casStatus(int cmp, int val) {
# Line 189 | Line 201 | public abstract class ForkJoinTask<V> im
201          ForkJoinPool pool = getPool();
202          if (pool != null) {
203              int s; // Clear signal bits while setting completion status
204 <            do;while ((s = status) >= 0 && !casStatus(s, completion));
204 >            do {} while ((s = status) >= 0 && !casStatus(s, completion));
205  
206              if ((s & SIGNAL_MASK) != 0) {
207                  if ((s &= INTERNAL_SIGNAL_MASK) != 0)
208                      pool.updateRunningCount(s);
209 <                synchronized(this) { notifyAll(); }
209 >                synchronized (this) { notifyAll(); }
210              }
211          }
212          else
# Line 207 | Line 219 | public abstract class ForkJoinTask<V> im
219       */
220      private void externallySetCompletion(int completion) {
221          int s;
222 <        do;while ((s = status) >= 0 &&
223 <                  !casStatus(s, (s & SIGNAL_MASK) | completion));
224 <        synchronized(this) { notifyAll(); }
222 >        do {} while ((s = status) >= 0 &&
223 >                     !casStatus(s, (s & SIGNAL_MASK) | completion));
224 >        synchronized (this) { notifyAll(); }
225      }
226  
227      /**
228 <     * Sets status to indicate normal completion
228 >     * Sets status to indicate normal completion.
229       */
230      final void setNormalCompletion() {
231          // Try typical fast case -- single CAS, no signal, not already done.
# Line 225 | Line 237 | public abstract class ForkJoinTask<V> im
237      // internal waiting and notification
238  
239      /**
240 <     * Performs the actual monitor wait for awaitDone
240 >     * Performs the actual monitor wait for awaitDone.
241       */
242      private void doAwaitDone() {
243          // Minimize lock bias and in/de-flation effects by maximizing
244          // chances of waiting inside sync
245          try {
246              while (status >= 0)
247 <                synchronized(this) { if (status >= 0) wait(); }
247 >                synchronized (this) { if (status >= 0) wait(); }
248          } catch (InterruptedException ie) {
249              onInterruptedWait();
250          }
251      }
252  
253      /**
254 <     * Performs the actual monitor wait for awaitDone
254 >     * Performs the actual timed monitor wait for awaitDone.
255       */
256      private void doAwaitDone(long startTime, long nanos) {
257 <        synchronized(this) {
257 >        synchronized (this) {
258              try {
259                  while (status >= 0) {
260 <                    long nt = nanos - System.nanoTime() - startTime;
260 >                    long nt = nanos - (System.nanoTime() - startTime);
261                      if (nt <= 0)
262                          break;
263 <                    wait(nt / 1000000, (int)(nt % 1000000));
263 >                    wait(nt / 1000000, (int) (nt % 1000000));
264                  }
265              } catch (InterruptedException ie) {
266                  onInterruptedWait();
# Line 264 | Line 276 | public abstract class ForkJoinTask<V> im
276       *
277       * @return status upon exit
278       */
279 <    private int awaitDone(ForkJoinWorkerThread w, boolean maintainParallelism) {
280 <        ForkJoinPool pool = w == null? null : w.pool;
279 >    private int awaitDone(ForkJoinWorkerThread w,
280 >                          boolean maintainParallelism) {
281 >        ForkJoinPool pool = (w == null) ? null : w.pool;
282          int s;
283          while ((s = status) >= 0) {
284 <            if (casStatus(s, pool == null? s|EXTERNAL_SIGNAL : s+1)) {
284 >            if (casStatus(s, (pool == null) ? s|EXTERNAL_SIGNAL : s+1)) {
285                  if (pool == null || !pool.preJoin(this, maintainParallelism))
286                      doAwaitDone();
287                  if (((s = status) & INTERNAL_SIGNAL_MASK) != 0)
# Line 281 | Line 294 | public abstract class ForkJoinTask<V> im
294  
295      /**
296       * Timed version of awaitDone
297 +     *
298       * @return status upon exit
299       */
300      private int awaitDone(ForkJoinWorkerThread w, long nanos) {
301 <        ForkJoinPool pool = w == null? null : w.pool;
301 >        ForkJoinPool pool = (w == null) ? null : w.pool;
302          int s;
303          while ((s = status) >= 0) {
304 <            if (casStatus(s, pool == null? s|EXTERNAL_SIGNAL : s+1)) {
304 >            if (casStatus(s, (pool == null) ? s|EXTERNAL_SIGNAL : s+1)) {
305                  long startTime = System.nanoTime();
306                  if (pool == null || !pool.preJoin(this, false))
307                      doAwaitDone(startTime, nanos);
# Line 309 | Line 323 | public abstract class ForkJoinTask<V> im
323       */
324      private void adjustPoolCountsOnUnblock(ForkJoinPool pool) {
325          int s;
326 <        do;while ((s = status) < 0 && !casStatus(s, s & COMPLETION_MASK));
326 >        do {} while ((s = status) < 0 && !casStatus(s, s & COMPLETION_MASK));
327          if (pool != null && (s &= INTERNAL_SIGNAL_MASK) != 0)
328              pool.updateRunningCount(s);
329      }
# Line 364 | Line 378 | public abstract class ForkJoinTask<V> im
378  
379      /**
380       * Returns result or throws exception using j.u.c.Future conventions.
381 <     * Only call when isDone known to be true.
381 >     * Only call when {@code isDone} known to be true.
382       */
383      private V reportFutureResult()
384          throws ExecutionException, InterruptedException {
# Line 430 | Line 444 | public abstract class ForkJoinTask<V> im
444              try {
445                  if (!exec())
446                      return;
447 <            } catch(Throwable rex) {
447 >            } catch (Throwable rex) {
448                  setDoneExceptionally(rex);
449                  return;
450              }
# Line 462 | Line 476 | public abstract class ForkJoinTask<V> im
476      final void cancelIgnoringExceptions() {
477          try {
478              cancel(false);
479 <        } catch(Throwable ignore) {
479 >        } catch (Throwable ignore) {
480          }
481      }
482  
# Line 474 | Line 488 | public abstract class ForkJoinTask<V> im
488          ForkJoinTask<?> t;
489          while ((s = status) >= 0 && (t = w.scanWhileJoining(this)) != null)
490              t.quietlyExec();
491 <        return (s >= 0)? awaitDone(w, false) : s; // block if no work
491 >        return (s >= 0) ? awaitDone(w, false) : s; // block if no work
492      }
493  
494      // public methods
# Line 482 | Line 496 | public abstract class ForkJoinTask<V> im
496      /**
497       * Arranges to asynchronously execute this task.  While it is not
498       * necessarily enforced, it is a usage error to fork a task more
499 <     * than once unless it has completed and been reinitialized.  This
500 <     * method may be invoked only from within ForkJoinTask
501 <     * computations (as may be determined using method {@link
502 <     * #inForkJoinPool}). Attempts to invoke in other contexts result
503 <     * in exceptions or errors possibly including ClassCastException.
504 <     */
505 <    public final void fork() {
506 <        ((ForkJoinWorkerThread)(Thread.currentThread())).pushTask(this);
499 >     * than once unless it has completed and been reinitialized.
500 >     *
501 >     * <p>This method may be invoked only from within {@code
502 >     * ForkJoinTask} computations (as may be determined using method
503 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
504 >     * result in exceptions or errors, possibly including {@code
505 >     * ClassCastException}.
506 >     *
507 >     * @return {@code this}, to simplify usage
508 >     */
509 >    public final ForkJoinTask<V> fork() {
510 >        ((ForkJoinWorkerThread) Thread.currentThread())
511 >            .pushTask(this);
512 >        return this;
513      }
514  
515      /**
516       * Returns the result of the computation when it is ready.
517 <     * This method differs from {@code get} in that abnormal
518 <     * completion results in RuntimeExceptions or Errors, not
519 <     * ExecutionExceptions.
517 >     * This method differs from {@link #get()} in that
518 >     * abnormal completion results in {@code RuntimeException} or
519 >     * {@code Error}, not {@code ExecutionException}.
520       *
521       * @return the computed result
522       */
# Line 523 | Line 543 | public abstract class ForkJoinTask<V> im
543      }
544  
545      /**
546 <     * Forks both tasks, returning when {@code isDone} holds for
547 <     * both of them or an exception is encountered. This method may be
548 <     * invoked only from within ForkJoinTask computations (as may be
549 <     * determined using method {@link #inForkJoinPool}). Attempts to
550 <     * invoke in other contexts result in exceptions or errors
551 <     * possibly including ClassCastException.
552 <     *
553 <     * @param t1 one task
554 <     * @param t2 the other task
555 <     * @throws NullPointerException if t1 or t2 are null
556 <     * @throws RuntimeException or Error if either task did so
546 >     * Forks the given tasks, returning when {@code isDone} holds
547 >     * for each task or an exception is encountered.
548 >     *
549 >     * <p>This method may be invoked only from within {@code
550 >     * ForkJoinTask} computations (as may be determined using method
551 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
552 >     * result in exceptions or errors, possibly including {@code
553 >     * ClassCastException}.
554 >     *
555 >     * @param t1 the first task
556 >     * @param t2 the second task
557 >     * @throws NullPointerException if any task is null
558 >     * @throws RuntimeException or Error if a task did so
559       */
560 <    public static void invokeAll(ForkJoinTask<?>t1, ForkJoinTask<?> t2) {
560 >    public static void invokeAll(ForkJoinTask<?> t1, ForkJoinTask<?> t2) {
561          t2.fork();
562          t1.invoke();
563          t2.join();
564      }
565  
566      /**
567 <     * Forks the given tasks, returning when {@code isDone} holds
568 <     * for all of them. If any task encounters an exception, others
569 <     * may be cancelled.  This method may be invoked only from within
570 <     * ForkJoinTask computations (as may be determined using method
571 <     * {@link #inForkJoinPool}). Attempts to invoke in other contexts
572 <     * result in exceptions or errors possibly including
573 <     * ClassCastException.
574 <     * @param tasks the array of tasks
567 >     * Forks the given tasks, returning when {@code isDone} holds for
568 >     * each task or an exception is encountered. If any task
569 >     * encounters an exception, others may be, but are not guaranteed
570 >     * to be, cancelled.
571 >     *
572 >     * <p>This method may be invoked only from within {@code
573 >     * ForkJoinTask} computations (as may be determined using method
574 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
575 >     * result in exceptions or errors, possibly including {@code
576 >     * ClassCastException}.
577 >     *
578 >     * @param tasks the tasks
579       * @throws NullPointerException if tasks or any element are null
580       * @throws RuntimeException or Error if any task did so
581       */
# Line 587 | Line 613 | public abstract class ForkJoinTask<V> im
613      }
614  
615      /**
616 <     * Forks all tasks in the collection, returning when
617 <     * {@code isDone} holds for all of them. If any task
618 <     * encounters an exception, others may be cancelled.  This method
619 <     * may be invoked only from within ForkJoinTask computations (as
620 <     * may be determined using method {@link
621 <     * #inForkJoinPool}). Attempts to invoke in other contexts resul!t
622 <     * in exceptions or errors possibly including ClassCastException.
616 >     * Forks all tasks in the specified collection, returning when
617 >     * {@code isDone} holds for each task or an exception is
618 >     * encountered.  If any task encounters an exception, others may
619 >     * be, but are not guaranteed to be, cancelled. The behavior of
620 >     * this operation is undefined if the specified collection is
621 >     * modified while the operation is in progress.
622 >     *
623 >     * <p>This method may be invoked only from within {@code
624 >     * ForkJoinTask} computations (as may be determined using method
625 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
626 >     * result in exceptions or errors, possibly including {@code
627 >     * ClassCastException}.
628       *
629       * @param tasks the collection of tasks
630 +     * @return the tasks argument, to simplify usage
631       * @throws NullPointerException if tasks or any element are null
632       * @throws RuntimeException or Error if any task did so
633       */
634 <    public static void invokeAll(Collection<? extends ForkJoinTask<?>> tasks) {
635 <        if (!(tasks instanceof List)) {
636 <            invokeAll(tasks.toArray(new ForkJoinTask[tasks.size()]));
637 <            return;
634 >    public static <T extends ForkJoinTask<?>> Collection<T> invokeAll(Collection<T> tasks) {
635 >        if (!(tasks instanceof RandomAccess) || !(tasks instanceof List<?>)) {
636 >            invokeAll(tasks.toArray(new ForkJoinTask<?>[tasks.size()]));
637 >            return tasks;
638          }
639 +        @SuppressWarnings("unchecked")
640          List<? extends ForkJoinTask<?>> ts =
641 <            (List<? extends ForkJoinTask<?>>)tasks;
641 >            (List<? extends ForkJoinTask<?>>) tasks;
642          Throwable ex = null;
643          int last = ts.size() - 1;
644          for (int i = last; i >= 0; --i) {
# Line 636 | Line 669 | public abstract class ForkJoinTask<V> im
669          }
670          if (ex != null)
671              rethrowException(ex);
672 +        return tasks;
673      }
674  
675      /**
676 <     * Returns true if the computation performed by this task has
677 <     * completed (or has been cancelled).
676 >     * Returns {@code true} if the computation performed by this task
677 >     * has completed (or has been cancelled).
678       *
679 <     * @return true if this computation has completed
679 >     * @return {@code true} if this computation has completed
680       */
681      public final boolean isDone() {
682          return status < 0;
683      }
684  
685      /**
686 <     * Returns true if this task was cancelled.
686 >     * Returns {@code true} if this task was cancelled.
687       *
688 <     * @return true if this task was cancelled
688 >     * @return {@code true} if this task was cancelled
689       */
690      public final boolean isCancelled() {
691          return (status & COMPLETION_MASK) == CANCELLED;
692      }
693  
694      /**
695 <     * Asserts that the results of this task's computation will not be
696 <     * used. If a cancellation occurs before attempting to execute this
697 <     * task, then execution will be suppressed, {@code isCancelled}
698 <     * will report true, and {@code join} will result in a
699 <     * {@code CancellationException} being thrown. Otherwise, when
700 <     * cancellation races with completion, there are no guarantees
701 <     * about whether {@code isCancelled} will report true, whether
668 <     * {@code join} will return normally or via an exception, or
669 <     * whether these behaviors will remain consistent upon repeated
670 <     * invocation.
695 >     * Attempts to cancel execution of this task. This attempt will
696 >     * fail if the task has already completed, has already been
697 >     * cancelled, or could not be cancelled for some other reason. If
698 >     * successful, and this task has not started when cancel is
699 >     * called, execution of this task is suppressed, {@link
700 >     * #isCancelled} will report true, and {@link #join} will result
701 >     * in a {@code CancellationException} being thrown.
702       *
703       * <p>This method may be overridden in subclasses, but if so, must
704       * still ensure that these minimal properties hold. In particular,
705 <     * the cancel method itself must not throw exceptions.
705 >     * the {@code cancel} method itself must not throw exceptions.
706       *
707 <     * <p> This method is designed to be invoked by <em>other</em>
707 >     * <p>This method is designed to be invoked by <em>other</em>
708       * tasks. To terminate the current task, you can just return or
709       * throw an unchecked exception from its computation method, or
710 <     * invoke {@code completeExceptionally}.
710 >     * invoke {@link #completeExceptionally}.
711       *
712       * @param mayInterruptIfRunning this value is ignored in the
713 <     * default implementation because tasks are not in general
714 <     * cancelled via interruption.
713 >     * default implementation because tasks are not
714 >     * cancelled via interruption
715       *
716 <     * @return true if this task is now cancelled
716 >     * @return {@code true} if this task is now cancelled
717       */
718      public boolean cancel(boolean mayInterruptIfRunning) {
719          setCompletion(CANCELLED);
# Line 690 | Line 721 | public abstract class ForkJoinTask<V> im
721      }
722  
723      /**
724 <     * Returns true if this task threw an exception or was cancelled.
724 >     * Returns {@code true} if this task threw an exception or was cancelled.
725       *
726 <     * @return true if this task threw an exception or was cancelled
726 >     * @return {@code true} if this task threw an exception or was cancelled
727       */
728      public final boolean isCompletedAbnormally() {
729          return (status & COMPLETION_MASK) < NORMAL;
# Line 700 | Line 731 | public abstract class ForkJoinTask<V> im
731  
732      /**
733       * Returns the exception thrown by the base computation, or a
734 <     * CancellationException if cancelled, or null if none or if the
735 <     * method has not yet completed.
734 >     * {@code CancellationException} if cancelled, or {@code null} if
735 >     * none or if the method has not yet completed.
736       *
737 <     * @return the exception, or null if none
737 >     * @return the exception, or {@code null} if none
738       */
739      public final Throwable getException() {
740          int s = status & COMPLETION_MASK;
# Line 720 | Line 751 | public abstract class ForkJoinTask<V> im
751       * {@code join} and related operations. This method may be used
752       * to induce exceptions in asynchronous tasks, or to force
753       * completion of tasks that would not otherwise complete.  Its use
754 <     * in other situations is likely to be wrong.  This method is
754 >     * in other situations is discouraged.  This method is
755       * overridable, but overridden versions must invoke {@code super}
756       * implementation to maintain guarantees.
757       *
# Line 730 | Line 761 | public abstract class ForkJoinTask<V> im
761       */
762      public void completeExceptionally(Throwable ex) {
763          setDoneExceptionally((ex instanceof RuntimeException) ||
764 <                             (ex instanceof Error)? ex :
764 >                             (ex instanceof Error) ? ex :
765                               new RuntimeException(ex));
766      }
767  
# Line 740 | Line 771 | public abstract class ForkJoinTask<V> im
771       * operations. This method may be used to provide results for
772       * asynchronous tasks, or to provide alternative handling for
773       * tasks that would not otherwise complete normally. Its use in
774 <     * other situations is likely to be wrong. This method is
774 >     * other situations is discouraged. This method is
775       * overridable, but overridden versions must invoke {@code super}
776       * implementation to maintain guarantees.
777       *
# Line 749 | Line 780 | public abstract class ForkJoinTask<V> im
780      public void complete(V value) {
781          try {
782              setRawResult(value);
783 <        } catch(Throwable rex) {
783 >        } catch (Throwable rex) {
784              setDoneExceptionally(rex);
785              return;
786          }
# Line 765 | Line 796 | public abstract class ForkJoinTask<V> im
796  
797      public final V get(long timeout, TimeUnit unit)
798          throws InterruptedException, ExecutionException, TimeoutException {
799 +        long nanos = unit.toNanos(timeout);
800          ForkJoinWorkerThread w = getWorker();
801          if (w == null || status < 0 || !w.unpushTask(this) || !tryQuietlyInvoke())
802 <            awaitDone(w, unit.toNanos(timeout));
802 >            awaitDone(w, nanos);
803          return reportTimedFutureResult();
804      }
805  
# Line 778 | Line 810 | public abstract class ForkJoinTask<V> im
810       * there are no potential dependencies between continuation of the
811       * current task and that of any other task that might be executed
812       * while helping. (This usually holds for pure divide-and-conquer
813 <     * tasks). This method may be invoked only from within
814 <     * ForkJoinTask computations (as may be determined using method
815 <     * {@link #inForkJoinPool}). Attempts to invoke in other contexts
816 <     * resul!t in exceptions or errors possibly including
817 <     * ClassCastException.
813 >     * tasks).
814 >     *
815 >     * <p>This method may be invoked only from within {@code
816 >     * ForkJoinTask} computations (as may be determined using method
817 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
818 >     * result in exceptions or errors, possibly including {@code
819 >     * ClassCastException}.
820       *
821       * @return the computed result
822       */
823      public final V helpJoin() {
824 <        ForkJoinWorkerThread w = (ForkJoinWorkerThread)(Thread.currentThread());
824 >        ForkJoinWorkerThread w = (ForkJoinWorkerThread) Thread.currentThread();
825          if (status < 0 || !w.unpushTask(this) || !tryExec())
826              reportException(busyJoin(w));
827          return getRawResult();
# Line 795 | Line 829 | public abstract class ForkJoinTask<V> im
829  
830      /**
831       * Possibly executes other tasks until this task is ready.  This
832 <     * method may be invoked only from within ForkJoinTask
833 <     * computations (as may be determined using method {@link
834 <     * #inForkJoinPool}). Attempts to invoke in other contexts resul!t
835 <     * in exceptions or errors possibly including ClassCastException.
832 >     * method may be useful when processing collections of tasks when
833 >     * some have been cancelled or otherwise known to have aborted.
834 >     *
835 >     * <p>This method may be invoked only from within {@code
836 >     * ForkJoinTask} computations (as may be determined using method
837 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
838 >     * result in exceptions or errors, possibly including {@code
839 >     * ClassCastException}.
840       */
841      public final void quietlyHelpJoin() {
842          if (status >= 0) {
843              ForkJoinWorkerThread w =
844 <                (ForkJoinWorkerThread)(Thread.currentThread());
844 >                (ForkJoinWorkerThread) Thread.currentThread();
845              if (!w.unpushTask(this) || !tryQuietlyInvoke())
846                  busyJoin(w);
847          }
# Line 837 | Line 875 | public abstract class ForkJoinTask<V> im
875  
876      /**
877       * Possibly executes tasks until the pool hosting the current task
878 <     * {@link ForkJoinPool#isQuiescent}. This method may be of use in
879 <     * designs in which many tasks are forked, but none are explicitly
880 <     * joined, instead executing them until all are processed.
878 >     * {@link ForkJoinPool#isQuiescent is quiescent}. This method may
879 >     * be of use in designs in which many tasks are forked, but none
880 >     * are explicitly joined, instead executing them until all are
881 >     * processed.
882 >     *
883 >     * <p>This method may be invoked only from within {@code
884 >     * ForkJoinTask} computations (as may be determined using method
885 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
886 >     * result in exceptions or errors, possibly including {@code
887 >     * ClassCastException}.
888       */
889      public static void helpQuiesce() {
890 <        ((ForkJoinWorkerThread)(Thread.currentThread())).
891 <            helpQuiescePool();
890 >        ((ForkJoinWorkerThread) Thread.currentThread())
891 >            .helpQuiescePool();
892      }
893  
894      /**
# Line 852 | Line 897 | public abstract class ForkJoinTask<V> im
897       * this task, but only if reuse occurs when this task has either
898       * never been forked, or has been forked, then completed and all
899       * outstanding joins of this task have also completed. Effects
900 <     * under any other usage conditions are not guaranteed, and are
901 <     * almost surely wrong. This method may be useful when executing
900 >     * under any other usage conditions are not guaranteed.
901 >     * This method may be useful when executing
902       * pre-constructed trees of subtasks in loops.
903       */
904      public void reinitialize() {
# Line 866 | Line 911 | public abstract class ForkJoinTask<V> im
911       * Returns the pool hosting the current task execution, or null
912       * if this task is executing outside of any ForkJoinPool.
913       *
914 <     * @return the pool, or null if none.
914 >     * @see #inForkJoinPool
915 >     * @return the pool, or {@code null} if none
916       */
917      public static ForkJoinPool getPool() {
918          Thread t = Thread.currentThread();
919 <        return ((t instanceof ForkJoinWorkerThread)?
920 <                ((ForkJoinWorkerThread)t).pool : null);
919 >        return (t instanceof ForkJoinWorkerThread) ?
920 >            ((ForkJoinWorkerThread) t).pool : null;
921      }
922  
923      /**
924 <     * Returns true if the current thread is executing as a
924 >     * Returns {@code true} if the current thread is executing as a
925       * ForkJoinPool computation.
926 <     * @return <code>true</code> if the current thread is executing as a
926 >     *
927 >     * @return {@code true} if the current thread is executing as a
928       * ForkJoinPool computation, or false otherwise
929       */
930      public static boolean inForkJoinPool() {
# Line 890 | Line 937 | public abstract class ForkJoinTask<V> im
937       * by the current thread, and has not commenced executing in
938       * another thread.  This method may be useful when arranging
939       * alternative local processing of tasks that could have been, but
940 <     * were not, stolen. This method may be invoked only from within
894 <     * ForkJoinTask computations (as may be determined using method
895 <     * {@link #inForkJoinPool}). Attempts to invoke in other contexts
896 <     * result in exceptions or errors possibly including
897 <     * ClassCastException.
940 >     * were not, stolen.
941       *
942 <     * @return true if unforked
942 >     * <p>This method may be invoked only from within {@code
943 >     * ForkJoinTask} computations (as may be determined using method
944 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
945 >     * result in exceptions or errors, possibly including {@code
946 >     * ClassCastException}.
947 >     *
948 >     * @return {@code true} if unforked
949       */
950      public boolean tryUnfork() {
951 <        return ((ForkJoinWorkerThread)(Thread.currentThread())).unpushTask(this);
951 >        return ((ForkJoinWorkerThread) Thread.currentThread())
952 >            .unpushTask(this);
953      }
954  
955      /**
# Line 908 | Line 958 | public abstract class ForkJoinTask<V> im
958       * value may be useful for heuristic decisions about whether to
959       * fork other tasks.
960       *
961 +     * <p>This method may be invoked only from within {@code
962 +     * ForkJoinTask} computations (as may be determined using method
963 +     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
964 +     * result in exceptions or errors, possibly including {@code
965 +     * ClassCastException}.
966 +     *
967       * @return the number of tasks
968       */
969      public static int getQueuedTaskCount() {
970 <        return ((ForkJoinWorkerThread)(Thread.currentThread())).
971 <            getQueueSize();
970 >        return ((ForkJoinWorkerThread) Thread.currentThread())
971 >            .getQueueSize();
972      }
973  
974      /**
# Line 925 | Line 981 | public abstract class ForkJoinTask<V> im
981       * tasks, and to process computations locally if this threshold is
982       * exceeded.
983       *
984 +     * <p>This method may be invoked only from within {@code
985 +     * ForkJoinTask} computations (as may be determined using method
986 +     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
987 +     * result in exceptions or errors, possibly including {@code
988 +     * ClassCastException}.
989 +     *
990       * @return the surplus number of tasks, which may be negative
991       */
992      public static int getSurplusQueuedTaskCount() {
993 <        return ((ForkJoinWorkerThread)(Thread.currentThread()))
993 >        return ((ForkJoinWorkerThread) Thread.currentThread())
994              .getEstimatedSurplusTaskCount();
995      }
996  
997      // Extension methods
998  
999      /**
1000 <     * Returns the result that would be returned by {@code join},
1001 <     * even if this task completed abnormally, or null if this task is
1002 <     * not known to have been completed.  This method is designed to
1003 <     * aid debugging, as well as to support extensions. Its use in any
1004 <     * other context is discouraged.
1000 >     * Returns the result that would be returned by {@link #join}, even
1001 >     * if this task completed abnormally, or {@code null} if this task
1002 >     * is not known to have been completed.  This method is designed
1003 >     * to aid debugging, as well as to support extensions. Its use in
1004 >     * any other context is discouraged.
1005       *
1006 <     * @return the result, or null if not completed
1006 >     * @return the result, or {@code null} if not completed
1007       */
1008      public abstract V getRawResult();
1009  
# Line 960 | Line 1022 | public abstract class ForkJoinTask<V> im
1022       * called otherwise. The return value controls whether this task
1023       * is considered to be done normally. It may return false in
1024       * asynchronous actions that require explicit invocations of
1025 <     * {@code complete} to become joinable. It may throw exceptions
1025 >     * {@link #complete} to become joinable. It may throw exceptions
1026       * to indicate abnormal exit.
1027       *
1028 <     * @return true if completed normally
1028 >     * @return {@code true} if completed normally
1029       * @throws Error or RuntimeException if encountered during computation
1030       */
1031      protected abstract boolean exec();
1032  
1033      /**
1034 <     * Returns, but does not unschedule or execute, the task queued by
1035 <     * the current thread but not yet executed, if one is
1034 >     * Returns, but does not unschedule or execute, a task queued by
1035 >     * the current thread but not yet executed, if one is immediately
1036       * available. There is no guarantee that this task will actually
1037 <     * be polled or executed next.  This method is designed primarily
1038 <     * to support extensions, and is unlikely to be useful otherwise.
1039 <     * This method may be invoked only from within ForkJoinTask
1040 <     * computations (as may be determined using method {@link
1041 <     * #inForkJoinPool}). Attempts to invoke in other contexts result
980 <     * in exceptions or errors possibly including ClassCastException.
1037 >     * be polled or executed next. Conversely, this method may return
1038 >     * null even if a task exists but cannot be accessed without
1039 >     * contention with other threads.  This method is designed
1040 >     * primarily to support extensions, and is unlikely to be useful
1041 >     * otherwise.
1042       *
1043 <     * @return the next task, or null if none are available
1043 >     * <p>This method may be invoked only from within {@code
1044 >     * ForkJoinTask} computations (as may be determined using method
1045 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
1046 >     * result in exceptions or errors, possibly including {@code
1047 >     * ClassCastException}.
1048 >     *
1049 >     * @return the next task, or {@code null} if none are available
1050       */
1051      protected static ForkJoinTask<?> peekNextLocalTask() {
1052 <        return ((ForkJoinWorkerThread)(Thread.currentThread())).peekTask();
1052 >        return ((ForkJoinWorkerThread) Thread.currentThread())
1053 >            .peekTask();
1054      }
1055  
1056      /**
1057       * Unschedules and returns, without executing, the next task
1058       * queued by the current thread but not yet executed.  This method
1059       * is designed primarily to support extensions, and is unlikely to
1060 <     * be useful otherwise.  This method may be invoked only from
1061 <     * within ForkJoinTask computations (as may be determined using
1062 <     * method {@link #inForkJoinPool}). Attempts to invoke in other
1063 <     * contexts result in exceptions or errors possibly including
1064 <     * ClassCastException.
1060 >     * be useful otherwise.
1061 >     *
1062 >     * <p>This method may be invoked only from within {@code
1063 >     * ForkJoinTask} computations (as may be determined using method
1064 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
1065 >     * result in exceptions or errors, possibly including {@code
1066 >     * ClassCastException}.
1067       *
1068 <     * @return the next task, or null if none are available
1068 >     * @return the next task, or {@code null} if none are available
1069       */
1070      protected static ForkJoinTask<?> pollNextLocalTask() {
1071 <        return ((ForkJoinWorkerThread)(Thread.currentThread())).pollLocalTask();
1071 >        return ((ForkJoinWorkerThread) Thread.currentThread())
1072 >            .pollLocalTask();
1073      }
1074  
1075      /**
# Line 1009 | Line 1080 | public abstract class ForkJoinTask<V> im
1080       * {@code null} result does not necessarily imply quiescence
1081       * of the pool this task is operating in.  This method is designed
1082       * primarily to support extensions, and is unlikely to be useful
1083 <     * otherwise.  This method may be invoked only from within
1013 <     * ForkJoinTask computations (as may be determined using method
1014 <     * {@link #inForkJoinPool}). Attempts to invoke in other contexts
1015 <     * result in exceptions or errors possibly including
1016 <     * ClassCastException.
1083 >     * otherwise.
1084       *
1085 <     * @return a task, or null if none are available
1085 >     * <p>This method may be invoked only from within {@code
1086 >     * ForkJoinTask} computations (as may be determined using method
1087 >     * {@link #inForkJoinPool}).  Attempts to invoke in other contexts
1088 >     * result in exceptions or errors, possibly including {@code
1089 >     * ClassCastException}.
1090 >     *
1091 >     * @return a task, or {@code null} if none are available
1092       */
1093      protected static ForkJoinTask<?> pollTask() {
1094 <        return ((ForkJoinWorkerThread)(Thread.currentThread())).
1095 <            pollTask();
1094 >        return ((ForkJoinWorkerThread) Thread.currentThread())
1095 >            .pollTask();
1096 >    }
1097 >
1098 >    /**
1099 >     * Adaptor for Runnables. This implements RunnableFuture
1100 >     * to be compliant with AbstractExecutorService constraints
1101 >     * when used in ForkJoinPool.
1102 >     */
1103 >    static final class AdaptedRunnable<T> extends ForkJoinTask<T>
1104 >        implements RunnableFuture<T> {
1105 >        final Runnable runnable;
1106 >        final T resultOnCompletion;
1107 >        T result;
1108 >        AdaptedRunnable(Runnable runnable, T result) {
1109 >            if (runnable == null) throw new NullPointerException();
1110 >            this.runnable = runnable;
1111 >            this.resultOnCompletion = result;
1112 >        }
1113 >        public T getRawResult() { return result; }
1114 >        public void setRawResult(T v) { result = v; }
1115 >        public boolean exec() {
1116 >            runnable.run();
1117 >            result = resultOnCompletion;
1118 >            return true;
1119 >        }
1120 >        public void run() { invoke(); }
1121 >        private static final long serialVersionUID = 5232453952276885070L;
1122 >    }
1123 >
1124 >    /**
1125 >     * Adaptor for Callables
1126 >     */
1127 >    static final class AdaptedCallable<T> extends ForkJoinTask<T>
1128 >        implements RunnableFuture<T> {
1129 >        final Callable<? extends T> callable;
1130 >        T result;
1131 >        AdaptedCallable(Callable<? extends T> callable) {
1132 >            if (callable == null) throw new NullPointerException();
1133 >            this.callable = callable;
1134 >        }
1135 >        public T getRawResult() { return result; }
1136 >        public void setRawResult(T v) { result = v; }
1137 >        public boolean exec() {
1138 >            try {
1139 >                result = callable.call();
1140 >                return true;
1141 >            } catch (Error err) {
1142 >                throw err;
1143 >            } catch (RuntimeException rex) {
1144 >                throw rex;
1145 >            } catch (Exception ex) {
1146 >                throw new RuntimeException(ex);
1147 >            }
1148 >        }
1149 >        public void run() { invoke(); }
1150 >        private static final long serialVersionUID = 2838392045355241008L;
1151 >    }
1152 >
1153 >    /**
1154 >     * Returns a new {@code ForkJoinTask} that performs the {@code run}
1155 >     * method of the given {@code Runnable} as its action, and returns
1156 >     * a null result upon {@link #join}.
1157 >     *
1158 >     * @param runnable the runnable action
1159 >     * @return the task
1160 >     */
1161 >    public static ForkJoinTask<?> adapt(Runnable runnable) {
1162 >        return new AdaptedRunnable<Void>(runnable, null);
1163 >    }
1164 >
1165 >    /**
1166 >     * Returns a new {@code ForkJoinTask} that performs the {@code run}
1167 >     * method of the given {@code Runnable} as its action, and returns
1168 >     * the given result upon {@link #join}.
1169 >     *
1170 >     * @param runnable the runnable action
1171 >     * @param result the result upon completion
1172 >     * @return the task
1173 >     */
1174 >    public static <T> ForkJoinTask<T> adapt(Runnable runnable, T result) {
1175 >        return new AdaptedRunnable<T>(runnable, result);
1176 >    }
1177 >
1178 >    /**
1179 >     * Returns a new {@code ForkJoinTask} that performs the {@code call}
1180 >     * method of the given {@code Callable} as its action, and returns
1181 >     * its result upon {@link #join}, translating any checked exceptions
1182 >     * encountered into {@code RuntimeException}.
1183 >     *
1184 >     * @param callable the callable action
1185 >     * @return the task
1186 >     */
1187 >    public static <T> ForkJoinTask<T> adapt(Callable<? extends T> callable) {
1188 >        return new AdaptedCallable<T>(callable);
1189      }
1190  
1191      // Serialization support
# Line 1030 | Line 1196 | public abstract class ForkJoinTask<V> im
1196       * Save the state to a stream.
1197       *
1198       * @serialData the current run status and the exception thrown
1199 <     * during execution, or null if none
1199 >     * during execution, or {@code null} if none
1200       * @param s the stream
1201       */
1202      private void writeObject(java.io.ObjectOutputStream s)
# Line 1051 | Line 1217 | public abstract class ForkJoinTask<V> im
1217          status |= EXTERNAL_SIGNAL; // conservatively set external signal
1218          Object ex = s.readObject();
1219          if (ex != null)
1220 <            setDoneExceptionally((Throwable)ex);
1220 >            setDoneExceptionally((Throwable) ex);
1221 >    }
1222 >
1223 >    // Unsafe mechanics
1224 >
1225 >    private static final sun.misc.Unsafe UNSAFE = getUnsafe();
1226 >    private static final long statusOffset =
1227 >        objectFieldOffset("status", ForkJoinTask.class);
1228 >
1229 >    private static long objectFieldOffset(String field, Class<?> klazz) {
1230 >        try {
1231 >            return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
1232 >        } catch (NoSuchFieldException e) {
1233 >            // Convert Exception to corresponding Error
1234 >            NoSuchFieldError error = new NoSuchFieldError(field);
1235 >            error.initCause(e);
1236 >            throw error;
1237 >        }
1238      }
1239  
1240 <    // Temporary Unsafe mechanics for preliminary release
1241 <    private static Unsafe getUnsafe() throws Throwable {
1240 >    /**
1241 >     * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package.
1242 >     * Replace with a simple call to Unsafe.getUnsafe when integrating
1243 >     * into a jdk.
1244 >     *
1245 >     * @return a sun.misc.Unsafe
1246 >     */
1247 >    private static sun.misc.Unsafe getUnsafe() {
1248          try {
1249 <            return Unsafe.getUnsafe();
1249 >            return sun.misc.Unsafe.getUnsafe();
1250          } catch (SecurityException se) {
1251              try {
1252                  return java.security.AccessController.doPrivileged
1253 <                    (new java.security.PrivilegedExceptionAction<Unsafe>() {
1254 <                        public Unsafe run() throws Exception {
1255 <                            return getUnsafePrivileged();
1253 >                    (new java.security
1254 >                     .PrivilegedExceptionAction<sun.misc.Unsafe>() {
1255 >                        public sun.misc.Unsafe run() throws Exception {
1256 >                            java.lang.reflect.Field f = sun.misc
1257 >                                .Unsafe.class.getDeclaredField("theUnsafe");
1258 >                            f.setAccessible(true);
1259 >                            return (sun.misc.Unsafe) f.get(null);
1260                          }});
1261              } catch (java.security.PrivilegedActionException e) {
1262 <                throw e.getCause();
1262 >                throw new RuntimeException("Could not initialize intrinsics",
1263 >                                           e.getCause());
1264              }
1265          }
1266      }
1073
1074    private static Unsafe getUnsafePrivileged()
1075            throws NoSuchFieldException, IllegalAccessException {
1076        Field f = Unsafe.class.getDeclaredField("theUnsafe");
1077        f.setAccessible(true);
1078        return (Unsafe) f.get(null);
1079    }
1080
1081    private static long fieldOffset(String fieldName)
1082            throws NoSuchFieldException {
1083        return UNSAFE.objectFieldOffset
1084            (ForkJoinTask.class.getDeclaredField(fieldName));
1085    }
1086
1087    static final Unsafe UNSAFE;
1088    static final long statusOffset;
1089
1090    static {
1091        try {
1092            UNSAFE = getUnsafe();
1093            statusOffset = fieldOffset("status");
1094        } catch (Throwable e) {
1095            throw new RuntimeException("Could not initialize intrinsics", e);
1096        }
1097    }
1098
1267   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines