1/* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 8086046 27 * @summary load bypasses arraycopy that sets the value after the ArrayCopyNode is expanded 28 * 29 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement 30 * -XX:CompileCommand=dontinline,compiler.arraycopy.TestLoadBypassArrayCopy::test_helper 31 * -XX:-TieredCompilation 32 * compiler.arraycopy.TestLoadBypassArrayCopy 33 */ 34 35package compiler.arraycopy; 36 37public class TestLoadBypassArrayCopy { 38 39 static long i; 40 static boolean test_helper() { 41 i++; 42 if ((i%10) == 0) { 43 return false; 44 } 45 return true; 46 } 47 48 static int test(int[] src, int len, boolean flag) { 49 int[] dest = new int[10]; 50 int res = 0; 51 while (test_helper()) { 52 System.arraycopy(src, 0, dest, 0, len); 53 // predicate moved out of loop so control of following 54 // load is not the ArrayCopyNode. Otherwise, if the memory 55 // of the load is changed and the control is set to the 56 // ArrayCopyNode the graph is unschedulable and the test 57 // doesn't fail. 58 if (flag) { 59 } 60 // The memory of this load shouldn't bypass the arraycopy 61 res = dest[0]; 62 } 63 return res; 64 } 65 66 static public void main(String[] args) { 67 int[] src = new int[10]; 68 src[0] = 0x42; 69 for (int i = 0; i < 20000; i++) { 70 int res = test(src, 10, false); 71 if (res != src[0]) { 72 throw new RuntimeException("test failed"); 73 } 74 } 75 } 76} 77