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