1 /*
 2  * Copyright (c) 2021, Red Hat, Inc. 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 /*
27  * @test BlackholeTest
28  * @summary Check that blackholes work with inline types
29  * @compile -XDenablePrimitiveClasses BlackholeTest.java
30  * @run main/othervm
31  *      -Xbatch
32  *      -XX:+UnlockExperimentalVMOptions
33  *      -XX:CompileCommand=blackhole,compiler/valhalla/inlinetypes/BlackholeTest.blackhole
34  *      compiler.valhalla.inlinetypes.BlackholeTest
35  */
36 
37 public class BlackholeTest {
38     static primitive class MyValue {
39         int x = 0;
40     }
41 
42     static MyValue v;
43     static volatile MyValue vv;
44 
45     public static void main(String[] args) {
46         for (int c = 0; c < 5; c++) {
47             testNew();
48             testDefault();
49             testField();
50             testVolatileField();
51         }
52     }
53 
54     private static void testNew() {
55         for (int c = 0; c < 100000; c++) {
56             blackhole(new MyValue());
57         }
58     }
59 
60     private static void testDefault() {
61         for (int c = 0; c < 100000; c++) {
62             blackhole(MyValue.default);
63         }
64     }
65 
66     private static void testField() {
67         for (int c = 0; c < 100000; c++) {
68             blackhole(v);
69         }
70     }
71 
72     private static void testVolatileField() {
73         for (int c = 0; c < 100000; c++) {
74             blackhole(vv);
75         }
76     }
77 
78     public static void blackhole(MyValue v) {
79         // Should be empty
80     }
81 }