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