RFR 8207314 : Unnecessary reallocation when constructing WeakHashMap from a large Map

Ivan Gerasimov ivan.gerasimov at oracle.com
Sat Jul 14 05:22:52 UTC 2018


When a WeakHashMap is constructed from another Map m, then the initial 
capacity is calculated as

(int) (m.size() / DEFAULT_LOAD_FACTOR) + 1.

For large values of m.size() this becomes negative due to integer overflow.

The result is that the WeakHashMap is initially constructed with the 
default initial capacity 16, and then is immediately resized.

Would you please help review a trivial patch?

BUGURL: https://bugs.openjdk.java.net/browse/JDK-8207314
WEBREV: http://cr.openjdk.java.net/~igerasim/8207314/00/webrev/

Thanks in advance!

With kind regards,
Ivan Gerasimov

More information about the core-libs-dev mailing list