On Fri, 4 Dec 2020 19:47:17 GMT, Peter Levart <plev...@openjdk.org> wrote:

>> This patch replaces some uses of `Reference::get` to `Reference::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 on `Reference::refersTo`.    
>> The remaining uses are left for the component owners to convert at 
>> appropriate time.
>
> src/java.management/share/classes/com/sun/jmx/mbeanserver/WeakIdentityHashMap.java
>  line 127:
> 
>> 125:             T got = get();
>> 126:             return got != null && wr.refersTo(got);
>> 127:         }
> 
> 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.

`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`.

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

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

Reply via email to