1 /* 2 * Copyright (c) 2024, Oracle and/or its affiliates. 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 /* 26 * @test id=static 27 * @requires vm.cds.write.archived.java.heap 28 * @library /test/jdk/lib/testlibrary /test/lib 29 * @build StringConcatStress2 30 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar StringConcatStress2App 31 * @run driver StringConcatStress2 STATIC 32 */ 33 34 /* 35 * @test id=leyden 36 * @requires vm.cds.write.archived.java.heap 37 * @library /test/jdk/lib/testlibrary /test/lib 38 * @build StringConcatStress2 39 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar StringConcatStress2App 40 * @run driver StringConcatStress2 LEYDEN 41 */ 42 43 import jdk.test.lib.cds.CDSAppTester; 44 import jdk.test.lib.helpers.ClassFileInstaller; 45 import jdk.test.lib.process.OutputAnalyzer; 46 47 public class StringConcatStress2 { 48 static final String appJar = ClassFileInstaller.getJarPath("app.jar"); 49 static final String mainClass = "StringConcatStress2App"; 50 51 public static void main(String[] args) throws Exception { 52 Tester t = new Tester(); 53 t.run(args); 54 } 55 56 static class Tester extends CDSAppTester { 57 public Tester() { 58 super(mainClass); 59 } 60 61 @Override 62 public String classpath(RunMode runMode) { 63 return appJar; 64 } 65 66 public String[] vmArgs(RunMode runMode) { 67 return new String[] { 68 "-XX:+AOTClassLinking", // by default enables AOTInvokeDynamicLinking 69 }; 70 } 71 72 @Override 73 public String[] appCommandLine(RunMode runMode) { 74 return new String[] { 75 mainClass 76 }; 77 } 78 79 @Override 80 public void checkExecution(OutputAnalyzer out, RunMode runMode) { 81 if (!runMode.isStaticDump()) { 82 out.shouldContain("Result = 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1END"); 83 } 84 } 85 } 86 } 87 88 class StringConcatStress2App { 89 public static void main(String args[]) { 90 System.out.println("Result = " + concat23String() + "END"); 91 } 92 93 // Test the handling of java.lang.invoke.StringConcat.highArityThreshold (default value is 20) 94 // in java.lang.invoke.StringConcatFactory. If we have more than this number of concats, a 95 // different form of CallSite is generated by StringConcatFactory that will uses 96 // different kinds of hidden classes than usual. 97 static String concat23String() { 98 return f0 + ","+ f1 + ","+ f2 + ","+ f3 + ","+ f4 + ","+ f5 + ","+ f6 + ","+ f7 + ","+ f8 + ","+ f9 + "," 99 + f10 + ","+ f11 + ","+ f12 + ","+ f13 + ","+ f14 + ","+ f15 + ","+ f16 + ","+ f17 + ","+ f18 + ","+ f19 + "," 100 + f20 + ","+ f21 + ","+ f22; 101 } 102 103 private static String 104 f0="1", f1="1", f2="1", f3="1", f4="1", f5="1", f6="1", f7="1", f8="1", f9="1", 105 f10="1", f11="1", f12="1", f13="1", f14="1", f15="1", f16="1", f17="1", f18="1", f19="1", 106 f20="1", f21="1", f22="1", f23="1", f24="1", f25="1", f26="1", f27="1", f28="1", f29="1", 107 f30="1", f31="1", f32="1", f33="1", f34="1", f35="1", f36="1", f37="1", f38="1", f39="1", 108 f40="1", f41="1", f42="1", f43="1", f44="1", f45="1", f46="1", f47="1", f48="1", f49="1", 109 f50="1", f51="1", f52="1", f53="1", f54="1", f55="1", f56="1", f57="1", f58="1", f59="1", 110 f60="1", f61="1", f62="1", f63="1", f64="1", f65="1", f66="1", f67="1", f68="1", f69="1", 111 f70="1", f71="1", f72="1", f73="1", f74="1", f75="1", f76="1", f77="1", f78="1", f79="1", 112 f80="1", f81="1", f82="1", f83="1", f84="1", f85="1", f86="1", f87="1", f88="1", f89="1", 113 f90="1", f91="1", f92="1", f93="1", f94="1", f95="1", f96="1", f97="1", f98="1", f99="1", 114 f100="1",f101="1",f102="1",f103="1",f104="1",f105="1",f106="1",f107="1",f108="1",f109="1", 115 f110="1",f111="1",f112="1",f113="1",f114="1",f115="1",f116="1",f117="1",f118="1",f119="1", 116 f120="1",f121="1",f122="1"; 117 118 }