Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyConjoint.java
64474 views
1
/*
2
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
package compiler.arraycopy;
25
import java.util.Random;
26
27
/**
28
* @test
29
* @bug 8251871 8285301
30
* @summary Optimize arrayCopy using AVX-512 masked instructions.
31
*
32
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions
33
* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=0 -XX:MaxVectorSize=32 -XX:+UnlockDiagnosticVMOptions
34
* compiler.arraycopy.TestArrayCopyConjoint
35
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions
36
* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=0 -XX:MaxVectorSize=64
37
* compiler.arraycopy.TestArrayCopyConjoint
38
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions
39
* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=32 -XX:+UnlockDiagnosticVMOptions -XX:MaxVectorSize=32 -XX:+UnlockDiagnosticVMOption
40
* compiler.arraycopy.TestArrayCopyConjoint
41
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions
42
* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=32 -XX:+UnlockDiagnosticVMOptions -XX:MaxVectorSize=64
43
* compiler.arraycopy.TestArrayCopyConjoint
44
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions
45
* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=64 -XX:MaxVectorSize=64
46
* compiler.arraycopy.TestArrayCopyConjoint
47
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions
48
* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=32 -XX:+UnlockDiagnosticVMOptions -XX:MaxVectorSize=32 -XX:+UnlockDiagnosticVMOption -XX:ArrayCopyLoadStoreMaxElem=16
49
* compiler.arraycopy.TestArrayCopyConjoint
50
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+IgnoreUnrecognizedVMOptions
51
* -XX:UseAVX=3 -XX:+UnlockDiagnosticVMOptions -XX:ArrayOperationPartialInlineSize=64 -XX:MaxVectorSize=64 -XX:ArrayCopyLoadStoreMaxElem=16
52
* compiler.arraycopy.TestArrayCopyConjoint
53
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch -XX:+UnlockExperimentalVMOptions -XX:+AlwaysAtomicAccesses
54
* compiler.arraycopy.TestArrayCopyConjoint
55
*
56
*/
57
58
public class TestArrayCopyConjoint {
59
60
public static final int SIZE = 4096;
61
public static byte[] fromByteArr, toByteArr, valByteArr;
62
public static char[] fromCharArr, toCharArr, valCharArr;
63
public static int[] fromIntArr, toIntArr, valIntArr;
64
public static long[] fromLongArr, toLongArr, valLongArr;
65
66
static public void reinit(Class<?> c) {
67
if (c == byte.class) {
68
for (int i = 0 ; i < SIZE ; i++) {
69
fromByteArr[i] = (byte)i;
70
}
71
} else if (c == char.class) {
72
for (int i = 0 ; i < SIZE ; i++) {
73
fromCharArr[i] = (char)i;
74
}
75
} else if (c == int.class) {
76
for (int i = 0 ; i < SIZE ; i++) {
77
fromIntArr[i] = i;
78
}
79
} else {
80
assert c == long.class;
81
for (int i = 0 ; i < SIZE ; i++) {
82
fromLongArr[i] = i;
83
}
84
}
85
}
86
87
static public void setup() {
88
// Both positions aligned
89
fromByteArr = new byte[SIZE];
90
valByteArr = new byte[SIZE];
91
toByteArr = fromByteArr;
92
fromCharArr = new char[SIZE];
93
valCharArr = new char[SIZE];
94
toCharArr = fromCharArr;
95
fromIntArr = new int[SIZE];
96
valIntArr = new int[SIZE];
97
toIntArr = fromIntArr;
98
fromLongArr = new long[SIZE];
99
valLongArr = new long[SIZE];
100
toLongArr = fromLongArr;
101
102
for (int i = 0 ; i < SIZE ; i++) {
103
fromByteArr[i] = (byte)i;
104
valByteArr[i] = (byte)i;
105
fromCharArr[i] = (char)i;
106
valCharArr[i] = (char)i;
107
fromIntArr[i] = i;
108
valIntArr[i] = i;
109
fromLongArr[i] = i;
110
valLongArr[i] = i;
111
}
112
}
113
114
public static int validate_ctr = 0;
115
public static <E> void validate(String msg, E arr, int length, int fromPos, int toPos) {
116
validate_ctr++;
117
if (arr instanceof byte []) {
118
byte [] barr = (byte [])arr;
119
for(int i = 0 ; i < length; i++)
120
if (valByteArr[i+fromPos] != barr[i+toPos]) {
121
System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i
122
+ " expected = " + valByteArr[i+fromPos]
123
+ " actual = " + barr[i+toPos]
124
+ " fromPos = " + fromPos
125
+ " toPos = " + toPos);
126
throw new Error("Fail");
127
128
}
129
}
130
else if (arr instanceof char []) {
131
char [] carr = (char [])arr;
132
for(int i = 0 ; i < length; i++)
133
if (valCharArr[i+fromPos] != carr[i+toPos]) {
134
System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i
135
+ " expected = " + valCharArr[i+fromPos]
136
+ " actual = " + carr[i+toPos]
137
+ " fromPos = " + fromPos
138
+ " toPos = " + toPos);
139
throw new Error("Fail");
140
}
141
}
142
else if (arr instanceof int []) {
143
int [] iarr = (int [])arr;
144
for(int i = 0 ; i < length; i++)
145
if (valIntArr[i+fromPos] != iarr[i+toPos]) {
146
System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i
147
+ " expected = " + valIntArr[i+fromPos]
148
+ " actual = " + iarr[i+toPos]
149
+ " fromPos = " + fromPos
150
+ " toPos = " + toPos);
151
throw new Error("Fail");
152
}
153
}
154
else if (arr instanceof long []) {
155
long [] larr = (long [])arr;
156
for(int i = 0 ; i < length; i++)
157
if (valLongArr[i+fromPos] != larr[i+toPos]) {
158
System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i
159
+ " expected = " + valLongArr[i+fromPos]
160
+ " actual = " + larr[i+toPos]
161
+ " fromPos = " + fromPos
162
+ " toPos = " + toPos);
163
throw new Error("Fail");
164
}
165
}
166
}
167
168
public static void testByte(int length, int fromPos, int toPos) {
169
System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, length);
170
validate(" Test ByteArr ", toByteArr, length, fromPos, toPos);
171
}
172
173
public static void testChar(int length, int fromPos, int toPos) {
174
System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, length);
175
validate(" Test CharArr ", toCharArr, length, fromPos, toPos);
176
}
177
178
public static void testInt(int length, int fromPos, int toPos) {
179
System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, length);
180
validate(" Test IntArr ", toIntArr, length, fromPos, toPos);
181
}
182
183
public static void testLong(int length, int fromPos, int toPos) {
184
System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, length);
185
validate(" Test LongArr ", toLongArr, length, fromPos, toPos);
186
}
187
188
public static void testByte_constant_LT32B(int fromPos, int toPos) {
189
System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 7);
190
validate(" Test Byte constant length 7 ", toByteArr, 7, fromPos, toPos);
191
}
192
public static void testByte_constant_LT64B(int fromPos, int toPos) {
193
System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 45);
194
validate(" Test Byte constant length 45 ", toByteArr, 45, fromPos, toPos);
195
}
196
197
public static void testChar_constant_LT32B(int fromPos, int toPos) {
198
System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 7);
199
validate(" Test Char constant length 7 ", toCharArr, 7, fromPos, toPos);
200
}
201
public static void testChar_constant_LT64B(int fromPos, int toPos) {
202
System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 22);
203
validate(" Test Char constant length 22 ", toCharArr, 22, fromPos, toPos);
204
}
205
206
public static void testInt_constant_LT32B(int fromPos, int toPos) {
207
System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 7);
208
validate(" Test Int constant length 7 ", toIntArr, 7, fromPos, toPos);
209
}
210
public static void testInt_constant_LT64B(int fromPos, int toPos) {
211
System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 11);
212
validate(" Test Int constant length 11 ", toIntArr, 11, fromPos, toPos);
213
}
214
215
public static void testLong_constant_LT32B(int fromPos, int toPos) {
216
System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 3);
217
validate(" Test Long constant length 3 ", toLongArr, 3, fromPos, toPos);
218
}
219
public static void testLong_constant_LT64B(int fromPos, int toPos) {
220
System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 6);
221
validate(" Test Long constant length 6 ", toLongArr, 6, fromPos, toPos);
222
}
223
224
225
public static void main(String [] args) {
226
// Cases to test each new optimized stub special blocks.
227
// Cases to test new PI handling (PI32 and PI64).
228
// Cases to test vectorized constant array copies for all primitive types.
229
// LT32B LT64B LT96B LT128B LT160B LT192B LOOP1 LOOP2
230
int [] lengths = { 29, 59, 89, 125, 159, 189, 194, 1024 };
231
Random r = new Random(1024);
232
233
setup();
234
235
try {
236
for (int i = 0 ; i < 1000000 ; i++ ) {
237
int index = r.nextInt(2048);
238
testByte(lengths[i % lengths.length], index , index+2);
239
reinit(byte.class);
240
testByte_constant_LT32B (index , index+2);
241
reinit(byte.class);
242
testByte_constant_LT64B (index , index+2);
243
reinit(byte.class);
244
245
testChar(lengths[i % lengths.length] >> 1, index , index+2);
246
reinit(char.class);
247
testChar_constant_LT32B (index , index+2);
248
reinit(char.class);
249
testChar_constant_LT64B (index , index+2);
250
reinit(char.class);
251
252
testInt(lengths[i % lengths.length] >> 2, index , index+2);
253
reinit(int.class);
254
testInt_constant_LT32B (index , index+2);
255
reinit(int.class);
256
testInt_constant_LT64B (index , index+2);
257
reinit(int.class);
258
259
testLong(lengths[i % lengths.length] >> 3, index , index+2);
260
reinit(long.class);
261
testLong_constant_LT32B (index , index+2);
262
reinit(long.class);
263
testLong_constant_LT64B (index , index+2);
264
reinit(long.class);
265
}
266
System.out.println("PASS : " + validate_ctr);
267
} catch (Exception e) {
268
System.out.println(e.getMessage());
269
}
270
}
271
}
272
273