Path: blob/master/test/hotspot/jtreg/gc/shenandoah/compiler/FoldIfAfterExpansion.java
64497 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* @bug 823838526* @summary CTW: C2 (Shenandoah) compilation fails with "Range check dependent CastII node was not removed"27* @requires vm.gc.Shenandoah28* @modules java.base/jdk.internal.misc:+open29*30* @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:-TieredCompilation -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC31* FoldIfAfterExpansion32*33*/3435import jdk.internal.misc.Unsafe;3637public class FoldIfAfterExpansion {38private static int[] field1 = new int[100];39private static int[] field2 = new int[100];40private static int[] field3;41private static volatile int barrier;4243static final jdk.internal.misc.Unsafe UNSAFE = Unsafe.getUnsafe();4445public static void main(String[] args) {46for (int i = 0; i < 20_000; i++) {47test(true, 10, false, true);48test(false, 10, false, false);49}50}5152private static Object test(boolean flag, int i, boolean flag2, boolean flag3) {53int[] array;54if (flag) {55barrier = 1;56array = field1;57final int length = array.length;58if (flag2) {59field3 = array;60}61} else {62barrier = 1;63array = field1;64final int length = array.length;65if (flag2) {66field3 = array;67}68}6970array = field1;7172if (flag3) {73if (i < 0 || i >= array.length) {74throw new RuntimeException();75}76long l = (long)i;77l = l * UNSAFE.ARRAY_INT_INDEX_SCALE + UNSAFE.ARRAY_INT_BASE_OFFSET;78UNSAFE.putInt(array, l, i);79} else {80if (i < 0 || i >= array.length) {81throw new RuntimeException();82}83long l = (long)i;84l = l * UNSAFE.ARRAY_INT_INDEX_SCALE + UNSAFE.ARRAY_INT_BASE_OFFSET;85UNSAFE.putInt(array, l, i);86}8788return array;89}90}919293