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 |
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 |
|
/** |
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 |
|
/** |
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 |
|
} |