hotspot/test/compiler/intrinsics/string/TestStringIntrinsics.java
author zmajo
Thu, 24 Mar 2016 11:44:12 +0100
changeset 36813 19edb36ba72a
parent 33628 09241459a8b8
child 40059 c2304140ed64
permissions -rw-r--r--
8152640: Quarantine compiler/intrinsics/string/TestHasNegatives.java Summary: Quarantine test Reviewed-by: thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     1
/*
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     4
 *
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     8
 *
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    13
 * accompanied this code).
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    14
 *
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    18
 *
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    21
 * questions.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    22
 */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    23
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    24
import java.lang.annotation.*;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    25
import java.lang.reflect.*;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    26
import java.util.Arrays;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    27
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    28
/*
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    29
 * @test
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    30
 * @bug 8054307
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    31
 * @summary Tests correctness of string related intrinsics and C2 optimizations.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    32
 * @run main/timeout=240 TestStringIntrinsics
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    33
 */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    34
public class TestStringIntrinsics {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    35
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    36
    public enum Operation {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    37
        ARR_EQUALS_B, ARR_EQUALS_C, EQUALS, COMPARE_TO, INDEX_OF, INDEX_OF_CON_U, INDEX_OF_CON_L,
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    38
        INDEX_OF_CON_UL, CONCAT, CONCAT_C, CONCAT_I, CONCAT_M, INDEX_OF_CHAR
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    39
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    40
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    41
    @Retention(RetentionPolicy.RUNTIME)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    42
    @Target(ElementType.METHOD)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    43
    @interface Test {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    44
        Operation op();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    45
        String constString() default "";
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    46
        String[] inStrings() default {};
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    47
        char[] inChars() default {};
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    48
        int[] inInts() default {};
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    49
        String[] outStrings() default {};
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    50
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    51
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    52
    public static void main(String[] args) throws Exception {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    53
        new TestStringIntrinsics().run();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    54
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    55
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    56
    public void run() throws Exception {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    57
        // Build latin1 and UTF16 strings
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    58
        StringBuilder latin1Builder = new StringBuilder();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    59
        for (int i = 0; i <= 255; ++i) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    60
            latin1Builder.append((char) i);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    61
        }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    62
        String latin1 = latin1Builder.toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    63
        StringBuilder utf16Builder = new StringBuilder();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    64
        for (int i = 0; i <= 10000; ++i) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    65
            utf16Builder.append((char) i);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    66
        }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    67
        String utf16 = utf16Builder.toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    68
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    69
        // Invoke test methods
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    70
        for (Method m : TestStringIntrinsics.class.getMethods()) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    71
            if (m.isAnnotationPresent(Test.class)) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    72
                System.out.print("Checking " + m.getName() + "... ");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    73
                Operation op = m.getAnnotation(Test.class).op();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    74
                Test antn = m.getAnnotation(Test.class);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    75
                if (isStringConcatTest(op)) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    76
                    checkStringConcat(op, m, antn);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    77
                } else {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    78
                    checkIntrinsics(op, m, latin1, utf16, antn);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    79
                }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    80
                System.out.println("Done.");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    81
            }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    82
        }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    83
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    84
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    85
    private boolean isStringConcatTest(Operation op) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    86
        return op == Operation.CONCAT ||
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    87
               op == Operation.CONCAT_C ||
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    88
               op == Operation.CONCAT_I ||
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    89
               op == Operation.CONCAT_M;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    90
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    91
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    92
    /**
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    93
     * Checks correctness of the String.equals, String.compareTo and String.indexOf intrinsics.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    94
     * -XX:SpecialStringEquals
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    95
     * -XX:SpecialStringCompareTo
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    96
     * -XX:SpecialStringIndexOf
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    97
     */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    98
    private void checkIntrinsics(Operation op, Method m, String latin1, String utf16, Test antn) throws Exception {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    99
        for (int i = 0; i < 50_000; ++i) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   100
            // Copy and permute latin1 and UTF16 string
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   101
            char[] arrL = latin1.toCharArray();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   102
            int indexL = i % arrL.length;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   103
            int mod = (arrL.length - arrL[indexL]);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   104
            int incL = i % ((mod != 0) ? mod : 1);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   105
            arrL[indexL] = (char) ((int) arrL[indexL] + incL);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   106
            String latin1Copy = String.valueOf(arrL);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   107
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   108
            char[] arrU = utf16.toCharArray();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   109
            int indexU = i % arrU.length;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   110
            mod = (arrU.length - arrU[indexU]);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   111
            int incU = i % ((mod != 0) ? mod : 1);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   112
            arrU[indexU] = (char) ((int) arrU[indexU] + incU);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   113
            String utf16Copy = String.valueOf(arrU);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   114
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   115
            switch (op) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   116
            case ARR_EQUALS_B:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   117
                invokeAndCheck(m, (incL == 0), latin1.getBytes("ISO-8859-1"), latin1Copy.getBytes("ISO-8859-1"));
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   118
                invokeAndCheck(m, true, new byte[] {1, 2, 3}, new byte[] {1, 2, 3});
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   119
                invokeAndCheck(m, true, new byte[] {1}, new byte[] {1});
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   120
                invokeAndCheck(m, true, new byte[] {}, new byte[] {});
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   121
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   122
            case ARR_EQUALS_C:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   123
                invokeAndCheck(m, (incU == 0), utf16.toCharArray(), arrU);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   124
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   125
            case EQUALS:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   126
                invokeAndCheck(m, (incL == 0), latin1, latin1Copy);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   127
                invokeAndCheck(m, false, latin1, "");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   128
                invokeAndCheck(m, false, "", latin1);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   129
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   130
                invokeAndCheck(m, (incU == 0), utf16, utf16Copy);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   131
                invokeAndCheck(m, false, utf16, "");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   132
                invokeAndCheck(m, false, "", utf16);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   133
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   134
                invokeAndCheck(m, false, latin1, utf16);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   135
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   136
            case COMPARE_TO:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   137
                invokeAndCheck(m, -incL, latin1, latin1Copy);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   138
                invokeAndCheck(m, latin1.length(), latin1, "");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   139
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   140
                invokeAndCheck(m, -incU, utf16, utf16Copy);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   141
                invokeAndCheck(m, utf16.length(), utf16, "");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   142
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   143
                // Cross coder
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   144
                char cL = latin1.charAt(indexL);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   145
                char cU = utf16.charAt(indexU);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   146
                invokeAndCheck(m, cL - cU, latin1, latin1.replace(cL, cU));
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   147
                invokeAndCheck(m, cU - cL, utf16, utf16.replace(cU, cL));
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   148
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   149
                // Different lengths
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   150
                invokeAndCheck(m, 1, "ABCD", "ABC");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   151
                invokeAndCheck(m, -1, "\uff21\uff22\uff23", "\uff21\uff22\uff23\uff24");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   152
                invokeAndCheck(m, 1, "ABC\uff24", "ABC");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   153
                invokeAndCheck(m, 3, "ABC\uff24\uff25\uff26", "ABC");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   154
                invokeAndCheck(m, -1, "ABC","ABC\uff24");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   155
                invokeAndCheck(m, -3, "ABC","ABC\uff24\uff25\uff26");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   156
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   157
            case INDEX_OF:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   158
                invokeAndCheck(m, indexL, latin1, latin1.substring(indexL), (indexL > 42) ? 42 : 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   159
                invokeAndCheck(m, 0, latin1, "", 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   160
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   161
                invokeAndCheck(m, indexU, utf16, utf16.substring(indexU), (indexU > 42) ? 42 : 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   162
                invokeAndCheck(m, 0, utf16, "", 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   163
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   164
                // Cross coder
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   165
                invokeAndCheck(m, -1, latin1.substring(0, indexL), utf16.substring(indexU), (indexL > 42) ? 42 : 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   166
                // Skip latin1 chars in utf16 string
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   167
                int start = 256;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   168
                int end = indexU > start ? indexU : start;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   169
                invokeAndCheck(m, end-start, utf16.substring(start, end) + latin1.substring(indexL), latin1.substring(indexL), 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   170
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   171
            case INDEX_OF_CON_L:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   172
                invokeAndCheck(m, antn.constString(), latin1);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   173
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   174
            case INDEX_OF_CON_U:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   175
                invokeAndCheck(m, antn.constString(), utf16);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   176
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   177
            case INDEX_OF_CON_UL:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   178
                invokeAndCheck(m, antn.constString(), utf16);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   179
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   180
            case INDEX_OF_CHAR:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   181
                invokeAndCheck(m, 7, "abcdefg\uD800\uDC00", 65536, 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   182
                invokeAndCheck(m, -1, "abcdefg\uD800\uDC01", 65536, 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   183
                invokeAndCheck(m, -1, "abcdefg\uD800", 65536, 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   184
                invokeAndCheck(m, 3, "abc\u0107", 263, 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   185
                invokeAndCheck(m, -1, "abc\u0108", 263, 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   186
                invokeAndCheck(m, 7, "abcdefg\u0107", 263, 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   187
                invokeAndCheck(m, 7, "abcdefg\u0107", 263, -1);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   188
                invokeAndCheck(m, 0, "\u0107", 263, 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   189
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   190
            default:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   191
                throw new RuntimeException("Unexpected operation.");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   192
            }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   193
        }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   194
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   195
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   196
    /**
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   197
     * Checks correctness of the C2 string concatenation optimization.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   198
     * -XX:OptimizeStringConcat
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   199
     */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   200
    private void checkStringConcat(Operation op, Method m, Test antn) throws Exception {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   201
        for (int i = 0; i < 50_000; ++i) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   202
            String[] result = antn.outStrings();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   203
            switch(op) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   204
            case CONCAT:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   205
                String[] strs = antn.inStrings();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   206
                for (int j = 0; j < strs.length; ++j) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   207
                    invokeAndCheck(m, result[j], strs[j]);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   208
                }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   209
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   210
            case CONCAT_C:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   211
                char[] ch = antn.inChars();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   212
                for (int j = 0; j < ch.length; ++j) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   213
                    invokeAndCheck(m, result[j], ch[j]);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   214
                }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   215
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   216
            case CONCAT_I:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   217
                int[] k = antn.inInts();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   218
                for (int j = 0; j < k.length; ++j) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   219
                    invokeAndCheck(m, result[j], k[j]);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   220
                }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   221
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   222
            case CONCAT_M:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   223
                strs = antn.inStrings();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   224
                ch = antn.inChars();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   225
                k = antn.inInts();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   226
                for (int j = 0; j < strs.length; ++j) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   227
                    invokeAndCheck(m, result[j], strs[j], ch[j], k[j]);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   228
                }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   229
                break;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   230
            default:
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   231
                throw new RuntimeException("Unexpected operation.");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   232
            }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   233
        }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   234
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   235
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   236
    /**
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   237
     * Invokes method 'm' by passing arguments 'args' and checks if the
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   238
     * returned value equals 'expectedResult'.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   239
     */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   240
    private void invokeAndCheck(Method m, Object expectedResult, Object... args) throws Exception {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   241
        Object result = m.invoke(null, args);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   242
        if (!result.equals(expectedResult)) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   243
//            System.out.println("Expected:");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   244
//            System.out.println(expectedResult);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   245
//            System.out.println("Returned:");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   246
//            System.out.println(result);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   247
            throw new RuntimeException("Result of '" + m.getName() + "' not equal to expected value.");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   248
        }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   249
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   250
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   251
    /*
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   252
     * Constants
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   253
     */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   254
    static final char charU = '\uff21';
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   255
    static final char charL = 'A';
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   256
    static final String emptyString = "";
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   257
    static final String stringL = "abcdefghijklmnop";
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   258
    static final String stringSmallL = "abc";
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   259
    static final String stringU = "\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28";
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   260
    static final String stringSmallU = "\u0f21\u0f22\u0f23";
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   261
    static final int constInt = 123;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   262
    static final int constIntNeg = -123;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   263
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   264
    /*
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   265
     * Arrays.equals
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   266
     */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   267
    @Test(op = Operation.ARR_EQUALS_B)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   268
    public static boolean arrayEqualsB(byte[] a, byte[] b) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   269
      return Arrays.equals(a, b);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   270
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   271
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   272
    @Test(op = Operation.ARR_EQUALS_C)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   273
    public static boolean arrayEqualsC(char[] a, char[] b) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   274
      return Arrays.equals(a, b);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   275
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   276
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   277
    /*
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   278
     * String.equals
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   279
     */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   280
    @Test(op = Operation.EQUALS)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   281
    public static boolean equals(String a, String b) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   282
        return a.equals(b);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   283
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   284
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   285
    /*
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   286
     * String.compareTo
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   287
     */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   288
    @Test(op = Operation.COMPARE_TO)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   289
    public static int compareTo(String a, String b) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   290
        return a.compareTo(b);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   291
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   292
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   293
    /*
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   294
     * String.indexOf
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   295
     */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   296
    @Test(op = Operation.INDEX_OF)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   297
    public static int indexOf(String a, String b, int from) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   298
        return a.indexOf(b, from);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   299
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   300
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   301
    @Test(op = Operation.INDEX_OF_CON_U, constString = stringSmallU)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   302
    public static String indexOfConstU(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   303
        int result = a.indexOf(stringSmallU);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   304
        return a.substring(result, result + stringSmallU.length());
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   305
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   306
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   307
    @Test(op = Operation.INDEX_OF_CON_U, constString = stringU)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   308
    public static String indexOfConstLargeU(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   309
        int result = a.indexOf(stringU);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   310
        return a.substring(result, result + stringU.length());
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   311
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   312
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   313
    @Test(op = Operation.INDEX_OF_CON_U, constString = emptyString)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   314
    public static String indexOfConstEmptyU(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   315
        int result = a.indexOf(emptyString);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   316
        return a.substring(result, result + emptyString.length());
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   317
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   318
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   319
    @Test(op = Operation.INDEX_OF_CON_L, constString = stringSmallL)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   320
    public static String indexOfConstL(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   321
        int result = a.indexOf(stringSmallL);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   322
        return a.substring(result, result + stringSmallL.length());
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   323
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   324
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   325
    @Test(op = Operation.INDEX_OF_CON_L, constString = stringL)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   326
    public static String indexOfConstLargeL(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   327
        int result = a.indexOf(stringL);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   328
        return a.substring(result, result + stringL.length());
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   329
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   330
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   331
    @Test(op = Operation.INDEX_OF_CON_L, constString = emptyString)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   332
    public static String indexOfConstEmptyL(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   333
        int result = a.indexOf(emptyString);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   334
        return a.substring(result, result + emptyString.length());
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   335
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   336
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   337
    @Test(op = Operation.INDEX_OF_CON_UL, constString = stringSmallL)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   338
    public static String indexOfConstUL(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   339
        int result = a.indexOf(stringSmallL);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   340
        return a.substring(result, result + stringSmallL.length());
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   341
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   342
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   343
    @Test(op = Operation.INDEX_OF_CON_UL, constString = stringL)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   344
    public static String indexOfConstLargeUL(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   345
        int result = a.indexOf(stringL);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   346
        return a.substring(result, result + stringL.length());
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   347
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   348
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   349
    @Test(op = Operation.INDEX_OF_CHAR)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   350
    public static int indexOfChar(String a, int ch, int from) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   351
        return a.indexOf(ch, from);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   352
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   353
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   354
    /*
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   355
     * String concatenation optimization
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   356
     */
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   357
    @Test(op = Operation.CONCAT, inStrings = {"ABC", "\uff21\uff22\uff23"}, outStrings = {"ABC", "\uff21\uff22\uff23"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   358
    public static String concatString(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   359
        return new StringBuilder().append(a).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   360
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   361
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   362
    @Test(op = Operation.CONCAT, inStrings = {""}, outStrings = {""})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   363
    public static String concatStringEmpty(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   364
        return new StringBuilder().toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   365
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   366
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   367
    @Test(op = Operation.CONCAT, inStrings = {""}, outStrings = {"null"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   368
    public static String concatStringNull(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   369
        return new StringBuilder().append((String)null).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   370
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   371
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   372
    @Test(op = Operation.CONCAT, inStrings = {"ABC", "\uff21\uff22\uff23"}, outStrings = {"abcdefghijklmnopABCabc", "abcdefghijklmnop\uff21\uff22\uff23abc"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   373
    public static String concatStringConstL(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   374
        return new StringBuilder().append(stringL).append(a).append(stringSmallL).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   375
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   376
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   377
    @Test(op = Operation.CONCAT, inStrings = {"ABC", "\uff21\uff22\uff23"}, outStrings = {"\u0f21\u0f22\u0f23ABC\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28", "\u0f21\u0f22\u0f23\uff21\uff22\uff23\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   378
    public static String concatStringConstU(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   379
        return new StringBuilder().append(stringSmallU).append(a).append(stringU).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   380
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   381
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   382
    @Test(op = Operation.CONCAT_C, inChars = {'A', '\uff21'}, outStrings = {"A", "\uff21"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   383
    public static String concatChar(char a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   384
        return new StringBuilder().append(a).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   385
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   386
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   387
    @Test(op = Operation.CONCAT_C, inChars = {'A', '\uff21'}, outStrings = {"abcdefghijklmnopAabcA\uff21", "abcdefghijklmnop\uff21abcA\uff21"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   388
    public static String concatCharConstL(char a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   389
        return new StringBuilder().append(stringL).append(a).append(stringSmallL).append(charL).append(charU).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   390
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   391
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   392
    @Test(op = Operation.CONCAT_C, inChars = {'A', '\uff21'}, outStrings = {"\u0f21\u0f22\u0f23A\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\uff21A", "\u0f21\u0f22\u0f23\uff21\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\uff21A"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   393
    public static String concatCharConstU(char a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   394
        return new StringBuilder().append(stringSmallU).append(a).append(stringU).append(charU).append(charL).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   395
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   396
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   397
    @Test(op = Operation.CONCAT_I, inInts = {Integer.MIN_VALUE, -42, 42, Integer.MAX_VALUE}, outStrings = {"-2147483648", "-42", "42", "2147483647"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   398
    public static String concatInt(int a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   399
        return new StringBuilder().append(a).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   400
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   401
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   402
    @Test(op = Operation.CONCAT_I, inInts = {Integer.MIN_VALUE, -42, 42, Integer.MAX_VALUE}, outStrings = {"abcdefghijklmnop-2147483648abc123-123", "abcdefghijklmnop-42abc123-123", "abcdefghijklmnop42abc123-123", "abcdefghijklmnop2147483647abc123-123"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   403
    public static String concatIntConstL(int b) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   404
        return new StringBuilder().append(stringL).append(b).append(stringSmallL).append(constInt).append(constIntNeg).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   405
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   406
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   407
    @Test(op = Operation.CONCAT_I, inInts = {Integer.MIN_VALUE, -42, 42, Integer.MAX_VALUE}, outStrings = {"\u0f21\u0f22\u0f23-2147483648\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28123-123", "\u0f21\u0f22\u0f23-42\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28123-123", "\u0f21\u0f22\u0f2342\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28123-123", "\u0f21\u0f22\u0f232147483647\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28123-123"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   408
    public static String concatIntConstU(int b) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   409
        return new StringBuilder().append(stringSmallU).append(b).append(stringU).append(constInt).append(constIntNeg).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   410
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   411
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   412
    @Test(op = Operation.CONCAT, inStrings = {""}, outStrings = {"nullabcabcdefghijklmnopA123-123"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   413
    public static String concatConstL(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   414
        return new StringBuilder().append((String)null).append(stringSmallL).append(stringL).append(charL).append(constInt).append(constIntNeg).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   415
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   416
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   417
    @Test(op = Operation.CONCAT, inStrings = {""}, outStrings = {"nullabcabcdefghijklmnop\u0f21\u0f22\u0f23\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28A\uff21123-123"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   418
    public static String concatConstU(String a) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   419
        return new StringBuilder().append((String)null).append(stringSmallL).append(stringL).append(stringSmallU).append(stringU).append(charL).append(charU).append(constInt).append(constIntNeg).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   420
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   421
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   422
    @Test(op = Operation.CONCAT_M,
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   423
          inStrings = {"ABCDEFG", "ABCDEFG", "\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28", "\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28"},
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   424
          inChars = {'A', '\uff21', 'A', '\uff21'},
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   425
          inInts = {Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE},
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   426
          outStrings = {"ABCDEFGA-2147483648nullabcdefghijklmnop123-123A\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\uff21ABCDEFGA-2147483648null",
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   427
                        "ABCDEFG\uff212147483647nullabcdefghijklmnop123-123A\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\uff21ABCDEFG\uff212147483647null",
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   428
                        "\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28A-2147483648nullabcdefghijklmnop123-123A\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\uff21\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28A-2147483648null",
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   429
            "\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\uff212147483647nullabcdefghijklmnop123-123A\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\uff21\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\uff212147483647null"})
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   430
    public static String concatMixed(String a, char b, int c) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   431
        return new StringBuilder().append(a).append(b).append(c).append((String)null)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   432
                .append(stringL).append(constInt).append(constIntNeg).append(charL).append(stringU).append(charU)
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   433
                .append(a).append(b).append(c).append((String)null).toString();
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   434
    }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   435
}