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.153 by jsr166, Wed Sep 29 03:40:19 2021 UTC vs.
Revision 1.154 by dl, Sun Nov 14 16:19:13 2021 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;
10   import java.lang.reflect.Constructor;
11   import java.util.Collection;
12   import java.util.List;
13   import java.util.RandomAccess;
14   import java.util.concurrent.locks.LockSupport;
15 + import jdk.internal.misc.Unsafe;
16  
17   /**
18   * Abstract base class for tasks that run within a {@link ForkJoinPool}.
# Line 189 | Line 188 | public abstract class ForkJoinTask<V> im
188       *
189       * Revision notes: The use of "Aux" field replaces previous
190       * reliance on a table to hold exceptions and synchronized blocks
191 <     * and monitors to wait for completion.
191 >     * and monitors to wait for completion. This class uses
192 >     * jdk-internal Unsafe for atomics and special memory modes,
193 >     * rather than VarHandles, to avoid initialization dependencies in
194 >     * other jdk components that require early parallelism.
195       */
196  
197      /**
# Line 206 | Line 208 | public abstract class ForkJoinTask<V> im
208              this.thread = thread;
209              this.ex = ex;
210          }
211 +        @SuppressWarnings("removal")
212          final boolean casNext(Aux c, Aux v) { // used only in cancellation
213 <            return NEXT.compareAndSet(this, c, v);
213 >            return U.compareAndSetObject(this, NEXT, c, v);
214          }
215 <        private static final VarHandle NEXT;
215 >        private static final Unsafe U;
216 >        private static final long NEXT;
217          static {
218 <            try {
219 <                NEXT = MethodHandles.lookup()
216 <                    .findVarHandle(Aux.class, "next", Aux.class);
217 <            } catch (ReflectiveOperationException e) {
218 <                throw new ExceptionInInitializerError(e);
219 <            }
218 >            U = Unsafe.getUnsafe();
219 >            NEXT = U.objectFieldOffset(Aux.class, "next");
220          }
221      }
222  
# Line 241 | Line 241 | public abstract class ForkJoinTask<V> im
241      private transient volatile Aux aux; // either waiters or thrown Exception
242  
243      // Support for atomic operations
244 <    private static final VarHandle STATUS;
245 <    private static final VarHandle AUX;
244 >    private static final Unsafe U;
245 >    private static final long STATUS;
246 >    private static final long AUX;
247      private int getAndBitwiseOrStatus(int v) {
248 <        return (int)STATUS.getAndBitwiseOr(this, v);
248 >        return U.getAndBitwiseOrInt(this, STATUS, v);
249      }
250      private boolean casStatus(int c, int v) {
251 <        return STATUS.compareAndSet(this, c, v);
251 >        return U.compareAndSetInt(this, STATUS, c, v);
252      }
253 +    @SuppressWarnings("removal")
254      private boolean casAux(Aux c, Aux v) {
255 <        return AUX.compareAndSet(this, c, v);
255 >        return U.compareAndSetObject(this, AUX, c, v);
256      }
257  
258      /** Removes and unparks waiters */
# Line 378 | Line 380 | public abstract class ForkJoinTask<V> im
380          }
381          else {
382              internal = false;
383 <            p = ForkJoinPool.common;
383 >            p = ForkJoinPool.commonPool();
384              if (pool == null)
385                  pool = p;
386              if (pool == p && p != null)
# Line 620 | Line 622 | public abstract class ForkJoinTask<V> im
622          if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread)
623              (w = (ForkJoinWorkerThread)t).workQueue.push(this, w.pool);
624          else
625 <            ForkJoinPool.common.externalPush(this);
625 >            ForkJoinPool.externalPushCommon(this);
626          return this;
627      }
628  
# Line 1041 | Line 1043 | public abstract class ForkJoinTask<V> im
1043              (p = (w = (ForkJoinWorkerThread)t).pool) != null)
1044              p.helpQuiescePool(w.workQueue, Long.MAX_VALUE, false);
1045          else
1046 <            ForkJoinPool.common.externalHelpQuiescePool(Long.MAX_VALUE, false);
1046 >            ForkJoinPool.commonPool().externalHelpQuiescePool(Long.MAX_VALUE, false);
1047      }
1048  
1049      /**
# Line 1553 | Line 1555 | public abstract class ForkJoinTask<V> im
1555      }
1556  
1557      static {
1558 <        try {
1559 <            MethodHandles.Lookup l = MethodHandles.lookup();
1560 <            STATUS = l.findVarHandle(ForkJoinTask.class, "status", int.class);
1559 <            AUX = l.findVarHandle(ForkJoinTask.class, "aux", Aux.class);
1560 <        } catch (ReflectiveOperationException e) {
1561 <            throw new ExceptionInInitializerError(e);
1562 <        }
1558 >        U = Unsafe.getUnsafe();
1559 >        STATUS = U.objectFieldOffset(ForkJoinTask.class, "status");
1560 >        AUX = U.objectFieldOffset(ForkJoinTask.class, "aux");
1561      }
1562  
1563   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines