[lworld] RFR: 8286824: [valhalla] WeakHashMap for value classes
Roger Riggs
rriggs at openjdk.org
Fri Jul 8 16:04:03 UTC 2022
On Thu, 7 Jul 2022 22:37:51 GMT, Mandy Chung <mchung at openjdk.org> wrote:
>> WeakHashMap uses WeakReference for keys, allowing it to retain only keys and values that are strongly referenced elsewhere.
>>
>> The behavior of WeakReference (or any Reference class) is not defined for value objects.
>>
>> Four (4) behaviors are proposed for WeakHashMap to give the developer a choice:
>> - SOFT - Keys that are value objects are retained until memory pressure clears soft references; then the keys that are value objects are removed automatically
>> - STRONG - Keys are value objects are retained until they are explicitly removed
>> - THROW - Keys that are value objects can not be put into the map; UnsupportedOperationException is thrown
>> - DISCARD - Keys that are value objects are silently discarded; as if they were removed immediately without being visible
>>
>> The default is SOFT - key/values are removed when there is memory pressure.
>> Entries will be removed automatically at some point, though less deterministically than with WeakReferences.
>
> src/java.base/share/classes/java/util/WeakHashMap.java line 46:
>
>> 44: * mapping for a given key will not prevent the key from being discarded by the
>> 45: * garbage collector, that is, made finalizable, finalized, and then reclaimed.
>> 46: * For keys that are {@linkplain Class#isValue() Value objects}, the retention of the
>
> should this be "value objects" rather than "Value objects"? This comment applies to all occurrences.
I was thinking there needs to be a link target that explains value objects. Class.isValue doesn't see quite the right one. But verbiage will be needed somewhere.
-------------
PR: https://git.openjdk.org/valhalla/pull/718
More information about the valhalla-dev
mailing list