1 /* 2 * Copyright (c) 2017, 2025, 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 import jdk.internal.vm.annotation.LooselyConsistentValue; 30 import jdk.internal.vm.annotation.NullRestricted; 31 import jdk.internal.vm.annotation.Strict; 32 33 @LooselyConsistentValue 34 value class MyValue2Inline { 35 double d; 36 long l; 37 38 @ForceInline 39 public MyValue2Inline(double d, long l) { 40 this.d = d; 41 this.l = l; 42 } 43 44 @ForceInline 45 static MyValue2Inline setD(MyValue2Inline v, double d) { 46 return new MyValue2Inline(d, v.l); 47 } 48 49 @ForceInline 50 static MyValue2Inline setL(MyValue2Inline v, long l) { 51 return new MyValue2Inline(v.d, l); 52 } 53 54 @ForceInline 55 public static MyValue2Inline createDefault() { 56 return new MyValue2Inline(0, 0); 57 } 58 59 @ForceInline 60 public static MyValue2Inline createWithFieldsInline(double d, long l) { 61 MyValue2Inline v = MyValue2Inline.createDefault(); 62 v = MyValue2Inline.setD(v, d); 63 v = MyValue2Inline.setL(v, l); 64 return v; 65 } 66 67 @Override 68 public String toString() { 69 return "MyValue2Inline[d=" + d + ", l=" + l + "]"; 70 } 71 } 72 73 @LooselyConsistentValue 74 public value class MyValue2 extends MyAbstract { 75 int x; 76 byte y; 77 @Strict 78 @NullRestricted 79 MyValue2Inline v; 80 81 static final MyValue2 DEFAULT = createDefaultInline(); 82 83 @ForceInline 84 public MyValue2(int x, byte y, MyValue2Inline v) { 85 this.x = x; 86 this.y = y; 87 this.v = v; 88 } 89 90 @ForceInline 91 public static MyValue2 createDefaultInline() { 92 return new MyValue2(0, (byte)0, MyValue2Inline.createDefault()); 93 } 94 95 @ForceInline 96 public static MyValue2 createWithFieldsInline(int x, long y, double d) { 97 MyValue2 v = createDefaultInline(); 98 v = setX(v, x); 99 v = setY(v, (byte)x); 100 v = setV(v, MyValue2Inline.createWithFieldsInline(d, y)); 101 return v; 102 } 103 104 @ForceInline 105 public static MyValue2 createWithFieldsInline(int x, double d) { 106 MyValue2 v = createDefaultInline(); 107 v = setX(v, x); 108 v = setY(v, (byte)x); 109 v = setV(v, MyValue2Inline.createWithFieldsInline(d, InlineTypes.rL)); 110 return v; 111 } 112 113 @DontInline 114 public static MyValue2 createWithFieldsDontInline(int x, double d) { 115 MyValue2 v = createDefaultInline(); 116 v = setX(v, x); 117 v = setY(v, (byte)x); 118 v = setV(v, MyValue2Inline.createWithFieldsInline(d, InlineTypes.rL)); 119 return v; 120 } 121 122 @ForceInline 123 public long hash() { 124 return x + y + (long)v.d + v.l; 125 } 126 127 @DontInline 128 public long hashInterpreted() { 129 return x + y + (long)v.d + v.l; 130 } 131 132 @ForceInline 133 static MyValue2 setX(MyValue2 v, int x) { 134 return new MyValue2(x, v.y, v.v); 135 } 136 137 @ForceInline 138 static MyValue2 setY(MyValue2 v, byte y) { 139 return new MyValue2(v.x, y, v.v); 140 } 141 142 @ForceInline 143 static MyValue2 setV(MyValue2 v, MyValue2Inline vi) { 144 return new MyValue2(v.x, v.y, vi); 145 } 146 147 @Override 148 public String toString() { 149 return "MyValue2[x=" + x + ", y=" + y + ", v=" + v + "]"; 150 } 151 }