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