< prev index next >

test/hotspot/jtreg/compiler/eliminateAutobox/TestIdentityWithEliminateBoxInDebugInfo.java

Print this page

  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

 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         });

  1 /*
  2  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2021, Huawei Technologies Co., Ltd. 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 /*
 26  * @test
 27  * @bug 8261137
 28  * @requires vm.flavor == "server"
 29  * @enablePreview
 30  * @summary Verify that box object content matches after deoptimization when it is eliminated.
 31  * @library /test/lib
 32  *
 33  * @run main/othervm -Xbatch compiler.eliminateAutobox.TestIdentityWithEliminateBoxInDebugInfo
 34  */
 35 
 36 package compiler.eliminateAutobox;
 37 
 38 import jdk.test.lib.Asserts;
 39 
 40 public class TestIdentityWithEliminateBoxInDebugInfo {
 41     interface TestF {
 42         void apply(boolean condition);
 43     }
 44 
 45     public static void helper(TestF f) {
 46         // warmup
 47         for (int i = 0; i < 100000; i++) {
 48             f.apply(true);
 49         }
 50         // deoptimize

 52     }
 53 
 54     public static void runTest() throws Exception {
 55         helper((c) -> {
 56             Integer a = Integer.valueOf(42);
 57             Integer b = Integer.valueOf(-42);
 58             if (!c) {
 59                 Asserts.assertTrue(a == Integer.valueOf(42));
 60                 Asserts.assertTrue(b == Integer.valueOf(-42));
 61             }
 62         });
 63 
 64         helper((c) -> {
 65             long highBitsOnly = 2L << 40;
 66             Long a = Long.valueOf(42L);
 67             Long b = Long.valueOf(-42L);
 68             Long h = Long.valueOf(highBitsOnly);
 69             if (!c) {
 70                 Asserts.assertTrue(a == Long.valueOf(42L));
 71                 Asserts.assertTrue(b == Long.valueOf(-42L));
 72                 Asserts.assertTrue(h == Long.valueOf(highBitsOnly));
 73             }
 74         });
 75 
 76         helper((c) -> {
 77             Character a = Character.valueOf('a');
 78             Character b = Character.valueOf('Z');
 79             if (!c) {
 80                 Asserts.assertTrue(a == Character.valueOf('a'));
 81                 Asserts.assertTrue(b == Character.valueOf('Z'));
 82             }
 83         });
 84 
 85         helper((c) -> {
 86             Short a = Short.valueOf((short)42);
 87             Short b = Short.valueOf((short)-42);
 88             if (!c) {
 89                 Asserts.assertTrue(a == Short.valueOf((short)42));
 90                 Asserts.assertTrue(b == Short.valueOf((short)-42));
 91             }
 92         });
< prev index next >