Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codegen/Test6942326.java
41149 views
1
/*
2
* Copyright (c) 2011, 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 6942326
27
* @summary x86 code in string_indexof() could read beyond reserved heap space
28
*
29
* @run main/othervm/timeout=300 -Xmx128m -Xbatch -XX:+IgnoreUnrecognizedVMOptions
30
* -XX:CompileCommand=exclude,compiler.codegen.Test6942326::main
31
* -XX:CompileCommand=exclude,compiler.codegen.Test6942326::test_varsub_indexof
32
* -XX:CompileCommand=exclude,compiler.codegen.Test6942326::test_varstr_indexof
33
* -XX:CompileCommand=exclude,compiler.codegen.Test6942326::test_missub_indexof
34
* -XX:CompileCommand=exclude,compiler.codegen.Test6942326::test_consub_indexof
35
* -XX:CompileCommand=exclude,compiler.codegen.Test6942326::test_conmis_indexof
36
* -XX:CompileCommand=exclude,compiler.codegen.Test6942326::test_subcon
37
* compiler.codegen.Test6942326
38
*/
39
40
package compiler.codegen;
41
42
public class Test6942326 {
43
44
static String[] strings = new String[1024];
45
private static final int ITERATIONS = 100000;
46
47
public static void main(String[] args) {
48
49
long start_total = System.currentTimeMillis();
50
51
// search variable size substring in string (33 chars).
52
String a = " 1111111111111xx1111111111111xx11y"; // +1 to execute a.substring(1) first
53
String b = "1111111111111xx1111111111111xx11y";
54
test_varsub_indexof(a, b);
55
56
// search variable size substring in string (32 chars).
57
a = " 1111111111111xx1111111111111xx1y";
58
b = "1111111111111xx1111111111111xx1y";
59
test_varsub_indexof(a, b);
60
61
// search variable size substring in string (17 chars).
62
a = " 1111111111111xx1y";
63
b = "1111111111111xx1y";
64
test_varsub_indexof(a, b);
65
66
// search variable size substring in string (16 chars).
67
a = " 111111111111xx1y";
68
b = "111111111111xx1y";
69
test_varsub_indexof(a, b);
70
71
// search variable size substring in string (8 chars).
72
a = " 1111xx1y";
73
b = "1111xx1y";
74
test_varsub_indexof(a, b);
75
76
// search variable size substring in string (7 chars).
77
a = " 111xx1y";
78
b = "111xx1y";
79
test_varsub_indexof(a, b);
80
81
82
83
// search substring (17 chars) in variable size string.
84
a = "1111111111111xx1x";
85
b = " 1111111111111xx1111111111111xx1x"; // +1 to execute b.substring(1) first
86
test_varstr_indexof(a, b);
87
88
// search substring (16 chars) in variable size string.
89
a = "111111111111xx1x";
90
b = " 1111111111111xx1111111111111xx1x";
91
test_varstr_indexof(a, b);
92
93
// search substring (9 chars) in variable size string.
94
a = "11111xx1x";
95
b = " 1111111111111xx1111111111111xx1x";
96
test_varstr_indexof(a, b);
97
98
// search substring (8 chars) in variable size string.
99
a = "1111xx1x";
100
b = " 1111111111111xx1111111111111xx1x";
101
test_varstr_indexof(a, b);
102
103
// search substring (4 chars) in variable size string.
104
a = "xx1x";
105
b = " 1111111111111xx1111111111111xx1x";
106
test_varstr_indexof(a, b);
107
108
// search substring (3 chars) in variable size string.
109
a = "x1x";
110
b = " 1111111111111xx1111111111111xx1x";
111
test_varstr_indexof(a, b);
112
113
// search substring (2 chars) in variable size string.
114
a = "1y";
115
b = " 1111111111111xx1111111111111xx1y";
116
test_varstr_indexof(a, b);
117
118
119
120
// search non matching variable size substring in string (33 chars).
121
a = " 1111111111111xx1111111111111xx11z"; // +1 to execute a.substring(1) first
122
b = "1111111111111xx1111111111111xx11y";
123
test_missub_indexof(a, b);
124
125
// search non matching variable size substring in string (32 chars).
126
a = " 1111111111111xx1111111111111xx1z";
127
b = "1111111111111xx1111111111111xx1y";
128
test_missub_indexof(a, b);
129
130
// search non matching variable size substring in string (17 chars).
131
a = " 1111111111111xx1z";
132
b = "1111111111111xx1y";
133
test_missub_indexof(a, b);
134
135
// search non matching variable size substring in string (16 chars).
136
a = " 111111111111xx1z";
137
b = "111111111111xx1y";
138
test_missub_indexof(a, b);
139
140
// search non matching variable size substring in string (8 chars).
141
a = " 1111xx1z";
142
b = "1111xx1y";
143
test_missub_indexof(a, b);
144
145
// search non matching variable size substring in string (7 chars).
146
a = " 111xx1z";
147
b = "111xx1y";
148
test_missub_indexof(a, b);
149
150
151
152
// Testing constant substring search in variable size string.
153
154
// search constant substring (17 chars).
155
b = " 1111111111111xx1111111111111xx1x"; // +1 to execute b.substring(1) first
156
TestCon tc = new TestCon17();
157
test_consub_indexof(tc, b);
158
159
// search constant substring (16 chars).
160
b = " 1111111111111xx1111111111111xx1x";
161
tc = new TestCon16();
162
test_consub_indexof(tc, b);
163
164
// search constant substring (9 chars).
165
b = " 1111111111111xx1111111111111xx1x";
166
tc = new TestCon9();
167
test_consub_indexof(tc, b);
168
169
// search constant substring (8 chars).
170
b = " 1111111111111xx1111111111111xx1x";
171
tc = new TestCon8();
172
test_consub_indexof(tc, b);
173
174
// search constant substring (4 chars).
175
b = " 1111111111111xx1111111111111xx1x";
176
tc = new TestCon4();
177
test_consub_indexof(tc, b);
178
179
// search constant substring (3 chars).
180
b = " 1111111111111xx1111111111111xx1x";
181
tc = new TestCon3();
182
test_consub_indexof(tc, b);
183
184
// search constant substring (2 chars).
185
b = " 1111111111111xx1111111111111xx1y";
186
tc = new TestCon2();
187
test_consub_indexof(tc, b);
188
189
// search constant substring (1 chars).
190
b = " 1111111111111xx1111111111111xx1y";
191
tc = new TestCon1();
192
test_consub_indexof(tc, b);
193
194
195
// search non matching constant substring (17 chars).
196
b = " 1111111111111xx1111111111111xx1z"; // +1 to execute b.substring(1) first
197
tc = new TestCon17();
198
test_conmis_indexof(tc, b);
199
200
// search non matching constant substring (16 chars).
201
b = " 1111111111111xx1111111111111xx1z";
202
tc = new TestCon16();
203
test_conmis_indexof(tc, b);
204
205
// search non matching constant substring (9 chars).
206
b = " 1111111111111xx1111111111111xx1z";
207
tc = new TestCon9();
208
test_conmis_indexof(tc, b);
209
210
// search non matching constant substring (8 chars).
211
b = " 1111111111111xx1111111111111xx1z";
212
tc = new TestCon8();
213
test_conmis_indexof(tc, b);
214
215
// search non matching constant substring (4 chars).
216
b = " 1111111111111xx1111111111111xx1z";
217
tc = new TestCon4();
218
test_conmis_indexof(tc, b);
219
220
// search non matching constant substring (3 chars).
221
b = " 1111111111111xx1111111111111xx1z";
222
tc = new TestCon3();
223
test_conmis_indexof(tc, b);
224
225
// search non matching constant substring (2 chars).
226
b = " 1111111111111xx1111111111111xx1z";
227
tc = new TestCon2();
228
test_conmis_indexof(tc, b);
229
230
// search non matching constant substring (1 chars).
231
b = " 1111111111111xx1111111111111xx1z";
232
tc = new TestCon1();
233
test_conmis_indexof(tc, b);
234
235
long end_total = System.currentTimeMillis();
236
System.out.println("End run time: " + (end_total - start_total));
237
238
}
239
240
public static long test_init(String a, String b) {
241
for (int i = 0; i < 512; i++) {
242
strings[i * 2] = new String(b.toCharArray());
243
strings[i * 2 + 1] = new String(a.toCharArray());
244
}
245
System.out.print(a.length() + " " + b.length() + " ");
246
return System.currentTimeMillis();
247
}
248
249
public static void test_end(String a, String b, int v, int expected, long start) {
250
long end = System.currentTimeMillis();
251
int res = (v/ITERATIONS);
252
System.out.print(" " + res);
253
System.out.println(" time:" + (end - start));
254
if (res != expected) {
255
System.out.println("wrong indexOf result: " + res + ", expected " + expected);
256
System.out.println("\"" + b + "\".indexOf(\"" + a + "\")");
257
System.exit(97);
258
}
259
}
260
261
public static int test_subvar() {
262
int s = 0;
263
int v = 0;
264
for (int i = 0; i < ITERATIONS; i++) {
265
v += strings[s].indexOf(strings[s + 1]);
266
s += 2;
267
if (s >= strings.length) s = 0;
268
}
269
return v;
270
}
271
272
public static void test_varsub_indexof(String a, String b) {
273
System.out.println("Start search variable size substring in string (" + b.length() + " chars)");
274
long start_it = System.currentTimeMillis();
275
int limit = 1; // last a.length() == 1
276
while (a.length() > limit) {
277
a = a.substring(1);
278
long start = test_init(a, b);
279
int v = test_subvar();
280
test_end(a, b, v, (b.length() - a.length()), start);
281
}
282
long end_it = System.currentTimeMillis();
283
System.out.println("End search variable size substring in string (" + b.length() + " chars), time: " + (end_it - start_it));
284
}
285
286
public static void test_varstr_indexof(String a, String b) {
287
System.out.println("Start search substring (" + a.length() + " chars) in variable size string");
288
long start_it = System.currentTimeMillis();
289
int limit = a.length();
290
while (b.length() > limit) {
291
b = b.substring(1);
292
long start = test_init(a, b);
293
int v = test_subvar();
294
test_end(a, b, v, (b.length() - a.length()), start);
295
}
296
long end_it = System.currentTimeMillis();
297
System.out.println("End search substring (" + a.length() + " chars) in variable size string, time: " + (end_it - start_it));
298
}
299
300
public static void test_missub_indexof(String a, String b) {
301
System.out.println("Start search non matching variable size substring in string (" + b.length() + " chars)");
302
long start_it = System.currentTimeMillis();
303
int limit = 1; // last a.length() == 1
304
while (a.length() > limit) {
305
a = a.substring(1);
306
long start = test_init(a, b);
307
int v = test_subvar();
308
test_end(a, b, v, (-1), start);
309
}
310
long end_it = System.currentTimeMillis();
311
System.out.println("End search non matching variable size substring in string (" + b.length() + " chars), time: " + (end_it - start_it));
312
}
313
314
315
316
public static void test_consub_indexof(TestCon tc, String b) {
317
System.out.println("Start search constant substring (" + tc.constr().length() + " chars)");
318
long start_it = System.currentTimeMillis();
319
int limit = tc.constr().length();
320
while (b.length() > limit) {
321
b = b.substring(1);
322
long start = test_init(tc.constr(), b);
323
int v = test_subcon(tc);
324
test_end(tc.constr(), b, v, (b.length() - tc.constr().length()), start);
325
}
326
long end_it = System.currentTimeMillis();
327
System.out.println("End search constant substring (" + tc.constr().length() + " chars), time: " + (end_it - start_it));
328
}
329
330
public static void test_conmis_indexof(TestCon tc, String b) {
331
System.out.println("Start search non matching constant substring (" + tc.constr().length() + " chars)");
332
long start_it = System.currentTimeMillis();
333
int limit = tc.constr().length();
334
while (b.length() > limit) {
335
b = b.substring(1);
336
long start = test_init(tc.constr(), b);
337
int v = test_subcon(tc);
338
test_end(tc.constr(), b, v, (-1), start);
339
}
340
long end_it = System.currentTimeMillis();
341
System.out.println("End search non matching constant substring (" + tc.constr().length() + " chars), time: " + (end_it - start_it));
342
}
343
344
public static int test_subcon(TestCon tc) {
345
int s = 0;
346
int v = 0;
347
for (int i = 0; i < ITERATIONS; i++) {
348
v += tc.indexOf(strings[s]);
349
s += 2;
350
if (s >= strings.length) s = 0;
351
}
352
return v;
353
}
354
355
private interface TestCon {
356
public String constr();
357
public int indexOf(String str);
358
}
359
360
// search constant substring (17 chars).
361
private final static class TestCon17 implements TestCon {
362
private static final String constr = "1111111111111xx1x";
363
public String constr() { return constr; }
364
public int indexOf(String str) { return str.indexOf(constr); }
365
}
366
367
// search constant substring (16 chars).
368
private final static class TestCon16 implements TestCon {
369
private static final String constr = "111111111111xx1x";
370
public String constr() { return constr; }
371
public int indexOf(String str) { return str.indexOf(constr); }
372
}
373
374
// search constant substring (9 chars).
375
private final static class TestCon9 implements TestCon {
376
private static final String constr = "11111xx1x";
377
public String constr() { return constr; }
378
public int indexOf(String str) { return str.indexOf(constr); }
379
}
380
381
// search constant substring (8 chars).
382
private final static class TestCon8 implements TestCon {
383
private static final String constr = "1111xx1x";
384
public String constr() { return constr; }
385
public int indexOf(String str) { return str.indexOf(constr); }
386
}
387
388
// search constant substring (4 chars).
389
private final static class TestCon4 implements TestCon {
390
private static final String constr = "xx1x";
391
public String constr() { return constr; }
392
public int indexOf(String str) { return str.indexOf(constr); }
393
}
394
395
// search constant substring (3 chars).
396
private final static class TestCon3 implements TestCon {
397
private static final String constr = "x1x";
398
public String constr() { return constr; }
399
public int indexOf(String str) { return str.indexOf(constr); }
400
}
401
402
// search constant substring (2 chars).
403
private final static class TestCon2 implements TestCon {
404
private static final String constr = "1y";
405
public String constr() { return constr; }
406
public int indexOf(String str) { return str.indexOf(constr); }
407
}
408
409
410
// search constant substring (1 chars).
411
private final static class TestCon1 implements TestCon {
412
private static final String constr = "y";
413
public String constr() { return constr; }
414
public int indexOf(String str) { return str.indexOf(constr); }
415
}
416
}
417
418