1 /* 2 * Copyright (c) 2017, 2018, 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.valuetypes; 25 26 import jdk.test.lib.Asserts; 27 import jdk.test.lib.Utils; 28 29 value final class MyValue3Inline { 30 final float f7; 31 final double f8; 32 33 private MyValue3Inline() { 34 this.f7 = 0; 35 this.f8 = 0; 36 } 37 38 @ForceInline 39 static MyValue3Inline setF7(MyValue3Inline v, float f7) { 40 v = __WithField(v.f7, f7); 41 return v; 42 } 43 44 @ForceInline 45 static MyValue3Inline setF8(MyValue3Inline v, double f8) { 46 v = __WithField(v.f8, f8); 47 return v; 48 } 49 50 @ForceInline 51 public static MyValue3Inline createDefault() { 52 return MyValue3Inline.default; 53 } 54 55 @ForceInline 56 public static MyValue3Inline createWithFieldsInline(float f7, double f8) { 57 MyValue3Inline v = createDefault(); 58 v = setF7(v, f7); 59 v = setF8(v, f8); 60 return v; 61 } 62 } 63 64 // Value type definition to stress test return of a value in registers 65 // (uses all registers of calling convention on x86_64) 66 value public final class MyValue3 implements MyInterface { 67 final char c; 68 final byte bb; 69 final short s; 70 final int i; 71 final long l; 72 final Object o; 73 final float f1; 74 final double f2; 75 final float f3; 76 final double f4; 77 final float f5; 78 final double f6; 79 final MyValue3Inline.val v1; 80 81 private MyValue3() { 82 this.c = 0; 83 this.bb = 0; 84 this.s = 0; 85 this.i = 0; 86 this.l = 0; 87 this.o = null; 88 this.f1 = 0; 89 this.f2 = 0; 90 this.f3 = 0; 91 this.f4 = 0; 92 this.f5 = 0; 93 this.f6 = 0; 94 this.v1 = MyValue3Inline.createDefault(); 95 } 96 97 @ForceInline 98 static MyValue3 setC(MyValue3 v, char c) { 99 v = __WithField(v.c, c); 100 return v; 101 } 102 103 @ForceInline 104 static MyValue3 setBB(MyValue3 v, byte bb) { 105 v = __WithField(v.bb, bb); 106 return v; 107 } 108 109 @ForceInline 110 static MyValue3 setS(MyValue3 v, short s) { 111 v = __WithField(v.s, s); 112 return v; 113 } 114 115 @ForceInline 116 static MyValue3 setI(MyValue3 v, int i) { 117 v = __WithField(v.i, i); 118 return v; 119 } 120 121 @ForceInline 122 static MyValue3 setL(MyValue3 v, long l) { 123 v = __WithField(v.l, l); 124 return v; 125 } 126 127 @ForceInline 128 static MyValue3 setO(MyValue3 v, Object o) { 129 v = __WithField(v.o, o); 130 return v; 131 } 132 133 @ForceInline 134 static MyValue3 setF1(MyValue3 v, float f1) { 135 v = __WithField(v.f1, f1); 136 return v; 137 } 138 139 @ForceInline 140 static MyValue3 setF2(MyValue3 v, double f2) { 141 v = __WithField(v.f2, f2); 142 return v; 143 } 144 145 @ForceInline 146 static MyValue3 setF3(MyValue3 v, float f3) { 147 v = __WithField(v.f3, f3); 148 return v; 149 } 150 151 @ForceInline 152 static MyValue3 setF4(MyValue3 v, double f4) { 153 v = __WithField(v.f4, f4); 154 return v; 155 } 156 157 @ForceInline 158 static MyValue3 setF5(MyValue3 v, float f5) { 159 v = __WithField(v.f5, f5); 160 return v; 161 } 162 163 @ForceInline 164 static MyValue3 setF6(MyValue3 v, double f6) { 165 v = __WithField(v.f6, f6); 166 return v; 167 } 168 169 @ForceInline 170 static MyValue3 setV1(MyValue3 v, MyValue3Inline v1) { 171 v = __WithField(v.v1, v1); 172 return v; 173 } 174 175 @ForceInline 176 public static MyValue3 createDefault() { 177 return MyValue3.default; 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