Path: blob/master/test/hotspot/jtreg/compiler/loopstripmining/TestStripMinedLimitBelowInit.java
41149 views
/*1* Copyright (c) 2020, Red Hat, Inc. 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 824408626* @summary Following 8241492, strip mined loop may run extra iterations27* @requires vm.compiler2.enabled28*29* @run main/othervm -XX:-BackgroundCompilation -XX:LoopUnrollLimit=0 -XX:-TieredCompilation TestStripMinedLimitBelowInit30*31*/3233public class TestStripMinedLimitBelowInit {34public static void main(String[] args) {35for (int i = 0; i < 20_000; i++) {36test1(0, 1000);37test2(1000, 0);38}39int sum = test1(1000, 0);40if (sum != 1000) {41throw new RuntimeException("wrong result: " + sum);42}43sum = test2(0, 1000);44if (sum != 0) {45throw new RuntimeException("wrong result: " + sum);46}47}4849private static int test1(int start, int stop) {50int sum = 0;51int i = start;52do {53// So ciTypeFlow doesn't clone the loop head54synchronized (new Object()) {55}56sum += i;57i++;58} while (i < stop);59return sum;60}6162private static int test2(int start, int stop) {63int sum = 0;64int i = start;65do {66synchronized (new Object()) {67}68sum += i;69i--;70} while (i >= stop);71return sum;72}73}747576