kvn@2877: /* kvn@2877: * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. kvn@2877: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. kvn@2877: * kvn@2877: * This code is free software; you can redistribute it and/or modify it kvn@2877: * under the terms of the GNU General Public License version 2 only, as kvn@2877: * published by the Free Software Foundation. kvn@2877: * kvn@2877: * This code is distributed in the hope that it will be useful, but WITHOUT kvn@2877: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or kvn@2877: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License kvn@2877: * version 2 for more details (a copy is included in the LICENSE file that kvn@2877: * accompanied this code). kvn@2877: * kvn@2877: * You should have received a copy of the GNU General Public License version kvn@2877: * 2 along with this work; if not, write to the Free Software Foundation, kvn@2877: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. kvn@2877: * kvn@2877: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA kvn@2877: * or visit www.oracle.com if you need additional information or have any kvn@2877: * questions. kvn@2877: * kvn@2877: */ kvn@2877: kvn@2877: /** kvn@2877: * @test kvn@2877: * @bug 6992759 kvn@2877: * @summary Bad code generated for integer <= comparison, fails for Integer.MAX_VALUE kvn@2877: * kvn@2877: * @run main Test6992759 kvn@2877: */ kvn@2877: kvn@2877: public class Test6992759 { kvn@2877: kvn@2877: static final int N_TESTS = 1000000000; kvn@2877: kvn@2877: public static void main(String[] args) throws Exception { kvn@2877: kvn@2877: /* kvn@2877: * If MAX_VALUE is changed to MAX_VALUE - 1 below, the test passes kvn@2877: * because (apparently) bad code is only generated when comparing kvn@2877: * <= MAX_VALUE in the doTest method. kvn@2877: */ kvn@2877: Test6992759 test = new Test6992759(); kvn@2877: for (int i = 0; i < N_TESTS; i += 1) { kvn@2877: test.doTest(10, Integer.MAX_VALUE, i); kvn@2877: //test.doTest(10, Integer.MAX_VALUE - 1, i); kvn@2877: } kvn@2877: System.out.println("No failure"); kvn@2877: } kvn@2877: kvn@2877: void doTest(int expected, int max, int i) { kvn@2877: int counted; kvn@2877: for (counted = 0; kvn@2877: (counted <= max) && (counted < expected); kvn@2877: counted += 1) { kvn@2877: } kvn@2877: if (counted != expected) { kvn@2877: throw new RuntimeException("Failed test iteration=" + i + kvn@2877: " max=" + max + kvn@2877: " counted=" + counted + kvn@2877: " expected=" + expected); kvn@2877: } kvn@2877: } kvn@2877: } kvn@2877: