Skip to content

Commit 4021033

Browse files
author
Viktor Klang
committed
8353659: SubmissionPublisherTest::testCap1Submit times out
Reviewed-by: dl, alanb
1 parent 60fbf73 commit 4021033

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,7 @@ final int queueSize() {
12781278
* @param internal if caller owns this queue
12791279
* @throws RejectedExecutionException if array could not be resized
12801280
*/
1281-
final void push(ForkJoinTask<?> task, ForkJoinPool pool,
1282-
boolean internal) {
1281+
final void push(ForkJoinTask<?> task, ForkJoinPool pool, boolean internal) {
12831282
int s = top, b = base, m, cap, room; ForkJoinTask<?>[] a;
12841283
if ((a = array) != null && (cap = a.length) > 0 && // else disabled
12851284
task != null) {
@@ -1383,8 +1382,7 @@ final boolean tryUnpush(ForkJoinTask<?> task, boolean internal) {
13831382
if (a != null && (cap = a.length) > 0 &&
13841383
U.getReference(a, k = slotOffset((cap - 1) & s)) == task &&
13851384
(internal || tryLockPhase())) {
1386-
if (top == p &&
1387-
U.compareAndSetReference(a, k, task, null)) {
1385+
if (top == p && U.compareAndSetReference(a, k, task, null)) {
13881386
taken = true;
13891387
updateTop(s);
13901388
}
@@ -2061,8 +2059,9 @@ private int deactivate(WorkQueue w, int phase) {
20612059
((e & SHUTDOWN) != 0L && ac == 0 && quiescent() > 0) ||
20622060
(qs = queues) == null || (n = qs.length) <= 0)
20632061
return IDLE; // terminating
2064-
int k = Math.max(n << 2, SPIN_WAITS << 1);
2065-
for (int prechecks = k / n;;) { // reactivation threshold
2062+
2063+
for (int prechecks = Math.min(ac, 2), // reactivation threshold
2064+
k = Math.max(n + (n << 1), SPIN_WAITS << 1);;) {
20662065
WorkQueue q; int cap; ForkJoinTask<?>[] a; long c;
20672066
if (w.phase == activePhase)
20682067
return activePhase;
@@ -2071,7 +2070,7 @@ private int deactivate(WorkQueue w, int phase) {
20712070
if ((q = qs[k & (n - 1)]) == null)
20722071
Thread.onSpinWait();
20732072
else if ((a = q.array) != null && (cap = a.length) > 0 &&
2074-
a[q.base & (cap - 1)] != null && --prechecks <= 0 &&
2073+
a[q.base & (cap - 1)] != null && --prechecks < 0 &&
20752074
(int)(c = ctl) == activePhase &&
20762075
compareAndSetCtl(c, (sp & LMASK) | ((c + RC_UNIT) & UMASK)))
20772076
return w.phase = activePhase; // reactivate

test/jdk/java/util/concurrent/tck/ForkJoinPool20Test.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ public void testScheduleWithFixedDelay_overflow() throws Exception {
528528
final CountDownLatch delayedDone = new CountDownLatch(1);
529529
final CountDownLatch immediateDone = new CountDownLatch(1);
530530
final ForkJoinPool p = new ForkJoinPool(2);
531+
p.cancelDelayedTasksOnShutdown();
531532
try (PoolCleaner cleaner = cleaner(p)) {
532533
final Runnable delayed = () -> {
533534
delayedDone.countDown();
@@ -568,8 +569,8 @@ public void testSubmitWithTimeoutCancels() throws InterruptedException {
568569
public Boolean call() throws Exception {
569570
Thread.sleep(LONGER_DELAY_MS); return Boolean.TRUE; }};
570571
ForkJoinTask<?> task = p.submitWithTimeout(c, 1, NANOSECONDS, null);
571-
Thread.sleep(timeoutMillis());
572-
assertTrue(task.isCancelled());
572+
while(!task.isCancelled())
573+
Thread.sleep(timeoutMillis());
573574
}
574575

575576
static final class SubmitWithTimeoutException extends RuntimeException {}
@@ -586,7 +587,6 @@ public Item call() throws Exception {
586587
c, 1, NANOSECONDS,
587588
(ForkJoinTask<Item> t) ->
588589
t.complete(two));
589-
Thread.sleep(timeoutMillis());
590590
assertEquals(task.join(), two);
591591
}
592592

@@ -602,7 +602,6 @@ public Boolean call() throws Exception {
602602
c, 1, NANOSECONDS,
603603
(ForkJoinTask<Boolean> t) ->
604604
t.completeExceptionally(new SubmitWithTimeoutException()));
605-
Thread.sleep(timeoutMillis());
606605
try {
607606
task.join();
608607
shouldThrow();

0 commit comments

Comments
 (0)