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