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.DontInline;
 27 import compiler.lib.ir_framework.ForceInline;
 28 
 29 final primitive class MyValue2Inline {
 30     final double d;
 31     final long l;
 32 
 33     @ForceInline
 34     public MyValue2Inline(double d, long l) {
 35         this.d = d;
 36         this.l = l;
 37     }
 38 
 39     @ForceInline
 40     static MyValue2Inline setD(MyValue2Inline v, double d) {
 41         return new MyValue2Inline(d, v.l);
 42     }
 43 
 44     @ForceInline
 45     static MyValue2Inline setL(MyValue2Inline v, long l) {
 46         return new MyValue2Inline(v.d, l);
 47     }
 48 
 49     @ForceInline
 50     public static MyValue2Inline createDefault() {
 51         return MyValue2Inline.default;
 52     }
 53 
 54     @ForceInline
 55     public static MyValue2Inline createWithFieldsInline(double d, long l) {
 56         MyValue2Inline v = MyValue2Inline.createDefault();
 57         v = MyValue2Inline.setD(v, d);
 58         v = MyValue2Inline.setL(v, l);
 59         return v;
 60     }
 61 }
 62 
 63 public final primitive class MyValue2 extends MyAbstract {
 64     final int x;
 65     final byte y;
 66     final MyValue2Inline v;
 67 
 68     @ForceInline
 69     public MyValue2(int x, byte y, MyValue2Inline v) {
 70         this.x = x;
 71         this.y = y;
 72         this.v = v;
 73     }
 74 
 75     @ForceInline
 76     public static MyValue2 createDefaultInline() {
 77         return MyValue2.default;
 78     }
 79 
 80     @ForceInline
 81     public static MyValue2 createWithFieldsInline(int x, long y, double d) {
 82         MyValue2 v = createDefaultInline();
 83         v = setX(v, x);
 84         v = setY(v, (byte)x);
 85         v = setV(v, MyValue2Inline.createWithFieldsInline(d, y));
 86         return v;
 87     }
 88 
 89     @ForceInline
 90     public static MyValue2 createWithFieldsInline(int x, double d) {
 91         MyValue2 v = createDefaultInline();
 92         v = setX(v, x);
 93         v = setY(v, (byte)x);
 94         v = setV(v, MyValue2Inline.createWithFieldsInline(d, InlineTypes.rL));
 95         return v;
 96     }
 97 
 98     @DontInline
 99     public static MyValue2 createWithFieldsDontInline(int x, double d) {
100         MyValue2 v = createDefaultInline();
101         v = setX(v, x);
102         v = setY(v, (byte)x);
103         v = setV(v, MyValue2Inline.createWithFieldsInline(d, InlineTypes.rL));
104         return v;
105     }
106 
107     @ForceInline
108     public long hash() {
109         return x + y + (long)v.d + v.l;
110     }
111 
112     @DontInline
113     public long hashInterpreted() {
114         return x + y + (long)v.d + v.l;
115     }
116 
117     @ForceInline
118     public void print() {
119         System.out.print("x=" + x + ", y=" + y + ", d=" + v.d + ", l=" + v.l);
120     }
121 
122     @ForceInline
123     static MyValue2 setX(MyValue2 v, int x) {
124         return new MyValue2(x, v.y, v.v);
125     }
126 
127     @ForceInline
128     static MyValue2 setY(MyValue2 v, byte y) {
129         return new MyValue2(v.x, y, v.v);
130     }
131 
132     @ForceInline
133     static MyValue2 setV(MyValue2 v, MyValue2Inline vi) {
134         return new MyValue2(v.x, v.y, vi);
135     }
136 }