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