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 7173584 27 * @summary arraycopy as macro node 28 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestArrayCopyMacro 29 * 30 */ 31 32 public class TestArrayCopyMacro { 33 static class A { 34 } 35 36 // In its own method so profiling reports both branches taken 37 static Object m2(Object o1, Object o2, int i) { 38 if (i == 4) { 39 return o1; 40 } 41 return o2; 42 } 43 44 static Object m1(A[] src, Object dest) { 45 int i = 1; 46 47 // won't be optimized out until after parsing 48 for (; i < 3; i *= 4) { 49 } 50 dest = m2(new A[10], dest, i); 51 52 // dest is new array here but C2 picks the "disjoint" stub 53 // only if stub to call is decided after parsing 54 System.arraycopy(src, 0, dest, 0, 10); 55 return dest; 56 } 57 58 public static void main(String[] args) { 59 A[] array_src = new A[10]; 60 61 for (int i = 0; i < array_src.length; i++) { 62 array_src[i] = new A(); 63 } 64 65 for (int i = 0; i < 20000; i++) { 66 m2(null, null, 0); 67 } 68 69 for (int i = 0; i < 20000; i++) { 70 Object[] array_dest = (Object[])m1(array_src, null); 71 72 for (int j = 0; j < array_src.length; j++) { 73 if (array_dest[j] != array_src[j]) { 74 throw new RuntimeException("copy failed at index " + j + " src = " + array_src[j] + " dest = " + array_dest[j]); 75 } 76 } 77 } 78 } 79 }