[lworld] RFR: 8286824: [valhalla] WeakHashMap for value classes [v2]

Roger Riggs rriggs at openjdk.org
Mon Nov 21 17:47:07 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.

Roger Riggs has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 13 commits:

 - Merge branch 'lworld' into 8286824-weakhashmap
 - Fix bug when key is null.
   Change to throw IdentityException from WeakHashmap when
   a value object is put and the ValuePolicy is throw.
 - Merge branch 'lworld' into 8286824-weakhashmap
 - Merge branch 'lworld' into 8286824-weakhashmap
 - review comment updates
 - Merge
 - javadoc cleanup
 - replace newIdentity with 'new Object()'
 - fix NPE
 - Merge branch 'lworld' into 8286824-weakhashmap
 - ... and 3 more: https://git.openjdk.org/valhalla/compare/02e11831...bba71353

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

Changes: https://git.openjdk.org/valhalla/pull/718/files
 Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=718&range=01
  Stats: 466 lines in 3 files changed: 460 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