1/* 2 * Copyright (c) 2016, 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 * @summary StringConcatFactory MH_INLINE_SIZED_EXACT strategy does not work with -XX:-CompactStrings 27 * @bug 8148869 28 * 29 * @compile -XDstringConcat=indy -source 1.9 -target 1.9 CompactStringsInitialCoder.java 30 * 31 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB -XX:+CompactStrings CompactStringsInitialCoder 32 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED -XX:+CompactStrings CompactStringsInitialCoder 33 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED -XX:+CompactStrings CompactStringsInitialCoder 34 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT -XX:+CompactStrings CompactStringsInitialCoder 35 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT -XX:+CompactStrings CompactStringsInitialCoder 36 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT -XX:+CompactStrings CompactStringsInitialCoder 37 * 38 * @compile -XDstringConcat=indyWithConstants -source 1.9 -target 1.9 CompactStringsInitialCoder.java 39 * 40 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB -XX:+CompactStrings CompactStringsInitialCoder 41 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED -XX:+CompactStrings CompactStringsInitialCoder 42 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED -XX:+CompactStrings CompactStringsInitialCoder 43 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT -XX:+CompactStrings CompactStringsInitialCoder 44 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT -XX:+CompactStrings CompactStringsInitialCoder 45 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT -XX:+CompactStrings CompactStringsInitialCoder 46 * 47 * @compile -XDstringConcat=indy -source 1.9 -target 1.9 CompactStringsInitialCoder.java 48 * 49 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB -XX:-CompactStrings CompactStringsInitialCoder 50 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED -XX:-CompactStrings CompactStringsInitialCoder 51 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED -XX:-CompactStrings CompactStringsInitialCoder 52 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT -XX:-CompactStrings CompactStringsInitialCoder 53 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT -XX:-CompactStrings CompactStringsInitialCoder 54 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT -XX:-CompactStrings CompactStringsInitialCoder 55 * 56 * @compile -XDstringConcat=indyWithConstants -source 1.9 -target 1.9 CompactStringsInitialCoder.java 57 * 58 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB -XX:-CompactStrings CompactStringsInitialCoder 59 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED -XX:-CompactStrings CompactStringsInitialCoder 60 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED -XX:-CompactStrings CompactStringsInitialCoder 61 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT -XX:-CompactStrings CompactStringsInitialCoder 62 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT -XX:-CompactStrings CompactStringsInitialCoder 63 * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT -XX:-CompactStrings CompactStringsInitialCoder 64*/ 65import java.lang.StringBuilder; 66 67public class CompactStringsInitialCoder { 68 69 static String strEmpty = ""; 70 static String strLatin1 = "\u0042"; 71 static String strUTF16 = "\u4242"; 72 static char charLatin1 = '\u0042'; 73 static char charUTF16 = '\u4242'; 74 75 public static void main(String[] args) throws Exception { 76 test("\u0042", "" + '\u0042'); 77 test("\u4242", "" + '\u4242'); 78 79 test("\u0042", "" + charLatin1); 80 test("\u4242", "" + charUTF16); 81 82 test("\u0042", strEmpty + '\u0042'); 83 test("\u4242", strEmpty + '\u4242'); 84 85 test("\u0042\u0042", strLatin1 + '\u0042'); 86 test("\u0042\u4242", strLatin1 + '\u4242'); 87 test("\u4242\u0042", strUTF16 + '\u0042'); 88 test("\u4242\u4242", strUTF16 + '\u4242'); 89 90 test("\u0042\u0042", "\u0042" + charLatin1); 91 test("\u0042\u4242", "\u0042" + charUTF16); 92 test("\u4242\u0042", "\u4242" + charLatin1); 93 test("\u4242\u4242", "\u4242" + charUTF16); 94 95 test("\u0042\u0042", "" + charLatin1 + charLatin1); 96 test("\u0042\u4242", "" + charLatin1 + charUTF16); 97 test("\u4242\u0042", "" + charUTF16 + charLatin1); 98 test("\u4242\u4242", "" + charUTF16 + charUTF16); 99 } 100 101 public static void test(String expected, String actual) { 102 if (!expected.equals(actual)) { 103 StringBuilder sb = new StringBuilder(); 104 sb.append("Expected = "); 105 sb.append(expected); 106 sb.append(", actual = "); 107 sb.append(actual); 108 throw new IllegalStateException(sb.toString()); 109 } 110 } 111 112 113} 114