Path: blob/master/test/hotspot/jtreg/compiler/c1/Test8011771.java
41149 views
/*1* Copyright (c) 2013, 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 801177126* @summary Array bound check elimination's in block motion doesn't always reset its data structures from one step to the other.27*28* @run main/othervm -XX:-BackgroundCompilation compiler.c1.Test801177129*/3031package compiler.c1;3233public class Test8011771 {3435static void m(int[] a, int[] b, int j) {36// Array bound check elimination inserts a predicate before37// the loop. We'll have the predicate fail, so the method is38// recompiled without optimistic optimizations39for (int i = 0; i < 10; i++) {40a[i] = i;41}4243// The test itself44a[j] = 0;45a[j+5] = 0;46b[j+4] = 0; // this range check shouldn't be eliminated47}4849static public void main(String[] args) {50int[] arr1 = new int[10], arr2 = new int[10];51// force compilation:52for (int i = 0; i < 5000; i++) {53m(arr1, arr2, 0);54}5556try {57m(new int[1], null, 0); // force predicate failure58} catch(ArrayIndexOutOfBoundsException e) {}5960// force compilation again (no optimistic opts):61for (int i = 0; i < 5000; i++) {62m(arr1, arr2, 0);63}6465// Check that the range check on the second array wasn't optimized out66boolean success = false;67try {68m(arr1, new int[1], 0);69} catch(ArrayIndexOutOfBoundsException e) {70success = true;71}72if (success) {73System.out.println("TEST PASSED");74} else {75throw new RuntimeException("TEST FAILED: erroneous bound check elimination");76}77}78}798081