Path: blob/master/test/hotspot/jtreg/compiler/eliminateAutobox/TestIdentityWithEliminateBoxInDebugInfo.java
41149 views
/*1* Copyright (c) 2021, Huawei Technologies Co., Ltd. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 826113726* @requires vm.flavor == "server"27* @summary Verify that box object identity matches after deoptimization When it is eliminated.28* @library /test/lib29*30* @run main/othervm -Xbatch compiler.c2.TestIdentityWithEliminateBoxInDebugInfo31*/32package compiler.c2;3334import jdk.test.lib.Asserts;3536public class TestIdentityWithEliminateBoxInDebugInfo {37interface TestF {38void apply(boolean condition);39}4041public static void helper(TestF f) {42// warmup43for(int i = 0; i < 100000; i++) {44f.apply(true);45}46// deoptimize47f.apply(false);48}4950public static void runTest() throws Exception {51helper((c) -> {52Integer a = Integer.valueOf(42);53Integer b = Integer.valueOf(-42);54if (!c) {55Asserts.assertTrue(a == Integer.valueOf(42));56Asserts.assertTrue(b == Integer.valueOf(-42));57}58});5960helper((c) -> {61long highBitsOnly = 2L << 40;62Long a = Long.valueOf(42L);63Long b = Long.valueOf(-42L);64Long h = Long.valueOf(highBitsOnly);65if (!c) {66Asserts.assertTrue(a == Long.valueOf(42L));67Asserts.assertTrue(b == Long.valueOf(-42L));68Asserts.assertFalse(h == Long.valueOf(highBitsOnly));69}70});7172helper((c) -> {73Character a = Character.valueOf('a');74Character b = Character.valueOf('Z');75if (!c) {76Asserts.assertTrue(a == Character.valueOf('a'));77Asserts.assertTrue(b == Character.valueOf('Z'));78}79});8081helper((c) -> {82Short a = Short.valueOf((short)42);83Short b = Short.valueOf((short)-42);84if (!c) {85Asserts.assertTrue(a == Short.valueOf((short)42));86Asserts.assertTrue(b == Short.valueOf((short)-42));87}88});8990helper((c) -> {91Byte a = Byte.valueOf((byte)42);92Byte b = Byte.valueOf((byte)-42);93if (!c) {94Asserts.assertTrue(a == Byte.valueOf((byte)42));95Asserts.assertTrue(b == Byte.valueOf((byte)-42));96}97});9899helper((c) -> {100Boolean a = Boolean.valueOf(true);101Boolean b = Boolean.valueOf(false);102if (!c) {103Asserts.assertTrue(a == Boolean.valueOf(true));104Asserts.assertTrue(b == Boolean.valueOf(false));105}106});107}108109public static void main(String[] args) throws Exception {110runTest();111}112}113114115