Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyDisjoint.java
64474 views
/*1* Copyright (c) 2020, 2022, 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*/2223package compiler.arraycopy;24import java.util.Random;2526/**27* @test28* @bug 8251871 828530129* @summary Optimize arrayCopy using AVX-512 masked instructions.30*31* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions32* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=0 -XX:MaxVectorSize=32 -XX:+UnlockDiagnosticVMOptions33* compiler.arraycopy.TestArrayCopyDisjoint34* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions35* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=0 -XX:MaxVectorSize=6436* compiler.arraycopy.TestArrayCopyDisjoint37* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions38* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=32 -XX:+UnlockDiagnosticVMOptions -XX:MaxVectorSize=32 -XX:+UnlockDiagnosticVMOption39* compiler.arraycopy.TestArrayCopyDisjoint40* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions41* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=32 -XX:+UnlockDiagnosticVMOptions -XX:MaxVectorSize=6442* compiler.arraycopy.TestArrayCopyDisjoint43* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions44* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=64 -XX:MaxVectorSize=6445* compiler.arraycopy.TestArrayCopyDisjoint46* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions47* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=32 -XX:+UnlockDiagnosticVMOptions -XX:MaxVectorSize=32 -XX:+UnlockDiagnosticVMOption -XX:ArrayCopyLoadStoreMaxElem=1648* compiler.arraycopy.TestArrayCopyDisjoint49* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions50* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=64 -XX:MaxVectorSize=64 -XX:ArrayCopyLoadStoreMaxElem=1651* compiler.arraycopy.TestArrayCopyDisjoint52* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+UnlockExperimentalVMOptions -XX:+AlwaysAtomicAccesses53* compiler.arraycopy.TestArrayCopyDisjoint54*55*/5657public class TestArrayCopyDisjoint {5859public static final int SIZE = 4096;60public static byte[] fromByteArr, toByteArr;61public static char[] fromCharArr, toCharArr;62public static int[] fromIntArr, toIntArr;63public static long[] fromLongArr, toLongArr;6465static public void setup() {66// Both positions aligned67fromByteArr = new byte[SIZE];68toByteArr = new byte[SIZE];69fromCharArr = new char[SIZE];70toCharArr = new char[SIZE];71fromIntArr = new int[SIZE];72toIntArr = new int[SIZE];73fromLongArr = new long[SIZE];74toLongArr = new long[SIZE];7576for (int i = 0 ; i < SIZE ; i++) {77fromByteArr[i] = (byte)i;78fromCharArr[i] = (char)i;79fromIntArr[i] = i;80fromLongArr[i] = i;81}82}8384public static int validate_ctr = 0;85public static <E> void validate(String msg, E arr, int length, int fromPos, int toPos) {86validate_ctr++;87if (arr instanceof byte []) {88byte [] barr = (byte [])arr;89for(int i = 0 ; i < length; i++)90if (fromByteArr[i+fromPos] != barr[i+toPos]) {91System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i92+ " expected = " + fromByteArr[i+fromPos]93+ " actual = " + barr[i+toPos]94+ " fromPos = " + fromPos95+ " toPos = " + toPos);96throw new Error("Fail");97}98}99else if (arr instanceof char []) {100char [] carr = (char [])arr;101for(int i = 0 ; i < length; i++)102if (fromCharArr[i+fromPos] != carr[i+toPos]) {103System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i104+ " expected = " + fromCharArr[i+fromPos]105+ " actual = " + carr[i+toPos]106+ " fromPos = " + fromPos107+ " toPos = " + toPos);108throw new Error("Fail");109}110}111else if (arr instanceof int []) {112int [] iarr = (int [])arr;113for(int i = 0 ; i < length; i++)114if (fromIntArr[i+fromPos] != iarr[i+toPos]) {115System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i116+ " expected = " + fromIntArr[i+fromPos]117+ " actual = " + iarr[i+toPos]118+ " fromPos = " + fromPos119+ " toPos = " + toPos);120throw new Error("Fail");121}122}123else if (arr instanceof long []) {124long [] larr = (long [])arr;125for(int i = 0 ; i < length; i++)126if (fromLongArr[i+fromPos] != larr[i+toPos]) {127System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i128+ " expected = " + fromLongArr[i+fromPos]129+ " actual = " + larr[i+toPos]130+ " fromPos = " + fromPos131+ " toPos = " + toPos);132throw new Error("Fail");133}134}135}136137public static void testByte(int length, int fromPos, int toPos) {138System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, length);139validate(" Test ByteArr ", toByteArr, length, fromPos, toPos);140}141142public static void testChar(int length, int fromPos, int toPos) {143System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, length);144validate(" Test CharArr ", toCharArr, length, fromPos, toPos);145}146147public static void testInt(int length, int fromPos, int toPos) {148System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, length);149validate(" Test IntArr ", toIntArr, length, fromPos, toPos);150}151152public static void testLong(int length, int fromPos, int toPos) {153System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, length);154validate(" Test LongArr ", toLongArr, length, fromPos, toPos);155}156157public static void testByte_constant_LT32B(int fromPos, int toPos) {158System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 7);159validate(" Test Byte constant length 7 ", toByteArr, 7, fromPos, toPos);160}161public static void testByte_constant_LT64B(int fromPos, int toPos) {162System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 45);163validate(" Test Byte constant length 45 ", toByteArr, 45, fromPos, toPos);164}165166public static void testChar_constant_LT32B(int fromPos, int toPos) {167System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 7);168validate(" Test Char constant length 7 ", toCharArr, 7, fromPos, toPos);169}170public static void testChar_constant_LT64B(int fromPos, int toPos) {171System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 22);172validate(" Test Char constant length 22 ", toCharArr, 22, fromPos, toPos);173}174175public static void testInt_constant_LT32B(int fromPos, int toPos) {176System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 7);177validate(" Test Int constant length 7 ", toIntArr, 7, fromPos, toPos);178}179public static void testInt_constant_LT64B(int fromPos, int toPos) {180System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 11);181validate(" Test Int constant length 11 ", toIntArr, 11, fromPos, toPos);182}183184public static void testLong_constant_LT32B(int fromPos, int toPos) {185System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 3);186validate(" Test Long constant length 3 ", toLongArr, 3, fromPos, toPos);187}188public static void testLong_constant_LT64B(int fromPos, int toPos) {189System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 6);190validate(" Test Long constant length 6 ", toLongArr, 6, fromPos, toPos);191}192193194public static void main(String [] args) {195// Cases to test each new optimized stub special blocks.196// Cases to test new PI handling (PI32 and PI64).197// Cases to test vectorized constant array copies for all primitive types.198// LT32B LT64B LT96B LT128B LT160B LT192B LOOP1 LOOP2199int [] lengths = { 29, 59, 89, 125, 159, 189, 194, 1024 };200Random r = new Random(1024);201202setup();203204try {205for (int i = 0 ; i < 1000000 ; i++ ) {206testByte(lengths[i % lengths.length], r.nextInt(2048) , r.nextInt(2048));207testByte_constant_LT32B (r.nextInt(2048) , r.nextInt(2048));208testByte_constant_LT64B (r.nextInt(2048) , r.nextInt(2048));209210testChar(lengths[i % lengths.length] >> 1, r.nextInt(2048) , r.nextInt(2048));211testChar_constant_LT32B (r.nextInt(2048) , r.nextInt(2048));212testChar_constant_LT64B (r.nextInt(2048) , r.nextInt(2048));213214testInt(lengths[i % lengths.length] >> 2, r.nextInt(2048) , r.nextInt(2048));215testInt_constant_LT32B (r.nextInt(2048) , r.nextInt(2048));216testInt_constant_LT64B (r.nextInt(2048) , r.nextInt(2048));217218testLong(lengths[i % lengths.length] >> 3, r.nextInt(2048) , r.nextInt(2048));219testLong_constant_LT32B (r.nextInt(2048) , r.nextInt(2048));220testLong_constant_LT64B (r.nextInt(2048) , r.nextInt(2048));221}222System.out.println("PASS : " + validate_ctr);223} catch (Exception e) {224System.out.println(e.getMessage());225}226}227}228229230