1 /*
 2  * Copyright (c) 2019, 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 /**
25  * @test
26  * @bug 8233415
27  * @summary Verify that TLAB allocated buffer initialization when returning a value object works properly with oops.
28  * @library /test/lib
29  * @enablePreview
30  * @run main/othervm -XX:CompileCommand=exclude,compiler.valhalla.inlinetypes.TestStressReturnBuffering::caller -Xmx4m
31  *                   compiler.valhalla.inlinetypes.TestStressReturnBuffering
32  */
33 
34 package compiler.valhalla.inlinetypes;
35 
36 import jdk.test.lib.Asserts;
37 
38 value class MyValue {
39     public Integer o1;
40     public Integer o2;
41     public Integer o3;
42     public Integer o4;
43     public Integer o5;
44 
45     public MyValue(Integer o) {
46         this.o1 = o;
47         this.o2 = o;
48         this.o3 = o;
49         this.o4 = o;
50         this.o5 = o;
51     }
52 }
53 
54 public class TestStressReturnBuffering {
55 
56     static Integer integer = 42;
57 
58     public static MyValue callee() {
59         return new MyValue(integer);
60     }
61 
62     public static int caller() {
63         int res = 0;
64         for (int i = 0; i < 100_000; ++i) {
65             MyValue vt = callee();
66             res += vt.o1 + vt.o2 + vt.o3 + vt.o4 + vt.o5;
67         }
68         return res;
69     }
70 
71     public static void main(String[] args) {
72         System.gc();
73         int res = caller();
74         Asserts.assertEQ(res, 100_000*5*42, "Unexpected result");
75     }
76 }