Skip to content

Commit bcf15a7

Browse files
committed
Remove some synchronization in Reference to avoid deadlock
Issue #13823 Signed-off-by: Peter Shipton <[email protected]>
1 parent 752c652 commit bcf15a7

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

jcl/src/java.base/share/classes/java/lang/ref/Reference.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public abstract sealed class Reference<T> extends Object permits PhantomReferenc
6060

6161
private T referent;
6262
private ReferenceQueue queue;
63-
private int state;
63+
private volatile int state;
6464

6565
/* jdk.lang.ref.disableClearBeforeEnqueue property allow reverting to the old behavior(non clear before enqueue)
6666
* defer initializing the immutable variable to avoid bootstrap error
@@ -181,9 +181,7 @@ public T get() {
181181
@Deprecated(since="16")
182182
/*[ENDIF] JAVA_SPEC_VERSION >= 16 */
183183
public boolean isEnqueued () {
184-
synchronized(this) {
185-
return state == STATE_ENQUEUED;
186-
}
184+
return state == STATE_ENQUEUED;
187185
}
188186

189187
/**
@@ -255,10 +253,7 @@ void initReference (T r, ReferenceQueue q) {
255253
* Set the enqueued field to false.
256254
*/
257255
void dequeue() {
258-
/*[PR 112508] not synchronized, so isEnqueued() could return wrong result */
259-
synchronized(this) {
260-
state = STATE_CLEARED;
261-
}
256+
state = STATE_CLEARED;
262257
}
263258

264259
/*[IF JAVA_SPEC_VERSION >= 9]*/

0 commit comments

Comments
 (0)