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