Path: blob/master/test/hotspot/jtreg/compiler/loopopts/TestLoopUnswitchingLostCastDependency.java
41149 views
/*1* Copyright (c) 2020, Red Hat, Inc. 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* @key stress randomness26* @bug 824190027* @summary Loop unswitching may cause dependence on null check to be lost28*29* @requires vm.compiler2.enabled30* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:+StressGCM -XX:+StressLCM TestLoopUnswitchingLostCastDependency31*/3233import java.util.Arrays;3435public class TestLoopUnswitchingLostCastDependency {36private static Object objectField;3738public static void main(String[] args) {39Object[] array = new Object[100];40Arrays.fill(array, new Object());41for (int i = 0; i < 20_000; i++) {42array[1] = null;43test(array);44array[1] = new Object();45objectField = null;46test(array);47array[1] = new Object();48objectField = new Object();49test(array);50}51}5253private static void test(Object[] array) {54Object o = objectField;55Object o3 = array[1];56int j = 0;57for (int i = 1; i < 100; i *= 2) {58Object o2 = array[i];59// Both branches taken: loop is unswitched.60if (o3 != null) {61if (o2 == null) {62}63// Both branches taken: loop is unswitched next.64if (o != null) {65// CastPP here becomes control dependent on o2 ==66// null check above.67if (o.getClass() == Object.class) {68}69// This causes partial peeling. When that happens,70// the o2 == null check becomes redundant with the71// o3 != null check in the peeled iteration. The72// CastPP with o as input that was control73// dependent on the o2 == null check becomes74// control dependent on the o3 != null check,75// above the o != null check.76if (j > 7) {7778}79j++;80}81}82}83}84}858687