|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, 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 | +package compiler.regalloc; |
| 25 | + |
| 26 | +/** |
| 27 | + * @test |
| 28 | + * @bug 8317507 |
| 29 | + * @summary Test that C2's PhaseRegAlloc::_node_regs (a post-register-allocation |
| 30 | + * mapping from machine nodes to assigned registers) does not overflow |
| 31 | + * in the face of a program with a high-density of CISC spilling |
| 32 | + * candidate nodes. |
| 33 | + * @run main/othervm -Xcomp -XX:CompileOnly=compiler.regalloc.TestNodeRegArrayOverflow::testWithCompilerUnrolling |
| 34 | + -XX:CompileCommand=dontinline,compiler.regalloc.TestNodeRegArrayOverflow::dontInline |
| 35 | + compiler.regalloc.TestNodeRegArrayOverflow compiler |
| 36 | + * @run main/othervm -Xcomp -XX:CompileOnly=compiler.regalloc.TestNodeRegArrayOverflow::testWithManualUnrolling |
| 37 | + -XX:CompileCommand=dontinline,compiler.regalloc.TestNodeRegArrayOverflow::dontInline |
| 38 | + compiler.regalloc.TestNodeRegArrayOverflow manual |
| 39 | + */ |
| 40 | + |
| 41 | +public class TestNodeRegArrayOverflow { |
| 42 | + |
| 43 | + static int dontInline() { |
| 44 | + return 0; |
| 45 | + } |
| 46 | + |
| 47 | + static float testWithCompilerUnrolling(float inc) { |
| 48 | + int i = 0, j = 0; |
| 49 | + // This non-inlined method call causes 'inc' to be spilled. |
| 50 | + float f = dontInline(); |
| 51 | + // This two-level reduction loop is unrolled 512 times, which is |
| 52 | + // requested by the SLP-specific unrolling analysis, but not vectorized. |
| 53 | + // Because 'inc' is spilled, each of the unrolled AddF nodes is |
| 54 | + // CISC-spill converted (PhaseChaitin::fixup_spills()). Before the fix, |
| 55 | + // this causes the unique node index counter (Compile::_unique) to grow |
| 56 | + // beyond the size of the node register array |
| 57 | + // (PhaseRegAlloc::_node_regs), and leads to overflow when accessed for |
| 58 | + // nodes that are created later (e.g. during the peephole phase). |
| 59 | + while (i++ < 128) { |
| 60 | + for (j = 0; j < 16; j++) { |
| 61 | + f += inc; |
| 62 | + } |
| 63 | + } |
| 64 | + return f; |
| 65 | + } |
| 66 | + |
| 67 | + // This test reproduces the same failure as 'testWithCompilerUnrolling' |
| 68 | + // without relying on loop transformations. |
| 69 | + static float testWithManualUnrolling(float inc) { |
| 70 | + int i = 0, j = 0; |
| 71 | + float f = dontInline(); |
| 72 | + f += inc; |
| 73 | + f += inc; |
| 74 | + f += inc; |
| 75 | + f += inc; |
| 76 | + f += inc; |
| 77 | + f += inc; |
| 78 | + f += inc; |
| 79 | + f += inc; |
| 80 | + f += inc; |
| 81 | + f += inc; |
| 82 | + f += inc; |
| 83 | + f += inc; |
| 84 | + f += inc; |
| 85 | + f += inc; |
| 86 | + f += inc; |
| 87 | + f += inc; |
| 88 | + f += inc; |
| 89 | + f += inc; |
| 90 | + f += inc; |
| 91 | + f += inc; |
| 92 | + f += inc; |
| 93 | + f += inc; |
| 94 | + f += inc; |
| 95 | + f += inc; |
| 96 | + f += inc; |
| 97 | + f += inc; |
| 98 | + f += inc; |
| 99 | + f += inc; |
| 100 | + f += inc; |
| 101 | + f += inc; |
| 102 | + f += inc; |
| 103 | + f += inc; |
| 104 | + f += inc; |
| 105 | + f += inc; |
| 106 | + f += inc; |
| 107 | + f += inc; |
| 108 | + f += inc; |
| 109 | + f += inc; |
| 110 | + f += inc; |
| 111 | + f += inc; |
| 112 | + f += inc; |
| 113 | + f += inc; |
| 114 | + f += inc; |
| 115 | + f += inc; |
| 116 | + f += inc; |
| 117 | + f += inc; |
| 118 | + f += inc; |
| 119 | + f += inc; |
| 120 | + f += inc; |
| 121 | + f += inc; |
| 122 | + f += inc; |
| 123 | + f += inc; |
| 124 | + f += inc; |
| 125 | + f += inc; |
| 126 | + f += inc; |
| 127 | + f += inc; |
| 128 | + f += inc; |
| 129 | + f += inc; |
| 130 | + f += inc; |
| 131 | + f += inc; |
| 132 | + f += inc; |
| 133 | + f += inc; |
| 134 | + f += inc; |
| 135 | + f += inc; |
| 136 | + f += inc; |
| 137 | + f += inc; |
| 138 | + f += inc; |
| 139 | + f += inc; |
| 140 | + f += inc; |
| 141 | + f += inc; |
| 142 | + f += inc; |
| 143 | + f += inc; |
| 144 | + f += inc; |
| 145 | + f += inc; |
| 146 | + f += inc; |
| 147 | + f += inc; |
| 148 | + f += inc; |
| 149 | + f += inc; |
| 150 | + f += inc; |
| 151 | + f += inc; |
| 152 | + f += inc; |
| 153 | + f += inc; |
| 154 | + f += inc; |
| 155 | + f += inc; |
| 156 | + f += inc; |
| 157 | + f += inc; |
| 158 | + f += inc; |
| 159 | + f += inc; |
| 160 | + f += inc; |
| 161 | + f += inc; |
| 162 | + f += inc; |
| 163 | + f += inc; |
| 164 | + f += inc; |
| 165 | + f += inc; |
| 166 | + f += inc; |
| 167 | + f += inc; |
| 168 | + f += inc; |
| 169 | + f += inc; |
| 170 | + f += inc; |
| 171 | + f += inc; |
| 172 | + f += inc; |
| 173 | + f += inc; |
| 174 | + f += inc; |
| 175 | + f += inc; |
| 176 | + f += inc; |
| 177 | + f += inc; |
| 178 | + f += inc; |
| 179 | + f += inc; |
| 180 | + f += inc; |
| 181 | + f += inc; |
| 182 | + f += inc; |
| 183 | + f += inc; |
| 184 | + f += inc; |
| 185 | + f += inc; |
| 186 | + f += inc; |
| 187 | + f += inc; |
| 188 | + f += inc; |
| 189 | + f += inc; |
| 190 | + f += inc; |
| 191 | + f += inc; |
| 192 | + f += inc; |
| 193 | + f += inc; |
| 194 | + f += inc; |
| 195 | + f += inc; |
| 196 | + f += inc; |
| 197 | + f += inc; |
| 198 | + f += inc; |
| 199 | + f += inc; |
| 200 | + f += inc; |
| 201 | + f += inc; |
| 202 | + f += inc; |
| 203 | + f += inc; |
| 204 | + f += inc; |
| 205 | + f += inc; |
| 206 | + f += inc; |
| 207 | + f += inc; |
| 208 | + f += inc; |
| 209 | + f += inc; |
| 210 | + f += inc; |
| 211 | + f += inc; |
| 212 | + f += inc; |
| 213 | + f += inc; |
| 214 | + f += inc; |
| 215 | + f += inc; |
| 216 | + f += inc; |
| 217 | + f += inc; |
| 218 | + f += inc; |
| 219 | + f += inc; |
| 220 | + f += inc; |
| 221 | + f += inc; |
| 222 | + f += inc; |
| 223 | + f += inc; |
| 224 | + f += inc; |
| 225 | + f += inc; |
| 226 | + f += inc; |
| 227 | + f += inc; |
| 228 | + f += inc; |
| 229 | + f += inc; |
| 230 | + f += inc; |
| 231 | + f += inc; |
| 232 | + f += inc; |
| 233 | + f += inc; |
| 234 | + f += inc; |
| 235 | + f += inc; |
| 236 | + f += inc; |
| 237 | + f += inc; |
| 238 | + f += inc; |
| 239 | + f += inc; |
| 240 | + f += inc; |
| 241 | + f += inc; |
| 242 | + f += inc; |
| 243 | + f += inc; |
| 244 | + f += inc; |
| 245 | + f += inc; |
| 246 | + f += inc; |
| 247 | + f += inc; |
| 248 | + f += inc; |
| 249 | + f += inc; |
| 250 | + f += inc; |
| 251 | + f += inc; |
| 252 | + f += inc; |
| 253 | + f += inc; |
| 254 | + f += inc; |
| 255 | + f += inc; |
| 256 | + f += inc; |
| 257 | + f += inc; |
| 258 | + f += inc; |
| 259 | + f += inc; |
| 260 | + f += inc; |
| 261 | + f += inc; |
| 262 | + f += inc; |
| 263 | + f += inc; |
| 264 | + f += inc; |
| 265 | + f += inc; |
| 266 | + f += inc; |
| 267 | + f += inc; |
| 268 | + f += inc; |
| 269 | + f += inc; |
| 270 | + f += inc; |
| 271 | + f += inc; |
| 272 | + f += inc; |
| 273 | + f += inc; |
| 274 | + f += inc; |
| 275 | + f += inc; |
| 276 | + f += inc; |
| 277 | + f += inc; |
| 278 | + f += inc; |
| 279 | + f += inc; |
| 280 | + f += inc; |
| 281 | + f += inc; |
| 282 | + f += inc; |
| 283 | + f += inc; |
| 284 | + f += inc; |
| 285 | + f += inc; |
| 286 | + f += inc; |
| 287 | + f += inc; |
| 288 | + f += inc; |
| 289 | + f += inc; |
| 290 | + f += inc; |
| 291 | + f += inc; |
| 292 | + f += inc; |
| 293 | + f += inc; |
| 294 | + f += inc; |
| 295 | + f += inc; |
| 296 | + f += inc; |
| 297 | + f += inc; |
| 298 | + f += inc; |
| 299 | + f += inc; |
| 300 | + f += inc; |
| 301 | + f += inc; |
| 302 | + f += inc; |
| 303 | + f += inc; |
| 304 | + f += inc; |
| 305 | + f += inc; |
| 306 | + f += inc; |
| 307 | + f += inc; |
| 308 | + f += inc; |
| 309 | + f += inc; |
| 310 | + f += inc; |
| 311 | + f += inc; |
| 312 | + f += inc; |
| 313 | + f += inc; |
| 314 | + f += inc; |
| 315 | + f += inc; |
| 316 | + f += inc; |
| 317 | + f += inc; |
| 318 | + f += inc; |
| 319 | + f += inc; |
| 320 | + f += inc; |
| 321 | + f += inc; |
| 322 | + f += inc; |
| 323 | + f += inc; |
| 324 | + f += inc; |
| 325 | + f += inc; |
| 326 | + f += inc; |
| 327 | + f += inc; |
| 328 | + f += inc; |
| 329 | + f += inc; |
| 330 | + f += inc; |
| 331 | + f += inc; |
| 332 | + f += inc; |
| 333 | + f += inc; |
| 334 | + f += inc; |
| 335 | + f += inc; |
| 336 | + f += inc; |
| 337 | + f += inc; |
| 338 | + f += inc; |
| 339 | + f += inc; |
| 340 | + f += inc; |
| 341 | + f += inc; |
| 342 | + f += inc; |
| 343 | + f += inc; |
| 344 | + f += inc; |
| 345 | + f += inc; |
| 346 | + f += inc; |
| 347 | + f += inc; |
| 348 | + f += inc; |
| 349 | + f += inc; |
| 350 | + f += inc; |
| 351 | + f += inc; |
| 352 | + f += inc; |
| 353 | + f += inc; |
| 354 | + f += inc; |
| 355 | + f += inc; |
| 356 | + f += inc; |
| 357 | + f += inc; |
| 358 | + f += inc; |
| 359 | + f += inc; |
| 360 | + f += inc; |
| 361 | + f += inc; |
| 362 | + f += inc; |
| 363 | + f += inc; |
| 364 | + f += inc; |
| 365 | + f += inc; |
| 366 | + f += inc; |
| 367 | + f += inc; |
| 368 | + f += inc; |
| 369 | + f += inc; |
| 370 | + f += inc; |
| 371 | + f += inc; |
| 372 | + f += inc; |
| 373 | + f += inc; |
| 374 | + f += inc; |
| 375 | + f += inc; |
| 376 | + f += inc; |
| 377 | + f += inc; |
| 378 | + f += inc; |
| 379 | + f += inc; |
| 380 | + f += inc; |
| 381 | + f += inc; |
| 382 | + f += inc; |
| 383 | + f += inc; |
| 384 | + f += inc; |
| 385 | + f += inc; |
| 386 | + f += inc; |
| 387 | + f += inc; |
| 388 | + f += inc; |
| 389 | + f += inc; |
| 390 | + f += inc; |
| 391 | + f += inc; |
| 392 | + f += inc; |
| 393 | + f += inc; |
| 394 | + f += inc; |
| 395 | + f += inc; |
| 396 | + f += inc; |
| 397 | + f += inc; |
| 398 | + f += inc; |
| 399 | + f += inc; |
| 400 | + f += inc; |
| 401 | + f += inc; |
| 402 | + f += inc; |
| 403 | + f += inc; |
| 404 | + f += inc; |
| 405 | + f += inc; |
| 406 | + f += inc; |
| 407 | + f += inc; |
| 408 | + f += inc; |
| 409 | + f += inc; |
| 410 | + f += inc; |
| 411 | + f += inc; |
| 412 | + f += inc; |
| 413 | + f += inc; |
| 414 | + f += inc; |
| 415 | + f += inc; |
| 416 | + f += inc; |
| 417 | + f += inc; |
| 418 | + f += inc; |
| 419 | + f += inc; |
| 420 | + f += inc; |
| 421 | + f += inc; |
| 422 | + f += inc; |
| 423 | + f += inc; |
| 424 | + f += inc; |
| 425 | + f += inc; |
| 426 | + f += inc; |
| 427 | + f += inc; |
| 428 | + f += inc; |
| 429 | + f += inc; |
| 430 | + f += inc; |
| 431 | + f += inc; |
| 432 | + f += inc; |
| 433 | + f += inc; |
| 434 | + f += inc; |
| 435 | + f += inc; |
| 436 | + f += inc; |
| 437 | + f += inc; |
| 438 | + f += inc; |
| 439 | + f += inc; |
| 440 | + f += inc; |
| 441 | + f += inc; |
| 442 | + f += inc; |
| 443 | + f += inc; |
| 444 | + f += inc; |
| 445 | + f += inc; |
| 446 | + f += inc; |
| 447 | + f += inc; |
| 448 | + f += inc; |
| 449 | + f += inc; |
| 450 | + f += inc; |
| 451 | + f += inc; |
| 452 | + f += inc; |
| 453 | + f += inc; |
| 454 | + f += inc; |
| 455 | + f += inc; |
| 456 | + f += inc; |
| 457 | + f += inc; |
| 458 | + f += inc; |
| 459 | + f += inc; |
| 460 | + f += inc; |
| 461 | + f += inc; |
| 462 | + f += inc; |
| 463 | + f += inc; |
| 464 | + f += inc; |
| 465 | + f += inc; |
| 466 | + f += inc; |
| 467 | + f += inc; |
| 468 | + f += inc; |
| 469 | + f += inc; |
| 470 | + f += inc; |
| 471 | + f += inc; |
| 472 | + f += inc; |
| 473 | + f += inc; |
| 474 | + f += inc; |
| 475 | + f += inc; |
| 476 | + f += inc; |
| 477 | + f += inc; |
| 478 | + f += inc; |
| 479 | + f += inc; |
| 480 | + f += inc; |
| 481 | + f += inc; |
| 482 | + f += inc; |
| 483 | + f += inc; |
| 484 | + f += inc; |
| 485 | + f += inc; |
| 486 | + f += inc; |
| 487 | + f += inc; |
| 488 | + f += inc; |
| 489 | + f += inc; |
| 490 | + f += inc; |
| 491 | + f += inc; |
| 492 | + f += inc; |
| 493 | + f += inc; |
| 494 | + f += inc; |
| 495 | + f += inc; |
| 496 | + f += inc; |
| 497 | + f += inc; |
| 498 | + f += inc; |
| 499 | + f += inc; |
| 500 | + f += inc; |
| 501 | + f += inc; |
| 502 | + f += inc; |
| 503 | + f += inc; |
| 504 | + f += inc; |
| 505 | + f += inc; |
| 506 | + f += inc; |
| 507 | + f += inc; |
| 508 | + f += inc; |
| 509 | + f += inc; |
| 510 | + f += inc; |
| 511 | + f += inc; |
| 512 | + f += inc; |
| 513 | + f += inc; |
| 514 | + f += inc; |
| 515 | + f += inc; |
| 516 | + f += inc; |
| 517 | + f += inc; |
| 518 | + f += inc; |
| 519 | + f += inc; |
| 520 | + f += inc; |
| 521 | + f += inc; |
| 522 | + f += inc; |
| 523 | + f += inc; |
| 524 | + f += inc; |
| 525 | + f += inc; |
| 526 | + f += inc; |
| 527 | + f += inc; |
| 528 | + f += inc; |
| 529 | + f += inc; |
| 530 | + f += inc; |
| 531 | + f += inc; |
| 532 | + f += inc; |
| 533 | + f += inc; |
| 534 | + f += inc; |
| 535 | + f += inc; |
| 536 | + f += inc; |
| 537 | + f += inc; |
| 538 | + f += inc; |
| 539 | + f += inc; |
| 540 | + f += inc; |
| 541 | + f += inc; |
| 542 | + f += inc; |
| 543 | + f += inc; |
| 544 | + f += inc; |
| 545 | + f += inc; |
| 546 | + f += inc; |
| 547 | + f += inc; |
| 548 | + f += inc; |
| 549 | + f += inc; |
| 550 | + f += inc; |
| 551 | + f += inc; |
| 552 | + f += inc; |
| 553 | + f += inc; |
| 554 | + f += inc; |
| 555 | + f += inc; |
| 556 | + f += inc; |
| 557 | + f += inc; |
| 558 | + f += inc; |
| 559 | + f += inc; |
| 560 | + f += inc; |
| 561 | + f += inc; |
| 562 | + f += inc; |
| 563 | + f += inc; |
| 564 | + f += inc; |
| 565 | + f += inc; |
| 566 | + f += inc; |
| 567 | + f += inc; |
| 568 | + f += inc; |
| 569 | + f += inc; |
| 570 | + f += inc; |
| 571 | + f += inc; |
| 572 | + f += inc; |
| 573 | + f += inc; |
| 574 | + f += inc; |
| 575 | + f += inc; |
| 576 | + f += inc; |
| 577 | + f += inc; |
| 578 | + f += inc; |
| 579 | + f += inc; |
| 580 | + f += inc; |
| 581 | + f += inc; |
| 582 | + f += inc; |
| 583 | + f += inc; |
| 584 | + return f; |
| 585 | + } |
| 586 | + |
| 587 | + public static void main(String[] args) { |
| 588 | + switch (args[0]) { |
| 589 | + case "compiler": |
| 590 | + testWithCompilerUnrolling(0); |
| 591 | + break; |
| 592 | + case "manual": |
| 593 | + testWithManualUnrolling(0); |
| 594 | + break; |
| 595 | + default: |
| 596 | + throw new IllegalArgumentException("Invalid mode: " + args[0]); |
| 597 | + } |
| 598 | + } |
| 599 | +} |
0 commit comments