Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestLoadBypassArrayCopy.java
41149 views
/*1* Copyright (c) 2015, 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 808604626* @summary load bypasses arraycopy that sets the value after the ArrayCopyNode is expanded27*28* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement29* -XX:CompileCommand=dontinline,compiler.arraycopy.TestLoadBypassArrayCopy::test_helper30* -XX:-TieredCompilation31* compiler.arraycopy.TestLoadBypassArrayCopy32*/3334package compiler.arraycopy;3536public class TestLoadBypassArrayCopy {3738static long i;39static boolean test_helper() {40i++;41if ((i%10) == 0) {42return false;43}44return true;45}4647static int test(int[] src, int len, boolean flag) {48int[] dest = new int[10];49int res = 0;50while (test_helper()) {51System.arraycopy(src, 0, dest, 0, len);52// predicate moved out of loop so control of following53// load is not the ArrayCopyNode. Otherwise, if the memory54// of the load is changed and the control is set to the55// ArrayCopyNode the graph is unschedulable and the test56// doesn't fail.57if (flag) {58}59// The memory of this load shouldn't bypass the arraycopy60res = dest[0];61}62return res;63}6465static public void main(String[] args) {66int[] src = new int[10];67src[0] = 0x42;68for (int i = 0; i < 20000; i++) {69int res = test(src, 10, false);70if (res != src[0]) {71throw new RuntimeException("test failed");72}73}74}75}767778