1 /*
 2  * Copyright (c) 2016, 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 runtime.valhalla.inlinetypes;
25 
26 import jdk.internal.value.ValueClass;
27 import jdk.internal.vm.annotation.ImplicitlyConstructible;
28 import jdk.internal.vm.annotation.LooselyConsistentValue;
29 
30 /*
31  * @test Test8186715
32  * @summary test return of buffered inline type passed in argument by caller
33  * @library /test/lib
34  * @modules java.base/jdk.internal.vm.annotation
35  *          java.base/jdk.internal.value
36  * @enablePreview
37  * @compile Test8186715.java
38  * @run main/othervm runtime.valhalla.inlinetypes.Test8186715
39  */
40 
41 public class Test8186715 {
42 
43     public static void main(String[] args) {
44         MyValueType v = MyValueType.testDefault();
45 
46         for (int i = 0; i < 1000000; i++) {
47             MyValueType.testBranchArg1(false, v);
48         }
49     }
50 }
51 
52 @ImplicitlyConstructible
53 @LooselyConsistentValue
54 value class MyValueType {
55     final int i;
56     final int j;
57 
58     private MyValueType(int i, int j) {
59         this.i = i;
60         this.j = j;
61     }
62 
63     static MyValueType testDefault() {
64         MyValueType[] array = (MyValueType[])ValueClass.newNullRestrictedArray(MyValueType.class, 1);
65         return array[0];
66     }
67 
68     static MyValueType testBranchArg1(boolean flag, MyValueType v1) {
69         if (flag) {
70             v1 = new MyValueType(3, 4);
71         }
72         return v1;
73     }
74 }