RFR: 8188055: (ref) Add Reference::refersTo predicate [v6]

Mandy Chung mchung at openjdk.java.net
Wed Nov 4 17:40:00 UTC 2020


On Wed, 4 Nov 2020 10:13:59 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Hello!
>> 
>> As an IDE developer, I'm thinking about IDE inspection that may suggest the new method. My idea is to suggest replacing every `ref.get() == obj` with `ref.refersTo(obj)`. Is this a good idea or there are cases when `ref.get() == obj` could be preferred? What do you think?
>
>> Hello!
>> 
>> As an IDE developer, I'm thinking about IDE inspection that may suggest the new method. My idea is to suggest replacing every `ref.get() == obj` with `ref.refersTo(obj)`. Is this a good idea or there are cases when `ref.get() == obj` could be preferred? What do you think?
> 
> Those have different behaviors when ref's class overrides get.  Sometimes that might be intentional (PhantomReference, where get blocks access to the referent, and SoftReference, where get may update heuristics for recent accesses delaying GC clearing).  But if some further subclass overrides get for some reason, such a change might not be appropriate.

Checking if a reference has been cleared i.e. `ref.get() == null` or `ref.get() != null` may benefit with IDE giving a hint.

-------------

PR: https://git.openjdk.java.net/jdk/pull/498


More information about the hotspot-gc-dev mailing list