aoqi@0: /* aoqi@0: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 8011771 aoqi@0: * @summary Array bound check elimination's in block motion doesn't always reset its data structures from one step to the other. aoqi@0: * @run main/othervm -XX:-BackgroundCompilation Test8011771 aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: public class Test8011771 { aoqi@0: aoqi@0: static void m(int[] a, int[] b, int j) { aoqi@0: // Array bound check elimination inserts a predicate before aoqi@0: // the loop. We'll have the predicate fail, so the method is aoqi@0: // recompiled without optimistic optimizations aoqi@0: for (int i = 0; i < 10; i++) { aoqi@0: a[i] = i; aoqi@0: } aoqi@0: aoqi@0: // The test itself aoqi@0: a[j] = 0; aoqi@0: a[j+5] = 0; aoqi@0: b[j+4] = 0; // this range check shouldn't be eliminated aoqi@0: } aoqi@0: aoqi@0: static public void main(String[] args) { aoqi@0: int[] arr1 = new int[10], arr2 = new int[10]; aoqi@0: // force compilation: aoqi@0: for (int i = 0; i < 5000; i++) { aoqi@0: m(arr1, arr2, 0); aoqi@0: } aoqi@0: aoqi@0: try { aoqi@0: m(new int[1], null, 0); // force predicate failure aoqi@0: } catch(ArrayIndexOutOfBoundsException e) {} aoqi@0: aoqi@0: // force compilation again (no optimistic opts): aoqi@0: for (int i = 0; i < 5000; i++) { aoqi@0: m(arr1, arr2, 0); aoqi@0: } aoqi@0: aoqi@0: // Check that the range check on the second array wasn't optimized out aoqi@0: boolean success = false; aoqi@0: try { aoqi@0: m(arr1, new int[1], 0); aoqi@0: } catch(ArrayIndexOutOfBoundsException e) { aoqi@0: success = true; aoqi@0: } aoqi@0: if (success) { aoqi@0: System.out.println("TEST PASSED"); aoqi@0: } else { aoqi@0: throw new RuntimeException("TEST FAILED: erroneous bound check elimination"); aoqi@0: } aoqi@0: } aoqi@0: }