-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
8256167: Convert JDK use of Reference::get
to Reference::refersTo
#1609
Conversation
👋 Welcome back mchung! A progress list of the required criteria for merging this PR into |
|
@mlchung The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
/label remove hotspot-compiler |
@mlchung |
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.
Hi Mandy,
Looks good. I guess, you are going to update the copyright comments before the push.
Thanks,
Serguei
@mlchung This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 6 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
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.
Replacements look fine to me.
// keeping a strong reference to the entry's referent | ||
if (e.refersTo(key)) return true; | ||
|
||
// then checks for equality |
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.
Obnoxiously minor nit: plurality is inconsistent. check if the given entry...
above, and then check[s] for equality
. Should be ...then check for equality
?
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.
OK. Fixed this grammatical nit.
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.
Hi Mandy,
This looks good to me. There are a few places where a single call to Reference::get
is replaced by multiple calls to Reference::refersTo
, allowing the reference to get cleared in between, but as far as I could see that doesn't affect the overall logic which is still sound.
So LGTM!
best regards,
-- daniel
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.
Good to use this done in the same release as refersTo was added.
|
||
// then checks for equality | ||
Object k = e.get(); | ||
return key == k || key.equals(k); |
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 think key == k
is already covered by refersTo. But k could be null; checking for that here might be useful, to skip the call to equals in that case.
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.
Good point on checking k != null. A cleaner check:
// then check for equality if the referent is not cleared
Object k = e.get();
return k != null || key.equals(k);
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.
You meant: return k != null && key.equals(k);
right?
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.
oops...yes.
@SuppressWarnings("unchecked") | ||
IdentityWeakReference<T> wr = (IdentityWeakReference<T>) o; | ||
T got = get(); | ||
return got != null && wr.refersTo(got); | ||
} |
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.
Here you could pre-screen the get() with:
if (this.refersTo(null) != wr.refersTo(null)) return false;
In case one of the two WeakReference(s) is cleared and the other is not, they are not equal and you don't call this.get() in such case.
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.
expunge
is called at get
, put
, and remove
. While there is a chance that a referent might be cleared, I will leave this as is and this patch simply replaces to use refersTo
.
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.
You're right. Where it would matter is in expunge() where the Map keys that get polled off the reference queue are all already cleared and when HashMap.remove(key) is called with such cleared key, it is this cleared key that is the target of key.equals(other) method invocation (and not vice versa), so it doesn't matter if .get() is called on such key as it is already cleared.
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.
You have a typo that will cause a compilation error.
@@ -428,7 +434,7 @@ public boolean containsKey(Object key) { | |||
Entry<K,V>[] tab = getTable(); | |||
int index = indexFor(h, tab.length); | |||
Entry<K,V> e = tab[index]; | |||
while (e != null && !(e.hash == h && eq(k, e.get()))) | |||
while (e != null && !(e.hash == h && matchesKey(e, k)) |
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 doesn't compile, which is why the checks from the GitHub actions build failed.
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 caught that and it's in my local repo that I haven't pushed the commit. Sorry for not syncing my branch for review.
/integrate |
@mlchung Since your change was applied there have been 8 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 972bc3b. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This patch replaces some uses of
Reference::get
toReference::refersTo
to avoid keeping a referent strongly reachable that could cause unnecessary delay in collecting such object. I only made change in some but not all classes in core libraries when working with Kim onReference::refersTo
. The remaining uses are left for the component owners to convert at appropriate time.Progress
Issue
Reference::get
toReference::refersTo
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/1609/head:pull/1609
$ git checkout pull/1609