Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyConjoint.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.TestArrayCopyConjoint34* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions35* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayCopyPartialInlineSize=0 -XX:MaxVectorSize=6436* compiler.arraycopy.TestArrayCopyConjoint37* @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.TestArrayCopyConjoint40* @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.TestArrayCopyConjoint43* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions44* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayCopyPartialInlineSize=64 -XX:MaxVectorSize=6445* compiler.arraycopy.TestArrayCopyConjoint46* @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.TestArrayCopyConjoint49* @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.TestArrayCopyConjoint52*53*/5455public class TestArrayCopyConjoint {5657public static final int SIZE = 4096;58public static byte[] fromByteArr, toByteArr, valByteArr;59public static char[] fromCharArr, toCharArr, valCharArr;60public static int[] fromIntArr, toIntArr, valIntArr;61public static long[] fromLongArr, toLongArr, valLongArr;6263static public void reinit(Class<?> c) {64if (c == byte.class) {65for (int i = 0 ; i < SIZE ; i++) {66fromByteArr[i] = (byte)i;67}68} else if (c == char.class) {69for (int i = 0 ; i < SIZE ; i++) {70fromCharArr[i] = (char)i;71}72} else if (c == int.class) {73for (int i = 0 ; i < SIZE ; i++) {74fromIntArr[i] = i;75}76} else {77assert c == long.class;78for (int i = 0 ; i < SIZE ; i++) {79fromLongArr[i] = i;80}81}82}8384static public void setup() {85// Both positions aligned86fromByteArr = new byte[SIZE];87valByteArr = new byte[SIZE];88toByteArr = fromByteArr;89fromCharArr = new char[SIZE];90valCharArr = new char[SIZE];91toCharArr = fromCharArr;92fromIntArr = new int[SIZE];93valIntArr = new int[SIZE];94toIntArr = fromIntArr;95fromLongArr = new long[SIZE];96valLongArr = new long[SIZE];97toLongArr = fromLongArr;9899for (int i = 0 ; i < SIZE ; i++) {100fromByteArr[i] = (byte)i;101valByteArr[i] = (byte)i;102fromCharArr[i] = (char)i;103valCharArr[i] = (char)i;104fromIntArr[i] = i;105valIntArr[i] = i;106fromLongArr[i] = i;107valLongArr[i] = i;108}109}110111public static int validate_ctr = 0;112public static <E> void validate(String msg, E arr, int length, int fromPos, int toPos) {113validate_ctr++;114if (arr instanceof byte []) {115byte [] barr = (byte [])arr;116for(int i = 0 ; i < length; i++)117if (valByteArr[i+fromPos] != barr[i+toPos]) {118System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i119+ " expected = " + valByteArr[i+fromPos]120+ " actual = " + barr[i+toPos]121+ " fromPos = " + fromPos122+ " toPos = " + toPos);123throw new Error("Fail");124125}126}127else if (arr instanceof char []) {128char [] carr = (char [])arr;129for(int i = 0 ; i < length; i++)130if (valCharArr[i+fromPos] != carr[i+toPos]) {131System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i132+ " expected = " + valCharArr[i+fromPos]133+ " actual = " + carr[i+toPos]134+ " fromPos = " + fromPos135+ " toPos = " + toPos);136throw new Error("Fail");137}138}139else if (arr instanceof int []) {140int [] iarr = (int [])arr;141for(int i = 0 ; i < length; i++)142if (valIntArr[i+fromPos] != iarr[i+toPos]) {143System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i144+ " expected = " + valIntArr[i+fromPos]145+ " actual = " + iarr[i+toPos]146+ " fromPos = " + fromPos147+ " toPos = " + toPos);148throw new Error("Fail");149}150}151else if (arr instanceof long []) {152long [] larr = (long [])arr;153for(int i = 0 ; i < length; i++)154if (valLongArr[i+fromPos] != larr[i+toPos]) {155System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i156+ " expected = " + valLongArr[i+fromPos]157+ " actual = " + larr[i+toPos]158+ " fromPos = " + fromPos159+ " toPos = " + toPos);160throw new Error("Fail");161}162}163}164165public static void testByte(int length, int fromPos, int toPos) {166System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, length);167validate(" Test ByteArr ", toByteArr, length, fromPos, toPos);168}169170public static void testChar(int length, int fromPos, int toPos) {171System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, length);172validate(" Test CharArr ", toCharArr, length, fromPos, toPos);173}174175public static void testInt(int length, int fromPos, int toPos) {176System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, length);177validate(" Test IntArr ", toIntArr, length, fromPos, toPos);178}179180public static void testLong(int length, int fromPos, int toPos) {181System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, length);182validate(" Test LongArr ", toLongArr, length, fromPos, toPos);183}184185public static void testByte_constant_LT32B(int fromPos, int toPos) {186System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 7);187validate(" Test Byte constant length 7 ", toByteArr, 7, fromPos, toPos);188}189public static void testByte_constant_LT64B(int fromPos, int toPos) {190System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 45);191validate(" Test Byte constant length 45 ", toByteArr, 45, fromPos, toPos);192}193194public static void testChar_constant_LT32B(int fromPos, int toPos) {195System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 7);196validate(" Test Char constant length 7 ", toCharArr, 7, fromPos, toPos);197}198public static void testChar_constant_LT64B(int fromPos, int toPos) {199System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 22);200validate(" Test Char constant length 22 ", toCharArr, 22, fromPos, toPos);201}202203public static void testInt_constant_LT32B(int fromPos, int toPos) {204System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 7);205validate(" Test Int constant length 7 ", toIntArr, 7, fromPos, toPos);206}207public static void testInt_constant_LT64B(int fromPos, int toPos) {208System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 11);209validate(" Test Int constant length 11 ", toIntArr, 11, fromPos, toPos);210}211212public static void testLong_constant_LT32B(int fromPos, int toPos) {213System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 3);214validate(" Test Long constant length 3 ", toLongArr, 3, fromPos, toPos);215}216public static void testLong_constant_LT64B(int fromPos, int toPos) {217System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 6);218validate(" Test Long constant length 6 ", toLongArr, 6, fromPos, toPos);219}220221222public static void main(String [] args) {223// Cases to test each new optimized stub special blocks.224// Cases to test new PI handling (PI32 and PI64).225// Cases to test vectorized constant array copies for all primitive types.226// LT32B LT64B LT96B LT128B LT160B LT192B LOOP1 LOOP2227int [] lengths = { 29, 59, 89, 125, 159, 189, 194, 1024 };228Random r = new Random(1024);229230setup();231232try {233for (int i = 0 ; i < 1000000 ; i++ ) {234int index = r.nextInt(2048);235testByte(lengths[i % lengths.length], index , index+2);236reinit(byte.class);237testByte_constant_LT32B (index , index+2);238reinit(byte.class);239testByte_constant_LT64B (index , index+2);240reinit(byte.class);241242testChar(lengths[i % lengths.length] >> 1, index , index+2);243reinit(char.class);244testChar_constant_LT32B (index , index+2);245reinit(char.class);246testChar_constant_LT64B (index , index+2);247reinit(char.class);248249testInt(lengths[i % lengths.length] >> 2, index , index+2);250reinit(int.class);251testInt_constant_LT32B (index , index+2);252reinit(int.class);253testInt_constant_LT64B (index , index+2);254reinit(int.class);255256testLong(lengths[i % lengths.length] >> 3, index , index+2);257reinit(long.class);258testLong_constant_LT32B (index , index+2);259reinit(long.class);260testLong_constant_LT64B (index , index+2);261reinit(long.class);262}263System.out.println("PASS : " + validate_ctr);264} catch (Exception e) {265System.out.println(e.getMessage());266}267}268}269270271