Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyConjoint.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.TestArrayCopyConjoint34* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions35* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=0 -XX:MaxVectorSize=6436* compiler.arraycopy.TestArrayCopyConjoint37* @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.TestArrayCopyConjoint40* @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.TestArrayCopyConjoint43* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions44* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=64 -XX:MaxVectorSize=6445* compiler.arraycopy.TestArrayCopyConjoint46* @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.TestArrayCopyConjoint49* @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.TestArrayCopyConjoint52* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+UnlockExperimentalVMOptions -XX:+AlwaysAtomicAccesses53* compiler.arraycopy.TestArrayCopyConjoint54*55*/5657public class TestArrayCopyConjoint {5859public static final int SIZE = 4096;60public static byte[] fromByteArr, toByteArr, valByteArr;61public static char[] fromCharArr, toCharArr, valCharArr;62public static int[] fromIntArr, toIntArr, valIntArr;63public static long[] fromLongArr, toLongArr, valLongArr;6465static public void reinit(Class<?> c) {66if (c == byte.class) {67for (int i = 0 ; i < SIZE ; i++) {68fromByteArr[i] = (byte)i;69}70} else if (c == char.class) {71for (int i = 0 ; i < SIZE ; i++) {72fromCharArr[i] = (char)i;73}74} else if (c == int.class) {75for (int i = 0 ; i < SIZE ; i++) {76fromIntArr[i] = i;77}78} else {79assert c == long.class;80for (int i = 0 ; i < SIZE ; i++) {81fromLongArr[i] = i;82}83}84}8586static public void setup() {87// Both positions aligned88fromByteArr = new byte[SIZE];89valByteArr = new byte[SIZE];90toByteArr = fromByteArr;91fromCharArr = new char[SIZE];92valCharArr = new char[SIZE];93toCharArr = fromCharArr;94fromIntArr = new int[SIZE];95valIntArr = new int[SIZE];96toIntArr = fromIntArr;97fromLongArr = new long[SIZE];98valLongArr = new long[SIZE];99toLongArr = fromLongArr;100101for (int i = 0 ; i < SIZE ; i++) {102fromByteArr[i] = (byte)i;103valByteArr[i] = (byte)i;104fromCharArr[i] = (char)i;105valCharArr[i] = (char)i;106fromIntArr[i] = i;107valIntArr[i] = i;108fromLongArr[i] = i;109valLongArr[i] = i;110}111}112113public static int validate_ctr = 0;114public static <E> void validate(String msg, E arr, int length, int fromPos, int toPos) {115validate_ctr++;116if (arr instanceof byte []) {117byte [] barr = (byte [])arr;118for(int i = 0 ; i < length; i++)119if (valByteArr[i+fromPos] != barr[i+toPos]) {120System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i121+ " expected = " + valByteArr[i+fromPos]122+ " actual = " + barr[i+toPos]123+ " fromPos = " + fromPos124+ " toPos = " + toPos);125throw new Error("Fail");126127}128}129else if (arr instanceof char []) {130char [] carr = (char [])arr;131for(int i = 0 ; i < length; i++)132if (valCharArr[i+fromPos] != carr[i+toPos]) {133System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i134+ " expected = " + valCharArr[i+fromPos]135+ " actual = " + carr[i+toPos]136+ " fromPos = " + fromPos137+ " toPos = " + toPos);138throw new Error("Fail");139}140}141else if (arr instanceof int []) {142int [] iarr = (int [])arr;143for(int i = 0 ; i < length; i++)144if (valIntArr[i+fromPos] != iarr[i+toPos]) {145System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i146+ " expected = " + valIntArr[i+fromPos]147+ " actual = " + iarr[i+toPos]148+ " fromPos = " + fromPos149+ " toPos = " + toPos);150throw new Error("Fail");151}152}153else if (arr instanceof long []) {154long [] larr = (long [])arr;155for(int i = 0 ; i < length; i++)156if (valLongArr[i+fromPos] != larr[i+toPos]) {157System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i158+ " expected = " + valLongArr[i+fromPos]159+ " actual = " + larr[i+toPos]160+ " fromPos = " + fromPos161+ " toPos = " + toPos);162throw new Error("Fail");163}164}165}166167public static void testByte(int length, int fromPos, int toPos) {168System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, length);169validate(" Test ByteArr ", toByteArr, length, fromPos, toPos);170}171172public static void testChar(int length, int fromPos, int toPos) {173System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, length);174validate(" Test CharArr ", toCharArr, length, fromPos, toPos);175}176177public static void testInt(int length, int fromPos, int toPos) {178System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, length);179validate(" Test IntArr ", toIntArr, length, fromPos, toPos);180}181182public static void testLong(int length, int fromPos, int toPos) {183System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, length);184validate(" Test LongArr ", toLongArr, length, fromPos, toPos);185}186187public static void testByte_constant_LT32B(int fromPos, int toPos) {188System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 7);189validate(" Test Byte constant length 7 ", toByteArr, 7, fromPos, toPos);190}191public static void testByte_constant_LT64B(int fromPos, int toPos) {192System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 45);193validate(" Test Byte constant length 45 ", toByteArr, 45, fromPos, toPos);194}195196public static void testChar_constant_LT32B(int fromPos, int toPos) {197System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 7);198validate(" Test Char constant length 7 ", toCharArr, 7, fromPos, toPos);199}200public static void testChar_constant_LT64B(int fromPos, int toPos) {201System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 22);202validate(" Test Char constant length 22 ", toCharArr, 22, fromPos, toPos);203}204205public static void testInt_constant_LT32B(int fromPos, int toPos) {206System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 7);207validate(" Test Int constant length 7 ", toIntArr, 7, fromPos, toPos);208}209public static void testInt_constant_LT64B(int fromPos, int toPos) {210System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 11);211validate(" Test Int constant length 11 ", toIntArr, 11, fromPos, toPos);212}213214public static void testLong_constant_LT32B(int fromPos, int toPos) {215System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 3);216validate(" Test Long constant length 3 ", toLongArr, 3, fromPos, toPos);217}218public static void testLong_constant_LT64B(int fromPos, int toPos) {219System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 6);220validate(" Test Long constant length 6 ", toLongArr, 6, fromPos, toPos);221}222223224public static void main(String [] args) {225// Cases to test each new optimized stub special blocks.226// Cases to test new PI handling (PI32 and PI64).227// Cases to test vectorized constant array copies for all primitive types.228// LT32B LT64B LT96B LT128B LT160B LT192B LOOP1 LOOP2229int [] lengths = { 29, 59, 89, 125, 159, 189, 194, 1024 };230Random r = new Random(1024);231232setup();233234try {235for (int i = 0 ; i < 1000000 ; i++ ) {236int index = r.nextInt(2048);237testByte(lengths[i % lengths.length], index , index+2);238reinit(byte.class);239testByte_constant_LT32B (index , index+2);240reinit(byte.class);241testByte_constant_LT64B (index , index+2);242reinit(byte.class);243244testChar(lengths[i % lengths.length] >> 1, index , index+2);245reinit(char.class);246testChar_constant_LT32B (index , index+2);247reinit(char.class);248testChar_constant_LT64B (index , index+2);249reinit(char.class);250251testInt(lengths[i % lengths.length] >> 2, index , index+2);252reinit(int.class);253testInt_constant_LT32B (index , index+2);254reinit(int.class);255testInt_constant_LT64B (index , index+2);256reinit(int.class);257258testLong(lengths[i % lengths.length] >> 3, index , index+2);259reinit(long.class);260testLong_constant_LT32B (index , index+2);261reinit(long.class);262testLong_constant_LT64B (index , index+2);263reinit(long.class);264}265System.out.println("PASS : " + validate_ctr);266} catch (Exception e) {267System.out.println(e.getMessage());268}269}270}271272273