Path: blob/master/test/jdk/java/lang/String/concat/CompactStringsInitialCoder.java
41153 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @summary StringConcatFactory MH_INLINE_SIZED_EXACT strategy does not work with -XX:-CompactStrings26* @bug 814886927*28* @compile -XDstringConcat=indy CompactStringsInitialCoder.java29* @run main/othervm -Xverify:all -XX:+CompactStrings CompactStringsInitialCoder30*31* @compile -XDstringConcat=indyWithConstants CompactStringsInitialCoder.java32* @run main/othervm -Xverify:all -XX:+CompactStrings CompactStringsInitialCoder33*34* @compile -XDstringConcat=indy CompactStringsInitialCoder.java35* @run main/othervm -Xverify:all -XX:-CompactStrings CompactStringsInitialCoder36*37* @compile -XDstringConcat=indyWithConstants CompactStringsInitialCoder.java38* @run main/othervm -Xverify:all -XX:-CompactStrings CompactStringsInitialCoder39*/40import java.lang.StringBuilder;4142public class CompactStringsInitialCoder {4344static String strEmpty = "";45static String strLatin1 = "\u0042";46static String strUTF16 = "\u4242";47static char charLatin1 = '\u0042';48static char charUTF16 = '\u4242';4950public static void main(String[] args) throws Exception {51test("\u0042", "" + '\u0042');52test("\u4242", "" + '\u4242');5354test("\u0042", "" + charLatin1);55test("\u4242", "" + charUTF16);5657test("\u0042", strEmpty + '\u0042');58test("\u4242", strEmpty + '\u4242');5960test("\u0042\u0042", strLatin1 + '\u0042');61test("\u0042\u4242", strLatin1 + '\u4242');62test("\u4242\u0042", strUTF16 + '\u0042');63test("\u4242\u4242", strUTF16 + '\u4242');6465test("\u0042\u0042", "\u0042" + charLatin1);66test("\u0042\u4242", "\u0042" + charUTF16);67test("\u4242\u0042", "\u4242" + charLatin1);68test("\u4242\u4242", "\u4242" + charUTF16);6970test("\u0042\u0042", "" + charLatin1 + charLatin1);71test("\u0042\u4242", "" + charLatin1 + charUTF16);72test("\u4242\u0042", "" + charUTF16 + charLatin1);73test("\u4242\u4242", "" + charUTF16 + charUTF16);74}7576public static void test(String expected, String actual) {77if (!expected.equals(actual)) {78StringBuilder sb = new StringBuilder();79sb.append("Expected = ");80sb.append(expected);81sb.append(", actual = ");82sb.append(actual);83throw new IllegalStateException(sb.toString());84}85}868788}899091