This is a SUNBUG for 100189: https://bugs.openjdk.java.net/show_bug.cgi?id=100189
Constructor does this:
public HashMap(int initialCapacity, float loadFactor) {
...
int capacity = 1;
while (capacity < initialCapacity)
capacity <<= 1;
...
}
It is magnitude+ faster to do this:
static final double LOG2 = Math.log(2.0);
public HashMap(int initialCapacity, float loadFactor) {
...
int capacity = 1 << ((int)Math.ceil(Math.log(initialCapacity)/LOG2 ));
...
}
Given the error checking in the head of the constructor, this code should just
plug-in.