1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8200696 27 * @summary Initial capacity of Class.enumConstantDirectory is not optimal 28 * @library /lib/testlibrary 29 * @modules java.base/java.lang:open 30 * java.base/java.util:open 31 * @build jdk.testlibrary.OptimalCapacity 32 * @run main ConstantDirectoryOptimalCapacity 33 */ 34 35 import jdk.testlibrary.OptimalCapacity; 36 37 public class ConstantDirectoryOptimalCapacity { 38 main(String[] args)39 public static void main(String[] args) throws Throwable { 40 test(E1.class); 41 test(E2.class); 42 test(E3.class); 43 test(E4.class); 44 test(E5.class); 45 test(E6.class); 46 test(E7.class); 47 test(E8.class); 48 test(E9.class); 49 test(E10.class); 50 test(E11.class); 51 test(E12.class); 52 test(E13.class); 53 test(E14.class); 54 test(E15.class); 55 test(E16.class); 56 test(E17.class); 57 test(E18.class); 58 test(E19.class); 59 test(E20.class); 60 test(E21.class); 61 test(E22.class); 62 test(E23.class); 63 test(E24.class); 64 test(E25.class); 65 test(E26.class); 66 } 67 test(Class<? extends Enum> e)68 private static void test(Class<? extends Enum> e) { 69 Enum.valueOf(e, "V0"); // trigger init of enumConstantDirectory 70 71 int initialCapacity = (int)(e.getEnumConstants().length / 0.75f) + 1; 72 OptimalCapacity.ofHashMap(e.getClass(), e, "enumConstantDirectory", 73 initialCapacity); 74 } 75 76 enum E1 { V0 } 77 enum E2 { V0, V1 } 78 enum E3 { V0, V1, V2 } 79 enum E4 { V0, V1, V2, V3 } 80 enum E5 { V0, V1, V2, V3, V4 } 81 enum E6 { V0, V1, V2, V3, V4, V5 } 82 enum E7 { V0, V1, V2, V3, V4, V5, V6 } 83 enum E8 { V0, V1, V2, V3, V4, V5, V6, V7 } 84 enum E9 { V0, V1, V2, V3, V4, V5, V6, V7, V8 } 85 enum E10 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9 } 86 enum E11 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10 } 87 enum E12 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11 } 88 enum E13 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12 } 89 enum E14 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13 } 90 enum E15 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 91 V14 } 92 enum E16 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 93 V14, V15 } 94 enum E17 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 95 V14, V15, V16 } 96 enum E18 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 97 V14, V15, V16, V17 } 98 enum E19 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 99 V14, V15, V16, V17, V18 } 100 enum E20 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 101 V14, V15, V16, V17, V18, V19 } 102 enum E21 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 103 V14, V15, V16, V17, V18, V19, V20 } 104 enum E22 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 105 V14, V15, V16, V17, V18, V19, V20, V21 } 106 enum E23 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 107 V14, V15, V16, V17, V18, V19, V20, V21, V22 } 108 enum E24 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 109 V14, V15, V16, V17, V18, V19, V20, V21, V22, V23 } 110 enum E25 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 111 V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24 } 112 enum E26 { V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, 113 V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25 } 114 } 115