Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyDisjoint.java
41149 views
/*1* Copyright (c) 2020, 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 825187129* @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:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=0 -XX:MaxVectorSize=6436* compiler.arraycopy.TestArrayCopyDisjoint37* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions38* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=64 -XX:MaxVectorSize=6445* compiler.arraycopy.TestArrayCopyDisjoint46* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions47* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=64 -XX:MaxVectorSize=64 -XX:ArrayCopyLoadStoreMaxElem=1651* compiler.arraycopy.TestArrayCopyDisjoint52*53*/5455public class TestArrayCopyDisjoint {5657public static final int SIZE = 4096;58public static byte[] fromByteArr, toByteArr;59public static char[] fromCharArr, toCharArr;60public static int[] fromIntArr, toIntArr;61public static long[] fromLongArr, toLongArr;6263static public void setup() {64// Both positions aligned65fromByteArr = new byte[SIZE];66toByteArr = new byte[SIZE];67fromCharArr = new char[SIZE];68toCharArr = new char[SIZE];69fromIntArr = new int[SIZE];70toIntArr = new int[SIZE];71fromLongArr = new long[SIZE];72toLongArr = new long[SIZE];7374for (int i = 0 ; i < SIZE ; i++) {75fromByteArr[i] = (byte)i;76fromCharArr[i] = (char)i;77fromIntArr[i] = i;78fromLongArr[i] = i;79}80}8182public static int validate_ctr = 0;83public static <E> void validate(String msg, E arr, int length, int fromPos, int toPos) {84validate_ctr++;85if (arr instanceof byte []) {86byte [] barr = (byte [])arr;87for(int i = 0 ; i < length; i++)88if (fromByteArr[i+fromPos] != barr[i+toPos]) {89System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i90+ " expected = " + fromByteArr[i+fromPos]91+ " actual = " + barr[i+toPos]92+ " fromPos = " + fromPos93+ " toPos = " + toPos);94throw new Error("Fail");95}96}97else if (arr instanceof char []) {98char [] carr = (char [])arr;99for(int i = 0 ; i < length; i++)100if (fromCharArr[i+fromPos] != carr[i+toPos]) {101System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i102+ " expected = " + fromCharArr[i+fromPos]103+ " actual = " + carr[i+toPos]104+ " fromPos = " + fromPos105+ " toPos = " + toPos);106throw new Error("Fail");107}108}109else if (arr instanceof int []) {110int [] iarr = (int [])arr;111for(int i = 0 ; i < length; i++)112if (fromIntArr[i+fromPos] != iarr[i+toPos]) {113System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i114+ " expected = " + fromIntArr[i+fromPos]115+ " actual = " + iarr[i+toPos]116+ " fromPos = " + fromPos117+ " toPos = " + toPos);118throw new Error("Fail");119}120}121else if (arr instanceof long []) {122long [] larr = (long [])arr;123for(int i = 0 ; i < length; i++)124if (fromLongArr[i+fromPos] != larr[i+toPos]) {125System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i126+ " expected = " + fromLongArr[i+fromPos]127+ " actual = " + larr[i+toPos]128+ " fromPos = " + fromPos129+ " toPos = " + toPos);130throw new Error("Fail");131}132}133}134135public static void testByte(int length, int fromPos, int toPos) {136System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, length);137validate(" Test ByteArr ", toByteArr, length, fromPos, toPos);138}139140public static void testChar(int length, int fromPos, int toPos) {141System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, length);142validate(" Test CharArr ", toCharArr, length, fromPos, toPos);143}144145public static void testInt(int length, int fromPos, int toPos) {146System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, length);147validate(" Test IntArr ", toIntArr, length, fromPos, toPos);148}149150public static void testLong(int length, int fromPos, int toPos) {151System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, length);152validate(" Test LongArr ", toLongArr, length, fromPos, toPos);153}154155public static void testByte_constant_LT32B(int fromPos, int toPos) {156System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 7);157validate(" Test Byte constant length 7 ", toByteArr, 7, fromPos, toPos);158}159public static void testByte_constant_LT64B(int fromPos, int toPos) {160System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 45);161validate(" Test Byte constant length 45 ", toByteArr, 45, fromPos, toPos);162}163164public static void testChar_constant_LT32B(int fromPos, int toPos) {165System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 7);166validate(" Test Char constant length 7 ", toCharArr, 7, fromPos, toPos);167}168public static void testChar_constant_LT64B(int fromPos, int toPos) {169System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 22);170validate(" Test Char constant length 22 ", toCharArr, 22, fromPos, toPos);171}172173public static void testInt_constant_LT32B(int fromPos, int toPos) {174System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 7);175validate(" Test Int constant length 7 ", toIntArr, 7, fromPos, toPos);176}177public static void testInt_constant_LT64B(int fromPos, int toPos) {178System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 11);179validate(" Test Int constant length 11 ", toIntArr, 11, fromPos, toPos);180}181182public static void testLong_constant_LT32B(int fromPos, int toPos) {183System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 3);184validate(" Test Long constant length 3 ", toLongArr, 3, fromPos, toPos);185}186public static void testLong_constant_LT64B(int fromPos, int toPos) {187System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 6);188validate(" Test Long constant length 6 ", toLongArr, 6, fromPos, toPos);189}190191192public static void main(String [] args) {193// Cases to test each new optimized stub special blocks.194// Cases to test new PI handling (PI32 and PI64).195// Cases to test vectorized constant array copies for all primitive types.196// LT32B LT64B LT96B LT128B LT160B LT192B LOOP1 LOOP2197int [] lengths = { 29, 59, 89, 125, 159, 189, 194, 1024 };198Random r = new Random(1024);199200setup();201202try {203for (int i = 0 ; i < 1000000 ; i++ ) {204testByte(lengths[i % lengths.length], r.nextInt(2048) , r.nextInt(2048));205testByte_constant_LT32B (r.nextInt(2048) , r.nextInt(2048));206testByte_constant_LT64B (r.nextInt(2048) , r.nextInt(2048));207208testChar(lengths[i % lengths.length] >> 1, r.nextInt(2048) , r.nextInt(2048));209testChar_constant_LT32B (r.nextInt(2048) , r.nextInt(2048));210testChar_constant_LT64B (r.nextInt(2048) , r.nextInt(2048));211212testInt(lengths[i % lengths.length] >> 2, r.nextInt(2048) , r.nextInt(2048));213testInt_constant_LT32B (r.nextInt(2048) , r.nextInt(2048));214testInt_constant_LT64B (r.nextInt(2048) , r.nextInt(2048));215216testLong(lengths[i % lengths.length] >> 3, r.nextInt(2048) , r.nextInt(2048));217testLong_constant_LT32B (r.nextInt(2048) , r.nextInt(2048));218testLong_constant_LT64B (r.nextInt(2048) , r.nextInt(2048));219}220System.out.println("PASS : " + validate_ctr);221} catch (Exception e) {222System.out.println(e.getMessage());223}224}225}226227228