Path: blob/master/test/hotspot/jtreg/compiler/codegen/TestGCMStorePlacement.java
41149 views
/*1* Copyright (c) 2020, 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*/2223package compiler.codegen;2425import jdk.test.lib.Asserts;2627/**28* @test29* @bug 8255763 825889430* @summary Tests GCM's store placement in different scenarios (regular and OSR31* compilations, reducible and irreducible CFGs).32* @library /test/lib /33* @run main/othervm -Xbatch compiler.codegen.TestGCMStorePlacement regularReducible134* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileOnly=compiler.codegen.TestGCMStorePlacement:: compiler.codegen.TestGCMStorePlacement regularReducible235* @run main/othervm -Xcomp -XX:CompileOnly=compiler.codegen.TestGCMStorePlacement:: compiler.codegen.TestGCMStorePlacement regularReducible336* @run main/othervm -Xcomp -XX:CompileOnly=compiler.codegen.TestGCMStorePlacement:: compiler.codegen.TestGCMStorePlacement regularReducible437* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileOnly=compiler.codegen.TestGCMStorePlacement:: compiler.codegen.TestGCMStorePlacement osrReducible138* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileOnly=compiler.codegen.TestGCMStorePlacement:: compiler.codegen.TestGCMStorePlacement osrReducible239* @run main/othervm -Xbatch compiler.codegen.TestGCMStorePlacement osrIrreducible140*/4142public class TestGCMStorePlacement {4344static int intCounter;45static long longCounter;4647static void testRegularReducible1() {48// This should not be placed into the loop.49intCounter++;50int acc = 0;51for (int i = 0; i < 50; i++) {52if (i % 2 == 0) {53acc += 1;54}55}56return;57}5859static void testRegularReducible2() {60int i;61for (i = 22; i < 384; i++)62longCounter += 1;63switch (i % 9) {64case 49:65int i17 = 70;66while (i17 > 0) {67longCounter = 42;68switch (9) {69case 97:70break;71case 11398:72for (int i18 = 1; ; );73default:74}75}76}77}7879static void testRegularReducible3() {80int i = 0, i23, i27 = 184;81for (int i21 = 0; i21 < 100; i21++) {82i23 = 1;83longCounter += 1;84while (++i23 < 190)85switch (i23 % 10) {86case 86:87continue;88case 0:89i += 76.854F;90for (; i27 < 1; i27++);91}92}93}9495static void testRegularReducible4() {96int i16 = 0, i17;97longCounter += 1;98while (++i16 < 100) {99i17 = 0;100while (++i17 < 200) {101switch ((i16 * 5) + 123) {102case 129:103break;104case 149:105break;106default:107}108}109}110}111112public static void bar() {113int[] a = new int[0];114long sum = 0;115for (int j = 0; j < 0; j++) {116sum += (a[j] / (j + 1) + a[j] % (j + 1));117}118}119static void foo() {120bar();121}122123static void testOsrReducible1() {124int count = 100;125for (int i = 0; i < 100; i++) {126for (int j = 0; j < 100; j++) {127foo();128try {129count = (100000 / count);130} catch (Exception e) {}131switch (0) {132case 0:133for (int k = 0; k < 2; k++) {134count = 0;135}136longCounter += 1;137}138}139}140}141142static void testOsrReducible2() {143System.out.println();144boolean cond = false;145for (int i = 0; i < 100; i++) {146for (int j = 0; j < 100; j++) {147intCounter = 42;148if (cond) {149break;150}151for (int k = 0; k < 2; k++);152}153}154}155156static void testOsrIrreducible1() {157for (int i = 0; i < 30; i++) {158switch (i % 3) {159case 0:160for (int j = 0; j < 50; j++) {161// OSR enters here.162for (int k = 0; k < 7000; k++) {}163if (i % 2 == 0) {164break;165}166}167// This should not be placed outside the "case 0" block.168intCounter++;169break;170case 1:171break;172case 2:173break;174}175}176return;177}178179public static void main(String[] args) {180switch (args[0]) {181case "regularReducible1":182for (int i = 0; i < 100_000; i++) {183intCounter = 0;184testRegularReducible1();185Asserts.assertEQ(intCounter, 1);186}187break;188case "regularReducible2":189longCounter = 0;190testRegularReducible2();191Asserts.assertEQ(longCounter, 362L);192break;193case "regularReducible3":194for (int i = 0; i < 10; i++) {195longCounter = 0;196testRegularReducible3();197Asserts.assertEQ(longCounter, 100L);198}199break;200case "regularReducible4":201for (int i = 0; i < 10; i++) {202longCounter = 0;203testRegularReducible4();204Asserts.assertEQ(longCounter, 1L);205}206break;207case "osrReducible1":208longCounter = 0;209testOsrReducible1();210Asserts.assertEQ(longCounter, 10000L);211break;212case "osrReducible2":213intCounter = 0;214testOsrReducible2();215Asserts.assertEQ(intCounter, 42);216break;217case "osrIrreducible1":218intCounter = 0;219testOsrIrreducible1();220Asserts.assertEQ(intCounter, 10);221break;222default:223System.out.println("invalid mode");224}225}226}227228229