--- old/src/java.base/share/classes/java/lang/Character.java 2018-12-11 09:57:17.120304704 -0800 +++ new/src/java.base/share/classes/java/lang/Character.java 2018-12-11 09:57:15.805278106 -0800 @@ -681,11 +681,12 @@ */ public static final class UnicodeBlock extends Subset { /** - * 649 - the expected number of entities + * 667 - the expected number of entities * 0.75 - the default load factor of HashMap */ + private static final int MAP_CAPACITY = (int)(667 / 0.75f + 1.0f); private static Map map = - new HashMap<>((int)(649 / 0.75f + 1.0f)); + new HashMap<>(MAP_CAPACITY); /** * Creates a UnicodeBlock with the given identifier name. --- old/test/jdk/java/lang/Character/UnicodeBlock/OptimalMapSize.java 2018-12-11 09:57:23.791439636 -0800 +++ new/test/jdk/java/lang/Character/UnicodeBlock/OptimalMapSize.java 2018-12-11 09:57:22.693417427 -0800 @@ -23,7 +23,7 @@ /** * @test - * @bug 8080535 8191410 + * @bug 8080535 8191410 8215194 * @summary Expected size of Character.UnicodeBlock.map is not optimal * @library /test/lib * @modules java.base/java.lang:open @@ -32,6 +32,7 @@ * @run main OptimalMapSize */ +import java.lang.reflect.Field; import jdk.test.lib.util.OptimalCapacity; // What will be the number of the Unicode blocks in the future. @@ -43,15 +44,24 @@ // // After implementing support of Unicode 9 and 10 in Java, there will // be 638 entries in Character.UnicodeBlock.map. +// +// As of Unicode 11, 667 entries are expected. // // Initialization of the map and this test will have to be adjusted // accordingly then. +// +// Note that HashMap's implementation aligns the initial capacity to +// a power of two size, so it will end up 1024 (and thus succeed) in +// cases, such as 638 and 667. public class OptimalMapSize { public static void main(String[] args) throws Throwable { // The initial size of Character.UnicodeBlock.map. // See src/java.base/share/classes/java/lang/Character.java - int initialCapacity = (int)(638 / 0.75f + 1.0f); + Field f = Character.UnicodeBlock.class.getDeclaredField("MAP_CAPACITY"); + f.setAccessible(true); + int initialCapacity = f.getInt(null); + assert initialCapacity == (int)(667 / 0.75f + 1.0f); OptimalCapacity.ofHashMap(Character.UnicodeBlock.class, "map", initialCapacity);