1 /* 2 * Copyright (c) 2023, 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 compiler.valhalla.inlinetypes; 25 26 import jdk.test.lib.Asserts; 27 import jdk.internal.misc.Unsafe; 28 import compiler.lib.ir_framework.*; 29 30 /* 31 * @test 32 * @summary Missing InlineTypeNode re-materialization during type sharpening. 33 * @library /test/lib / 34 * @enablePreview 35 * @modules java.base/jdk.internal.misc 36 * @run main/othervm/timeout=300 compiler.valhalla.inlinetypes.TestValueRematDuringTypeSharpening 37 */ 38 39 abstract value class topValue { 40 } 41 42 value class dummyValue1 extends topValue { 43 int field; 44 public dummyValue1(int val) { 45 field = val; 46 } 47 } 48 49 value class dummyValue2 extends topValue { 50 int field; 51 public dummyValue2(int val) { 52 field = val; 53 } 54 } 55 56 public class TestValueRematDuringTypeSharpening { 57 58 public static final Unsafe UNSAFE = Unsafe.getUnsafe(); 59 60 @DontInline 61 public static int getUnsafeFieldValue(topValue obj, int incr) { 62 return UNSAFE.getInt(obj, 12) + incr; 63 } 64 65 @Test 66 @IR(phase = {CompilePhase.AFTER_PARSING}, counts = {IRNode.INLINE_TYPE, " > 0 "}) 67 public static int test(topValue obj) { 68 int val = 0; 69 if (obj.getClass() != dummyValue1.class) { 70 val += 10; 71 } else if (obj.getClass() != dummyValue2.class) { 72 val += 20; 73 } 74 return getUnsafeFieldValue(obj, val); 75 } 76 77 @Run(test = {"test"}, mode = RunMode.NORMAL) 78 public static void kernel() { 79 test(new dummyValue1(10)); 80 test(new dummyValue2(20)); 81 } 82 83 public static void main(String [] args) { 84 TestFramework.runWithFlags("-XX:-TieredCompilation", "--enable-preview", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED"); 85 System.out.println("PASS"); 86 } 87 } 88