RFR 8200696 : Optimal initial capacity of java.lang.Class.enumConstantDirectory

David Holmes david.holmes at oracle.com
Tue Apr 3 23:49:20 UTC 2018

Hi Ivan,

On 4/04/2018 9:22 AM, Ivan Gerasimov wrote:
> Hello!
> Yet another occurrence of not-optimally pre-sized HashMap.
> When java.lang.Class.enumConstantDirectory is created, the initial 
> capacity is set to be (2 * universe.length), which is more than 
> necessary in some cases.
> Choosing the capacity optimally will allow us to save a few bytes with 
> some enum classes.

How are you defining optimal? The bug report only gives one example 
where the current calculation produces a too large value. If the HashMap 
itself rounds up the initial capacity to a power of 2, how much extra 
space do we need compared to universe.length? Do we just need to pass 
(universe.length+1) to get the smallest power of 2 greater than 


> Would you please help review this trivial fix?
> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8200696
> WEBREV: http://cr.openjdk.java.net/~igerasim/8200696/00/webrev/

More information about the core-libs-dev mailing list