1 /* 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /** 26 * @test 27 * @bug 7052494 28 * @summary Eclipse test fails on JDK 7 b142 29 * 30 * @run main/othervm -Xbatch compiler.loopopts.Test7052494 31 */ 32 33 package compiler.loopopts; 34 35 public class Test7052494 { 36 37 static int test1(int i, int limit) { 38 int result = 0; 39 while (i++ != 0) { 40 if (result >= limit) 41 break; 42 result = i * 2; 43 } 44 return result; 45 } 46 47 static int test2(int i, int limit) { 48 int result = 0; 49 while (i-- != 0) { 50 if (result <= limit) 51 break; 52 result = i * 2; 53 } 54 return result; 55 } 56 57 static void test3(int i, int limit, int arr[]) { 58 while (i++ != 0) { 59 if (arr[i - 1] >= limit) 60 break; 61 arr[i] = i * 2; 62 } 63 } 64 65 static void test4(int i, int limit, int arr[]) { 66 while (i-- != 0) { 67 if (arr[arr.length + i + 1] <= limit) 68 break; 69 arr[arr.length + i] = i * 2; 70 } 71 } 72 73 // Empty loop rolls through MAXINT if i > 0 74 75 static final int limit5 = Integer.MIN_VALUE + 10000; 76 77 static int test5(int i) { 78 int result = 0; 79 while (i++ != limit5) { 80 result = i * 2; 81 } 82 return result; 83 } 84 85 // Empty loop rolls through MININT if i < 0 86 87 static final int limit6 = Integer.MAX_VALUE - 10000; 88 89 static int test6(int i) { 90 int result = 0; 91 while (i-- != limit6) { 92 result = i * 2; 93 } 94 return result; 95 } 96 97 public static void main(String[] args) { 98 boolean failed = false; 99 int[] arr = new int[8]; 100 int[] ar3 = {0, 0, 4, 6, 8, 10, 0, 0}; 101 int[] ar4 = {0, 0, 0, -10, -8, -6, -4, 0}; 102 System.out.println("test1"); 103 for (int i = 0; i < 11000; i++) { 104 int k = test1(1, 10); 105 if (k != 10) { 106 System.out.println("FAILED: " + k + " != 10"); 107 failed = true; 108 break; 109 } 110 } 111 System.out.println("test2"); 112 for (int i = 0; i < 11000; i++) { 113 int k = test2(-1, -10); 114 if (k != -10) { 115 System.out.println("FAILED: " + k + " != -10"); 116 failed = true; 117 break; 118 } 119 } 120 System.out.println("test3"); 121 for (int i = 0; i < 11000; i++) { 122 java.util.Arrays.fill(arr, 0); 123 test3(1, 10, arr); 124 if (!java.util.Arrays.equals(arr, ar3)) { 125 System.out.println("FAILED: arr = { " + arr[0] + ", " 126 + arr[1] + ", " 127 + arr[2] + ", " 128 + arr[3] + ", " 129 + arr[4] + ", " 130 + arr[5] + ", " 131 + arr[6] + ", " 132 + arr[7] + " }"); 133 failed = true; 134 break; 135 } 136 } 137 System.out.println("test4"); 138 for (int i = 0; i < 11000; i++) { 139 java.util.Arrays.fill(arr, 0); 140 test4(-1, -10, arr); 141 if (!java.util.Arrays.equals(arr, ar4)) { 142 System.out.println("FAILED: arr = { " + arr[0] + ", " 143 + arr[1] + ", " 144 + arr[2] + ", " 145 + arr[3] + ", " 146 + arr[4] + ", " 147 + arr[5] + ", " 148 + arr[6] + ", " 149 + arr[7] + " }"); 150 failed = true; 151 break; 152 } 153 } 154 System.out.println("test5"); 155 for (int i = 0; i < 11000; i++) { 156 int k = test5(limit6); 157 if (k != limit5 * 2) { 158 System.out.println("FAILED: " + k + " != " + limit5 * 2); 159 failed = true; 160 break; 161 } 162 } 163 System.out.println("test6"); 164 for (int i = 0; i < 11000; i++) { 165 int k = test6(limit5); 166 if (k != limit6 * 2) { 167 System.out.println("FAILED: " + k + " != " + limit6 * 2); 168 failed = true; 169 break; 170 } 171 } 172 System.out.println("finish"); 173 if (failed) { 174 System.exit(97); 175 } 176 } 177 }