1 /*
  2  * Copyright (c) 2022, 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 compiler.lib.ir_framework.DontInline;
 27 import compiler.lib.ir_framework.ForceInline;
 28 
 29 value class MyValueClass2Inline {
 30     double d;
 31     long l;
 32 
 33     @ForceInline
 34     public MyValueClass2Inline(double d, long l) {
 35         this.d = d;
 36         this.l = l;
 37     }
 38 
 39     @ForceInline
 40     static MyValueClass2Inline setD(MyValueClass2Inline v, double d) {
 41         return new MyValueClass2Inline(d, v.l);
 42     }
 43 
 44     @ForceInline
 45     static MyValueClass2Inline setL(MyValueClass2Inline v, long l) {
 46         return new MyValueClass2Inline(v.d, l);
 47     }
 48 
 49     @ForceInline
 50     public static MyValueClass2Inline createDefault() {
 51         return new MyValueClass2Inline(0, 0);
 52     }
 53 
 54     @ForceInline
 55     public static MyValueClass2Inline createWithFieldsInline(double d, long l) {
 56         MyValueClass2Inline v = MyValueClass2Inline.createDefault();
 57         v = MyValueClass2Inline.setD(v, d);
 58         v = MyValueClass2Inline.setL(v, l);
 59         return v;
 60     }
 61 }
 62 
 63 public value class MyValueClass2 extends MyAbstract {
 64     int x;
 65     byte y;
 66     MyValueClass2Inline v;
 67 
 68     @ForceInline
 69     public MyValueClass2(int x, byte y, MyValueClass2Inline v) {
 70         this.x = x;
 71         this.y = y;
 72         this.v = v;
 73     }
 74 
 75     @ForceInline
 76     public static MyValueClass2 createDefaultInline() {
 77         return new MyValueClass2(0, (byte)0, null);
 78     }
 79 
 80     @ForceInline
 81     public static MyValueClass2 createWithFieldsInline(int x, long y, double d) {
 82         MyValueClass2 v = createDefaultInline();
 83         v = setX(v, x);
 84         v = setY(v, (byte)x);
 85         v = setV(v, MyValueClass2Inline.createWithFieldsInline(d, y));
 86         return v;
 87     }
 88 
 89     @ForceInline
 90     public static MyValueClass2 createWithFieldsInline(int x, double d) {
 91         MyValueClass2 v = createDefaultInline();
 92         v = setX(v, x);
 93         v = setY(v, (byte)x);
 94         v = setV(v, MyValueClass2Inline.createWithFieldsInline(d, InlineTypes.rL));
 95         return v;
 96     }
 97 
 98     @DontInline
 99     public static MyValueClass2 createWithFieldsDontInline(int x, double d) {
100         MyValueClass2 v = createDefaultInline();
101         v = setX(v, x);
102         v = setY(v, (byte)x);
103         v = setV(v, MyValueClass2Inline.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 MyValueClass2 setX(MyValueClass2 v, int x) {
124         return new MyValueClass2(x, v.y, v.v);
125     }
126 
127     @ForceInline
128     static MyValueClass2 setY(MyValueClass2 v, byte y) {
129         return new MyValueClass2(v.x, y, v.v);
130     }
131 
132     @ForceInline
133     static MyValueClass2 setV(MyValueClass2 v, MyValueClass2Inline vi) {
134         return new MyValueClass2(v.x, v.y, vi);
135     }
136 }