1 /* 2 * Copyright (c) 2017, 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.ForceInline; 27 28 import jdk.internal.vm.annotation.ImplicitlyConstructible; 29 import jdk.internal.vm.annotation.LooselyConsistentValue; 30 import jdk.internal.vm.annotation.NullRestricted; 31 32 // Inline type definition with too many fields to return in registers 33 @ImplicitlyConstructible 34 @LooselyConsistentValue 35 value class MyValue4 extends MyAbstract { 36 @NullRestricted 37 MyValue3 v1; 38 @NullRestricted 39 MyValue3 v2; 40 41 @ForceInline 42 public MyValue4(MyValue3 v1, MyValue3 v2) { 43 this.v1 = v1; 44 this.v2 = v2; 45 } 46 47 @ForceInline 48 static MyValue4 setV1(MyValue4 v, MyValue3 v1) { 49 return new MyValue4(v1, v.v2); 50 } 51 52 @ForceInline 53 static MyValue4 setV2(MyValue4 v, MyValue3 v2) { 54 return new MyValue4(v.v1, v2); 55 } 56 57 @ForceInline 58 public static MyValue4 createDefault() { 59 return new MyValue4(MyValue3.createDefault(), MyValue3.createDefault()); 60 } 61 62 @ForceInline 63 public static MyValue4 create() { 64 MyValue4 v = createDefault(); 65 MyValue3 v1 = MyValue3.create(); 66 v = setV1(v, v1); 67 MyValue3 v2 = MyValue3.create(); 68 v = setV2(v, v2); 69 return v; 70 } 71 72 public void verify(MyValue4 other) { 73 v1.verify(other.v1); 74 v2.verify(other.v2); 75 } 76 77 @ForceInline 78 public long hash() { 79 return v1.hash() + v2.hash(); 80 } 81 }