Path: blob/master/test/hotspot/jtreg/compiler/loopopts/Test7052494.java
41149 views
/*1* Copyright (c) 2011, 2014, 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 705249426* @summary Eclipse test fails on JDK 7 b14227*28* @run main/othervm -Xbatch compiler.loopopts.Test705249429*/3031package compiler.loopopts;3233public class Test7052494 {3435static int test1(int i, int limit) {36int result = 0;37while (i++ != 0) {38if (result >= limit)39break;40result = i * 2;41}42return result;43}4445static int test2(int i, int limit) {46int result = 0;47while (i-- != 0) {48if (result <= limit)49break;50result = i * 2;51}52return result;53}5455static void test3(int i, int limit, int arr[]) {56while (i++ != 0) {57if (arr[i - 1] >= limit)58break;59arr[i] = i * 2;60}61}6263static void test4(int i, int limit, int arr[]) {64while (i-- != 0) {65if (arr[arr.length + i + 1] <= limit)66break;67arr[arr.length + i] = i * 2;68}69}7071// Empty loop rolls through MAXINT if i > 07273static final int limit5 = Integer.MIN_VALUE + 10000;7475static int test5(int i) {76int result = 0;77while (i++ != limit5) {78result = i * 2;79}80return result;81}8283// Empty loop rolls through MININT if i < 08485static final int limit6 = Integer.MAX_VALUE - 10000;8687static int test6(int i) {88int result = 0;89while (i-- != limit6) {90result = i * 2;91}92return result;93}9495public static void main(String[] args) {96boolean failed = false;97int[] arr = new int[8];98int[] ar3 = {0, 0, 4, 6, 8, 10, 0, 0};99int[] ar4 = {0, 0, 0, -10, -8, -6, -4, 0};100System.out.println("test1");101for (int i = 0; i < 11000; i++) {102int k = test1(1, 10);103if (k != 10) {104System.out.println("FAILED: " + k + " != 10");105failed = true;106break;107}108}109System.out.println("test2");110for (int i = 0; i < 11000; i++) {111int k = test2(-1, -10);112if (k != -10) {113System.out.println("FAILED: " + k + " != -10");114failed = true;115break;116}117}118System.out.println("test3");119for (int i = 0; i < 11000; i++) {120java.util.Arrays.fill(arr, 0);121test3(1, 10, arr);122if (!java.util.Arrays.equals(arr, ar3)) {123System.out.println("FAILED: arr = { " + arr[0] + ", "124+ arr[1] + ", "125+ arr[2] + ", "126+ arr[3] + ", "127+ arr[4] + ", "128+ arr[5] + ", "129+ arr[6] + ", "130+ arr[7] + " }");131failed = true;132break;133}134}135System.out.println("test4");136for (int i = 0; i < 11000; i++) {137java.util.Arrays.fill(arr, 0);138test4(-1, -10, arr);139if (!java.util.Arrays.equals(arr, ar4)) {140System.out.println("FAILED: arr = { " + arr[0] + ", "141+ arr[1] + ", "142+ arr[2] + ", "143+ arr[3] + ", "144+ arr[4] + ", "145+ arr[5] + ", "146+ arr[6] + ", "147+ arr[7] + " }");148failed = true;149break;150}151}152System.out.println("test5");153for (int i = 0; i < 11000; i++) {154int k = test5(limit6);155if (k != limit5 * 2) {156System.out.println("FAILED: " + k + " != " + limit5 * 2);157failed = true;158break;159}160}161System.out.println("test6");162for (int i = 0; i < 11000; i++) {163int k = test6(limit5);164if (k != limit6 * 2) {165System.out.println("FAILED: " + k + " != " + limit6 * 2);166failed = true;167break;168}169}170System.out.println("finish");171if (failed) {172System.exit(97);173}174}175}176177178