Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/string/TestStringUTF16IntrinsicRangeChecks.java
41153 views
1
/*
2
* Copyright (c) 2017, 2018, 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
/*
25
* @test
26
* @bug 8158168
27
* @summary Verifies that callers of StringUTF16 intrinsics throw array out of bounds exceptions.
28
* @library /compiler/patches /test/lib
29
* @build java.base/java.lang.Helper
30
* @run main/othervm -Xbatch -XX:CompileThreshold=100 -XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_getCharStringU,_putCharStringU compiler.intrinsics.string.TestStringUTF16IntrinsicRangeChecks
31
* @run main/othervm -Xbatch -XX:CompileThreshold=100 -esa -ea -XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_getCharStringU,_putCharStringU compiler.intrinsics.string.TestStringUTF16IntrinsicRangeChecks
32
*/
33
package compiler.intrinsics.string;
34
35
import java.lang.reflect.Field;
36
import java.util.Arrays;
37
38
public class TestStringUTF16IntrinsicRangeChecks {
39
40
public static void main(String[] args) throws Exception {
41
byte[] val = new byte[2];
42
byte[] b4 = new byte[4];
43
char[] c4 = new char[4];
44
String s4 = new String(c4);
45
byte[] valHigh = new byte[2];
46
byte[] valLow = new byte[2];
47
Helper.putCharSB(valHigh, 0, Character.MIN_HIGH_SURROGATE);
48
Helper.putCharSB(valLow, 0, Character.MIN_LOW_SURROGATE);
49
50
for (int i = 0; i < 1000; ++i) {
51
getChars((int)1234, -5, -5 + 4, val);
52
getChars((int)1234, -1, -1 + 4, val);
53
getChars((int)1234, 0, 0 + 4, val);
54
getChars((int)1234, 1, 1 + 4, val);
55
56
getChars((long)1234, -5, -5 + 4, val);
57
getChars((long)1234, -1, -1 + 4, val);
58
getChars((long)1234, 0, 0 + 4, val);
59
getChars((long)1234, 1, 1 + 4, val);
60
61
byte[] val2 = Arrays.copyOf(val, val.length);
62
putCharSB(val2, -1, '!');
63
putCharSB(val2, 1, '!');
64
65
byte[] val4 = Arrays.copyOf(b4, b4.length);
66
char[] c2 = new char[2];
67
String s2 = new String(c2);
68
69
putCharsSB(val4, -3, c2, 0, 2);
70
putCharsSB(val4, -1, c2, 0, 2);
71
putCharsSB(val4, 0, c4, 0, 4);
72
putCharsSB(val4, 1, c2, 0, 2);
73
putCharsSB(val4, -3, s2, 0, 2);
74
putCharsSB(val4, -1, s2, 0, 2);
75
putCharsSB(val4, 0, s4, 0, 4);
76
putCharsSB(val4, 1, s2, 0, 2);
77
78
codePointAtSB(valHigh, -1, 1);
79
codePointAtSB(valHigh, -1, 2);
80
codePointAtSB(valHigh, 0, 2);
81
codePointAtSB(valHigh, 1, 2);
82
83
codePointBeforeSB(valLow, 0);
84
codePointBeforeSB(valLow, -1);
85
codePointBeforeSB(valLow, 2);
86
87
if (Helper.codePointCountSB(valHigh, 0, 1) != 1) {
88
throw new AssertionError("codePointCountSB");
89
}
90
if (Helper.codePointCountSB(valLow, 0, 1) != 1) {
91
throw new AssertionError("codePointCountSB");
92
}
93
codePointCountSB(valHigh, -1, 0);
94
codePointCountSB(valHigh, -1, 2);
95
codePointCountSB(valHigh, 0, 2);
96
97
charAt(val, -1);
98
charAt(val, 1);
99
100
contentEquals(b4, val, -1);
101
contentEquals(b4, val, 2);
102
contentEquals(val, s4, 2);
103
contentEquals(val, s4, -1);
104
105
StringBuilder sb = new StringBuilder();
106
sb.append((String)null).append(true).append(false);
107
if (!sb.toString().equals("nulltruefalse")) {
108
throw new AssertionError("append");
109
}
110
111
putCharsAt(val2, -1, '1', '2', '3', '4');
112
putCharsAt(val2, 0, '1', '2', '3', '4');
113
putCharsAt(val2, 2, '1', '2', '3', '4');
114
putCharsAt(val2, -1, '1', '2', '3', '4', '5');
115
putCharsAt(val2, 0, '1', '2', '3', '4', '5');
116
putCharsAt(val2, 2, '1', '2', '3', '4', '5');
117
118
reverse(valHigh, -1);
119
reverse(valHigh, 2);
120
reverse(valLow, -1);
121
reverse(valLow, 2);
122
123
byte[] d4 = new byte[4];
124
inflate(b4, 0, d4, -1, 2);
125
inflate(b4, 0, d4, 3, 2);
126
inflate(b4, 0, d4, 4, 1);
127
128
byte[] b0 = new byte[0];
129
byte[] b1 = new byte[1];
130
byte[] b2 = new byte[2];
131
byte[] t1 = new byte[] {1};
132
byte[] t2 = new byte[] {1, 2};
133
byte[] t4 = new byte[] {1, 2, 3, 4};
134
indexOf(b1, 1, t2, 1, 0);
135
indexOf(b2, 1, t1, 1, 0);
136
indexOf(b2, 2, t2, 1, 0);
137
indexOf(b2, 1, t2, 2, 0);
138
indexOf(b2, -1, t2, 1, 0);
139
indexOf(b2, 1, t2, -1, 0);
140
indexOf(b2, 1, t2, 1, 1);
141
142
indexOfLatin1(b1, 1, t1, 1, 0);
143
indexOfLatin1(b2, 2, t1, 1, 0);
144
indexOfLatin1(b2, 1, b0, 1, 0);
145
indexOfLatin1(b2, 1, t1, 2, 0);
146
indexOfLatin1(b2, -1, t1, 1, 0);
147
indexOfLatin1(b2, 2, t1, 1, 0);
148
indexOfLatin1(b2, 1, t1, -1, 0);
149
indexOfLatin1(b2, 1, t1, 2, 0);
150
151
lastIndexOf(b1, t2, 1, 0);
152
lastIndexOf(b2, t4, 2, 0);
153
lastIndexOf(b2, t2, 1, 0);
154
lastIndexOf(b2, t2, 1, 1);
155
156
lastIndexOfLatin1(b1, t1, 1, 0);
157
lastIndexOfLatin1(b2, t2, 2, 0);
158
lastIndexOfLatin1(b2, t1, 1, 0);
159
lastIndexOfLatin1(b2, t1, 1, 1);
160
}
161
}
162
163
static void getChars(int i, int begin, int end, byte[] value) {
164
try {
165
Helper.getChars(i, begin, end, value);
166
throw new AssertionError("getChars");
167
} catch (IndexOutOfBoundsException io) {
168
}
169
}
170
171
static void getChars(long l, int begin, int end, byte[] value) {
172
try {
173
Helper.getChars(l, begin, end, value);
174
throw new AssertionError("getChars");
175
} catch (IndexOutOfBoundsException io) {
176
}
177
}
178
179
static void putCharSB(byte[] val, int index, int c) {
180
try {
181
Helper.putCharSB(val, index, c);
182
throw new AssertionError("putCharSB");
183
} catch (IndexOutOfBoundsException io) {
184
}
185
}
186
187
static void putCharsSB(byte[] val, int index, char[] ca, int off, int end) {
188
try {
189
Helper.putCharsSB(val, index, ca, off, end);
190
throw new AssertionError("putCharsSB");
191
} catch (IndexOutOfBoundsException io) {
192
}
193
}
194
195
static void putCharsSB(byte[] val, int index, CharSequence s, int off, int end) {
196
try {
197
Helper.putCharsSB(val, index, s, off, end);
198
throw new AssertionError("putCharsSB");
199
} catch (IndexOutOfBoundsException io) {
200
}
201
}
202
203
static void codePointAtSB(byte[] val, int index, int end) {
204
try {
205
Helper.codePointAtSB(val, index, end);
206
throw new AssertionError("codePointAtSB");
207
} catch (IndexOutOfBoundsException io) {
208
}
209
}
210
211
static void codePointBeforeSB(byte[] val, int index) {
212
try {
213
Helper.codePointBeforeSB(val, index);
214
throw new AssertionError("codePointBeforeSB");
215
} catch (IndexOutOfBoundsException io) {
216
}
217
}
218
219
static void codePointCountSB(byte[] val, int beginIndex, int endIndex) {
220
try {
221
Helper.codePointCountSB(val, beginIndex, endIndex);
222
throw new AssertionError("codePointCountSB");
223
} catch (IndexOutOfBoundsException io) {
224
}
225
}
226
227
static void charAt(byte[] v, int index) {
228
try {
229
Helper.charAt(v, index);
230
throw new AssertionError("charAt");
231
} catch (IndexOutOfBoundsException io) {
232
}
233
}
234
235
static void contentEquals(byte[] v1, byte[] v2, int len) {
236
try {
237
Helper.contentEquals(v1, v2, len);
238
throw new AssertionError("contentEquals");
239
} catch (IndexOutOfBoundsException io) {
240
}
241
}
242
243
static void contentEquals(byte[] v, CharSequence cs, int len) {
244
try {
245
Helper.contentEquals(v, cs, len);
246
throw new AssertionError("contentEquals");
247
} catch (IndexOutOfBoundsException io) {
248
}
249
}
250
251
static void putCharsAt(byte[] v, int i, char c1, char c2, char c3, char c4) {
252
try {
253
Helper.putCharsAt(v, i, c1, c2, c3, c4);
254
throw new AssertionError("putCharsAt");
255
} catch (IndexOutOfBoundsException io) {
256
}
257
}
258
259
static void putCharsAt(byte[] v, int i, char c1, char c2, char c3, char c4, char c5) {
260
try {
261
Helper.putCharsAt(v, i, c1, c2, c3, c4, c5);
262
throw new AssertionError("putCharsAt");
263
} catch (IndexOutOfBoundsException io) {
264
}
265
}
266
267
static void reverse(byte[] v, int len) {
268
try {
269
Helper.reverse(v, len);
270
throw new AssertionError("reverse");
271
} catch (IndexOutOfBoundsException io) {
272
}
273
}
274
275
static void inflate(byte[] v1, int o1, byte[] v2, int o2, int len) {
276
try {
277
Helper.inflate(v1, o1, v2, o2, len);
278
throw new AssertionError("inflate");
279
} catch (IndexOutOfBoundsException io) {
280
}
281
}
282
283
static void indexOf(byte[] v1, int l1, byte[] v2, int l2, int from) {
284
try {
285
if (Helper.indexOf(v1, l1, v2, l2, from) != -1) {
286
throw new AssertionError("indexOf");
287
}
288
} catch (IndexOutOfBoundsException io) {
289
}
290
}
291
292
static void lastIndexOf(byte[] v1, byte[] v2, int l2, int from) {
293
try {
294
if (Helper.lastIndexOf(v1, v2, l2, from) != -1) {
295
throw new AssertionError("lastIndexOf");
296
}
297
} catch (IndexOutOfBoundsException io) {
298
}
299
}
300
301
static void indexOfLatin1(byte[] v1, int l1, byte[] v2, int l2, int from) {
302
try {
303
if (Helper.indexOfLatin1(v1, l1, v2, l2, from) != -1) {
304
throw new AssertionError("indexOfLatin1");
305
}
306
} catch (IndexOutOfBoundsException io) {
307
}
308
}
309
310
static void lastIndexOfLatin1(byte[] v1, byte[] v2, int l2, int from) {
311
try {
312
if (Helper.lastIndexOfLatin1(v1, v2, l2, from) != -1) {
313
throw new AssertionError("lastIndexOfLatin1");
314
}
315
} catch (IndexOutOfBoundsException io) {
316
}
317
}
318
}
319
320