Path: blob/master/test/hotspot/jtreg/compiler/eliminateAutobox/TestShortBoxing.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* @summary enable parts of EliminateAutoBox by default27*28* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+EliminateAutoBox29* compiler.eliminateAutobox.TestShortBoxing30* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+EliminateAutoBox31* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestShortBoxing::dummy32* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestShortBoxing::foo33* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestShortBoxing::foob34* compiler.eliminateAutobox.TestShortBoxing35* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-EliminateAutoBox36* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestShortBoxing::dummy37* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestShortBoxing::foo38* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestShortBoxing::foob39* compiler.eliminateAutobox.TestShortBoxing40*/4142package compiler.eliminateAutobox;4344public class TestShortBoxing {4546static final Short ibc = new Short((short)1);4748//===============================================49// Non-inlined methods to test deoptimization info50static void dummy() { }51static short foo(short i) { return i; }52static Short foob(short i) { return Short.valueOf(i); }535455static short simple(short i) {56Short ib = new Short(i);57return ib;58}5960static short simpleb(short i) {61Short ib = Short.valueOf(i);62return ib;63}6465static short simplec() {66Short ib = ibc;67return ib;68}6970static short simplef(short i) {71Short ib = foob(i);72return ib;73}7475static short simplep(Short ib) {76return ib;77}7879static short simple2(short i) {80Short ib1 = new Short(i);81Short ib2 = new Short((short)(i+1));82return (short)(ib1 + ib2);83}8485static short simpleb2(short i) {86Short ib1 = Short.valueOf(i);87Short ib2 = Short.valueOf((short)(i+1));88return (short)(ib1 + ib2);89}9091static short simplem2(short i) {92Short ib1 = new Short(i);93Short ib2 = Short.valueOf((short)(i+1));94return (short)(ib1 + ib2);95}9697static short simplep2(short i, Short ib1) {98Short ib2 = Short.valueOf((short)(i+1));99return (short)(ib1 + ib2);100}101102static short simplec2(short i) {103Short ib1 = ibc;104Short ib2 = Short.valueOf((short)(i+1));105return (short)(ib1 + ib2);106}107108//===============================================109static short test(short i) {110Short ib = new Short(i);111if ((i&1) == 0)112ib = (short)(i+1);113return ib;114}115116static short testb(short i) {117Short ib = i;118if ((i&1) == 0)119ib = (short)(i+1);120return ib;121}122123static short testm(short i) {124Short ib = i;125if ((i&1) == 0)126ib = new Short((short)(i+1));127return ib;128}129130static short testp(short i, Short ib) {131if ((i&1) == 0)132ib = new Short((short)(i+1));133return ib;134}135136static short testc(short i) {137Short ib = ibc;138if ((i&1) == 0)139ib = new Short((short)(i+1));140return ib;141}142143static short test2(short i) {144Short ib1 = new Short(i);145Short ib2 = new Short((short)(i+1));146if ((i&1) == 0) {147ib1 = new Short((short)(i+1));148ib2 = new Short((short)(i+2));149}150return (short)(ib1+ib2);151}152153static short testb2(short i) {154Short ib1 = i;155Short ib2 = (short)(i+1);156if ((i&1) == 0) {157ib1 = (short)(i+1);158ib2 = (short)(i+2);159}160return (short)(ib1 + ib2);161}162163static short testm2(short i) {164Short ib1 = new Short(i);165Short ib2 = (short)(i+1);166if ((i&1) == 0) {167ib1 = new Short((short)(i+1));168ib2 = (short)(i+2);169}170return (short)(ib1 + ib2);171}172173static short testp2(short i, Short ib1) {174Short ib2 = (short)(i+1);175if ((i&1) == 0) {176ib1 = new Short((short)(i+1));177ib2 = (short)(i+2);178}179return (short)(ib1 + ib2);180}181182static short testc2(short i) {183Short ib1 = ibc;184Short ib2 = (short)(i+1);185if ((i&1) == 0) {186ib1 = (short)(ibc+1);187ib2 = (short)(i+2);188}189return (short)(ib1 + ib2);190}191192//===============================================193static short sum(short[] a) {194short result = 1;195for (Short i : a)196result += i;197return result;198}199200static short sumb(short[] a) {201Short result = 1;202for (Short i : a)203result = (short)(result + i);204return result;205}206207static short sumc(short[] a) {208Short result = ibc;209for (Short i : a)210result = (short)(result + i);211return result;212}213214static short sumf(short[] a) {215Short result = foob((short)1);216for (Short i : a)217result = (short)(result + i);218return result;219}220221static short sump(short[] a, Short result) {222for (Short i : a)223result = (short)(result + i);224return result;225}226227static short sum2(short[] a) {228short result1 = 1;229short result2 = 1;230for (Short i : a) {231result1 += i;232result2 += i + 1;233}234return (short)(result1 + result2);235}236237static short sumb2(short[] a) {238Short result1 = 1;239Short result2 = 1;240for (Short i : a) {241result1 = (short)(result1 + i);242result2 = (short)(result2 + i + 1);243}244return (short)(result1 + result2);245}246247static short summ2(short[] a) {248Short result1 = 1;249Short result2 = new Short((short)1);250for (Short i : a) {251result1 = (short)(result1 + i);252result2 = (short)(result2 + new Short((short)(i + 1)));253}254return (short)(result1 + result2);255}256257static short sump2(short[] a, Short result2) {258Short result1 = 1;259for (Short i : a) {260result1 = (short)(result1 + i);261result2 = (short)(result2 + i + 1);262}263return (short)(result1 + result2);264}265266static short sumc2(short[] a) {267Short result1 = 1;268Short result2 = ibc;269for (Short i : a) {270result1 = (short)(result1 + i);271result2 = (short)(result2 + i + ibc);272}273return (short)(result1 + result2);274}275276//===============================================277static short remi_sum() {278Short j = new Short((short)1);279for (int i = 0; i< 1000; i++) {280j = new Short((short)(j + 1));281}282return j;283}284285static short remi_sumb() {286Short j = Short.valueOf((short)1);287for (int i = 0; i< 1000; i++) {288j = (short)(j + 1);289}290return j;291}292293static short remi_sumf() {294Short j = foob((short)1);295for (int i = 0; i< 1000; i++) {296j = (short)(j + 1);297}298return j;299}300301static short remi_sump(Short j) {302for (int i = 0; i< 1000; i++) {303j = new Short((short)(j + 1));304}305return j;306}307308static short remi_sumc() {309Short j = ibc;310for (int i = 0; i< 1000; i++) {311j = (short)(j + ibc);312}313return j;314}315316static short remi_sum2() {317Short j1 = new Short((short)1);318Short j2 = new Short((short)1);319for (int i = 0; i< 1000; i++) {320j1 = new Short((short)(j1 + 1));321j2 = new Short((short)(j2 + 2));322}323return (short)(j1 + j2);324}325326static short remi_sumb2() {327Short j1 = Short.valueOf((short)1);328Short j2 = Short.valueOf((short)1);329for (int i = 0; i< 1000; i++) {330j1 = (short)(j1 + 1);331j2 = (short)(j2 + 2);332}333return (short)(j1 + j2);334}335336static short remi_summ2() {337Short j1 = new Short((short)1);338Short j2 = Short.valueOf((short)1);339for (int i = 0; i< 1000; i++) {340j1 = new Short((short)(j1 + 1));341j2 = (short)(j2 + 2);342}343return (short)(j1 + j2);344}345346static short remi_sump2(Short j1) {347Short j2 = Short.valueOf((short)1);348for (int i = 0; i< 1000; i++) {349j1 = new Short((short)(j1 + 1));350j2 = (short)(j2 + 2);351}352return (short)(j1 + j2);353}354355static short remi_sumc2() {356Short j1 = ibc;357Short j2 = Short.valueOf((short)1);358for (int i = 0; i< 1000; i++) {359j1 = (short)(j1 + ibc);360j2 = (short)(j2 + 2);361}362return (short)(j1 + j2);363}364365366//===============================================367// Safepointa and debug info for deoptimization368static short simple_deop(short i) {369Short ib = new Short(foo(i));370dummy();371return ib;372}373374static short simpleb_deop(short i) {375Short ib = Short.valueOf(foo(i));376dummy();377return ib;378}379380static short simplef_deop(short i) {381Short ib = foob(i);382dummy();383return ib;384}385386static short simplep_deop(Short ib) {387dummy();388return ib;389}390391static short simplec_deop(short i) {392Short ib = ibc;393dummy();394return ib;395}396397static short test_deop(short i) {398Short ib = new Short(foo(i));399if ((i&1) == 0)400ib = foo((short)(i+1));401dummy();402return ib;403}404405static short testb_deop(short i) {406Short ib = foo(i);407if ((i&1) == 0)408ib = foo((short)(i+1));409dummy();410return ib;411}412413static short testf_deop(short i) {414Short ib = foob(i);415if ((i&1) == 0)416ib = foo((short)(i+1));417dummy();418return ib;419}420421static short testp_deop(short i, Short ib) {422if ((i&1) == 0)423ib = foo((short)(i+1));424dummy();425return ib;426}427428static short testc_deop(short i) {429Short ib = ibc;430if ((i&1) == 0)431ib = foo((short)(i+1));432dummy();433return ib;434}435436static short sum_deop(short[] a) {437short result = 1;438for (Short i : a)439result += foo(i);440dummy();441return result;442}443444static short sumb_deop(short[] a) {445Short result = 1;446for (Short i : a)447result = (short)(result + foo(i));448dummy();449return result;450}451452static short sumf_deop(short[] a) {453Short result = 1;454for (Short i : a)455result = (short)(result + foob(i));456dummy();457return result;458}459460static short sump_deop(short[] a, Short result) {461for (Short i : a)462result = (short)(result + foob(i));463dummy();464return result;465}466467static short sumc_deop(short[] a) {468Short result = ibc;469for (Short i : a)470result = (short)(result + foo(i));471dummy();472return result;473}474475static short remi_sum_deop() {476Short j = new Short(foo((short)1));477for (int i = 0; i< 1000; i++) {478j = new Short(foo((short)(j + 1)));479}480dummy();481return j;482}483484static short remi_sumb_deop() {485Short j = Short.valueOf(foo((short)1));486for (int i = 0; i< 1000; i++) {487j = foo((short)(j + 1));488}489dummy();490return j;491}492493static short remi_sumf_deop() {494Short j = foob((short)1);495for (int i = 0; i< 1000; i++) {496j = foo((short)(j + 1));497}498dummy();499return j;500}501502static short remi_sump_deop(Short j) {503for (int i = 0; i< 1000; i++) {504j = foo((short)(j + 1));505}506dummy();507return j;508}509510static short remi_sumc_deop() {511Short j = ibc;512for (int i = 0; i< 1000; i++) {513j = foo((short)(j + 1));514}515dummy();516return j;517}518519//===============================================520// Conditional increment521static short remi_sum_cond() {522Short j = new Short((short)1);523for (int i = 0; i< 1000; i++) {524if ((i&1) == 0) {525j = new Short((short)(j + 1));526}527}528return j;529}530531static short remi_sumb_cond() {532Short j = Short.valueOf((short)1);533for (int i = 0; i< 1000; i++) {534if ((i&1) == 0) {535j = (short)(j + 1);536}537}538return j;539}540541static short remi_sumf_cond() {542Short j = foob((short)1);543for (int i = 0; i< 1000; i++) {544if ((i&1) == 0) {545j = (short)(j + 1);546}547}548return j;549}550551static short remi_sump_cond(Short j) {552for (int i = 0; i< 1000; i++) {553if ((i&1) == 0) {554j = (short)(j + 1);555}556}557return j;558}559560static short remi_sumc_cond() {561Short j = ibc;562for (int i = 0; i< 1000; i++) {563if ((i&1) == 0) {564j = (short)(j + ibc);565}566}567return j;568}569570static short remi_sum2_cond() {571Short j1 = new Short((short)1);572Short j2 = new Short((short)1);573for (int i = 0; i< 1000; i++) {574if ((i&1) == 0) {575j1 = new Short((short)(j1 + 1));576} else {577j2 = new Short((short)(j2 + 2));578}579}580return (short)(j1 + j2);581}582583static short remi_sumb2_cond() {584Short j1 = Short.valueOf((short)1);585Short j2 = Short.valueOf((short)1);586for (int i = 0; i< 1000; i++) {587if ((i&1) == 0) {588j1 = (short)(j1 + 1);589} else {590j2 = (short)(j2 + 2);591}592}593return (short)(j1 + j2);594}595596static short remi_summ2_cond() {597Short j1 = new Short((short)1);598Short j2 = Short.valueOf((short)1);599for (int i = 0; i< 1000; i++) {600if ((i&1) == 0) {601j1 = new Short((short)(j1 + 1));602} else {603j2 = (short)(j2 + 2);604}605}606return (short)(j1 + j2);607}608609static short remi_sump2_cond(Short j1) {610Short j2 = Short.valueOf((short)1);611for (int i = 0; i< 1000; i++) {612if ((i&1) == 0) {613j1 = new Short((short)(j1 + 1));614} else {615j2 = (short)(j2 + 2);616}617}618return (short)(j1 + j2);619}620621static short remi_sumc2_cond() {622Short j1 = ibc;623Short j2 = Short.valueOf((short)1);624for (int i = 0; i< 1000; i++) {625if ((i&1) == 0) {626j1 = (short)(j1 + ibc);627} else {628j2 = (short)(j2 + 2);629}630}631return (short)(j1 + j2);632}633634635public static void main(String[] args) {636final int ntests = 70;637638String[] test_name = new String[] {639"simple", "simpleb", "simplec", "simplef", "simplep",640"simple2", "simpleb2", "simplec2", "simplem2", "simplep2",641"simple_deop", "simpleb_deop", "simplec_deop", "simplef_deop", "simplep_deop",642"test", "testb", "testc", "testm", "testp",643"test2", "testb2", "testc2", "testm2", "testp2",644"test_deop", "testb_deop", "testc_deop", "testf_deop", "testp_deop",645"sum", "sumb", "sumc", "sumf", "sump",646"sum2", "sumb2", "sumc2", "summ2", "sump2",647"sum_deop", "sumb_deop", "sumc_deop", "sumf_deop", "sump_deop",648"remi_sum", "remi_sumb", "remi_sumc", "remi_sumf", "remi_sump",649"remi_sum2", "remi_sumb2", "remi_sumc2", "remi_summ2", "remi_sump2",650"remi_sum_deop", "remi_sumb_deop", "remi_sumc_deop", "remi_sumf_deop", "remi_sump_deop",651"remi_sum_cond", "remi_sumb_cond", "remi_sumc_cond", "remi_sumf_cond", "remi_sump_cond",652"remi_sum2_cond", "remi_sumb2_cond", "remi_sumc2_cond", "remi_summ2_cond", "remi_sump2_cond"653};654655final int[] val = new int[] {65671994000, 71994000, 12000, 71994000, 71994000,657144000000, 144000000, 72018000, 144000000, 144000000,65871994000, 71994000, 12000, 71994000, 71994000,65972000000, 72000000, 36006000, 72000000, 72000000,660144012000, 144012000, 72030000, 144012000, 144012000,66172000000, 72000000, 36006000, 72000000, 72000000,662-24787, -24787, -24787, -24787, -24787,66316962, 16962, 16962, 16962, 16962,664-24787, -24787, -24787, -24787, -24787,6651001, 1001, 1001, 1001, 1001,6663002, 3002, 3002, 3002, 3002,6671001, 1001, 1001, 1001, 1001,668501, 501, 501, 501, 501,6691502, 1502, 1502, 1502, 1502670};671672int[] res = new int[ntests];673for (int i = 0; i < ntests; i++) {674res[i] = 0;675}676677678for (int i = 0; i < 12000; i++) {679res[0] += simple((short)i);680res[1] += simpleb((short)i);681res[2] += simplec();682res[3] += simplef((short)i);683res[4] += simplep((short)i);684685res[5] += simple2((short)i);686res[6] += simpleb2((short)i);687res[7] += simplec2((short)i);688res[8] += simplem2((short)i);689res[9] += simplep2((short)i, (short)i);690691res[10] += simple_deop((short)i);692res[11] += simpleb_deop((short)i);693res[12] += simplec_deop((short)i);694res[13] += simplef_deop((short)i);695res[14] += simplep_deop((short)i);696697res[15] += test((short)i);698res[16] += testb((short)i);699res[17] += testc((short)i);700res[18] += testm((short)i);701res[19] += testp((short)i, (short)i);702703res[20] += test2((short)i);704res[21] += testb2((short)i);705res[22] += testc2((short)i);706res[23] += testm2((short)i);707res[24] += testp2((short)i, (short)i);708709res[25] += test_deop((short)i);710res[26] += testb_deop((short)i);711res[27] += testc_deop((short)i);712res[28] += testf_deop((short)i);713res[29] += testp_deop((short)i, (short)i);714}715716short[] ia = new short[1000];717for (int i = 0; i < 1000; i++) {718ia[i] = (short)i;719}720721for (int i = 0; i < 100; i++) {722res[30] = sum(ia);723res[31] = sumb(ia);724res[32] = sumc(ia);725res[33] = sumf(ia);726res[34] = sump(ia, (short)1);727728res[35] = sum2(ia);729res[36] = sumb2(ia);730res[37] = sumc2(ia);731res[38] = summ2(ia);732res[39] = sump2(ia, (short)1);733734res[40] = sum_deop(ia);735res[41] = sumb_deop(ia);736res[42] = sumc_deop(ia);737res[43] = sumf_deop(ia);738res[44] = sump_deop(ia, (short)1);739740res[45] = remi_sum();741res[46] = remi_sumb();742res[47] = remi_sumc();743res[48] = remi_sumf();744res[49] = remi_sump((short)1);745746res[50] = remi_sum2();747res[51] = remi_sumb2();748res[52] = remi_sumc2();749res[53] = remi_summ2();750res[54] = remi_sump2((short)1);751752res[55] = remi_sum_deop();753res[56] = remi_sumb_deop();754res[57] = remi_sumc_deop();755res[58] = remi_sumf_deop();756res[59] = remi_sump_deop((short)1);757758res[60] = remi_sum_cond();759res[61] = remi_sumb_cond();760res[62] = remi_sumc_cond();761res[63] = remi_sumf_cond();762res[64] = remi_sump_cond((short)1);763764res[65] = remi_sum2_cond();765res[66] = remi_sumb2_cond();766res[67] = remi_sumc2_cond();767res[68] = remi_summ2_cond();768res[69] = remi_sump2_cond((short)1);769}770771int failed = 0;772for (int i = 0; i < ntests; i++) {773if (res[i] != val[i]) {774System.err.println(test_name[i] + ": " + res[i] + " != " + val[i]);775failed++;776}777}778if (failed > 0) {779System.err.println("Failed " + failed + " tests.");780throw new InternalError();781} else {782System.out.println("Passed.");783}784}785}786787788