Path: blob/master/test/hotspot/jtreg/compiler/eliminateAutobox/TestByteBoxing.java
41152 views
/*1* Copyright (c) 2013, 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* @bug 693460426*27* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+EliminateAutoBox28* compiler.eliminateAutobox.TestByteBoxing29* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+EliminateAutoBox30* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestByteBoxing::dummy31* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestByteBoxing::foo32* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestByteBoxing::foob33* compiler.eliminateAutobox.TestByteBoxing34* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-EliminateAutoBox35* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestByteBoxing::dummy36* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestByteBoxing::foo37* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestByteBoxing::foob38* compiler.eliminateAutobox.TestByteBoxing39*/4041package compiler.eliminateAutobox;4243public class TestByteBoxing {4445static final Byte ibc = new Byte((byte)1);4647//===============================================48// Non-inlined methods to test deoptimization info49static void dummy() { }50static byte foo(byte i) { return i; }51static Byte foob(byte i) { return Byte.valueOf(i); }525354static byte simple(byte i) {55Byte ib = new Byte(i);56return ib;57}5859static byte simpleb(byte i) {60Byte ib = Byte.valueOf(i);61return ib;62}6364static byte simplec() {65Byte ib = ibc;66return ib;67}6869static byte simplef(byte i) {70Byte ib = foob(i);71return ib;72}7374static byte simplep(Byte ib) {75return ib;76}7778static byte simple2(byte i) {79Byte ib1 = new Byte(i);80Byte ib2 = new Byte((byte)(i+1));81return (byte)(ib1 + ib2);82}8384static byte simpleb2(byte i) {85Byte ib1 = Byte.valueOf(i);86Byte ib2 = Byte.valueOf((byte)(i+1));87return (byte)(ib1 + ib2);88}8990static byte simplem2(byte i) {91Byte ib1 = new Byte(i);92Byte ib2 = Byte.valueOf((byte)(i+1));93return (byte)(ib1 + ib2);94}9596static byte simplep2(byte i, Byte ib1) {97Byte ib2 = Byte.valueOf((byte)(i+1));98return (byte)(ib1 + ib2);99}100101static byte simplec2(byte i) {102Byte ib1 = ibc;103Byte ib2 = Byte.valueOf((byte)(i+1));104return (byte)(ib1 + ib2);105}106107//===============================================108static byte test(byte i) {109Byte ib = new Byte(i);110if ((i&1) == 0)111ib = (byte)(i+1);112return ib;113}114115static byte testb(byte i) {116Byte ib = i;117if ((i&1) == 0)118ib = (byte)(i+1);119return ib;120}121122static byte testm(byte i) {123Byte ib = i;124if ((i&1) == 0)125ib = new Byte((byte)(i+1));126return ib;127}128129static byte testp(byte i, Byte ib) {130if ((i&1) == 0)131ib = new Byte((byte)(i+1));132return ib;133}134135static byte testc(byte i) {136Byte ib = ibc;137if ((i&1) == 0)138ib = new Byte((byte)(i+1));139return ib;140}141142static byte test2(byte i) {143Byte ib1 = new Byte(i);144Byte ib2 = new Byte((byte)(i+1));145if ((i&1) == 0) {146ib1 = new Byte((byte)(i+1));147ib2 = new Byte((byte)(i+2));148}149return (byte)(ib1+ib2);150}151152static byte testb2(byte i) {153Byte ib1 = i;154Byte ib2 = (byte)(i+1);155if ((i&1) == 0) {156ib1 = (byte)(i+1);157ib2 = (byte)(i+2);158}159return (byte)(ib1 + ib2);160}161162static byte testm2(byte i) {163Byte ib1 = new Byte(i);164Byte ib2 = (byte)(i+1);165if ((i&1) == 0) {166ib1 = new Byte((byte)(i+1));167ib2 = (byte)(i+2);168}169return (byte)(ib1 + ib2);170}171172static byte testp2(byte i, Byte ib1) {173Byte ib2 = (byte)(i+1);174if ((i&1) == 0) {175ib1 = new Byte((byte)(i+1));176ib2 = (byte)(i+2);177}178return (byte)(ib1 + ib2);179}180181static byte testc2(byte i) {182Byte ib1 = ibc;183Byte ib2 = (byte)(i+1);184if ((i&1) == 0) {185ib1 = (byte)(ibc+1);186ib2 = (byte)(i+2);187}188return (byte)(ib1 + ib2);189}190191//===============================================192static byte sum(byte[] a) {193byte result = 1;194for (Byte i : a)195result += i;196return result;197}198199static byte sumb(byte[] a) {200Byte result = 1;201for (Byte i : a)202result = (byte)(result + i);203return result;204}205206static byte sumc(byte[] a) {207Byte result = ibc;208for (Byte i : a)209result = (byte)(result + i);210return result;211}212213static byte sumf(byte[] a) {214Byte result = foob((byte)1);215for (Byte i : a)216result = (byte)(result + i);217return result;218}219220static byte sump(byte[] a, Byte result) {221for (Byte i : a)222result = (byte)(result + i);223return result;224}225226static byte sum2(byte[] a) {227byte result1 = 1;228byte result2 = 1;229for (Byte i : a) {230result1 += i;231result2 += i + 1;232}233return (byte)(result1 + result2);234}235236static byte sumb2(byte[] a) {237Byte result1 = 1;238Byte result2 = 1;239for (Byte i : a) {240result1 = (byte)(result1 + i);241result2 = (byte)(result2 + i + 1);242}243return (byte)(result1 + result2);244}245246static byte summ2(byte[] a) {247Byte result1 = 1;248Byte result2 = new Byte((byte)1);249for (Byte i : a) {250result1 = (byte)(result1 + i);251result2 = (byte)(result2 + new Byte((byte)(i + 1)));252}253return (byte)(result1 + result2);254}255256static byte sump2(byte[] a, Byte result2) {257Byte result1 = 1;258for (Byte i : a) {259result1 = (byte)(result1 + i);260result2 = (byte)(result2 + i + 1);261}262return (byte)(result1 + result2);263}264265static byte sumc2(byte[] a) {266Byte result1 = 1;267Byte result2 = ibc;268for (Byte i : a) {269result1 = (byte)(result1 + i);270result2 = (byte)(result2 + i + ibc);271}272return (byte)(result1 + result2);273}274275//===============================================276static byte remi_sum() {277Byte j = new Byte((byte)1);278for (int i = 0; i< 1000; i++) {279j = new Byte((byte)(j + 1));280}281return j;282}283284static byte remi_sumb() {285Byte j = Byte.valueOf((byte)1);286for (int i = 0; i< 1000; i++) {287j = (byte)(j + 1);288}289return j;290}291292static byte remi_sumf() {293Byte j = foob((byte)1);294for (int i = 0; i< 1000; i++) {295j = (byte)(j + 1);296}297return j;298}299300static byte remi_sump(Byte j) {301for (int i = 0; i< 1000; i++) {302j = new Byte((byte)(j + 1));303}304return j;305}306307static byte remi_sumc() {308Byte j = ibc;309for (int i = 0; i< 1000; i++) {310j = (byte)(j + ibc);311}312return j;313}314315static byte remi_sum2() {316Byte j1 = new Byte((byte)1);317Byte j2 = new Byte((byte)1);318for (int i = 0; i< 1000; i++) {319j1 = new Byte((byte)(j1 + 1));320j2 = new Byte((byte)(j2 + 2));321}322return (byte)(j1 + j2);323}324325static byte remi_sumb2() {326Byte j1 = Byte.valueOf((byte)1);327Byte j2 = Byte.valueOf((byte)1);328for (int i = 0; i< 1000; i++) {329j1 = (byte)(j1 + 1);330j2 = (byte)(j2 + 2);331}332return (byte)(j1 + j2);333}334335static byte remi_summ2() {336Byte j1 = new Byte((byte)1);337Byte j2 = Byte.valueOf((byte)1);338for (int i = 0; i< 1000; i++) {339j1 = new Byte((byte)(j1 + 1));340j2 = (byte)(j2 + 2);341}342return (byte)(j1 + j2);343}344345static byte remi_sump2(Byte j1) {346Byte j2 = Byte.valueOf((byte)1);347for (int i = 0; i< 1000; i++) {348j1 = new Byte((byte)(j1 + 1));349j2 = (byte)(j2 + 2);350}351return (byte)(j1 + j2);352}353354static byte remi_sumc2() {355Byte j1 = ibc;356Byte j2 = Byte.valueOf((byte)1);357for (int i = 0; i< 1000; i++) {358j1 = (byte)(j1 + ibc);359j2 = (byte)(j2 + 2);360}361return (byte)(j1 + j2);362}363364365//===============================================366// Safepointa and debug info for deoptimization367static byte simple_deop(byte i) {368Byte ib = new Byte(foo(i));369dummy();370return ib;371}372373static byte simpleb_deop(byte i) {374Byte ib = Byte.valueOf(foo(i));375dummy();376return ib;377}378379static byte simplef_deop(byte i) {380Byte ib = foob(i);381dummy();382return ib;383}384385static byte simplep_deop(Byte ib) {386dummy();387return ib;388}389390static byte simplec_deop(byte i) {391Byte ib = ibc;392dummy();393return ib;394}395396static byte test_deop(byte i) {397Byte ib = new Byte(foo(i));398if ((i&1) == 0)399ib = foo((byte)(i+1));400dummy();401return ib;402}403404static byte testb_deop(byte i) {405Byte ib = foo(i);406if ((i&1) == 0)407ib = foo((byte)(i+1));408dummy();409return ib;410}411412static byte testf_deop(byte i) {413Byte ib = foob(i);414if ((i&1) == 0)415ib = foo((byte)(i+1));416dummy();417return ib;418}419420static byte testp_deop(byte i, Byte ib) {421if ((i&1) == 0)422ib = foo((byte)(i+1));423dummy();424return ib;425}426427static byte testc_deop(byte i) {428Byte ib = ibc;429if ((i&1) == 0)430ib = foo((byte)(i+1));431dummy();432return ib;433}434435static byte sum_deop(byte[] a) {436byte result = 1;437for (Byte i : a)438result += foo(i);439dummy();440return result;441}442443static byte sumb_deop(byte[] a) {444Byte result = 1;445for (Byte i : a)446result = (byte)(result + foo(i));447dummy();448return result;449}450451static byte sumf_deop(byte[] a) {452Byte result = 1;453for (Byte i : a)454result = (byte)(result + foob(i));455dummy();456return result;457}458459static byte sump_deop(byte[] a, Byte result) {460for (Byte i : a)461result = (byte)(result + foob(i));462dummy();463return result;464}465466static byte sumc_deop(byte[] a) {467Byte result = ibc;468for (Byte i : a)469result = (byte)(result + foo(i));470dummy();471return result;472}473474static byte remi_sum_deop() {475Byte j = new Byte(foo((byte)1));476for (int i = 0; i< 1000; i++) {477j = new Byte(foo((byte)(j + 1)));478}479dummy();480return j;481}482483static byte remi_sumb_deop() {484Byte j = Byte.valueOf(foo((byte)1));485for (int i = 0; i< 1000; i++) {486j = foo((byte)(j + 1));487}488dummy();489return j;490}491492static byte remi_sumf_deop() {493Byte j = foob((byte)1);494for (int i = 0; i< 1000; i++) {495j = foo((byte)(j + 1));496}497dummy();498return j;499}500501static byte remi_sump_deop(Byte j) {502for (int i = 0; i< 1000; i++) {503j = foo((byte)(j + 1));504}505dummy();506return j;507}508509static byte remi_sumc_deop() {510Byte j = ibc;511for (int i = 0; i< 1000; i++) {512j = foo((byte)(j + 1));513}514dummy();515return j;516}517518//===============================================519// Conditional increment520static byte remi_sum_cond() {521Byte j = new Byte((byte)1);522for (int i = 0; i< 1000; i++) {523if ((i&1) == 0) {524j = new Byte((byte)(j + 1));525}526}527return j;528}529530static byte remi_sumb_cond() {531Byte j = Byte.valueOf((byte)1);532for (int i = 0; i< 1000; i++) {533if ((i&1) == 0) {534j = (byte)(j + 1);535}536}537return j;538}539540static byte remi_sumf_cond() {541Byte j = foob((byte)1);542for (int i = 0; i< 1000; i++) {543if ((i&1) == 0) {544j = (byte)(j + 1);545}546}547return j;548}549550static byte remi_sump_cond(Byte j) {551for (int i = 0; i< 1000; i++) {552if ((i&1) == 0) {553j = (byte)(j + 1);554}555}556return j;557}558559static byte remi_sumc_cond() {560Byte j = ibc;561for (int i = 0; i< 1000; i++) {562if ((i&1) == 0) {563j = (byte)(j + ibc);564}565}566return j;567}568569static byte remi_sum2_cond() {570Byte j1 = new Byte((byte)1);571Byte j2 = new Byte((byte)1);572for (int i = 0; i< 1000; i++) {573if ((i&1) == 0) {574j1 = new Byte((byte)(j1 + 1));575} else {576j2 = new Byte((byte)(j2 + 2));577}578}579return (byte)(j1 + j2);580}581582static byte remi_sumb2_cond() {583Byte j1 = Byte.valueOf((byte)1);584Byte j2 = Byte.valueOf((byte)1);585for (int i = 0; i< 1000; i++) {586if ((i&1) == 0) {587j1 = (byte)(j1 + 1);588} else {589j2 = (byte)(j2 + 2);590}591}592return (byte)(j1 + j2);593}594595static byte remi_summ2_cond() {596Byte j1 = new Byte((byte)1);597Byte j2 = Byte.valueOf((byte)1);598for (int i = 0; i< 1000; i++) {599if ((i&1) == 0) {600j1 = new Byte((byte)(j1 + 1));601} else {602j2 = (byte)(j2 + 2);603}604}605return (byte)(j1 + j2);606}607608static byte remi_sump2_cond(Byte j1) {609Byte j2 = Byte.valueOf((byte)1);610for (int i = 0; i< 1000; i++) {611if ((i&1) == 0) {612j1 = new Byte((byte)(j1 + 1));613} else {614j2 = (byte)(j2 + 2);615}616}617return (byte)(j1 + j2);618}619620static byte remi_sumc2_cond() {621Byte j1 = ibc;622Byte j2 = Byte.valueOf((byte)1);623for (int i = 0; i< 1000; i++) {624if ((i&1) == 0) {625j1 = (byte)(j1 + ibc);626} else {627j2 = (byte)(j2 + 2);628}629}630return (byte)(j1 + j2);631}632633634public static void main(String[] args) {635final int ntests = 70;636637String[] test_name = new String[] {638"simple", "simpleb", "simplec", "simplef", "simplep",639"simple2", "simpleb2", "simplec2", "simplem2", "simplep2",640"simple_deop", "simpleb_deop", "simplec_deop", "simplef_deop", "simplep_deop",641"test", "testb", "testc", "testm", "testp",642"test2", "testb2", "testc2", "testm2", "testp2",643"test_deop", "testb_deop", "testc_deop", "testf_deop", "testp_deop",644"sum", "sumb", "sumc", "sumf", "sump",645"sum2", "sumb2", "sumc2", "summ2", "sump2",646"sum_deop", "sumb_deop", "sumc_deop", "sumf_deop", "sump_deop",647"remi_sum", "remi_sumb", "remi_sumc", "remi_sumf", "remi_sump",648"remi_sum2", "remi_sumb2", "remi_sumc2", "remi_summ2", "remi_sump2",649"remi_sum_deop", "remi_sumb_deop", "remi_sumc_deop", "remi_sumf_deop", "remi_sump_deop",650"remi_sum_cond", "remi_sumb_cond", "remi_sumc_cond", "remi_sumf_cond", "remi_sump_cond",651"remi_sum2_cond", "remi_sumb2_cond", "remi_sumc2_cond", "remi_summ2_cond", "remi_sump2_cond"652};653654final int[] val = new int[] {655-5488, -5488, 12000, -5488, -5488,6561024, 1024, -5552, 1024, 1024,657-5488, -5488, 12000, -5488, -5488,658512, 512, 6256, 512, 512,65913024, 13024, -5584, 13024, 13024,660512, 512, 6256, 512, 512,66145, 45, 45, 45, 45,66266, 66, 66, 66, 66,66345, 45, 45, 45, 45,664-23, -23, -23, -23, -23,665-70, -70, -70, -70, -70,666-23, -23, -23, -23, -23,667-11, -11, -11, -11, -11,668-34, -34, -34, -34, -34669};670671int[] res = new int[ntests];672for (int i = 0; i < ntests; i++) {673res[i] = 0;674}675676677for (int i = 0; i < 12000; i++) {678res[0] += simple((byte)i);679res[1] += simpleb((byte)i);680res[2] += simplec();681res[3] += simplef((byte)i);682res[4] += simplep((byte)i);683684res[5] += simple2((byte)i);685res[6] += simpleb2((byte)i);686res[7] += simplec2((byte)i);687res[8] += simplem2((byte)i);688res[9] += simplep2((byte)i, (byte)i);689690res[10] += simple_deop((byte)i);691res[11] += simpleb_deop((byte)i);692res[12] += simplec_deop((byte)i);693res[13] += simplef_deop((byte)i);694res[14] += simplep_deop((byte)i);695696res[15] += test((byte)i);697res[16] += testb((byte)i);698res[17] += testc((byte)i);699res[18] += testm((byte)i);700res[19] += testp((byte)i, (byte)i);701702res[20] += test2((byte)i);703res[21] += testb2((byte)i);704res[22] += testc2((byte)i);705res[23] += testm2((byte)i);706res[24] += testp2((byte)i, (byte)i);707708res[25] += test_deop((byte)i);709res[26] += testb_deop((byte)i);710res[27] += testc_deop((byte)i);711res[28] += testf_deop((byte)i);712res[29] += testp_deop((byte)i, (byte)i);713}714715byte[] ia = new byte[1000];716for (int i = 0; i < 1000; i++) {717ia[i] = (byte)i;718}719720for (int i = 0; i < 100; i++) {721res[30] = sum(ia);722res[31] = sumb(ia);723res[32] = sumc(ia);724res[33] = sumf(ia);725res[34] = sump(ia, (byte)1);726727res[35] = sum2(ia);728res[36] = sumb2(ia);729res[37] = sumc2(ia);730res[38] = summ2(ia);731res[39] = sump2(ia, (byte)1);732733res[40] = sum_deop(ia);734res[41] = sumb_deop(ia);735res[42] = sumc_deop(ia);736res[43] = sumf_deop(ia);737res[44] = sump_deop(ia, (byte)1);738739res[45] = remi_sum();740res[46] = remi_sumb();741res[47] = remi_sumc();742res[48] = remi_sumf();743res[49] = remi_sump((byte)1);744745res[50] = remi_sum2();746res[51] = remi_sumb2();747res[52] = remi_sumc2();748res[53] = remi_summ2();749res[54] = remi_sump2((byte)1);750751res[55] = remi_sum_deop();752res[56] = remi_sumb_deop();753res[57] = remi_sumc_deop();754res[58] = remi_sumf_deop();755res[59] = remi_sump_deop((byte)1);756757res[60] = remi_sum_cond();758res[61] = remi_sumb_cond();759res[62] = remi_sumc_cond();760res[63] = remi_sumf_cond();761res[64] = remi_sump_cond((byte)1);762763res[65] = remi_sum2_cond();764res[66] = remi_sumb2_cond();765res[67] = remi_sumc2_cond();766res[68] = remi_summ2_cond();767res[69] = remi_sump2_cond((byte)1);768}769770int failed = 0;771for (int i = 0; i < ntests; i++) {772if (res[i] != val[i]) {773System.err.println(test_name[i] + ": " + res[i] + " != " + val[i]);774failed++;775}776}777if (failed > 0) {778System.err.println("Failed " + failed + " tests.");779throw new InternalError();780} else {781System.out.println("Passed.");782}783}784}785786787