|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 IBM Corporation. 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 8373524 |
| 27 | + * @summary C2: no reachable node should have no use |
| 28 | + * @run main/othervm -Xbatch ${test.main.class} |
| 29 | + * @run main ${test.main.class} |
| 30 | + */ |
| 31 | + |
| 32 | +package compiler.igvn; |
| 33 | + |
| 34 | +public class TestNodeWithNoUseAfterPhiIdeal { |
| 35 | + volatile boolean _mutatorToggle; |
| 36 | + |
| 37 | + boolean _mutatorFlip() { |
| 38 | + synchronized (TestNodeWithNoUseAfterPhiIdeal.class) { |
| 39 | + _mutatorToggle = new MyBoolean(!_mutatorToggle).v; |
| 40 | + return _mutatorToggle; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + class MyBoolean { |
| 45 | + boolean v; |
| 46 | + MyBoolean(boolean v) { |
| 47 | + int N = 32; |
| 48 | + for (int i = 0; i < N; i++) { |
| 49 | + this.v = v; |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + int[] arr; |
| 55 | + void test() { |
| 56 | + int limit = 2; |
| 57 | + boolean flag1 = _mutatorFlip(); |
| 58 | + for (; limit < 4; limit *= 2) { |
| 59 | + if (flag1) { |
| 60 | + break; |
| 61 | + } |
| 62 | + } |
| 63 | + int zero = 34; |
| 64 | + for (int peel = 2; peel < limit; peel++) { |
| 65 | + synchronized (TestNodeWithNoUseAfterPhiIdeal.class) { |
| 66 | + zero = 0; |
| 67 | + } |
| 68 | + } |
| 69 | + if (zero == 0) { |
| 70 | + arr = new int[8]; |
| 71 | + } else { |
| 72 | + int M = 4; |
| 73 | + for (int i = 0; i < M; i++) { |
| 74 | + boolean flag2 = _mutatorFlip(); |
| 75 | + boolean flag3 = _mutatorFlip(); |
| 76 | + if (flag2) { |
| 77 | + break; |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + public static void main(String[] args) { |
| 84 | + TestNodeWithNoUseAfterPhiIdeal t = new TestNodeWithNoUseAfterPhiIdeal(); |
| 85 | + for (int i = 0; i < 10_000; i++) { |
| 86 | + t.test(); |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments