test/compiler/5091921/Test5091921.java

Mon, 28 Jul 2014 15:06:38 -0700

author
fzhinkin
date
Mon, 28 Jul 2014 15:06:38 -0700
changeset 6997
dbb05f6d93c4
parent 0
f90c822e73f8
permissions
-rw-r--r--

8051344: JVM crashed in Compile::start() during method parsing w/ UseRTMDeopt turned on
Summary: call rtm_deopt() only if there were no compilation bailouts before.
Reviewed-by: kvn

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2011 Hewlett-Packard Company. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 /**
aoqi@0 26 * @test
aoqi@0 27 * @bug 5091921
aoqi@0 28 * @summary Sign flip issues in loop optimizer
aoqi@0 29 *
aoqi@0 30 * @run main/othervm -Xcomp -XX:CompileOnly=Test5091921 -XX:MaxInlineSize=1 Test5091921
aoqi@0 31 */
aoqi@0 32
aoqi@0 33 public class Test5091921 {
aoqi@0 34 private static int result = 0;
aoqi@0 35
aoqi@0 36
aoqi@0 37 /* Test for the bug of transforming indx >= MININT to indx > MININT-1 */
aoqi@0 38 public static int test_ge1(int limit) {
aoqi@0 39 int indx;
aoqi@0 40 int sum = 0;
aoqi@0 41 for (indx = 500; indx >= limit; indx -= 2) {
aoqi@0 42 sum += 2000 / indx;
aoqi@0 43 result = sum;
aoqi@0 44 }
aoqi@0 45 return sum;
aoqi@0 46 }
aoqi@0 47
aoqi@0 48 /* Test for the bug of transforming indx <= MAXINT to indx < MAXINT+1 */
aoqi@0 49 public static int test_le1(int limit) {
aoqi@0 50 int indx;
aoqi@0 51 int sum = 0;
aoqi@0 52 for (indx = -500; indx <= limit; indx += 2)
aoqi@0 53 {
aoqi@0 54 sum += 3000 / indx;
aoqi@0 55 result = sum;
aoqi@0 56 }
aoqi@0 57 return sum;
aoqi@0 58 }
aoqi@0 59
aoqi@0 60 /* Run with -Xcomp -XX:CompileOnly=wrap1.test1 -XX:MaxInlineSize=1 */
aoqi@0 61 /* limit reset to ((limit-init+stride-1)/stride)*stride+init */
aoqi@0 62 /* Calculation may overflow */
aoqi@0 63 public static volatile int c = 1;
aoqi@0 64 public static int test_wrap1(int limit)
aoqi@0 65 {
aoqi@0 66 int indx;
aoqi@0 67 int sum = 0;
aoqi@0 68 for (indx = 0xffffffff; indx < limit; indx += 0x20000000)
aoqi@0 69 {
aoqi@0 70 sum += c;
aoqi@0 71 }
aoqi@0 72 return sum;
aoqi@0 73 }
aoqi@0 74
aoqi@0 75 /* Test for range check elimination with bit flip issue for
aoqi@0 76 scale*i+offset<limit where offset is not 0 */
aoqi@0 77 static int[] box5 = {1,2,3,4,5,6,7,8,9};
aoqi@0 78 public static int test_rce5(int[] b, int limit)
aoqi@0 79 {
aoqi@0 80 int indx;
aoqi@0 81 int sum = b[1];
aoqi@0 82 result = sum;
aoqi@0 83 for (indx = 0x80000000; indx < limit; ++indx)
aoqi@0 84 {
aoqi@0 85 if (indx > 0x80000000)
aoqi@0 86 {
aoqi@0 87 // this test is not issued in pre-loop but issued in main loop
aoqi@0 88 // trick rce into thinking expression is false when indx >= 0
aoqi@0 89 // in fact it is false when indx==0x80000001
aoqi@0 90 if (indx - 9 < -9)
aoqi@0 91 {
aoqi@0 92 sum += indx;
aoqi@0 93 result = sum;
aoqi@0 94 sum ^= b[indx & 7];
aoqi@0 95 result = sum;
aoqi@0 96 }
aoqi@0 97 else
aoqi@0 98 break;
aoqi@0 99 }
aoqi@0 100 else
aoqi@0 101 {
aoqi@0 102 sum += b[indx & 3];
aoqi@0 103 result = sum;
aoqi@0 104 }
aoqi@0 105 }
aoqi@0 106 return sum;
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 /* Test for range check elimination with bit flip issue for
aoqi@0 110 scale*i<limit where scale > 1 */
aoqi@0 111 static int[] box6 = {1,2,3,4,5,6,7,8,9};
aoqi@0 112 public static int test_rce6(int[] b, int limit)
aoqi@0 113 {
aoqi@0 114 int indx;
aoqi@0 115 int sum = b[1];
aoqi@0 116 result = sum;
aoqi@0 117 for (indx = 0x80000000; indx < limit; ++indx)
aoqi@0 118 {
aoqi@0 119 if (indx > 0x80000000)
aoqi@0 120 {
aoqi@0 121 // harmless rce target
aoqi@0 122 if (indx < 0)
aoqi@0 123 {
aoqi@0 124 sum += result;
aoqi@0 125 result = sum;
aoqi@0 126 }
aoqi@0 127 else
aoqi@0 128 break;
aoqi@0 129 // this test is not issued in pre-loop but issued in main loop
aoqi@0 130 // trick rce into thinking expression is false when indx >= 0
aoqi@0 131 // in fact it is false when indx==0x80000001
aoqi@0 132 // In compilers that transform mulI to shiftI may mask this issue.
aoqi@0 133 if (indx * 28 + 1 < 0)
aoqi@0 134 {
aoqi@0 135 sum += indx;
aoqi@0 136 result = sum;
aoqi@0 137 sum ^= b[indx & 7];
aoqi@0 138 result = sum;
aoqi@0 139 }
aoqi@0 140 else
aoqi@0 141 break;
aoqi@0 142 }
aoqi@0 143 else
aoqi@0 144 {
aoqi@0 145 sum += b[indx & 3];
aoqi@0 146 result = sum;
aoqi@0 147 }
aoqi@0 148 }
aoqi@0 149 return sum;
aoqi@0 150 }
aoqi@0 151
aoqi@0 152 /* Test for range check elimination with i <= limit */
aoqi@0 153 static int[] box7 = {1,2,3,4,5,6,7,8,9,0x7fffffff};
aoqi@0 154 public static int test_rce7(int[] b)
aoqi@0 155 {
aoqi@0 156 int indx;
aoqi@0 157 int max = b[9];
aoqi@0 158 int sum = b[7];
aoqi@0 159 result = sum;
aoqi@0 160 for (indx = 0; indx < b.length; ++indx)
aoqi@0 161 {
aoqi@0 162 if (indx <= max)
aoqi@0 163 {
aoqi@0 164 sum += (indx ^ 15) + ((result != 0) ? 0 : sum);
aoqi@0 165 result = sum;
aoqi@0 166 }
aoqi@0 167 else
aoqi@0 168 throw new RuntimeException();
aoqi@0 169 }
aoqi@0 170 for (indx = -7; indx < b.length; ++indx)
aoqi@0 171 {
aoqi@0 172 if (indx <= 9)
aoqi@0 173 {
aoqi@0 174 sum += (sum ^ 15) + ((result != 0) ? 0 : sum);
aoqi@0 175 result = sum;
aoqi@0 176 }
aoqi@0 177 else
aoqi@0 178 throw new RuntimeException();
aoqi@0 179 }
aoqi@0 180 return sum;
aoqi@0 181 }
aoqi@0 182
aoqi@0 183 /* Test for range check elimination with i >= limit */
aoqi@0 184 static int[] box8 = {-1,0,1,2,3,4,5,6,7,8,0x80000000};
aoqi@0 185 public static int test_rce8(int[] b)
aoqi@0 186 {
aoqi@0 187 int indx;
aoqi@0 188 int sum = b[5];
aoqi@0 189 int min = b[10];
aoqi@0 190 result = sum;
aoqi@0 191 for (indx = b.length-1; indx >= 0; --indx)
aoqi@0 192 {
aoqi@0 193 if (indx >= min)
aoqi@0 194 {
aoqi@0 195 sum += (sum ^ 9) + ((result != 0) ? 0 :sum);
aoqi@0 196 result = sum;
aoqi@0 197 }
aoqi@0 198 else
aoqi@0 199 throw new RuntimeException();
aoqi@0 200 }
aoqi@0 201 return sum;
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 public static void main(String[] args)
aoqi@0 205 {
aoqi@0 206 result=1;
aoqi@0 207 int r = 0;
aoqi@0 208 try {
aoqi@0 209 r = test_ge1(0x80000000);
aoqi@0 210 System.out.println(result);
aoqi@0 211 System.out.println("test_ge1 FAILED");
aoqi@0 212 System.exit(1);
aoqi@0 213 }
aoqi@0 214 catch (ArithmeticException e1) {
aoqi@0 215 System.out.println("test_ge1: Expected exception caught");
aoqi@0 216 if (result != 5986) {
aoqi@0 217 System.out.println(result);
aoqi@0 218 System.out.println("test_ge1 FAILED");
aoqi@0 219 System.exit(97);
aoqi@0 220 }
aoqi@0 221 }
aoqi@0 222 System.out.println("test_ge1 WORKED");
aoqi@0 223
aoqi@0 224 result=0;
aoqi@0 225 try
aoqi@0 226 {
aoqi@0 227 r = test_le1(0x7fffffff);
aoqi@0 228 System.out.println(result);
aoqi@0 229 System.out.println("test_le1 FAILED");
aoqi@0 230 System.exit(1);
aoqi@0 231 }
aoqi@0 232 catch (ArithmeticException e1)
aoqi@0 233 {
aoqi@0 234 System.out.println("test_le1: Expected exception caught");
aoqi@0 235 if (result != -9039)
aoqi@0 236 {
aoqi@0 237 System.out.println(result);
aoqi@0 238 System.out.println("test_le1 FAILED");
aoqi@0 239 System.exit(97);
aoqi@0 240 }
aoqi@0 241 }
aoqi@0 242 System.out.println("test_le1 WORKED");
aoqi@0 243
aoqi@0 244 result=0;
aoqi@0 245 r = test_wrap1(0x7fffffff);
aoqi@0 246 if (r != 4)
aoqi@0 247 {
aoqi@0 248 System.out.println(result);
aoqi@0 249 System.out.println("test_wrap1 FAILED");
aoqi@0 250 System.exit(97);
aoqi@0 251 }
aoqi@0 252 else
aoqi@0 253 {
aoqi@0 254 System.out.println("test_wrap1 WORKED");
aoqi@0 255 }
aoqi@0 256
aoqi@0 257 result=0;
aoqi@0 258 r = test_rce5(box5,0x80000100);
aoqi@0 259 if (result != 3)
aoqi@0 260 {
aoqi@0 261 System.out.println(result);
aoqi@0 262 System.out.println("test_rce5 FAILED");
aoqi@0 263 System.exit(97);
aoqi@0 264 }
aoqi@0 265 else
aoqi@0 266 {
aoqi@0 267 System.out.println("test_rce5 WORKED");
aoqi@0 268 }
aoqi@0 269
aoqi@0 270 result=0;
aoqi@0 271 r = test_rce6(box6,0x80000100);
aoqi@0 272 if (result != 6)
aoqi@0 273 {
aoqi@0 274 System.out.println(result);
aoqi@0 275 System.out.println("test_rce6 FAILED");
aoqi@0 276 System.exit(97);
aoqi@0 277 }
aoqi@0 278 else
aoqi@0 279 {
aoqi@0 280 System.out.println("test_rce6 WORKED");
aoqi@0 281 }
aoqi@0 282
aoqi@0 283 result=0;
aoqi@0 284 r = test_rce7(box7);
aoqi@0 285 if (result != 14680079)
aoqi@0 286 {
aoqi@0 287 System.out.println(result);
aoqi@0 288 System.out.println("test_rce7 FAILED");
aoqi@0 289 System.exit(97);
aoqi@0 290 }
aoqi@0 291 else
aoqi@0 292 {
aoqi@0 293 System.out.println("test_rce7 WORKED");
aoqi@0 294 }
aoqi@0 295
aoqi@0 296 result=0;
aoqi@0 297 r = test_rce8(box8);
aoqi@0 298 if (result != 16393)
aoqi@0 299 {
aoqi@0 300 System.out.println(result);
aoqi@0 301 System.out.println("test_rce8 FAILED");
aoqi@0 302 System.exit(97);
aoqi@0 303 }
aoqi@0 304 else
aoqi@0 305 {
aoqi@0 306 System.out.println("test_rce8 WORKED");
aoqi@0 307 }
aoqi@0 308 }
aoqi@0 309 }

mercurial