|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 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 8335747 |
| 27 | + * @summary Integer overflow in LoopLimit::Value during PhaseIdealLoop::split_thru_phi |
| 28 | + * @run main/othervm -Xbatch -XX:CompileCommand=compileonly,TestLoopLimitOverflowDuringSplitThruPhi::test |
| 29 | + * compiler.loopopts.TestLoopLimitOverflowDuringSplitThruPhi |
| 30 | + * @run driver compiler.loopopts.TestLoopLimitOverflowDuringSplitThruPhi |
| 31 | + */ |
| 32 | + |
| 33 | +package compiler.loopopts; |
| 34 | + |
| 35 | +public class TestLoopLimitOverflowDuringSplitThruPhi { |
| 36 | + public static void main(String[] args) { |
| 37 | + int[] a = new int[1005]; |
| 38 | + for (int i = 0; i < 20_000; i++) { |
| 39 | + test(i % 2 == 0, a); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + static void test(boolean flag, int[] a) { |
| 44 | + int x = flag ? 1000 : 2147483647; |
| 45 | + // Creates a Phi(1000, 2147483647) |
| 46 | + |
| 47 | + // We do loop-predication, and add a |
| 48 | + // LoopLimitNode(init=0, limit=x, stride=4) |
| 49 | + // |
| 50 | + // Later, we find try to PhaseIdealLoop::split_thru_phi |
| 51 | + // the LoopLimitNode, through the Phi(1000, 2147483647). |
| 52 | + // |
| 53 | + // This creates a temporary |
| 54 | + // LoopLimitNode(init=0, limit=2147483647, stride=4) |
| 55 | + // |
| 56 | + // And then we get this: |
| 57 | + // init_con 0 |
| 58 | + // limit_con 2147483647 |
| 59 | + // stride_con 4 |
| 60 | + // trip_count 536870912 |
| 61 | + // final_int -2147483648 |
| 62 | + // final_con 2147483648 |
| 63 | + // |
| 64 | + for (int i = 0; i < x; i+=4 /* works for at least 2..64 */) { |
| 65 | + // Break before going out of bounds |
| 66 | + // but with quadratic check to not affect limit. |
| 67 | + if (i * i > 1000_000) { return; } |
| 68 | + a[i] = 34; |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments