1 /* 2 * Copyright (c) 2021, Huawei Technologies Co., Ltd. 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 8261137 27 * @requires vm.flavor == "server" 28 * @summary Verify that box object identity matches after deoptimization when it is eliminated. 29 * @library /test/lib 30 * 31 * @run main/othervm -Xbatch compiler.eliminateAutobox.TestIdentityWithEliminateBoxInDebugInfo 32 */ 33 34 package compiler.eliminateAutobox; 35 36 import jdk.test.lib.Asserts; 37 38 public class TestIdentityWithEliminateBoxInDebugInfo { 39 interface TestF { 40 void apply(boolean condition); 41 } 42 43 public static void helper(TestF f) { 44 // warmup 45 for (int i = 0; i < 100000; i++) { 46 f.apply(true); 47 } 48 // deoptimize 49 f.apply(false); 50 } 51 52 public static void runTest() throws Exception { 53 helper((c) -> { 54 Integer a = Integer.valueOf(42); 55 Integer b = Integer.valueOf(-42); 56 if (!c) { 57 Asserts.assertTrue(a == Integer.valueOf(42)); 58 Asserts.assertTrue(b == Integer.valueOf(-42)); 59 } 60 }); 61 62 helper((c) -> { 63 long highBitsOnly = 2L << 40; 64 Long a = Long.valueOf(42L); 65 Long b = Long.valueOf(-42L); 66 Long h = Long.valueOf(highBitsOnly); 67 if (!c) { 68 Asserts.assertTrue(a == Long.valueOf(42L)); 69 Asserts.assertTrue(b == Long.valueOf(-42L)); 70 Asserts.assertFalse(h == Long.valueOf(highBitsOnly)); 71 } 72 }); 73 74 helper((c) -> { 75 Character a = Character.valueOf('a'); 76 Character b = Character.valueOf('Z'); 77 if (!c) { 78 Asserts.assertTrue(a == Character.valueOf('a')); 79 Asserts.assertTrue(b == Character.valueOf('Z')); 80 } 81 }); 82 83 helper((c) -> { 84 Short a = Short.valueOf((short)42); 85 Short b = Short.valueOf((short)-42); 86 if (!c) { 87 Asserts.assertTrue(a == Short.valueOf((short)42)); 88 Asserts.assertTrue(b == Short.valueOf((short)-42)); 89 } 90 }); 91 92 helper((c) -> { 93 Byte a = Byte.valueOf((byte)42); 94 Byte b = Byte.valueOf((byte)-42); 95 if (!c) { 96 Asserts.assertTrue(a == Byte.valueOf((byte)42)); 97 Asserts.assertTrue(b == Byte.valueOf((byte)-42)); 98 } 99 }); 100 101 helper((c) -> { 102 Boolean a = Boolean.valueOf(true); 103 Boolean b = Boolean.valueOf(false); 104 if (!c) { 105 Asserts.assertTrue(a == Boolean.valueOf(true)); 106 Asserts.assertTrue(b == Boolean.valueOf(false)); 107 } 108 }); 109 } 110 111 public static void main(String[] args) throws Exception { 112 runTest(); 113 } 114 }