Path: blob/master/test/hotspot/jtreg/compiler/loopopts/LoadVectorFromStableArray.java
41149 views
/*1* Copyright (c) 2018, 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 821434426* @summary LoadVector from a known element of a stable array shouldn't attempt to constant fold27* @modules java.base/jdk.internal.vm.annotation28*29* @run main/bootclasspath/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement LoadVectorFromStableArray30*31*/3233import jdk.internal.vm.annotation.Stable;3435public class LoadVectorFromStableArray {36public static void main(String[] args) {37byte[] byte_array = new byte[100];38for (int i = 0; i < 20_000; i++) {39test_helper(0, 0);40test_helper(42, 0);41test_helper2(0, 20, byte_array, byte_array);42}43for (int i = 0; i < 20_000; i++) {44test(20, true);45test(20, false);46}47}4849static @Stable byte[] stable_array1 = new byte[100];50static @Stable byte[] stable_array2 = new byte[100];5152private static void test(int stop, boolean flag) {53int start = 0;54byte[] byte_array1 = stable_array1;55byte[] byte_array2 = flag ? stable_array1 : stable_array2;56int k = 2;57for (; k < 4; k *= 2);58int i = test_helper(k, stop);59// Loop in this method is unrolled and vectorized, then, upper60// bound is found to be constant and small. A single iteration61// of the main loop is executed. That iteration attempts to62// load a vector element from the array at a constant offset.63test_helper2(start, i, byte_array1, byte_array2);64}656667private static void test_helper2(int start, int stop, byte[] byte_array1, byte[] byte_array2) {68for (int j = start; j < stop; j++) {69byte b = byte_array1[j+3];70byte_array2[j+3] = b;71}72}7374private static int test_helper(int k, int stop) {75int i = 0;76if (k == 42) {77i = stop;78} else {79i = 5;80}81return i;82}83}848586