JDK-4500542 : (coll) WeakIdentityHashMap wanted
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 6
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic,linux,solaris_7,windows_xp
  • CPU: generic,x86
  • Submitted: 2001-09-06
  • Updated: 2018-09-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Related Reports
Duplicate :  
Relates :  
A weak identity hash map would be faster and more useful than the existing
weak hash map.  The ThreadLocal mechanism shows how well it can be implemented
(very fast in 1.4) and how useful it can be.  I have a similar need but I don't
want to spawn threads just to get the effect.  What I really need is a

Name: rmT116609			Date: 01/29/2003

In JDK1.4, we have

* IdentityHashMap: Which ignores hashCode() for the keys and always uses identityHashCode().

* WeakHashMap - which allows "non-intrusive object extension". The Javadoc says:
"This class is intended primarily for use with key objects whose equals methods test for object identity using the == operator".

However, if you have objects which do *not* test like this (e.g. all Collections!), you are out of luck (with the predefined classes).

It would make much sense to also provide a WeakIdentityHashMap which could be used with all keys according to the WeakHashMap documentation.

Implement your own IdentityWeakHashMap; you cannot use WeakHashMap or IdentityHashMap there - so you must start at a pretty basic level ...
(Review ID: 180535)

EVALUATION Jason Mehrens writes: "I hope that if any new Reference Map is added to the JDK it implements ConcurrentMap. The behavior of the weak/soft references exactly align with the behavior of the ConcurrentMap. Allowing null to be added to a reference or a ConcurrentMap has ambiguous meanings. The WeakHashMap methods read just like the ConcurrentMap wrt size, isEmpty, equals, hashCode. The WeakHashMap spec even implies that another thread (g.c) is using the map. A lot of the RFEs for new reference maps predate the ConcurrentMap. Maybe they will be updated to say ConcurrentMap instead of just Map someday."

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang

EVALUATION This is a reasonable RFE. The interesting question is, could a general purpose WeakIdentityHashMap be as fast as the custom implementation inside ThreadLocal (as of 1.4). ###@###.### 2001-09-10 At this point, the need for this functionality has been well-established. (Arguably we should have provided WeakIdentityHashMap rather than WeakhashMap in the first place.) ###@###.### 2003-01-29