|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, Red Hat, Inc. 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 8324517 |
| 27 | + * @summary C2: out of bound array load because of dependency on removed range check CastIIs |
| 28 | + * |
| 29 | + * @run main/othervm -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:-BackgroundCompilation |
| 30 | + * -XX:CompileCommand=dontinline,TestArrayAccessAboveRCAfterRCCastIIEliminated::notInlined |
| 31 | + * TestArrayAccessAboveRCAfterRCCastIIEliminated |
| 32 | + * @run main/othervm -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:-BackgroundCompilation |
| 33 | + * -XX:CompileCommand=dontinline,TestArrayAccessAboveRCAfterRCCastIIEliminated::notInlined |
| 34 | + * -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM TestArrayAccessAboveRCAfterRCCastIIEliminated |
| 35 | + * @run main/othervm TestArrayAccessAboveRCAfterRCCastIIEliminated |
| 36 | + * @run main/othervm -XX:CompileCommand=dontinline,TestArrayAccessAboveRCAfterRCCastIIEliminated::notInlined |
| 37 | + * TestArrayAccessAboveRCAfterRCCastIIEliminated |
| 38 | + * |
| 39 | + */ |
| 40 | + |
| 41 | +public class TestArrayAccessAboveRCAfterRCCastIIEliminated { |
| 42 | + private static int intField; |
| 43 | + private static long longField; |
| 44 | + private static volatile int volatileField; |
| 45 | + |
| 46 | + public static void main(String[] args) { |
| 47 | + int[] array = new int[100]; |
| 48 | + for (int i = 0; i < 20_000; i++) { |
| 49 | + test1(9, 10, 1, true); |
| 50 | + test1(9, 10, 1, false); |
| 51 | + test2(9, 10, 1, true); |
| 52 | + test2(9, 10, 1, false); |
| 53 | + test3(9, 10, 1, true); |
| 54 | + test3(9, 10, 1, false); |
| 55 | + test4(9, 10, 1, true); |
| 56 | + test4(9, 10, 1, false); |
| 57 | + test5(9, 10, 1, true); |
| 58 | + test5(9, 10, 1, false); |
| 59 | + test6(9, 10, 1, true); |
| 60 | + test6(9, 10, 1, false); |
| 61 | + test7(9, 10, 1, true); |
| 62 | + test7(9, 10, 1, false); |
| 63 | + test8(9, 10, 1, true); |
| 64 | + test8(9, 10, 1, false); |
| 65 | + test9(9, 10, 1, true); |
| 66 | + test9(9, 10, 1, false); |
| 67 | + test10(9, 10, 1, true); |
| 68 | + test10(9, 10, 1, false); |
| 69 | + test11(9, 10, 1, true); |
| 70 | + test11(9, 10, 1, false); |
| 71 | + test12(9, 10, 1, true); |
| 72 | + test12(9, 10, 1, false); |
| 73 | + test13(9, 10, 1, true); |
| 74 | + test13(9, 10, 1, false); |
| 75 | + } |
| 76 | + try { |
| 77 | + test1(-1, 10, 1, true); |
| 78 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 79 | + } |
| 80 | + try { |
| 81 | + test2(-1, 10, 1, true); |
| 82 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 83 | + } |
| 84 | + try { |
| 85 | + test3(-1, 10, 1, true); |
| 86 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 87 | + } |
| 88 | + try { |
| 89 | + test4(-1, 10, 1, true); |
| 90 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 91 | + } |
| 92 | + try { |
| 93 | + test5(-1, 10, 1, true); |
| 94 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 95 | + } |
| 96 | + try { |
| 97 | + test6(-1, 10, 1, true); |
| 98 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 99 | + } |
| 100 | + try { |
| 101 | + test7(-1, 10, 1, true); |
| 102 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 103 | + } |
| 104 | + try { |
| 105 | + test8(-1, 10, 1, true); |
| 106 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 107 | + } |
| 108 | + try { |
| 109 | + test9(-1, 10, 1, true); |
| 110 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 111 | + } |
| 112 | + try { |
| 113 | + test10(-1, 10, 1, true); |
| 114 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 115 | + } |
| 116 | + try { |
| 117 | + test11(-1, 10, 1, true); |
| 118 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 119 | + } |
| 120 | + try { |
| 121 | + test12(-1, 10, 1, true); |
| 122 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 123 | + } |
| 124 | + try { |
| 125 | + test13(-1, 10, 1, true); |
| 126 | + } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + private static void test1(int i, int j, int flag, boolean flag2) { |
| 131 | + i = Math.min(i, 9); |
| 132 | + int[] array = new int[10]; |
| 133 | + notInlined(array); |
| 134 | + if (flag == 0) { |
| 135 | + } |
| 136 | + if (flag2) { |
| 137 | + float[] newArray = new float[j]; |
| 138 | + newArray[i] = 42; |
| 139 | + float[] otherArray = new float[i]; |
| 140 | + if (flag == 0) { |
| 141 | + } |
| 142 | + intField = array[otherArray.length]; |
| 143 | + } else { |
| 144 | + float[] newArray = new float[j]; |
| 145 | + newArray[i] = 42; |
| 146 | + float[] otherArray = new float[i]; |
| 147 | + if (flag == 0) { |
| 148 | + } |
| 149 | + intField = array[otherArray.length]; |
| 150 | + } |
| 151 | + for (int k = 0; k < 10; k++) { |
| 152 | + |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + private static void test2(int i, int j, int flag, boolean flag2) { |
| 157 | + i = Math.min(i, 9); |
| 158 | + int[] array = new int[10]; |
| 159 | + notInlined(array); |
| 160 | + if (flag == 0) { |
| 161 | + } |
| 162 | + if (flag2) { |
| 163 | + float[] newArray = new float[j]; |
| 164 | + newArray[i] = 42; |
| 165 | + float[] otherArray = new float[i]; |
| 166 | + if (flag == 0) { |
| 167 | + } |
| 168 | + intField = 1 / (otherArray.length + 1); |
| 169 | + } else { |
| 170 | + float[] newArray = new float[j]; |
| 171 | + newArray[i] = 42; |
| 172 | + float[] otherArray = new float[i]; |
| 173 | + if (flag == 0) { |
| 174 | + } |
| 175 | + intField = 1 / (otherArray.length + 1); |
| 176 | + } |
| 177 | + for (int k = 0; k < 10; k++) { |
| 178 | + |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + private static void test3(int i, int j, int flag, boolean flag2) { |
| 183 | + i = Math.min(i, 9); |
| 184 | + int[] array = new int[10]; |
| 185 | + notInlined(array); |
| 186 | + if (flag == 0) { |
| 187 | + } |
| 188 | + if (flag2) { |
| 189 | + float[] newArray = new float[j]; |
| 190 | + newArray[i] = 42; |
| 191 | + float[] otherArray = new float[i]; |
| 192 | + if (flag == 0) { |
| 193 | + } |
| 194 | + longField = 1L / (otherArray.length + 1); |
| 195 | + } else { |
| 196 | + float[] newArray = new float[j]; |
| 197 | + newArray[i] = 42; |
| 198 | + float[] otherArray = new float[i]; |
| 199 | + if (flag == 0) { |
| 200 | + } |
| 201 | + longField = 1L / (otherArray.length + 1); |
| 202 | + } |
| 203 | + for (int k = 0; k < 10; k++) { |
| 204 | + |
| 205 | + } |
| 206 | + } |
| 207 | + |
| 208 | + private static void test4(int i, int j, int flag, boolean flag2) { |
| 209 | + i = Math.min(i, 9); |
| 210 | + int[] array = new int[10]; |
| 211 | + notInlined(array); |
| 212 | + if (flag == 0) { |
| 213 | + } |
| 214 | + if (flag2) { |
| 215 | + float[] newArray = new float[j]; |
| 216 | + newArray[i] = 42; |
| 217 | + float[] otherArray = new float[i]; |
| 218 | + if (flag == 0) { |
| 219 | + } |
| 220 | + intField = 1 % (otherArray.length + 1); |
| 221 | + } else { |
| 222 | + float[] newArray = new float[j]; |
| 223 | + newArray[i] = 42; |
| 224 | + float[] otherArray = new float[i]; |
| 225 | + if (flag == 0) { |
| 226 | + } |
| 227 | + intField = 1 % (otherArray.length + 1); |
| 228 | + } |
| 229 | + for (int k = 0; k < 10; k++) { |
| 230 | + |
| 231 | + } |
| 232 | + } |
| 233 | + |
| 234 | + private static void test5(int i, int j, int flag, boolean flag2) { |
| 235 | + i = Math.min(i, 9); |
| 236 | + int[] array = new int[10]; |
| 237 | + notInlined(array); |
| 238 | + if (flag == 0) { |
| 239 | + } |
| 240 | + if (flag2) { |
| 241 | + float[] newArray = new float[j]; |
| 242 | + newArray[i] = 42; |
| 243 | + float[] otherArray = new float[i]; |
| 244 | + if (flag == 0) { |
| 245 | + } |
| 246 | + longField = 1L % (otherArray.length + 1); |
| 247 | + } else { |
| 248 | + float[] newArray = new float[j]; |
| 249 | + newArray[i] = 42; |
| 250 | + float[] otherArray = new float[i]; |
| 251 | + if (flag == 0) { |
| 252 | + } |
| 253 | + longField = 1L % (otherArray.length + 1); |
| 254 | + } |
| 255 | + for (int k = 0; k < 10; k++) { |
| 256 | + |
| 257 | + } |
| 258 | + } |
| 259 | + |
| 260 | + private static void test6(int i, int j, int flag, boolean flag2) { |
| 261 | + i = Math.min(i, 9); |
| 262 | + int[] array = new int[10]; |
| 263 | + notInlined(array); |
| 264 | + if (flag == 0) { |
| 265 | + } |
| 266 | + if (flag2) { |
| 267 | + float[] newArray = new float[j]; |
| 268 | + newArray[i] = 42; |
| 269 | + float[] otherArray = new float[i]; |
| 270 | + if (flag == 0) { |
| 271 | + } |
| 272 | + intField = 1 % (otherArray.length + 1) + 1 / (otherArray.length + 1); |
| 273 | + } else { |
| 274 | + float[] newArray = new float[j]; |
| 275 | + newArray[i] = 42; |
| 276 | + float[] otherArray = new float[i]; |
| 277 | + if (flag == 0) { |
| 278 | + } |
| 279 | + intField = 1 % (otherArray.length + 1) + 1 / (otherArray.length + 1); |
| 280 | + } |
| 281 | + for (int k = 0; k < 10; k++) { |
| 282 | + |
| 283 | + } |
| 284 | + } |
| 285 | + |
| 286 | + private static void test7(int i, int j, int flag, boolean flag2) { |
| 287 | + i = Math.min(i, 9); |
| 288 | + int[] array = new int[10]; |
| 289 | + notInlined(array); |
| 290 | + if (flag == 0) { |
| 291 | + } |
| 292 | + if (flag2) { |
| 293 | + float[] newArray = new float[j]; |
| 294 | + newArray[i] = 42; |
| 295 | + float[] otherArray = new float[i]; |
| 296 | + if (flag == 0) { |
| 297 | + } |
| 298 | + longField = 1L % (otherArray.length + 1) + 1L / (otherArray.length + 1); |
| 299 | + } else { |
| 300 | + float[] newArray = new float[j]; |
| 301 | + newArray[i] = 42; |
| 302 | + float[] otherArray = new float[i]; |
| 303 | + if (flag == 0) { |
| 304 | + } |
| 305 | + longField = 1L % (otherArray.length + 1) + 1L / (otherArray.length + 1); |
| 306 | + } |
| 307 | + for (int k = 0; k < 10; k++) { |
| 308 | + |
| 309 | + } |
| 310 | + } |
| 311 | + private static void test8(int i, int j, int flag, boolean flag2) { |
| 312 | + i = Math.min(i, 9); |
| 313 | + int[] array = new int[10]; |
| 314 | + notInlined(array); |
| 315 | + if (flag == 0) { |
| 316 | + } |
| 317 | + if (flag2) { |
| 318 | + float[] newArray = new float[j]; |
| 319 | + newArray[i] = 42; |
| 320 | + float[] otherArray = new float[i]; |
| 321 | + if (flag == 0) { |
| 322 | + } |
| 323 | + intField = Integer.divideUnsigned(1, (otherArray.length + 1)); |
| 324 | + } else { |
| 325 | + float[] newArray = new float[j]; |
| 326 | + newArray[i] = 42; |
| 327 | + float[] otherArray = new float[i]; |
| 328 | + if (flag == 0) { |
| 329 | + } |
| 330 | + intField = Integer.divideUnsigned(1, (otherArray.length + 1)); |
| 331 | + } |
| 332 | + for (int k = 0; k < 10; k++) { |
| 333 | + |
| 334 | + } |
| 335 | + } |
| 336 | + |
| 337 | + private static void test9(int i, int j, int flag, boolean flag2) { |
| 338 | + i = Math.min(i, 9); |
| 339 | + int[] array = new int[10]; |
| 340 | + notInlined(array); |
| 341 | + if (flag == 0) { |
| 342 | + } |
| 343 | + if (flag2) { |
| 344 | + float[] newArray = new float[j]; |
| 345 | + newArray[i] = 42; |
| 346 | + float[] otherArray = new float[i]; |
| 347 | + if (flag == 0) { |
| 348 | + } |
| 349 | + longField = Long.divideUnsigned(1L, (otherArray.length + 1)); |
| 350 | + } else { |
| 351 | + float[] newArray = new float[j]; |
| 352 | + newArray[i] = 42; |
| 353 | + float[] otherArray = new float[i]; |
| 354 | + if (flag == 0) { |
| 355 | + } |
| 356 | + longField = Long.divideUnsigned(1L, (otherArray.length + 1)); |
| 357 | + } |
| 358 | + for (int k = 0; k < 10; k++) { |
| 359 | + |
| 360 | + } |
| 361 | + } |
| 362 | + |
| 363 | + private static void test10(int i, int j, int flag, boolean flag2) { |
| 364 | + i = Math.min(i, 9); |
| 365 | + int[] array = new int[10]; |
| 366 | + notInlined(array); |
| 367 | + if (flag == 0) { |
| 368 | + } |
| 369 | + if (flag2) { |
| 370 | + float[] newArray = new float[j]; |
| 371 | + newArray[i] = 42; |
| 372 | + float[] otherArray = new float[i]; |
| 373 | + if (flag == 0) { |
| 374 | + } |
| 375 | + intField = Integer.remainderUnsigned(1, (otherArray.length + 1)); |
| 376 | + } else { |
| 377 | + float[] newArray = new float[j]; |
| 378 | + newArray[i] = 42; |
| 379 | + float[] otherArray = new float[i]; |
| 380 | + if (flag == 0) { |
| 381 | + } |
| 382 | + intField = Integer.remainderUnsigned(1, (otherArray.length + 1)); |
| 383 | + } |
| 384 | + for (int k = 0; k < 10; k++) { |
| 385 | + |
| 386 | + } |
| 387 | + } |
| 388 | + |
| 389 | + private static void test11(int i, int j, int flag, boolean flag2) { |
| 390 | + i = Math.min(i, 9); |
| 391 | + int[] array = new int[10]; |
| 392 | + notInlined(array); |
| 393 | + if (flag == 0) { |
| 394 | + } |
| 395 | + if (flag2) { |
| 396 | + float[] newArray = new float[j]; |
| 397 | + newArray[i] = 42; |
| 398 | + float[] otherArray = new float[i]; |
| 399 | + if (flag == 0) { |
| 400 | + } |
| 401 | + longField = Long.remainderUnsigned(1L, (otherArray.length + 1)); |
| 402 | + } else { |
| 403 | + float[] newArray = new float[j]; |
| 404 | + newArray[i] = 42; |
| 405 | + float[] otherArray = new float[i]; |
| 406 | + if (flag == 0) { |
| 407 | + } |
| 408 | + longField = Long.remainderUnsigned(1L, (otherArray.length + 1)); |
| 409 | + } |
| 410 | + for (int k = 0; k < 10; k++) { |
| 411 | + |
| 412 | + } |
| 413 | + } |
| 414 | + |
| 415 | + private static void test12(int i, int j, int flag, boolean flag2) { |
| 416 | + i = Math.min(i, 9); |
| 417 | + int[] array = new int[10]; |
| 418 | + notInlined(array); |
| 419 | + if (flag == 0) { |
| 420 | + } |
| 421 | + if (flag2) { |
| 422 | + float[] newArray = new float[j]; |
| 423 | + newArray[i] = 42; |
| 424 | + float[] otherArray = new float[i]; |
| 425 | + if (flag == 0) { |
| 426 | + } |
| 427 | + intField = Integer.divideUnsigned(1, (otherArray.length + 1)) + |
| 428 | + Integer.remainderUnsigned(1, (otherArray.length + 1)); |
| 429 | + } else { |
| 430 | + float[] newArray = new float[j]; |
| 431 | + newArray[i] = 42; |
| 432 | + float[] otherArray = new float[i]; |
| 433 | + if (flag == 0) { |
| 434 | + } |
| 435 | + intField = Integer.divideUnsigned(1, (otherArray.length + 1)) + |
| 436 | + Integer.remainderUnsigned(1, (otherArray.length + 1)); |
| 437 | + } |
| 438 | + for (int k = 0; k < 10; k++) { |
| 439 | + |
| 440 | + } |
| 441 | + } |
| 442 | + |
| 443 | + private static void test13(int i, int j, int flag, boolean flag2) { |
| 444 | + i = Math.min(i, 9); |
| 445 | + int[] array = new int[10]; |
| 446 | + notInlined(array); |
| 447 | + if (flag == 0) { |
| 448 | + } |
| 449 | + if (flag2) { |
| 450 | + float[] newArray = new float[j]; |
| 451 | + newArray[i] = 42; |
| 452 | + float[] otherArray = new float[i]; |
| 453 | + if (flag == 0) { |
| 454 | + } |
| 455 | + longField = Long.remainderUnsigned(1L, (otherArray.length + 1)) + |
| 456 | + Long.divideUnsigned(1L, (otherArray.length + 1)); |
| 457 | + } else { |
| 458 | + float[] newArray = new float[j]; |
| 459 | + newArray[i] = 42; |
| 460 | + float[] otherArray = new float[i]; |
| 461 | + if (flag == 0) { |
| 462 | + } |
| 463 | + longField = Long.remainderUnsigned(1L, (otherArray.length + 1)) + |
| 464 | + Long.divideUnsigned(1L, (otherArray.length + 1)); |
| 465 | + } |
| 466 | + for (int k = 0; k < 10; k++) { |
| 467 | + |
| 468 | + } |
| 469 | + } |
| 470 | + |
| 471 | + private static void notInlined(int[] array) { |
| 472 | + |
| 473 | + } |
| 474 | +} |
0 commit comments