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