1320 }
1321 }
1322 else
1323 h = b | Integer.MIN_VALUE; // to sense movement on re-poll
1324 return h;
1325 }
1326
1327 /**
1328 * Returns true if owned and not known to be blocked.
1329 */
1330 final boolean isApparentlyUnblocked() {
1331 Thread wt; Thread.State s;
1332 return (scanState >= 0 &&
1333 (wt = owner) != null &&
1334 (s = wt.getState()) != Thread.State.BLOCKED &&
1335 s != Thread.State.WAITING &&
1336 s != Thread.State.TIMED_WAITING);
1337 }
1338
1339 // Unsafe mechanics. Note that some are (and must be) the same as in FJP
1340 private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
1341 private static final long QLOCK;
1342 private static final int ABASE;
1343 private static final int ASHIFT;
1344 static {
1345 try {
1346 QLOCK = U.objectFieldOffset
1347 (WorkQueue.class.getDeclaredField("qlock"));
1348 ABASE = U.arrayBaseOffset(ForkJoinTask[].class);
1349 int scale = U.arrayIndexScale(ForkJoinTask[].class);
1350 if ((scale & (scale - 1)) != 0)
1351 throw new Error("array index scale not a power of two");
1352 ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
1353 } catch (ReflectiveOperationException e) {
1354 throw new Error(e);
1355 }
1356 }
1357 }
1358
1359 // static fields (initialized in static initializer below)
1360
3435 }
3436 else {
3437 do {} while (!blocker.isReleasable() &&
3438 !blocker.block());
3439 }
3440 }
3441
3442 // AbstractExecutorService overrides. These rely on undocumented
3443 // fact that ForkJoinTask.adapt returns ForkJoinTasks that also
3444 // implement RunnableFuture.
3445
3446 protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
3447 return new ForkJoinTask.AdaptedRunnable<T>(runnable, value);
3448 }
3449
3450 protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
3451 return new ForkJoinTask.AdaptedCallable<T>(callable);
3452 }
3453
3454 // Unsafe mechanics
3455 private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
3456 private static final long CTL;
3457 private static final long RUNSTATE;
3458 private static final int ABASE;
3459 private static final int ASHIFT;
3460
3461 static {
3462 try {
3463 CTL = U.objectFieldOffset
3464 (ForkJoinPool.class.getDeclaredField("ctl"));
3465 RUNSTATE = U.objectFieldOffset
3466 (ForkJoinPool.class.getDeclaredField("runState"));
3467 ABASE = U.arrayBaseOffset(ForkJoinTask[].class);
3468 int scale = U.arrayIndexScale(ForkJoinTask[].class);
3469 if ((scale & (scale - 1)) != 0)
3470 throw new Error("array index scale not a power of two");
3471 ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
3472 } catch (ReflectiveOperationException e) {
3473 throw new Error(e);
3474 }
3475
|
1320 }
1321 }
1322 else
1323 h = b | Integer.MIN_VALUE; // to sense movement on re-poll
1324 return h;
1325 }
1326
1327 /**
1328 * Returns true if owned and not known to be blocked.
1329 */
1330 final boolean isApparentlyUnblocked() {
1331 Thread wt; Thread.State s;
1332 return (scanState >= 0 &&
1333 (wt = owner) != null &&
1334 (s = wt.getState()) != Thread.State.BLOCKED &&
1335 s != Thread.State.WAITING &&
1336 s != Thread.State.TIMED_WAITING);
1337 }
1338
1339 // Unsafe mechanics. Note that some are (and must be) the same as in FJP
1340 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
1341 private static final long QLOCK;
1342 private static final int ABASE;
1343 private static final int ASHIFT;
1344 static {
1345 try {
1346 QLOCK = U.objectFieldOffset
1347 (WorkQueue.class.getDeclaredField("qlock"));
1348 ABASE = U.arrayBaseOffset(ForkJoinTask[].class);
1349 int scale = U.arrayIndexScale(ForkJoinTask[].class);
1350 if ((scale & (scale - 1)) != 0)
1351 throw new Error("array index scale not a power of two");
1352 ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
1353 } catch (ReflectiveOperationException e) {
1354 throw new Error(e);
1355 }
1356 }
1357 }
1358
1359 // static fields (initialized in static initializer below)
1360
3435 }
3436 else {
3437 do {} while (!blocker.isReleasable() &&
3438 !blocker.block());
3439 }
3440 }
3441
3442 // AbstractExecutorService overrides. These rely on undocumented
3443 // fact that ForkJoinTask.adapt returns ForkJoinTasks that also
3444 // implement RunnableFuture.
3445
3446 protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
3447 return new ForkJoinTask.AdaptedRunnable<T>(runnable, value);
3448 }
3449
3450 protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
3451 return new ForkJoinTask.AdaptedCallable<T>(callable);
3452 }
3453
3454 // Unsafe mechanics
3455 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
3456 private static final long CTL;
3457 private static final long RUNSTATE;
3458 private static final int ABASE;
3459 private static final int ASHIFT;
3460
3461 static {
3462 try {
3463 CTL = U.objectFieldOffset
3464 (ForkJoinPool.class.getDeclaredField("ctl"));
3465 RUNSTATE = U.objectFieldOffset
3466 (ForkJoinPool.class.getDeclaredField("runState"));
3467 ABASE = U.arrayBaseOffset(ForkJoinTask[].class);
3468 int scale = U.arrayIndexScale(ForkJoinTask[].class);
3469 if ((scale & (scale - 1)) != 0)
3470 throw new Error("array index scale not a power of two");
3471 ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
3472 } catch (ReflectiveOperationException e) {
3473 throw new Error(e);
3474 }
3475
|