|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Red Hat, Inc. |
| 3 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | + * accompanied this code). |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License version |
| 17 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | + * |
| 20 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 21 | + * or visit www.oracle.com if you need additional information or have any |
| 22 | + * questions. |
| 23 | + */ |
| 24 | + |
| 25 | +/** |
| 26 | + * @test |
| 27 | + * @bug 8371716 |
| 28 | + * @summary Ranges can be proven to be disjoint but not orderable (thanks to unsigned range) |
| 29 | + * Comparing such values in such range with != should always be true. |
| 30 | + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions |
| 31 | + * -XX:-TieredCompilation |
| 32 | + * -XX:-UseOnStackReplacement |
| 33 | + * -XX:-BackgroundCompilation |
| 34 | + * -XX:CompileOnly=${test.main.class}::test1 |
| 35 | + * -XX:CompileCommand=quiet |
| 36 | + * -XX:TypeProfileLevel=222 |
| 37 | + * -XX:+AlwaysIncrementalInline |
| 38 | + * -XX:VerifyIterativeGVN=10 |
| 39 | + * -XX:CompileCommand=dontinline,${test.main.class}::notInlined1 |
| 40 | + * ${test.main.class} |
| 41 | + * |
| 42 | + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions |
| 43 | + * -XX:+UnlockDiagnosticVMOptions |
| 44 | + * -XX:-TieredCompilation |
| 45 | + * -XX:-UseOnStackReplacement |
| 46 | + * -XX:-BackgroundCompilation |
| 47 | + * -XX:CompileOnly=${test.main.class}::test2 |
| 48 | + * -XX:CompileOnly=${test.main.class}::inlined3 |
| 49 | + * -XX:CompileCommand=quiet |
| 50 | + * -XX:TypeProfileLevel=200 |
| 51 | + * -XX:+AlwaysIncrementalInline |
| 52 | + * -XX:VerifyIterativeGVN=10 |
| 53 | + * -XX:CompileCommand=dontinline,${test.main.class}::notInlined1 |
| 54 | + * -XX:+StressIncrementalInlining |
| 55 | + * ${test.main.class} |
| 56 | + * |
| 57 | + * @run main ${test.main.class} |
| 58 | + */ |
| 59 | + |
| 60 | +package compiler.igvn; |
| 61 | + |
| 62 | +public class ClashingSpeculativeTypePhiNode { |
| 63 | + public static void main(String[] args) { |
| 64 | + main1(); |
| 65 | + main2(); |
| 66 | + } |
| 67 | + |
| 68 | + // 1st case |
| 69 | + |
| 70 | + static void main1() { |
| 71 | + for (int i = 0; i < 20_000; i++) { |
| 72 | + test1(false); // returns null |
| 73 | + inlined1(true, true); // returns C1 |
| 74 | + inlined2(false); // returns C2 |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + private static Object test1(boolean flag1) { |
| 79 | + return inlined1(flag1, false); |
| 80 | + // When inlined1 is inlined |
| 81 | + // return Phi(flag1, inlined2(flag2), null) |
| 82 | + // inlined2 is speculatively returning C1, known from the calls `inlined1(true, true)` in main1 |
| 83 | + // Phi node gets speculative type C1 |
| 84 | + // When inline2 is inlined |
| 85 | + // return Phi[C1](flag1, Phi(false, new C1(), notInlined1()), null) |
| 86 | + // => Phi[C1](flag1, notInlined1(), null) |
| 87 | + // notInlined1 is speculatively returning C2, known from `inline2(false)` in main1 |
| 88 | + // return Phi[C1](flag1, notInlined1()[C2], null) |
| 89 | + // Clashing speculative type between Phi's _type (C1) and union of inputs (C2). |
| 90 | + } |
| 91 | + |
| 92 | + private static Object inlined1(boolean flag1, boolean flag2) { |
| 93 | + if (flag1) { |
| 94 | + return inlined2(flag2); // C1 |
| 95 | + } |
| 96 | + return null; |
| 97 | + } |
| 98 | + |
| 99 | + private static Object inlined2(boolean flag2) { |
| 100 | + if (flag2) { |
| 101 | + return new C1(); |
| 102 | + } |
| 103 | + return notInlined1(); // C2 |
| 104 | + } |
| 105 | + |
| 106 | + private static Object notInlined1() { |
| 107 | + return new C2(); |
| 108 | + } |
| 109 | + |
| 110 | + // 2nd case |
| 111 | + |
| 112 | + static void main2() { |
| 113 | + for (int i = 0; i < 20_000; i++) { |
| 114 | + inlined3(new C1()); |
| 115 | + } |
| 116 | + for (int i = 0; i < 20_000; i++) { |
| 117 | + test2(true, new C2()); |
| 118 | + test2(false, new C2()); |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + |
| 123 | + private static Object test2(boolean flag1, Object o) { |
| 124 | + o = inlined4(o); |
| 125 | + if (flag1) { |
| 126 | + return inlined3(o); |
| 127 | + } |
| 128 | + return null; |
| 129 | + // We profile only parameters. Param o is speculated to be C2. |
| 130 | + // return Phi(flag1, inline3(inline4(o[C2])), null) |
| 131 | + // We inline inline3 |
| 132 | + // return Phi(flag1, inline4(o[C2])[C1], null) |
| 133 | + // As input of inline3, inline4(o) is speculated to be C1. The Phi has C1 as speculative type in _type |
| 134 | + // return Phi[C1](flag1, o[C2], null) |
| 135 | + // Since o is speculated to be C2 as parameter of test2, we get a clash. |
| 136 | + } |
| 137 | + |
| 138 | + private static Object inlined3(Object o) { |
| 139 | + return o; // C1 |
| 140 | + } |
| 141 | + |
| 142 | + private static Object inlined4(Object o) { |
| 143 | + return o; |
| 144 | + } |
| 145 | + |
| 146 | + static class C1 { |
| 147 | + |
| 148 | + } |
| 149 | + |
| 150 | + static class C2 { |
| 151 | + |
| 152 | + } |
| 153 | +} |
0 commit comments