< prev index next >
test/jdk/java/lang/Character/UnicodeBlock/OptimalMapSize.java
Print this page
rev 52948 : 8215194: Initial size of UnicodeBlock map is incorrect
Reviewed-by: rriggs, rgoel
*** 21,39 ****
* questions.
*/
/**
* @test
! * @bug 8080535 8191410
* @summary Expected size of Character.UnicodeBlock.map is not optimal
* @library /test/lib
* @modules java.base/java.lang:open
* java.base/java.util:open
* @build jdk.test.lib.util.OptimalCapacity
* @run main OptimalMapSize
*/
import jdk.test.lib.util.OptimalCapacity;
// What will be the number of the Unicode blocks in the future.
//
// According to http://www.unicode.org/versions/Unicode7.0.0/ ,
--- 21,40 ----
* questions.
*/
/**
* @test
! * @bug 8080535 8191410 8215194
* @summary Expected size of Character.UnicodeBlock.map is not optimal
* @library /test/lib
* @modules java.base/java.lang:open
* java.base/java.util:open
* @build jdk.test.lib.util.OptimalCapacity
* @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.
//
// According to http://www.unicode.org/versions/Unicode7.0.0/ ,
*** 42,59 ****
// in Unicode 8 there will be added 10 more blocks (30 with aliases).
//
// After implementing support of Unicode 9 and 10 in Java, there will
// be 638 entries in Character.UnicodeBlock.map.
//
// Initialization of the map and this test will have to be adjusted
// accordingly then.
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);
OptimalCapacity.ofHashMap(Character.UnicodeBlock.class,
"map", initialCapacity);
}
}
--- 43,69 ----
// in Unicode 8 there will be added 10 more blocks (30 with aliases).
//
// 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
! 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);
}
}
< prev index next >