Path: blob/master/test/hotspot/jtreg/compiler/rangechecks/TestRangeCheckSmearingLoopOpts.java
41149 views
/*1* Copyright (c) 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 804817026* @summary Following range check smearing, range check cannot be replaced by dominating identical test.27*28* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement29* compiler.rangechecks.TestRangeCheckSmearingLoopOpts30*/3132package compiler.rangechecks;3334public class TestRangeCheckSmearingLoopOpts {3536static int dummy;3738static int m1(int[] array, int i) {39for (;;) {40for (;;) {41if (array[i] < 0) { // range check (i+0) dominates equivalent check below42break;43}44i++;45}4647// A control flow that stops IfNode::up_one_dom()48if ((i % 2)== 0) {49if ((array[i] % 2) == 0) {50dummy = i;51}52}5354// IfNode::Ideal will rewrite some range checks if Compile::allow_range_check_smearing55if (array[i-1] == 9) { // range check (i-1) unchanged56int res = array[i-3]; // range check (i-3) unchanged57res += array[i]; // range check (i+0) unchanged58res += array[i-2]; // removed redundant range check59// the previous access might be hoisted by60// PhaseIdealLoop::split_if_with_blocks_post because61// it appears to have the same guard, but it also62// depends on the previous guards63return res;64}65i++;66}67}6869static public void main(String[] args) {70int[] array = { 0, 1, 2, -3, 4, 5, -2, 7, 8, 9, -1 };71for (int i = 0; i < 20000; i++) {72m1(array, 0);73}74array[0] = -1;75try {76m1(array, 0);77} catch(ArrayIndexOutOfBoundsException aioobe) {}78}79}808182