Path: blob/master/test/hotspot/jtreg/compiler/eliminateAutobox/TestSafepointDebugInfo.java
64474 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. 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* @key randomness26* @bug 827611227* @summary Verify consistency of safepoint debug info when boxes are scalar28* replaced during incremental inlining.29* @library /test/lib30* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline31* -XX:CompileCommand=compileonly,compiler.eliminateAutobox.TestSafepointDebugInfo::test*32* compiler.eliminateAutobox.TestSafepointDebugInfo33*/3435package compiler.eliminateAutobox;3637import java.util.Random;3839import jdk.test.lib.Asserts;40import jdk.test.lib.Utils;4142public class TestSafepointDebugInfo {4344private static final Random random = Utils.getRandomInstance();4546static Integer fBox;4748public static Integer helper(int i) {49return Integer.valueOf(i);50}5152// assert(local) failed: use _top instead of null53public static int test1(int i) {54Integer box = helper(i);55fBox = Integer.valueOf(i);56return box.intValue();57}5859// Wrong execution, same types60public static int test2(int i1, int i2) {61Integer box1 = helper(i1);62Integer box2 = Integer.valueOf(i2);63fBox = Integer.valueOf(i1);64return box1.intValue() + box2.intValue();65}6667// Wrong execution, different types68public static long test3(int i1, long i2) {69Integer box1 = helper(i1);70Long box2 = Long.valueOf(i2);71fBox = Integer.valueOf(i1);72return box1.intValue() + box2.longValue();73}7475// assert(i < _max) failed: oob: i=16, _max=1676public static int test4(int i1, int i2) {77Integer box1 = helper(i1);78Integer box2 = helper(i2);79fBox = Integer.valueOf(i1);80return box1.intValue() + box2.intValue();81}8283public static Integer test5_helper(int i1, int i2) {84Integer box1 = helper(i1);85Integer box2 = helper(i2);86fBox = Integer.valueOf(i1);87return box1.intValue() + box2.intValue();88}8990// assert(local) failed: use _top instead of null91// Variant with deeper inlining92public static int test5(int i1, int i2) {93return test5_helper(i1, i2);94}9596public static int test6_helper(int i1, int i2) {97Integer box = helper(i1);98fBox = Integer.valueOf(i2);99return box.intValue();100}101102// Wrong execution, variant with more arguments103public static int test6(int i1, int i2, int i3, int i4) {104Integer box1 = helper(i1);105Integer box2 = helper(i2);106int res = test6_helper(i3, i4);107res += box1.intValue() + box2.intValue();108return res;109}110111public static void main(String[] args) {112// Warmup113for (int i = 0; i < 100_000; ++i) {114int val = (i % 10);115Asserts.assertEquals(test1(val), val);116Asserts.assertEquals(fBox, val);117Asserts.assertEquals(test2(val, val), 2*val);118Asserts.assertEquals(fBox, val);119Asserts.assertEquals(test3(val, val), 2L*val);120Asserts.assertEquals(fBox, val);121Asserts.assertEquals(test4(val, val), 2*val);122Asserts.assertEquals(fBox, val);123Asserts.assertEquals(test5(val, val), 2*val);124Asserts.assertEquals(fBox, val);125Asserts.assertEquals(test6(val, val, val, val), 3*val);126Asserts.assertEquals(fBox, val);127}128129// Trigger deoptimization by choosing a value that does not130// fit in the Integer cache and check the result.131int val = 4000;132Asserts.assertEquals(test1(val), val);133switch (random.nextInt(3)) {134case 0:135Asserts.assertEquals(test2(val, 1), val + 1);136Asserts.assertEquals(fBox, val);137Asserts.assertEquals(test3(val, 1), (long)val + 1);138Asserts.assertEquals(fBox, val);139Asserts.assertEquals(test4(val, 1), val + 1);140Asserts.assertEquals(fBox, val);141Asserts.assertEquals(test5(val, 1), val + 1);142Asserts.assertEquals(fBox, val);143Asserts.assertEquals(test6(val, 1, 2, 3), val + 3);144Asserts.assertEquals(fBox, 3);145break;146case 1:147Asserts.assertEquals(test2(1, val), val + 1);148Asserts.assertEquals(fBox, 1);149Asserts.assertEquals(test3(1, val), (long)val + 1);150Asserts.assertEquals(fBox, 1);151Asserts.assertEquals(test4(1, val), val + 1);152Asserts.assertEquals(fBox, 1);153Asserts.assertEquals(test5(1, val), val + 1);154Asserts.assertEquals(fBox, 1);155Asserts.assertEquals(test6(1, val, 2, 3), val + 3);156Asserts.assertEquals(fBox, 3);157break;158case 2:159Asserts.assertEquals(test2(1, 2), 3);160Asserts.assertEquals(fBox, 1);161Asserts.assertEquals(test3(1, 2), 3L);162Asserts.assertEquals(fBox, 1);163Asserts.assertEquals(test4(1, 2), 3);164Asserts.assertEquals(fBox, 1);165Asserts.assertEquals(test5(1, 2), 3);166Asserts.assertEquals(fBox, 1);167Asserts.assertEquals(test6(1, 2, 3, val), 6);168Asserts.assertEquals(fBox, val);169break;170}171}172}173174175