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

Comparing jsr166/src/main/java/util/concurrent/CountedCompleter.java (file contents):
Revision 1.69 by dl, Fri Nov 27 17:41:59 2020 UTC vs.
Revision 1.70 by dl, Sun Nov 14 16:19:13 2021 UTC

# Line 6 | Line 6
6  
7   package java.util.concurrent;
8  
9 < import java.lang.invoke.MethodHandles;
10 < import java.lang.invoke.VarHandle;
9 > import jdk.internal.misc.Unsafe;
10  
11   /**
12   * A {@link ForkJoinTask} with a completion action performed when
# Line 509 | Line 508 | public abstract class CountedCompleter<T
508       * @param delta the value to add
509       */
510      public final void addToPendingCount(int delta) {
511 <        PENDING.getAndAdd(this, delta);
511 >        U.getAndAddInt(this, PENDING, delta);
512      }
513  
514      /**
# Line 521 | Line 520 | public abstract class CountedCompleter<T
520       * @return {@code true} if successful
521       */
522      public final boolean compareAndSetPendingCount(int expected, int count) {
523 <        return PENDING.compareAndSet(this, expected, count);
523 >        return U.compareAndSetInt(this, PENDING, expected, count);
524      }
525  
526      // internal-only weak version
527      final boolean weakCompareAndSetPendingCount(int expected, int count) {
528 <        return PENDING.weakCompareAndSet(this, expected, count);
528 >        return U.weakCompareAndSetInt(this, PENDING, expected, count);
529      }
530  
531      /**
# Line 748 | Line 747 | public abstract class CountedCompleter<T
747      @Override
748      protected void setRawResult(T t) { }
749  
750 <    // VarHandle mechanics
751 <    private static final VarHandle PENDING;
750 >    /*
751 >      This class uses
752 >     * jdk-internal Unsafe for atomics and special memory modes,
753 >     * rather than VarHandles, to avoid initialization dependencies in
754 >     * other jdk components that require early parallelism.
755 >     */
756 >    private static final Unsafe U;
757 >    private static final long PENDING;
758      static {
759 <        try {
760 <            MethodHandles.Lookup l = MethodHandles.lookup();
756 <            PENDING = l.findVarHandle(CountedCompleter.class, "pending", int.class);
757 <
758 <        } catch (ReflectiveOperationException e) {
759 <            throw new ExceptionInInitializerError(e);
760 <        }
759 >        U = Unsafe.getUnsafe();
760 >        PENDING = U.objectFieldOffset(CountedCompleter.class, "pending");
761      }
762   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines