Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyMemoryChain.java
41149 views
/*1* Copyright (c) 2019, 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 823316426* @summary Test correct wiring of load/store memory for arraycopy ideal transformation.27* @run main/othervm -XX:CompileCommand=dontinline,compiler.arraycopy.TestArrayCopyMemoryChain::test* -Xbatch28* compiler.arraycopy.TestArrayCopyMemoryChain29*/3031package compiler.arraycopy;3233public class TestArrayCopyMemoryChain {3435private String mySweetEscape1 = null;3637private String getString(int i) {38return "A" + i + "B";39}4041// Original test depending on Indify String Concat42public void test1(int i) {43mySweetEscape1 = getString(i) + "CD";44}4546private byte[] mySweetEscape2;4748class Wrapper {49public final byte[] array;50public Wrapper(byte[] array) {51this.array = array;52}53}5455// Simplified test independent of Strings56public void test2(int idx, int size) {57// Create destination array with unknown size and let it escape.58byte[] dst = new byte[size];59mySweetEscape2 = dst;60// Create constant src1 array.61byte[] src1 = {43, 44};62// Wrap src2 into an Object such that it's only available after63// Escape Analys determined that the Object is non-escaping.64byte[] array = {42};65Wrapper wrapper = new Wrapper(array);66byte[] src2 = wrapper.array;67// Copy src1 and scr2 into destination array.68System.arraycopy(src1, 0, dst, idx, src1.length);69System.arraycopy(src2, 0, dst, 0, src2.length);70}7172public static void main(String[] args) {73TestArrayCopyMemoryChain t = new TestArrayCopyMemoryChain();74for (int i = 0; i < 100_000; ++i) {75t.test1(0);76if (!t.mySweetEscape1.equals("A0BCD")) {77throw new RuntimeException("Test1 failed");78}79t.test2(1, 3);80if (t.mySweetEscape2[0] != 42 || t.mySweetEscape2[1] != 43 || t.mySweetEscape2[2] != 44) {81throw new RuntimeException("Test2 failed");82}83}84}85}868788