test/hotspot/jtreg/compiler/intrinsics/Test8215792.java
author dpochepk
Wed, 22 May 2019 20:12:19 +0300
changeset 54990 cbc557f166f2
permissions -rw-r--r--
8215792: AArch64: String.indexOf generates incorrect result Reviewed-by: dsamersoff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54990
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
     1
/*
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
     3
 * Copyright (c) 2019, Arm Limited. All rights reserved.
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
     5
 *
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
     8
 * published by the Free Software Foundation.
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
     9
 *
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    14
 * accompanied this code).
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    15
 *
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    19
 *
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    22
 * questions.
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    23
 */
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    24
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    25
/*
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    26
 * @test
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    27
 * @bug 8215792
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    28
 * @summary Fix a bug in AArch64 string intrinsics
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    29
 *
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    30
 * @run main/othervm compiler.intrinsics.Test8215792
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    31
 * @run main/othervm -XX:-CompactStrings compiler.intrinsics.Test8215792
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    32
 */
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    33
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    34
package compiler.intrinsics;
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    35
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    36
public class Test8215792 {
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    37
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    38
    private static final int ITERATIONS = 10000;
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    39
    private static final String pattern = "01234567890123456789";
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    40
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    41
    public static void main(String[] args) {
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    42
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    43
        // Repeat many times to trigger compilation
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    44
        for (int iter = 0; iter < ITERATIONS; iter++) {
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    45
            StringBuilder str1 = new StringBuilder("ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890123456789");
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    46
            StringBuilder str2 = new StringBuilder("\u4f60\u598dCDEFGHIJKLMNOPQRSTUVWXYZ01234567890123456789");
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    47
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    48
            for (int i = 0; i < 20; i++) {
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    49
                // Remove one character from the tail
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    50
                str1.setLength(str1.length() - 1);
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    51
                str2.setLength(str2.length() - 1);
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    52
                // Pattern string should not be found after characters removed from the tail
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    53
                if (str1.indexOf(pattern) != -1 || str2.indexOf(pattern) != -1) {
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    54
                    System.out.println("FAILED");
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    55
                    System.exit(1);
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    56
                }
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    57
            }
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    58
        }
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    59
        System.out.println("PASSED");
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    60
    }
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    61
}
cbc557f166f2 8215792: AArch64: String.indexOf generates incorrect result
dpochepk
parents:
diff changeset
    62