[lworld] RFR: 8286824: [valhalla] WeakHashMap for value classes
Roger Riggs
rriggs at openjdk.org
Thu Jun 30 14:08:38 UTC 2022
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.
-------------
Commit messages:
- Merge
- javadoc cleanup
- replace newIdentity with 'new Object()'
- fix NPE
- Merge branch 'lworld' into 8286824-weakhashmap
- Minor updates
- Implement enum ValuePolicy for WeakHashMap
- Implement enum ValuePolicy for WeakHashMap
Changes: https://git.openjdk.org/valhalla/pull/718/files
Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=718&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8286824
Stats: 427 lines in 3 files changed: 421 ins; 1 del; 5 mod
Patch: https://git.openjdk.org/valhalla/pull/718.diff
Fetch: git fetch https://git.openjdk.org/valhalla pull/718/head:pull/718
PR: https://git.openjdk.org/valhalla/pull/718
More information about the valhalla-dev
mailing list