|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 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 8251527 |
| 27 | + * @summary CTW: C2 (Shenandoah) compilation fails with SEGV due to unhandled catchproj == NUL |
| 28 | + * @requires vm.flavor == "server" |
| 29 | + * @requires vm.gc.Shenandoah & !vm.graal.enabled |
| 30 | + * |
| 31 | + * @run main/othervm -XX:+UseShenandoahGC -XX:CompileOnly=TestLoadPinnedAfterCall.test -XX:CompileCommand=dontinline,TestLoadPinnedAfterCall.not_inlined -XX:-TieredCompilation -XX:-BackgroundCompilation TestLoadPinnedAfterCall |
| 32 | + * |
| 33 | + */ |
| 34 | + |
| 35 | +public class TestLoadPinnedAfterCall { |
| 36 | + private A staticField1; |
| 37 | + private static Object staticField2 = new Object(); |
| 38 | + private static volatile int staticField3; |
| 39 | + private static int staticField4; |
| 40 | + static TestLoadPinnedAfterCall object = new TestLoadPinnedAfterCall(); |
| 41 | + |
| 42 | + public static void main(String[] args) { |
| 43 | + final A a = new A(); |
| 44 | + try { |
| 45 | + throw new Exception(); |
| 46 | + } catch (Exception ex) { |
| 47 | + } |
| 48 | + for (int i = 0; i < 20_000; i++) { |
| 49 | + inlined(0, 0, 0); |
| 50 | + inlined(2, 0, 0); |
| 51 | + inlined(2, 2, 2); |
| 52 | + |
| 53 | + object.staticField1 = new A(); |
| 54 | + test(true, a, a, false, 2, 2); |
| 55 | + test(false, a, a, true, 2, 2); |
| 56 | + test(false, a, a, false, 2, 2); |
| 57 | + object.staticField1 = a; |
| 58 | + test(true, a, a, false, 2, 2); |
| 59 | + test(false, a, a, true, 2, 2); |
| 60 | + test(false, a, a, false, 2, 2); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + private static void test(boolean flag, A a, A a2, boolean flag2, int i1, int i2) { |
| 65 | + |
| 66 | + int ii = 1; |
| 67 | + for (; ii < 2; ii *= 2) { |
| 68 | + |
| 69 | + } |
| 70 | + ii = ii / 2; |
| 71 | + |
| 72 | + i1 = 0; |
| 73 | + for (; i1 < 2; i1 += ii) { |
| 74 | + for (int i = 0; i < 2; i += ii) { |
| 75 | + |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + i2 = 0; |
| 80 | + for (; i2 < 2; i2 += ii) { |
| 81 | + for (int i = 0; i < 2; i += ii) { |
| 82 | + for (int j = 0; j < 2; j += ii) { |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + TestLoadPinnedAfterCall obj = object; |
| 90 | + if (obj == null) { |
| 91 | + } |
| 92 | + counter = 10; |
| 93 | + for (;;) { |
| 94 | + synchronized (staticField2) { |
| 95 | + } |
| 96 | + int i = 0; |
| 97 | + for (; i < 2; i += ii) { |
| 98 | + |
| 99 | + } |
| 100 | + |
| 101 | + inlined(i, i1, i2); |
| 102 | + |
| 103 | + if (flag) { |
| 104 | + staticField3 = 0x42; |
| 105 | + break; |
| 106 | + } |
| 107 | + try { |
| 108 | + not_inlined(); |
| 109 | + if (flag2) { |
| 110 | + break; |
| 111 | + } |
| 112 | + } catch (Throwable throwable) { |
| 113 | + if (a == obj.staticField1) { |
| 114 | + staticField4 = 0x42; |
| 115 | + } |
| 116 | + break; |
| 117 | + } |
| 118 | + } |
| 119 | + if (a2 == obj.staticField1) { |
| 120 | + staticField4 = 0x42; |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + private static void inlined(int i, int j, int k) { |
| 125 | + if (i == 2) { |
| 126 | + if (j == 2) { |
| 127 | + staticField3 = 0x42; |
| 128 | + } |
| 129 | + if (k == 2) { |
| 130 | + staticField3 = 0x42; |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + static int counter = 0; |
| 136 | + private static void not_inlined() { |
| 137 | + counter--; |
| 138 | + if (counter <= 0) { |
| 139 | + throw new RuntimeException(); |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + private static class A { |
| 144 | + } |
| 145 | +} |
0 commit comments