Skip to content

Commit fbe4cc9

Browse files
author
Viktor Klang
committed
8336384: AbstractQueuedSynchronizer.acquire should cancel acquire when failing due to a LinkageError or other errors
Reviewed-by: alanb
1 parent ba69ed7 commit fbe4cc9

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,19 @@ final int acquire(Node node, long arg, boolean shared,
369369
} else if (node.status == 0) {
370370
node.status = WAITING; // enable signal and recheck
371371
} else {
372-
long nanos;
373372
spins = postSpins = (byte)((postSpins << 1) | 1);
374-
if (!timed)
375-
LockSupport.park(this);
376-
else if ((nanos = time - System.nanoTime()) > 0L)
377-
LockSupport.parkNanos(this, nanos);
378-
else
379-
break;
373+
try {
374+
long nanos;
375+
if (!timed)
376+
LockSupport.park(this);
377+
else if ((nanos = time - System.nanoTime()) > 0L)
378+
LockSupport.parkNanos(this, nanos);
379+
else
380+
break;
381+
} catch (Error | RuntimeException ex) {
382+
cancelAcquire(node, interrupted, interruptible); // cancel & rethrow
383+
throw ex;
384+
}
380385
node.clearStatus();
381386
if ((interrupted |= Thread.interrupted()) && interruptible)
382387
break;

src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -748,14 +748,19 @@ final int acquire(Node node, int arg, boolean shared,
748748
} else if (node.status == 0) {
749749
node.status = WAITING; // enable signal and recheck
750750
} else {
751-
long nanos;
752751
spins = postSpins = (byte)((postSpins << 1) | 1);
753-
if (!timed)
754-
LockSupport.park(this);
755-
else if ((nanos = time - System.nanoTime()) > 0L)
756-
LockSupport.parkNanos(this, nanos);
757-
else
758-
break;
752+
try {
753+
long nanos;
754+
if (!timed)
755+
LockSupport.park(this);
756+
else if ((nanos = time - System.nanoTime()) > 0L)
757+
LockSupport.parkNanos(this, nanos);
758+
else
759+
break;
760+
} catch (Error | RuntimeException ex) {
761+
cancelAcquire(node, interrupted, interruptible); // cancel & rethrow
762+
throw ex;
763+
}
759764
node.clearStatus();
760765
if ((interrupted |= Thread.interrupted()) && interruptible)
761766
break;

0 commit comments

Comments
 (0)