Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyMacro.java
41152 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 717358426* @summary arraycopy as macro node27*28* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement29* compiler.arraycopy.TestArrayCopyMacro30*/3132package compiler.arraycopy;3334public class TestArrayCopyMacro {35static class A {36}3738// In its own method so profiling reports both branches taken39static Object m2(Object o1, Object o2, int i) {40if (i == 4) {41return o1;42}43return o2;44}4546static Object m1(A[] src, Object dest) {47int i = 1;4849// won't be optimized out until after parsing50for (; i < 3; i *= 4) {51}52dest = m2(new A[10], dest, i);5354// dest is new array here but C2 picks the "disjoint" stub55// only if stub to call is decided after parsing56System.arraycopy(src, 0, dest, 0, 10);57return dest;58}5960public static void main(String[] args) {61A[] array_src = new A[10];6263for (int i = 0; i < array_src.length; i++) {64array_src[i] = new A();65}6667for (int i = 0; i < 20000; i++) {68m2(null, null, 0);69}7071for (int i = 0; i < 20000; i++) {72Object[] array_dest = (Object[])m1(array_src, null);7374for (int j = 0; j < array_src.length; j++) {75if (array_dest[j] != array_src[j]) {76throw new RuntimeException("copy failed at index " + j + " src = " + array_src[j] + " dest = " + array_dest[j]);77}78}79}80}81}828384