1 /*
  2  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2019, Red Hat, Inc. 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 8231620
 28  * @summary assert(bol->is_Bool()) crash during split if due to FastLockNode
 29  *
 30  * @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement SplitIfSharedFastLockBehindCastPP
 31  */
 32 
 33 
 34 public class SplitIfSharedFastLockBehindCastPP {
 35     private static boolean field;
 36     private static A obj_field;
 37 
 38     public static void main(String[] args) {
 39         A lock = new A();
 40         obj_field = lock;
 41         for (int i = 0; i < 20_000; i++) {
 42             test1(true, lock);
 43             test1(false, lock);
 44             test2(true);
 45             test2(false);
 46         }
 47     }
 48 
 49     private static void test1(boolean flag, Object obj) {
 50         if (obj == null) {
 51         }
 52 
 53         boolean flag2;
 54         if (flag) {
 55             flag2 = true;
 56         } else {
 57             flag2 = false;
 58             obj = obj_field;
 59         }
 60 
 61         // This loop will be unswitched. The condition becomes candidate for split if
 62         for (int i = 0; i < 100; i++) {
 63             if (flag2) {
 64                 field = true;
 65             } else {
 66                 field = false;
 67             }
 68             synchronized (obj) {
 69                 field = true;
 70             }
 71         }
 72     }
 73 
 74     static class MyBox {
 75         int val;
 76 
 77         public MyBox(int val) {
 78             this.val = val;
 79         }
 80     }
 81 
 82     private static Object test2(boolean flag) {
 83         int integer;
 84         if (flag) {
 85             field = true;
 86             integer = 1;
 87         } else {
 88             field = false;
 89             integer = 2;
 90         }
 91 
 92         Object obj = new MyBox(integer);
 93 
 94         // This loop will be unswitched. The condition becomes candidate for split if
 95         for (int i = 0; i < 100; i++) {
 96             if (integer == 1) {
 97                 field = true;
 98             } else {
 99                 field = false;
100             }
101             synchronized (obj) {
102                 field = true;
103             }
104         }
105         return obj;
106     }
107 
108     private static final class A {
109     }
110 }