Path: blob/master/test/hotspot/jtreg/compiler/eliminateAutobox/TestIdentityWithEliminateBoxInDebugInfo.java
64474 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.eliminateAutobox.TestIdentityWithEliminateBoxInDebugInfo31*/3233package compiler.eliminateAutobox;3435import jdk.test.lib.Asserts;3637public class TestIdentityWithEliminateBoxInDebugInfo {38interface TestF {39void apply(boolean condition);40}4142public static void helper(TestF f) {43// warmup44for (int i = 0; i < 100000; i++) {45f.apply(true);46}47// deoptimize48f.apply(false);49}5051public static void runTest() throws Exception {52helper((c) -> {53Integer a = Integer.valueOf(42);54Integer b = Integer.valueOf(-42);55if (!c) {56Asserts.assertTrue(a == Integer.valueOf(42));57Asserts.assertTrue(b == Integer.valueOf(-42));58}59});6061helper((c) -> {62long highBitsOnly = 2L << 40;63Long a = Long.valueOf(42L);64Long b = Long.valueOf(-42L);65Long h = Long.valueOf(highBitsOnly);66if (!c) {67Asserts.assertTrue(a == Long.valueOf(42L));68Asserts.assertTrue(b == Long.valueOf(-42L));69Asserts.assertFalse(h == Long.valueOf(highBitsOnly));70}71});7273helper((c) -> {74Character a = Character.valueOf('a');75Character b = Character.valueOf('Z');76if (!c) {77Asserts.assertTrue(a == Character.valueOf('a'));78Asserts.assertTrue(b == Character.valueOf('Z'));79}80});8182helper((c) -> {83Short a = Short.valueOf((short)42);84Short b = Short.valueOf((short)-42);85if (!c) {86Asserts.assertTrue(a == Short.valueOf((short)42));87Asserts.assertTrue(b == Short.valueOf((short)-42));88}89});9091helper((c) -> {92Byte a = Byte.valueOf((byte)42);93Byte b = Byte.valueOf((byte)-42);94if (!c) {95Asserts.assertTrue(a == Byte.valueOf((byte)42));96Asserts.assertTrue(b == Byte.valueOf((byte)-42));97}98});99100helper((c) -> {101Boolean a = Boolean.valueOf(true);102Boolean b = Boolean.valueOf(false);103if (!c) {104Asserts.assertTrue(a == Boolean.valueOf(true));105Asserts.assertTrue(b == Boolean.valueOf(false));106}107});108}109110public static void main(String[] args) throws Exception {111runTest();112}113}114115116