1 /* 2 * Copyright (c) 2017, 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 package compiler.valhalla.inlinetypes; 25 26 import jdk.test.lib.Asserts; 27 import jdk.test.lib.Utils; 28 import compiler.lib.ir_framework.DontInline; 29 import compiler.lib.ir_framework.ForceInline; 30 31 import jdk.internal.vm.annotation.ImplicitlyConstructible; 32 import jdk.internal.vm.annotation.LooselyConsistentValue; 33 import jdk.internal.vm.annotation.NullRestricted; 34 35 @ImplicitlyConstructible 36 @LooselyConsistentValue 37 value class MyValue3Inline { 38 float f7; 39 double f8; 40 41 @ForceInline 42 public MyValue3Inline(float f7, double f8) { 43 this.f7 = f7; 44 this.f8 = f8; 45 } 46 47 @ForceInline 48 static MyValue3Inline setF7(MyValue3Inline v, float f7) { 49 return new MyValue3Inline(f7, v.f8); 50 } 51 52 @ForceInline 53 static MyValue3Inline setF8(MyValue3Inline v, double f8) { 54 return new MyValue3Inline(v.f7, f8); 55 } 56 57 @ForceInline 58 public static MyValue3Inline createDefault() { 59 return new MyValue3Inline(0, 0); 60 } 61 62 @ForceInline 63 public static MyValue3Inline createWithFieldsInline(float f7, double f8) { 64 MyValue3Inline v = createDefault(); 65 v = setF7(v, f7); 66 v = setF8(v, f8); 67 return v; 68 } 69 } 70 71 // Inline type definition to stress test return of an inline type in registers 72 // (uses all registers of calling convention on x86_64) 73 @ImplicitlyConstructible 74 @LooselyConsistentValue 75 public value class MyValue3 extends MyAbstract { 76 char c; 77 byte bb; 78 short s; 79 int i; 80 long l; 81 Object o; 82 float f1; 83 double f2; 84 float f3; 85 double f4; 86 float f5; 87 double f6; 88 @NullRestricted 89 MyValue3Inline v1; 90 91 @ForceInline 92 public MyValue3(char c, byte bb, short s, int i, long l, Object o, 93 float f1, double f2, float f3, double f4, float f5, double f6, 94 MyValue3Inline v1) { 95 this.c = c; 96 this.bb = bb; 97 this.s = s; 98 this.i = i; 99 this.l = l; 100 this.o = o; 101 this.f1 = f1; 102 this.f2 = f2; 103 this.f3 = f3; 104 this.f4 = f4; 105 this.f5 = f5; 106 this.f6 = f6; 107 this.v1 = v1; 108 } 109 110 @ForceInline 111 static MyValue3 setC(MyValue3 v, char c) { 112 return new MyValue3(c, v.bb, v.s, v.i, v.l, v.o, v.f1, v.f2, v.f3, v.f4, v.f5, v.f6, v.v1); 113 } 114 115 @ForceInline 116 static MyValue3 setBB(MyValue3 v, byte bb) { 117 return new MyValue3(v.c, bb, v.s, v.i, v.l, v.o, v.f1, v.f2, v.f3, v.f4, v.f5, v.f6, v.v1); 118 } 119 120 @ForceInline 121 static MyValue3 setS(MyValue3 v, short s) { 122 return new MyValue3(v.c, v.bb, s, v.i, v.l, v.o, v.f1, v.f2, v.f3, v.f4, v.f5, v.f6, v.v1); 123 } 124 125 @ForceInline 126 static MyValue3 setI(MyValue3 v, int i) { 127 return new MyValue3(v.c, v.bb, v.s, i, v.l, v.o, v.f1, v.f2, v.f3, v.f4, v.f5, v.f6, v.v1); 128 } 129 130 @ForceInline 131 static MyValue3 setL(MyValue3 v, long l) { 132 return new MyValue3(v.c, v.bb, v.s, v.i, l, v.o, v.f1, v.f2, v.f3, v.f4, v.f5, v.f6, v.v1); 133 } 134 135 @ForceInline 136 static MyValue3 setO(MyValue3 v, Object o) { 137 return new MyValue3(v.c, v.bb, v.s, v.i, v.l, o, v.f1, v.f2, v.f3, v.f4, v.f5, v.f6, v.v1); 138 } 139 140 @ForceInline 141 static MyValue3 setF1(MyValue3 v, float f1) { 142 return new MyValue3(v.c, v.bb, v.s, v.i, v.l, v.o, f1, v.f2, v.f3, v.f4, v.f5, v.f6, v.v1); 143 } 144 145 @ForceInline 146 static MyValue3 setF2(MyValue3 v, double f2) { 147 return new MyValue3(v.c, v.bb, v.s, v.i, v.l, v.o, v.f1, f2, v.f3, v.f4, v.f5, v.f6, v.v1); 148 } 149 150 @ForceInline 151 static MyValue3 setF3(MyValue3 v, float f3) { 152 return new MyValue3(v.c, v.bb, v.s, v.i, v.l, v.o, v.f1, v.f2, f3, v.f4, v.f5, v.f6, v.v1); 153 } 154 155 @ForceInline 156 static MyValue3 setF4(MyValue3 v, double f4) { 157 return new MyValue3(v.c, v.bb, v.s, v.i, v.l, v.o, v.f1, v.f2, v.f3, f4, v.f5, v.f6, v.v1); 158 } 159 160 @ForceInline 161 static MyValue3 setF5(MyValue3 v, float f5) { 162 return new MyValue3(v.c, v.bb, v.s, v.i, v.l, v.o, v.f1, v.f2, v.f3, v.f4, f5, v.f6, v.v1); 163 } 164 165 @ForceInline 166 static MyValue3 setF6(MyValue3 v, double f6) { 167 return new MyValue3(v.c, v.bb, v.s, v.i, v.l, v.o, v.f1, v.f2, v.f3, v.f4, v.f5, f6, v.v1); 168 } 169 170 @ForceInline 171 static MyValue3 setV1(MyValue3 v, MyValue3Inline v1) { 172 return new MyValue3(v.c, v.bb, v.s, v.i, v.l, v.o, v.f1, v.f2, v.f3, v.f4, v.f5, v.f6, v1); 173 } 174 175 @ForceInline 176 public static MyValue3 createDefault() { 177 return new MyValue3((char)0, (byte)0, (short)0, 0, 0, null, 0, 0, 0, 0, 0, 0, MyValue3Inline.createDefault()); 178 } 179 180 @ForceInline 181 public static MyValue3 create() { 182 java.util.Random r = Utils.getRandomInstance(); 183 MyValue3 v = createDefault(); 184 v = setC(v, (char)r.nextInt()); 185 v = setBB(v, (byte)r.nextInt()); 186 v = setS(v, (short)r.nextInt()); 187 v = setI(v, r.nextInt()); 188 v = setL(v, r.nextLong()); 189 v = setO(v, new Object()); 190 v = setF1(v, r.nextFloat()); 191 v = setF2(v, r.nextDouble()); 192 v = setF3(v, r.nextFloat()); 193 v = setF4(v, r.nextDouble()); 194 v = setF5(v, r.nextFloat()); 195 v = setF6(v, r.nextDouble()); 196 v = setV1(v, MyValue3Inline.createWithFieldsInline(r.nextFloat(), r.nextDouble())); 197 return v; 198 } 199 200 @DontInline 201 public static MyValue3 createDontInline() { 202 return create(); 203 } 204 205 @ForceInline 206 public static MyValue3 copy(MyValue3 other) { 207 MyValue3 v = createDefault(); 208 v = setC(v, other.c); 209 v = setBB(v, other.bb); 210 v = setS(v, other.s); 211 v = setI(v, other.i); 212 v = setL(v, other.l); 213 v = setO(v, other.o); 214 v = setF1(v, other.f1); 215 v = setF2(v, other.f2); 216 v = setF3(v, other.f3); 217 v = setF4(v, other.f4); 218 v = setF5(v, other.f5); 219 v = setF6(v, other.f6); 220 v = setV1(v, other.v1); 221 return v; 222 } 223 224 @DontInline 225 public void verify(MyValue3 other) { 226 Asserts.assertEQ(c, other.c); 227 Asserts.assertEQ(bb, other.bb); 228 Asserts.assertEQ(s, other.s); 229 Asserts.assertEQ(i, other.i); 230 Asserts.assertEQ(l, other.l); 231 Asserts.assertEQ(o, other.o); 232 Asserts.assertEQ(f1, other.f1); 233 Asserts.assertEQ(f2, other.f2); 234 Asserts.assertEQ(f3, other.f3); 235 Asserts.assertEQ(f4, other.f4); 236 Asserts.assertEQ(f5, other.f5); 237 Asserts.assertEQ(f6, other.f6); 238 Asserts.assertEQ(v1.f7, other.v1.f7); 239 Asserts.assertEQ(v1.f8, other.v1.f8); 240 } 241 242 @ForceInline 243 public long hash() { 244 return c + 245 bb + 246 s + 247 i + 248 l + 249 o.hashCode() + 250 Float.hashCode(f1) + 251 Double.hashCode(f2) + 252 Float.hashCode(f3) + 253 Double.hashCode(f4) + 254 Float.hashCode(f5) + 255 Double.hashCode(f6) + 256 Float.hashCode(v1.f7) + 257 Double.hashCode(v1.f8); 258 } 259 } 260