Skip to content

Commit

Permalink
Ensure ReferenceQueue/Reference synchronization order in enqueueImpl
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Shipton <[email protected]>
  • Loading branch information
pshipton committed Nov 28, 2024
1 parent bcf15a7 commit 83e3657
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions jcl/src/java.base/share/classes/java/lang/ref/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,31 @@ public boolean isEnqueued () {
@NotCheckpointSafe
/*[ENDIF] CRIU_SUPPORT */
boolean enqueueImpl() {
final ReferenceQueue tempQueue;
boolean result;
T tempReferent = referent;
synchronized(this) {
/* Static order for the following code (DO NOT CHANGE) */
tempQueue = queue;
queue = null;
if (state == STATE_ENQUEUED || tempQueue == null) {
return false;
}
result = tempQueue.enqueue(this);
if (result) {
state = STATE_ENQUEUED;
if (null != tempReferent) {
reprocess();
ReferenceQueue tempQueue = queue;
while (true) {
synchronized(tempQueue) {
synchronized(this) {
if (tempQueue != queue) {
break;
}
/* Static order for the following code (DO NOT CHANGE) */
queue = null;
if (state == STATE_ENQUEUED || tempQueue == null) {
return false;
}
result = tempQueue.enqueue(this);
if (result) {
state = STATE_ENQUEUED;
if (null != tempReferent) {
reprocess();
}
}
return result;
}
}
return result;
tempQueue = queue;
}
}

Expand Down

0 comments on commit 83e3657

Please sign in to comment.