1 /* 2 * Copyright (c) 2017, 2021, 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 package compiler.valhalla.inlinetypes; 25 26 import compiler.lib.ir_framework.DontCompile; 27 import compiler.lib.ir_framework.DontInline; 28 import compiler.lib.ir_framework.ForceCompileClassInitializer; 29 import compiler.lib.ir_framework.ForceInline; 30 31 @ForceCompileClassInitializer 32 public final primitive class MyValue1 extends MyAbstract { 33 static int s; 34 static final long sf = InlineTypes.rL; 35 final int x; 36 final long y; 37 final short z; 38 final Integer o; 39 final int[] oa; 40 final MyValue2 v1; 41 final MyValue2 v2; 42 static final MyValue2 v3 = MyValue2.createWithFieldsInline(InlineTypes.rI, InlineTypes.rD); 43 final MyValue2.ref v4; 44 final MyValue2 v5; 45 final int c; 46 47 @ForceInline 48 public MyValue1(int x, long y, short z, Integer o, int[] oa, MyValue2 v1, MyValue2 v2, MyValue2.ref v4, MyValue2.ref v5, int c) { 49 s = 0; 50 this.x = x; 51 this.y = y; 52 this.z = z; 53 this.o = o; 54 this.oa = oa; 55 this.v1 = v1; 56 this.v2 = v2; 57 this.v4 = v4; 58 this.v5 = v5; 59 this.c = c; 60 } 61 62 @DontInline 63 static MyValue1 createDefaultDontInline() { 64 return createDefaultInline(); 65 } 66 67 @ForceInline 68 static MyValue1 createDefaultInline() { 69 return MyValue1.default; 70 } 71 72 @DontInline 73 static MyValue1 createWithFieldsDontInline(int x, long y) { 74 return createWithFieldsInline(x, y); 75 } 76 77 @ForceInline 78 static MyValue1 createWithFieldsInline(int x, long y) { 79 MyValue1 v = createDefaultInline(); 80 v = setX(v, x); 81 v = setY(v, y); 82 v = setZ(v, (short)x); 83 // Don't use Integer.valueOf here to avoid control flow added by Integer cache check 84 v = setO(v, new Integer(x)); 85 int[] oa = {x}; 86 v = setOA(v, oa); 87 v = setV1(v, MyValue2.createWithFieldsInline(x, y, InlineTypes.rD)); 88 v = setV2(v, MyValue2.createWithFieldsInline(x + 1, y + 1, InlineTypes.rD + 1)); 89 v = setV4(v, MyValue2.createWithFieldsInline(x + 2, y + 2, InlineTypes.rD + 2)); 90 v = setV5(v, MyValue2.createWithFieldsInline(x + 3, y + 3, InlineTypes.rD + 3)); 91 v = setC(v, (int)(x+y)); 92 return v; 93 } 94 95 // Hash only primitive and inline type fields to avoid NullPointerException 96 @ForceInline 97 public long hashPrimitive() { 98 return s + sf + x + y + z + c + v1.hash() + v2.hash() + v3.hash() + v5.hash(); 99 } 100 101 @ForceInline 102 public long hash() { 103 long res = hashPrimitive(); 104 try { 105 res += o; 106 } catch (NullPointerException npe) {} 107 try { 108 res += oa[0]; 109 } catch (NullPointerException npe) {} 110 try { 111 res += v4.hash(); 112 } catch (NullPointerException npe) {} 113 return res; 114 } 115 116 @DontCompile 117 public long hashInterpreted() { 118 return s + sf + x + y + z + o + oa[0] + c + v1.hashInterpreted() + v2.hashInterpreted() + v3.hashInterpreted() + v4.hashInterpreted() + v5.hashInterpreted(); 119 } 120 121 @ForceInline 122 public void print() { 123 System.out.print("s=" + s + ", sf=" + sf + ", x=" + x + ", y=" + y + ", z=" + z + ", o=" + (o != null ? (Integer)o : "NULL") + ", oa=" + (oa != null ? oa[0] : "NULL") + ", v1["); 124 v1.print(); 125 System.out.print("], v2["); 126 v2.print(); 127 System.out.print("], v3["); 128 v3.print(); 129 System.out.print("], v4["); 130 v4.print(); 131 System.out.print("], v5["); 132 v5.print(); 133 System.out.print("], c=" + c); 134 } 135 136 @ForceInline 137 static MyValue1 setX(MyValue1 v, int x) { 138 return new MyValue1(x, v.y, v.z, v.o, v.oa, v.v1, v.v2, v.v4, v.v5, v.c); 139 } 140 141 @ForceInline 142 static MyValue1 setY(MyValue1 v, long y) { 143 return new MyValue1(v.x, y, v.z, v.o, v.oa, v.v1, v.v2, v.v4, v.v5, v.c); 144 } 145 146 @ForceInline 147 static MyValue1 setZ(MyValue1 v, short z) { 148 return new MyValue1(v.x, v.y, z, v.o, v.oa, v.v1, v.v2, v.v4, v.v5, v.c); 149 } 150 151 @ForceInline 152 static MyValue1 setO(MyValue1 v, Integer o) { 153 return new MyValue1(v.x, v.y, v.z, o, v.oa, v.v1, v.v2, v.v4, v.v5, v.c); 154 } 155 156 @ForceInline 157 static MyValue1 setOA(MyValue1 v, int[] oa) { 158 return new MyValue1(v.x, v.y, v.z, v.o, oa, v.v1, v.v2, v.v4, v.v5, v.c); 159 } 160 161 @ForceInline 162 static MyValue1 setC(MyValue1 v, int c) { 163 return new MyValue1(v.x, v.y, v.z, v.o, v.oa, v.v1, v.v2, v.v4, v.v5, c); 164 } 165 166 @ForceInline 167 static MyValue1 setV1(MyValue1 v, MyValue2 v1) { 168 return new MyValue1(v.x, v.y, v.z, v.o, v.oa, v1, v.v2, v.v4, v.v5, v.c); 169 } 170 171 @ForceInline 172 static MyValue1 setV2(MyValue1 v, MyValue2 v2) { 173 return new MyValue1(v.x, v.y, v.z, v.o, v.oa, v.v1, v2, v.v4, v.v5, v.c); 174 } 175 176 @ForceInline 177 static MyValue1 setV4(MyValue1 v, MyValue2.ref v4) { 178 return new MyValue1(v.x, v.y, v.z, v.o, v.oa, v.v1, v.v2, v4, v.v5, v.c); 179 } 180 181 @ForceInline 182 static MyValue1 setV5(MyValue1 v, MyValue2.ref v5) { 183 return new MyValue1(v.x, v.y, v.z, v.o, v.oa, v.v1, v.v2, v.v4, v5, v.c); 184 } 185 }