On Thu, 24 Apr 2025 21:01:11 GMT, Erik Österlund <eosterl...@openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/util/ReferencedKeyMap.java line 355:
>> 
>>> 353:             if (referent == null) {
>>> 354:                 // We don't need this key anymore. Add to stale queue
>>> 355:                 ((Reference)key).enqueue();
>> 
>> Is enqueue necessary here? Afaik this map only uses the queue to be alert of 
>> member reference being garbage collected and then remove stale elements. 
>> Since at this stage this map is no longer used, maybe `key.unused()` is 
>> sufficient?
>
> I'm not sure what you are proposing. But enqueue is used to ensure that 
> inactive references are pruned from the data structure so that dumping only 
> includes active references. This way, the JVM that loads these objects create 
> these references as active and hence follow the usual life cycle that every 
> other reference does. I want to avoid having a new "special" life cycles for 
> dumped references.

The map is still being used (and will be stored into the AOT cache). The key no 
longer has a referent, so we need to remove the key from the map. Adding the 
key to the stale queue and calling `removeStaleReferences()` will accomplish 
this. `key.unused()` does not remove the key from the map.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24757#discussion_r2059235560

Reply via email to