1 /* 2 * Copyright (c) 2021, 2024, Red Hat, Inc. All rights reserved. 3 * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 package compiler.valhalla.inlinetypes; 26 27 import jdk.internal.vm.annotation.LooselyConsistentValue; 28 import jdk.internal.vm.annotation.NullRestricted; 29 import jdk.internal.vm.annotation.Strict; 30 31 /* 32 * @test BlackholeTest 33 * @summary Check that blackholes work with inline types 34 * @enablePreview 35 * @modules java.base/jdk.internal.value 36 * java.base/jdk.internal.vm.annotation 37 * @run main/othervm 38 * -Xbatch -XX:+UnlockExperimentalVMOptions 39 * -XX:CompileCommand=blackhole,compiler/valhalla/inlinetypes/BlackholeTest.blackhole 40 * compiler.valhalla.inlinetypes.BlackholeTest 41 */ 42 43 public class BlackholeTest { 44 @LooselyConsistentValue 45 static value class MyValue { 46 int x = 0; 47 } 48 49 @Strict 50 @NullRestricted 51 static MyValue v = new MyValue(); 52 @Strict 53 @NullRestricted 54 static volatile MyValue vv = new MyValue(); 55 56 public static void main(String[] args) { 57 for (int c = 0; c < 5; c++) { 58 testNew(); 59 testField(); 60 testVolatileField(); 61 } 62 } 63 64 private static void testNew() { 65 for (int c = 0; c < 100_000; c++) { 66 blackhole(new MyValue()); 67 } 68 } 69 70 private static void testField() { 71 for (int c = 0; c < 100_000; c++) { 72 blackhole(v); 73 } 74 } 75 76 private static void testVolatileField() { 77 for (int c = 0; c < 100_000; c++) { 78 blackhole(vv); 79 } 80 } 81 82 public static void blackhole(MyValue v) { 83 // Should be empty 84 } 85 }