Path: blob/master/test/hotspot/jtreg/compiler/c2/Test6559156.java
41149 views
/*1* Copyright (c) 2011, 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 655915626* @summary Server compiler generates bad code for "<= Integer.MAX_VALUE" expression27*28* @run main compiler.c2.Test655915629*/3031package compiler.c2;3233public class Test6559156 {3435static final int N_TESTS = 1000000;3637public static void main(String[] args) throws Exception {3839/*40* If MAX_VALUE is changed to MAX_VALUE - 1 below, the test passes41* because (apparently) bad code is only generated when comparing42* <= MAX_VALUE in the doTest method.43*/44Test6559156 test = new Test6559156();45for (int i = 0; i < N_TESTS; i += 1) {46test.doTest1(10, Integer.MAX_VALUE, i);47test.doTest2(10, Integer.MAX_VALUE, i);48}49System.out.println("No failure");50}5152void doTest1(int expected, int max, int i) {53int counted;54for (counted = 0;55(counted <= max) && (counted < expected);56counted += 1) {57}58if (counted != expected) {59throw new RuntimeException("Failed test1 iteration=" + i +60" max=" + max +61" counted=" + counted +62" expected=" + expected);63}64}6566void doTest2(int expected, int max, int i) {67int counted;68for (counted = 0;69// change test sequence.70(counted < expected) && (counted <= max);71counted += 1) {72}73if (counted != expected) {74throw new RuntimeException("Failed test1 iteration=" + i +75" max=" + max +76" counted=" + counted +77" expected=" + expected);78}79}80}81828384