|
| 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 | + * @test |
| 26 | + * @bug 8331736 |
| 27 | + * @summary Check that C2 does not exceed max live node limit when splitting unique types of large allocation merge. |
| 28 | + * @library /test/lib / |
| 29 | + * @requires vm.debug & vm.compiler2.enabled |
| 30 | + * @compile -XDstringConcat=inline TestScalarReplacementMaxLiveNodes.java |
| 31 | + * @run main/othervm compiler.c2.TestScalarReplacementMaxLiveNodes |
| 32 | + * @run main/othervm -Xbatch -XX:-OptimizeStringConcat -XX:-TieredCompilation |
| 33 | + * -XX:+UnlockDiagnosticVMOptions -XX:+ReduceAllocationMerges |
| 34 | + * -XX:CompileCommand=dontinline,compiler.c2.TestScalarReplacementMaxLiveNodes::test |
| 35 | + * -XX:CompileCommand=compileonly,*TestScalarReplacementMaxLiveNodes*::*test* |
| 36 | + * -XX:CompileCommand=inline,*String*::* |
| 37 | + * -XX:CompileCommand=dontinline,*StringBuilder*::ensureCapacityInternal |
| 38 | + * -XX:CompileCommand=dontinline,*String*::substring |
| 39 | + * -XX:NodeCountInliningCutoff=220000 |
| 40 | + * -XX:DesiredMethodLimit=100000 |
| 41 | + * compiler.c2.TestScalarReplacementMaxLiveNodes |
| 42 | + */ |
| 43 | +package compiler.c2; |
| 44 | + |
| 45 | +public class TestScalarReplacementMaxLiveNodes { |
| 46 | + public static void main(String[] args) { |
| 47 | + TestScalarReplacementMaxLiveNodes obj = new TestScalarReplacementMaxLiveNodes(); |
| 48 | + |
| 49 | + int result = 0; |
| 50 | + for (int i = 0; i < 100; i++) { |
| 51 | + for (int val = 0; val < 50; val++) { |
| 52 | + result += obj.test(val, val+10, val+20, val+30, val+40).length(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + System.out.println("Result is: " + result); |
| 57 | + } |
| 58 | + |
| 59 | + public String test(int param1, int param2, int param3, int param4, int param5) { |
| 60 | + String a = null, b = null, c = null, d = null, e = null; |
| 61 | + |
| 62 | + if (param1 == 0) { |
| 63 | + a = new String("first" + param1); |
| 64 | + param1 = (int) Math.cos(param1); |
| 65 | + } else if (param1 == 1) { |
| 66 | + a = new String("second" + param2); |
| 67 | + param1 = (int) Math.cos(param1); |
| 68 | + } else if (param1 == 2) { |
| 69 | + a = ""; |
| 70 | + param1 = (int) Math.cos(param1); |
| 71 | + } else if (param1 == 3) { |
| 72 | + b = new String("third" + param2); |
| 73 | + param2 = (int) Math.sin(param2); |
| 74 | + } else if (param1 == 4) { |
| 75 | + b = new String("fourth" + param1); |
| 76 | + param2 = (int) Math.sin(param2); |
| 77 | + } else if (param1 == 5) { |
| 78 | + b = new String("fifth" + param2); |
| 79 | + param2 = (int) Math.sin(param2); |
| 80 | + } else if (param1 == 6) { |
| 81 | + c = new String("sixth" + param2); |
| 82 | + param2 = (int) Math.sin(param2); |
| 83 | + } else if (param1 == 7) { |
| 84 | + c = new String("seventh" + param2); |
| 85 | + param3 = (int) Math.tan(param3); |
| 86 | + } else if (param1 == 8) { |
| 87 | + c = new String("eighth" + param3); |
| 88 | + param3 = (int) Math.tan(param3); |
| 89 | + } else if (param1 == 9) { |
| 90 | + d = new String("nineth" + param2); |
| 91 | + param3 = (int) Math.tan(param3); |
| 92 | + } else if (param1 == 10) { |
| 93 | + d = ""; |
| 94 | + param3 = (int) Math.tan(param3); |
| 95 | + } else if (param1 == 11) { |
| 96 | + d = new String("tenth" + param2); |
| 97 | + param4 = (int) Math.atan(param1 + param2); |
| 98 | + } else if (param1 == 12) { |
| 99 | + e = new String("eleventh" + param3); |
| 100 | + param4 = (int) Math.atan(param1 + param2); |
| 101 | + } else if (param1 == 13) { |
| 102 | + e = ""; |
| 103 | + param4 = (int) Math.atan(param1 + param2); |
| 104 | + } else if (param1 == 14) { |
| 105 | + e = new String("twelveth" + param1); |
| 106 | + b = e; |
| 107 | + } else if (param1 == 15) { |
| 108 | + a = new String("thirteenth" + param2); |
| 109 | + param4 = (int) Math.atan(param1 + param2); |
| 110 | + } else if (param1 == 16) { |
| 111 | + b = ""; |
| 112 | + param5 = (int) Math.abs(Math.sqrt(param1*param2)); |
| 113 | + } else if (param1 == 17) { |
| 114 | + c = new String("fourteenth" + param2); |
| 115 | + param5 = (int) Math.abs(Math.sqrt(param1*param2)); |
| 116 | + } else if (param1 == 18) { |
| 117 | + e = new String("fifteenth" + param3); |
| 118 | + param5 = (int) Math.abs(Math.sqrt(param1*param2)); |
| 119 | + } else if (param1 == 19) { |
| 120 | + e = new String("sixteenth" + param2); |
| 121 | + a = e; |
| 122 | + } else if (param1 == 20) { |
| 123 | + a = new String("seventeenth" + param2); |
| 124 | + param1 = param2 + param3; |
| 125 | + } else if (param1 == 21) { |
| 126 | + b = new String("eighteenth" + param2); |
| 127 | + c = b; |
| 128 | + } else if (param1 == 22) { |
| 129 | + c = ""; |
| 130 | + param3 = param4 + param5; |
| 131 | + } else if (param1 == 23) { |
| 132 | + e = new String("nineteenth" + param3); |
| 133 | + param4 = param5 + param1; |
| 134 | + } else if (param1 == 24) { |
| 135 | + e = new String("tweenth" + param2); |
| 136 | + } else if (param1 == 25) { |
| 137 | + c = ""; |
| 138 | + param3 = param4 + param5; |
| 139 | + } |
| 140 | + |
| 141 | + int val1 = (a != null ? a.length() : 10) + param1; |
| 142 | + int val2 = (b != null ? b.length() : 20) + param2; |
| 143 | + int val3 = (c != null ? c.length() : 20) + param3; |
| 144 | + int val4 = (d != null ? d.length() : 20) + param4; |
| 145 | + int val5 = (e != null ? e.length() : 20) + param5; |
| 146 | + |
| 147 | + String result = "Really Really Long String"; |
| 148 | + for (int i=0; i<16; i++) { |
| 149 | + for (int j=0; j<4; j++) { |
| 150 | + val1 += (int) (val1 >= 10 ? Math.sqrt(val1*val2*val3*val4 / 10) : i * j * Math.sin(Math.cos(val1))); |
| 151 | + val2 += (int) (val2 >= 10 ? Math.sqrt(val1*val2*val3*val4 / 20) : i * j * Math.sin(Math.cos(val2))); |
| 152 | + val3 += (int) (val3 >= 10 ? Math.sqrt(val1*val2*val3*val4 / 30) : i * j * Math.sin(Math.cos(val3))); |
| 153 | + val4 += (int) (val4 >= 10 ? Math.sqrt(val1*val2*val3*val4 / 40) : i * j * Math.sin(Math.cos(val4))); |
| 154 | + val5 += (int) (val5 >= 10 ? Math.sqrt(val1*val2*val3*val4 / 50) : i * j * Math.sin(Math.cos(val5))); |
| 155 | + int val6 = (int) (val1 + val2 + val3 + val4 + val5); |
| 156 | + |
| 157 | + try { |
| 158 | + result += "Result is: " + result.substring(10, 20) + val1; |
| 159 | + } catch (IndexOutOfBoundsException except) { |
| 160 | + result += "Reaally Long String" + val6; |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + return result; |
| 166 | + } |
| 167 | +} |
0 commit comments