1 /*
  2  * Copyright (c) 2019, 2024, Oracle and/or its affiliates. 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 8230397
 27  * @summary Test removal of an already dead AllocateNode with not-yet removed proj outputs.
 28  * @enablePreview
 29  * @modules java.base/jdk.internal.value
 30  *          java.base/jdk.internal.vm.annotation
 31  * @run main/othervm -Xbatch TestDeadAllocationRemoval
 32  */
 33 
 34 import jdk.internal.vm.annotation.ImplicitlyConstructible;
 35 import jdk.internal.vm.annotation.LooselyConsistentValue;
 36 import jdk.internal.vm.annotation.NullRestricted;
 37 
 38 public class TestDeadAllocationRemoval {
 39 
 40     public static void main(String[] args) {
 41         Test test = new Test();
 42         for (int i = 0; i < 10; ++i) {
 43             test.test();
 44         }
 45     }
 46 }
 47 
 48 @ImplicitlyConstructible
 49 @LooselyConsistentValue
 50 value class MyValue {
 51     public static long instanceCount = 0;
 52     public float fFld = 0;
 53     public boolean bFld = true;
 54     public float fFld1 = 0;
 55 }
 56 
 57 class Test {
 58     public static final int N = 400;
 59 
 60     public static long instanceCount=2149450457L;
 61     public static double dFld=63.1805;
 62     public static boolean bFld1=false;
 63     public static int iFld=-4;
 64     public static double dArrFld[]=new double[N];
 65     public static int iArrFld[]=new int[N];
 66     @NullRestricted
 67     public static MyValue OFld=new MyValue();
 68 
 69     public static long vMeth_check_sum = 0;
 70     public static long lMeth_check_sum = 0;
 71 
 72     public void vMeth(int i) {
 73         for (double d = 8; d < 307; d++) {
 74             for (int i3 = 1; i3 < 6; i3 += 2) {
 75                 i <<= -23877;
 76             }
 77         }
 78     }
 79 
 80     public void test() {
 81         int i21=-35918, i22=11, i23=31413, i24=-7, i25=0, i26=70;
 82         double d3=0.122541;
 83 
 84         vMeth(Test.iFld);
 85         for (i21 = 20; i21 < 396; ++i21) {
 86             d3 = 1;
 87             while (++d3 < 67) {
 88                 byte by=38;
 89                 Test.dArrFld[(int)(d3)] = -7;
 90                 switch ((i21 % 9) + 1) {
 91                 case 1:
 92                     for (i23 = 1; i23 < 1; i23 += 3) {
 93                         Test.instanceCount = i22;
 94                         Test.iFld -= (int)Test.OFld.fFld1;
 95                         Test.instanceCount >>= MyValue.instanceCount;
 96                         i22 = (int)Test.OFld.fFld1;
 97                         Test.bFld1 = false;
 98                         Test.iArrFld[(int)(d3 - 1)] &= i23;
 99                         i22 += (i23 + i24);
100                         i22 -= (int)d3;
101                         Test.iFld |= (int)MyValue.instanceCount;
102                     }
103                     Test.iFld -= (int)Test.instanceCount;
104                     break;
105                 case 2:
106                     for (i25 = 1; i25 < 1; i25++) {
107                         i26 += i22;
108                         i26 += i25;
109                         Test.iArrFld[i25 + 1] += (int)MyValue.instanceCount;
110                         i22 += (i25 - Test.instanceCount);
111                         i26 += (i25 + i21);
112                     }
113                     Test.instanceCount -= 2;
114                     Test.dFld = i22;
115                     Test.iFld += (int)(((d3 * by) + by) - i24);
116                     break;
117                 case 3:
118                     i24 = (int)1.84829;
119                     Test.OFld = new MyValue();
120                     break;
121                 case 4:
122                     Test.OFld = new MyValue();
123                     MyValue.instanceCount += (long)d3;
124                     break;
125                 case 5:
126                     MyValue.instanceCount += (long)(d3 * d3);
127                     break;
128                 case 6:
129                     Test.dFld -= i25;
130                 case 7:
131                     try {
132                         i24 = (78 / Test.iFld);
133                         Test.iFld = (-5836 / Test.iArrFld[(int)(d3 + 1)]);
134                         i24 = (i23 / -205);
135                     } catch (ArithmeticException a_e) {}
136                     break;
137                 case 8:
138                     if (Test.bFld1) continue;
139                 case 9:
140                 default:
141                     try {
142                         i26 = (i24 / -929688879);
143                         i24 = (Test.iArrFld[(int)(d3)] % -1067487586);
144                         Test.iArrFld[(int)(d3)] = (-208 % i24);
145                     } catch (ArithmeticException a_e) {}
146                 }
147             }
148         }
149 
150         System.out.println("i21 i22 d3 = " + i21 + "," + i22 + "," + Double.doubleToLongBits(d3));
151         System.out.println("i23 i24 Test.OFld.fFld1 = " + i23 + "," + i24 + "," + Float.floatToIntBits(Test.OFld.fFld1));
152         System.out.println("MyValue = " + MyValue.instanceCount);
153         System.out.println("Test.instanceCount Test.dFld Test.bFld1 = " + Test.instanceCount + "," + Double.doubleToLongBits(Test.dFld) + "," + (Test.bFld1 ? 1 : 0));
154         System.out.println("MyValue = " + MyValue.instanceCount);
155         System.out.println("lMeth_check_sum: " + lMeth_check_sum);
156         System.out.println("vMeth_check_sum: " + vMeth_check_sum);
157     }
158 }