|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, 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 8328107 |
| 27 | + * @summary Barrier expanded on backedge break loop verification code |
| 28 | + * @requires vm.gc.Shenandoah |
| 29 | + * |
| 30 | + * @run main/othervm -XX:+UseShenandoahGC -XX:-BackgroundCompilation -XX:CompileCommand=dontinline,TestBarrierOnLoopBackedge::notInlined |
| 31 | + * -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyLoopOptimizations TestBarrierOnLoopBackedge |
| 32 | + * @run main/othervm -XX:+UseShenandoahGC -XX:-BackgroundCompilation -XX:CompileCommand=dontinline,TestBarrierOnLoopBackedge::notInlined |
| 33 | + * -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyLoopOptimizations -XX:-UseCountedLoopSafepoints TestBarrierOnLoopBackedge |
| 34 | + */ |
| 35 | + |
| 36 | +public class TestBarrierOnLoopBackedge { |
| 37 | + private static A field = new A(); |
| 38 | + private static final A finalField = new A(); |
| 39 | + private static float floatField; |
| 40 | + |
| 41 | + public static void main(String[] args) { |
| 42 | + A[] array = new A[1]; |
| 43 | + array[0] = finalField; |
| 44 | + for (int i = 0; i < 20_000; i++) { |
| 45 | + test1(); |
| 46 | + test2(); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + private static void test1() { |
| 51 | + floatField = field.f; |
| 52 | + for (int i = 0; i < 1000; i++) { |
| 53 | + notInlined(field); // load barrier split thru phi and ends up on back edge |
| 54 | + if (i % 2 == 0) { |
| 55 | + field = finalField; |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + private static void test2() { |
| 61 | + A[] array = new A[1]; |
| 62 | + notInlined(array); |
| 63 | + int i = 0; |
| 64 | + A a = array[0]; |
| 65 | + for (;;) { |
| 66 | + synchronized (new Object()) { |
| 67 | + } |
| 68 | + notInlined(a); |
| 69 | + i++; |
| 70 | + if (i >= 1000) { |
| 71 | + break; |
| 72 | + } |
| 73 | + a = array[0]; // load barrier pinned on backedge |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + private static void notInlined(Object a) { |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + private static class A { |
| 82 | + float f; |
| 83 | + } |
| 84 | +} |
0 commit comments