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

Comparing jsr166/src/main/java/util/concurrent/ForkJoinTask.java (file contents):
Revision 1.108 by jsr166, Tue Apr 19 22:55:30 2016 UTC vs.
Revision 1.109 by dl, Thu Jun 2 13:16:27 2016 UTC

# Line 7 | Line 7
7   package java.util.concurrent;
8  
9   import java.io.Serializable;
10 + import java.lang.invoke.MethodHandles;
11 + import java.lang.invoke.VarHandle;
12   import java.lang.ref.ReferenceQueue;
13   import java.lang.ref.WeakReference;
14   import java.lang.reflect.Constructor;
# Line 230 | Line 232 | public abstract class ForkJoinTask<V> im
232          for (int s;;) {
233              if ((s = status) < 0)
234                  return s;
235 <            if (U.compareAndSwapInt(this, STATUS, s, s | completion)) {
235 >            if (STATUS.compareAndSet(this, s, s | completion)) {
236                  if ((s >>> 16) != 0)
237                      synchronized (this) { notifyAll(); }
238                  return completion;
# Line 268 | Line 270 | public abstract class ForkJoinTask<V> im
270      final void internalWait(long timeout) {
271          int s;
272          if ((s = status) >= 0 && // force completer to issue notify
273 <            U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) {
273 >            STATUS.compareAndSet(this, s, s | SIGNAL)) {
274              synchronized (this) {
275                  if (status >= 0)
276                      try { wait(timeout); } catch (InterruptedException ie) { }
# Line 290 | Line 292 | public abstract class ForkJoinTask<V> im
292          if (s >= 0 && (s = status) >= 0) {
293              boolean interrupted = false;
294              do {
295 <                if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) {
295 >                if (STATUS.compareAndSet(this, s, s | SIGNAL)) {
296                      synchronized (this) {
297                          if (status >= 0) {
298                              try {
# Line 324 | Line 326 | public abstract class ForkJoinTask<V> im
326                    ForkJoinPool.common.tryExternalUnpush(this) ? doExec() :
327                    0)) >= 0) {
328              while ((s = status) >= 0) {
329 <                if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) {
329 >                if (STATUS.compareAndSet(this, s, s | SIGNAL)) {
330                      synchronized (this) {
331                          if (status >= 0)
332                              wait(0L);
# Line 1002 | Line 1004 | public abstract class ForkJoinTask<V> im
1004                  while ((s = status) >= 0 &&
1005                         (ns = deadline - System.nanoTime()) > 0L) {
1006                      if ((ms = TimeUnit.NANOSECONDS.toMillis(ns)) > 0L &&
1007 <                        U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) {
1007 >                        STATUS.compareAndSet(this, s, s | SIGNAL)) {
1008                          synchronized (this) {
1009                              if (status >= 0)
1010                                  wait(ms); // OK to throw InterruptedException
# Line 1295 | Line 1297 | public abstract class ForkJoinTask<V> im
1297       */
1298      public final short setForkJoinTaskTag(short newValue) {
1299          for (int s;;) {
1300 <            if (U.compareAndSwapInt(this, STATUS, s = status,
1301 <                                    (s & ~SMASK) | (newValue & SMASK)))
1300 >            if (STATUS.compareAndSet(this, s = status,
1301 >                                     (s & ~SMASK) | (newValue & SMASK)))
1302                  return (short)s;
1303          }
1304      }
# Line 1319 | Line 1321 | public abstract class ForkJoinTask<V> im
1321          for (int s;;) {
1322              if ((short)(s = status) != expect)
1323                  return false;
1324 <            if (U.compareAndSwapInt(this, STATUS, s,
1325 <                                    (s & ~SMASK) | (update & SMASK)))
1324 >            if (STATUS.compareAndSet(this, s,
1325 >                                     (s & ~SMASK) | (update & SMASK)))
1326                  return true;
1327          }
1328      }
# Line 1481 | Line 1483 | public abstract class ForkJoinTask<V> im
1483              setExceptionalCompletion((Throwable)ex);
1484      }
1485  
1486 <    // Unsafe mechanics
1487 <    private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
1486 <    private static final long STATUS;
1487 <
1486 >    // VarHandle mechanics
1487 >    private static final VarHandle STATUS;
1488      static {
1489          exceptionTableLock = new ReentrantLock();
1490          exceptionTableRefQueue = new ReferenceQueue<Object>();
1491          exceptionTable = new ExceptionNode[EXCEPTION_MAP_CAPACITY];
1492          try {
1493 <            STATUS = U.objectFieldOffset
1494 <                (ForkJoinTask.class.getDeclaredField("status"));
1493 >            MethodHandles.Lookup l = MethodHandles.lookup();
1494 >            STATUS = l.findVarHandle(ForkJoinTask.class, "status", int.class);
1495          } catch (ReflectiveOperationException e) {
1496              throw new Error(e);
1497          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines