test/hotspot/jtreg/compiler/stringopts/TestOptimizeStringConcat.java
author iklam
Tue, 28 Nov 2017 09:47:04 -0800
changeset 48155 551de50b4ff7
parent 47216 71c04702a3d5
permissions -rw-r--r--
8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX Summary: Added "@requires vm.cds.custom.loaders" to mark tests related to custom loaders Reviewed-by: simonis, mseledtsov Contributed-by: volker.simonis@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28642
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
     1
/*
35594
cc13089c6327 8147937: Adapt SAP copyrights to new company name.
goetz
parents: 28642
diff changeset
     2
 * Copyright (c) 2015 SAP SE. All rights reserved.
28642
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
     4
 *
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
     8
 *
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    13
 * accompanied this code).
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    14
 *
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    18
 *
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    21
 * questions.
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    22
 */
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    23
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    24
/*
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    25
 * @test
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    26
 * @bug 8068909
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    27
 * @key regression
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    28
 * @summary test that string optimizations produce code, that doesn't lead to a crash.
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    29
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    30
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    31
 *                   compiler.stringopts.TestOptimizeStringConcat
28642
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    32
 * @author axel.siebenborn@sap.com
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    33
 */
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    34
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    35
package compiler.stringopts;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    36
28642
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    37
public class TestOptimizeStringConcat {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    38
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    39
    static boolean checkArgumentSyntax(String value, String allowedchars, String notallowedchars, String logmsg) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    40
        String rc = null;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    41
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    42
        int maxchar = 99999;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    43
        int minchar = 1;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    44
        if ((allowedchars != null && notallowedchars != null) || minchar > maxchar) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    45
            rc = "internal error";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    46
        } else {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    47
            if (value == null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    48
                rc = "the value null is not allowed, it is missing";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    49
            } else if (value != null && minchar > 0 && value.trim().equals("")) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    50
                rc = "the value must not be empty";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    51
            } else if (value != null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    52
                if (value.length() < minchar || value.length() > maxchar) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    53
                    if (rc == null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    54
                        rc = "the value length must be between +minchar+ and +maxchar";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    55
                    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    56
                }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    57
                char[] _value = value.toCharArray();
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    58
                boolean dotfound = false;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    59
                int i = 1;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    60
                if (_value[i] == '.' && !dotfound) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    61
                    dotfound = true;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    62
                } else if (allowedchars != null && allowedchars.indexOf(_value[i]) == -1) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    63
                    if (rc == null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    64
                        rc = "the value contains an illegal character: '" + _value[i] + "', only following characters are allowed: '+allowedchars+'";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    65
                    } else {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    66
                        rc += " / the value contains an illegal character: '" + _value[i] + "', only following characters are allowed: '+allowedchars+'";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    67
                    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    68
                } else if (notallowedchars != null && notallowedchars.indexOf(_value[i]) != -1) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    69
                    if (rc == null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    70
                        rc = "the value contains an illegal character: '" + _value[i] + "', following characters are not allowed '+notallowedchars+'";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    71
                    } else {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    72
                        rc += " / the value contains an illegal character: '" + _value[i] + "', following characters are not allowed '+notallowedchars+'";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    73
                    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    74
                }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    75
            }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    76
        }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    77
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    78
        if (rc != null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    79
            System.out.println(logmsg + " ==> " + rc);
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    80
            return false;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    81
        }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    82
        return true;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    83
    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    84
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    85
    public static void main(String[] args) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    86
        boolean failed = false;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    87
        for (int i = 0; i < 10000; i++) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    88
            failed |= !checkArgumentSyntax("theName", null, "\"<&", "Error consistencyCheck: name in component definition");
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    89
            failed |= !checkArgumentSyntax(null, null, "\"<&", "Error consistencyCheck: name in component definition");
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    90
            failed |= !checkArgumentSyntax("42", "0123456789.", null, "Error consistencyCheck: counter in component definition");
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    91
        }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    92
        System.out.println(failed);
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    93
    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    94
}