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