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; |
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; |
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) { } |
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 { |
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); |
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 |
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 |
|
} |
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 |
|
} |
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 |
|
} |