-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove some synchronization in Reference to avoid deadlock #20694
base: master
Are you sure you want to change the base?
Conversation
jenkins test sanity plinux jdk8 |
The successful PR build https://openj9-jenkins.osuosl.org/job/PullRequest-OpenJ9/6578/ |
The deadlock happens because the two locks are acquired in different order in the two code paths.
Removing the |
The correct fix is to avoid the different order in which the two locks are acquired. Example: In
@dmitripivkine Does it matter if we move the dequeue operation at the end? Also, is there a requirement to |
Because this is a public class, we don't have complete control over the synchronization order. Removing synchronization in All of the uses of |
Once the |
I don't think the change to remove() is correct in #20694 (comment) I've pushed a new commit (I can squash before merge) to ensure lock ordering and consistency between enqueue and dequeue. |
|
jenkins test sanity plinux jdk8 |
/*[PR CMVC 96472] deadlock loading sun.misc.Cleaner */ | ||
/*[PR 102259] call Cleaner.clean(), do not enqueue */ | ||
if (reference instanceof Cleaner) { | ||
reference.dequeue(); | ||
((Cleaner)reference).clean(); | ||
return true; | ||
reference.setEnqueued(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this, and the other a few lines below, should be removed, but it's what was done previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want this call to setEnqueued()
, nor the one on line 213.
/*[PR CMVC 96472] deadlock loading sun.misc.Cleaner */ | ||
/*[PR 102259] call Cleaner.clean(), do not enqueue */ | ||
if (reference instanceof Cleaner) { | ||
reference.dequeue(); | ||
((Cleaner)reference).clean(); | ||
return true; | ||
reference.setEnqueued(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want this call to setEnqueued()
, nor the one on line 213.
} | ||
|
||
/** | ||
* Called when a Reference has been added to it's ReferenceQueue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct the spelling of "its".
Previous PR build https://openj9-jenkins.osuosl.org/job/PullRequest-OpenJ9/6597/ passed. |
jenkins compile plinux jdk8 |
jenkins compile plinux jdk11 |
Just some known problems in the test results, the non-network failures passed in reruns. |
7ffa7c4
to
2ecb6c9
Compare
jenkins compile plinux jdk8,jdk21 |
jcl/src/java.base/share/classes/java/lang/ref/ReferenceQueue.java
Outdated
Show resolved
Hide resolved
|
jenkins compile amac jdk21 |
Created ibmruntimes/openj9-openjdk-jdk#900 and a backport for jdk23. I accidentally pushed the same change to jdk21. We shouldn't remove the constructor until z/OS and valhalla are also updated. |
T tempReferent = referent; | ||
synchronized(this) { | ||
/* Static order for the following code (DO NOT CHANGE) */ | ||
tempQueue = queue; | ||
final ReferenceQueue tempQueue = queue; | ||
queue = null; | ||
if (state == STATE_ENQUEUED || tempQueue == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this test could be reordered to (sometimes) avoid a volatile read of state
?
if ((null == tempQueue) || (STATE_ENQUEUED == state)) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and again
reprocess(); | ||
} | ||
tempQueue.enqueue(this); | ||
if (null != tempReferent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 200 and 204 should be consistent: the null
(or the constant) go on the left or the right, but not a mix of both, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STATE_ENQUEUED
is also a constant: it should go on the left just like null
.
reprocess(); | ||
} | ||
tempQueue.enqueue(this); | ||
if (null != tempReferent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STATE_ENQUEUED
is also a constant: it should go on the left just like null
.
ReferenceQueue(int value) { | ||
this(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constructor can also be removed now that ibmruntimes/openj9-openjdk-jdk#899 and back-ports have been merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, see #20694 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I didn't consider z/OS or Valhalla.
Issue eclipse-openj9#13823 Signed-off-by: Peter Shipton <[email protected]>
Signed-off-by: Peter Shipton <[email protected]>
Issue #13823