Path: blob/master/test/hotspot/jtreg/gc/shenandoah/compiler/FoldIfAfterExpansion.java
41155 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* @test 823838525* @summary CTW: C2 (Shenandoah) compilation fails with "Range check dependent CastII node was not removed"26* @requires vm.gc.Shenandoah27* @modules java.base/jdk.internal.misc:+open28*29* @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:-TieredCompilation -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC30* FoldIfAfterExpansion31*32*/3334import jdk.internal.misc.Unsafe;3536public class FoldIfAfterExpansion {37private static int[] field1 = new int[100];38private static int[] field2 = new int[100];39private static int[] field3;40private static volatile int barrier;4142static final jdk.internal.misc.Unsafe UNSAFE = Unsafe.getUnsafe();4344public static void main(String[] args) {45for (int i = 0; i < 20_000; i++) {46test(true, 10, false, true);47test(false, 10, false, false);48}49}5051private static Object test(boolean flag, int i, boolean flag2, boolean flag3) {52int[] array;53if (flag) {54barrier = 1;55array = field1;56final int length = array.length;57if (flag2) {58field3 = array;59}60} else {61barrier = 1;62array = field1;63final int length = array.length;64if (flag2) {65field3 = array;66}67}6869array = field1;7071if (flag3) {72if (i < 0 || i >= array.length) {73throw new RuntimeException();74}75long l = (long)i;76l = l * UNSAFE.ARRAY_INT_INDEX_SCALE + UNSAFE.ARRAY_INT_BASE_OFFSET;77UNSAFE.putInt(array, l, i);78} else {79if (i < 0 || i >= array.length) {80throw new RuntimeException();81}82long l = (long)i;83l = l * UNSAFE.ARRAY_INT_INDEX_SCALE + UNSAFE.ARRAY_INT_BASE_OFFSET;84UNSAFE.putInt(array, l, i);85}8687return array;88}89}909192