Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyConjoint.java
41149 views
1
/*
2
* Copyright (c) 2020, 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
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:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=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:ArrayCopyPartialInlineSize=64 -XX:MaxVectorSize=64 -XX:ArrayCopyLoadStoreMaxElem=16
52
* compiler.arraycopy.TestArrayCopyConjoint
53
*
54
*/
55
56
public class TestArrayCopyConjoint {
57
58
public static final int SIZE = 4096;
59
public static byte[] fromByteArr, toByteArr, valByteArr;
60
public static char[] fromCharArr, toCharArr, valCharArr;
61
public static int[] fromIntArr, toIntArr, valIntArr;
62
public static long[] fromLongArr, toLongArr, valLongArr;
63
64
static public void reinit(Class<?> c) {
65
if (c == byte.class) {
66
for (int i = 0 ; i < SIZE ; i++) {
67
fromByteArr[i] = (byte)i;
68
}
69
} else if (c == char.class) {
70
for (int i = 0 ; i < SIZE ; i++) {
71
fromCharArr[i] = (char)i;
72
}
73
} else if (c == int.class) {
74
for (int i = 0 ; i < SIZE ; i++) {
75
fromIntArr[i] = i;
76
}
77
} else {
78
assert c == long.class;
79
for (int i = 0 ; i < SIZE ; i++) {
80
fromLongArr[i] = i;
81
}
82
}
83
}
84
85
static public void setup() {
86
// Both positions aligned
87
fromByteArr = new byte[SIZE];
88
valByteArr = new byte[SIZE];
89
toByteArr = fromByteArr;
90
fromCharArr = new char[SIZE];
91
valCharArr = new char[SIZE];
92
toCharArr = fromCharArr;
93
fromIntArr = new int[SIZE];
94
valIntArr = new int[SIZE];
95
toIntArr = fromIntArr;
96
fromLongArr = new long[SIZE];
97
valLongArr = new long[SIZE];
98
toLongArr = fromLongArr;
99
100
for (int i = 0 ; i < SIZE ; i++) {
101
fromByteArr[i] = (byte)i;
102
valByteArr[i] = (byte)i;
103
fromCharArr[i] = (char)i;
104
valCharArr[i] = (char)i;
105
fromIntArr[i] = i;
106
valIntArr[i] = i;
107
fromLongArr[i] = i;
108
valLongArr[i] = i;
109
}
110
}
111
112
public static int validate_ctr = 0;
113
public static <E> void validate(String msg, E arr, int length, int fromPos, int toPos) {
114
validate_ctr++;
115
if (arr instanceof byte []) {
116
byte [] barr = (byte [])arr;
117
for(int i = 0 ; i < length; i++)
118
if (valByteArr[i+fromPos] != barr[i+toPos]) {
119
System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i
120
+ " expected = " + valByteArr[i+fromPos]
121
+ " actual = " + barr[i+toPos]
122
+ " fromPos = " + fromPos
123
+ " toPos = " + toPos);
124
throw new Error("Fail");
125
126
}
127
}
128
else if (arr instanceof char []) {
129
char [] carr = (char [])arr;
130
for(int i = 0 ; i < length; i++)
131
if (valCharArr[i+fromPos] != carr[i+toPos]) {
132
System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i
133
+ " expected = " + valCharArr[i+fromPos]
134
+ " actual = " + carr[i+toPos]
135
+ " fromPos = " + fromPos
136
+ " toPos = " + toPos);
137
throw new Error("Fail");
138
}
139
}
140
else if (arr instanceof int []) {
141
int [] iarr = (int [])arr;
142
for(int i = 0 ; i < length; i++)
143
if (valIntArr[i+fromPos] != iarr[i+toPos]) {
144
System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i
145
+ " expected = " + valIntArr[i+fromPos]
146
+ " actual = " + iarr[i+toPos]
147
+ " fromPos = " + fromPos
148
+ " toPos = " + toPos);
149
throw new Error("Fail");
150
}
151
}
152
else if (arr instanceof long []) {
153
long [] larr = (long [])arr;
154
for(int i = 0 ; i < length; i++)
155
if (valLongArr[i+fromPos] != larr[i+toPos]) {
156
System.out.println(msg + "[" + arr.getClass() + "] Result mismtach at i = " + i
157
+ " expected = " + valLongArr[i+fromPos]
158
+ " actual = " + larr[i+toPos]
159
+ " fromPos = " + fromPos
160
+ " toPos = " + toPos);
161
throw new Error("Fail");
162
}
163
}
164
}
165
166
public static void testByte(int length, int fromPos, int toPos) {
167
System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, length);
168
validate(" Test ByteArr ", toByteArr, length, fromPos, toPos);
169
}
170
171
public static void testChar(int length, int fromPos, int toPos) {
172
System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, length);
173
validate(" Test CharArr ", toCharArr, length, fromPos, toPos);
174
}
175
176
public static void testInt(int length, int fromPos, int toPos) {
177
System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, length);
178
validate(" Test IntArr ", toIntArr, length, fromPos, toPos);
179
}
180
181
public static void testLong(int length, int fromPos, int toPos) {
182
System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, length);
183
validate(" Test LongArr ", toLongArr, length, fromPos, toPos);
184
}
185
186
public static void testByte_constant_LT32B(int fromPos, int toPos) {
187
System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 7);
188
validate(" Test Byte constant length 7 ", toByteArr, 7, fromPos, toPos);
189
}
190
public static void testByte_constant_LT64B(int fromPos, int toPos) {
191
System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, 45);
192
validate(" Test Byte constant length 45 ", toByteArr, 45, fromPos, toPos);
193
}
194
195
public static void testChar_constant_LT32B(int fromPos, int toPos) {
196
System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 7);
197
validate(" Test Char constant length 7 ", toCharArr, 7, fromPos, toPos);
198
}
199
public static void testChar_constant_LT64B(int fromPos, int toPos) {
200
System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, 22);
201
validate(" Test Char constant length 22 ", toCharArr, 22, fromPos, toPos);
202
}
203
204
public static void testInt_constant_LT32B(int fromPos, int toPos) {
205
System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 7);
206
validate(" Test Int constant length 7 ", toIntArr, 7, fromPos, toPos);
207
}
208
public static void testInt_constant_LT64B(int fromPos, int toPos) {
209
System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, 11);
210
validate(" Test Int constant length 11 ", toIntArr, 11, fromPos, toPos);
211
}
212
213
public static void testLong_constant_LT32B(int fromPos, int toPos) {
214
System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 3);
215
validate(" Test Long constant length 3 ", toLongArr, 3, fromPos, toPos);
216
}
217
public static void testLong_constant_LT64B(int fromPos, int toPos) {
218
System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, 6);
219
validate(" Test Long constant length 6 ", toLongArr, 6, fromPos, toPos);
220
}
221
222
223
public static void main(String [] args) {
224
// Cases to test each new optimized stub special blocks.
225
// Cases to test new PI handling (PI32 and PI64).
226
// Cases to test vectorized constant array copies for all primitive types.
227
// LT32B LT64B LT96B LT128B LT160B LT192B LOOP1 LOOP2
228
int [] lengths = { 29, 59, 89, 125, 159, 189, 194, 1024 };
229
Random r = new Random(1024);
230
231
setup();
232
233
try {
234
for (int i = 0 ; i < 1000000 ; i++ ) {
235
int index = r.nextInt(2048);
236
testByte(lengths[i % lengths.length], index , index+2);
237
reinit(byte.class);
238
testByte_constant_LT32B (index , index+2);
239
reinit(byte.class);
240
testByte_constant_LT64B (index , index+2);
241
reinit(byte.class);
242
243
testChar(lengths[i % lengths.length] >> 1, index , index+2);
244
reinit(char.class);
245
testChar_constant_LT32B (index , index+2);
246
reinit(char.class);
247
testChar_constant_LT64B (index , index+2);
248
reinit(char.class);
249
250
testInt(lengths[i % lengths.length] >> 2, index , index+2);
251
reinit(int.class);
252
testInt_constant_LT32B (index , index+2);
253
reinit(int.class);
254
testInt_constant_LT64B (index , index+2);
255
reinit(int.class);
256
257
testLong(lengths[i % lengths.length] >> 3, index , index+2);
258
reinit(long.class);
259
testLong_constant_LT32B (index , index+2);
260
reinit(long.class);
261
testLong_constant_LT64B (index , index+2);
262
reinit(long.class);
263
}
264
System.out.println("PASS : " + validate_ctr);
265
} catch (Exception e) {
266
System.out.println(e.getMessage());
267
}
268
}
269
}
270
271