hotspot/test/compiler/stringopts/TestOptimizeStringConcat.java
author asiebenborn
Fri, 16 Jan 2015 13:58:22 +0100
changeset 28642 a42fefc69922
child 35594 cc13089c6327
permissions -rw-r--r--
8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat Reviewed-by: kvn
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
/*
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
     2
 * Copyright 2015 SAP AG.  All Rights Reserved.
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.
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    29
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestOptimizeStringConcat
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    30
 * @author axel.siebenborn@sap.com
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    31
 */
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    32
public class TestOptimizeStringConcat {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    33
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    34
    static boolean checkArgumentSyntax(String value, String allowedchars, String notallowedchars, String logmsg) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    35
        String rc = null;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    36
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    37
        int maxchar = 99999;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    38
        int minchar = 1;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    39
        if ((allowedchars != null && notallowedchars != null) || minchar > maxchar) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    40
            rc = "internal error";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    41
        } else {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    42
            if (value == null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    43
                rc = "the value null is not allowed, it is missing";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    44
            } else if (value != null && minchar > 0 && value.trim().equals("")) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    45
                rc = "the value must not be empty";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    46
            } else if (value != null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    47
                if (value.length() < minchar || value.length() > maxchar) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    48
                    if (rc == null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    49
                        rc = "the value length must be between +minchar+ and +maxchar";
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    50
                    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    51
                }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    52
                char[] _value = value.toCharArray();
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    53
                boolean dotfound = false;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    54
                int i = 1;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    55
                if (_value[i] == '.' && !dotfound) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    56
                    dotfound = true;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    57
                } else if (allowedchars != null && allowedchars.indexOf(_value[i]) == -1) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    58
                    if (rc == null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    59
                        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
    60
                    } else {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    61
                        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
    62
                    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    63
                } else if (notallowedchars != null && notallowedchars.indexOf(_value[i]) != -1) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    64
                    if (rc == null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    65
                        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
    66
                    } else {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    67
                        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
    68
                    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    69
                }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    70
            }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    71
        }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    72
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    73
        if (rc != null) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    74
            System.out.println(logmsg + " ==> " + rc);
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    75
            return false;
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
        return true;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    78
    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    79
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    80
    public static void main(String[] args) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    81
        boolean failed = false;
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    82
        for (int i = 0; i < 10000; i++) {
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    83
            failed |= !checkArgumentSyntax("theName", null, "\"<&", "Error consistencyCheck: name in component definition");
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    84
            failed |= !checkArgumentSyntax(null, null, "\"<&", "Error consistencyCheck: name in component definition");
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    85
            failed |= !checkArgumentSyntax("42", "0123456789.", null, "Error consistencyCheck: counter in component definition");
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    86
        }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    87
        System.out.println(failed);
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    88
    }
a42fefc69922 8068909: SIGSEGV in c2 compiled code with OptimizeStringConcat
asiebenborn
parents:
diff changeset
    89
}