Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/eliminateAutobox/TestIntBoxing.java
41149 views
1
/*
2
* Copyright (c) 2013, 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 6934604
27
* @summary enable parts of EliminateAutoBox by default
28
*
29
* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+EliminateAutoBox
30
* compiler.eliminateAutobox.TestIntBoxing
31
* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+EliminateAutoBox
32
* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestIntBoxing::dummy
33
* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestIntBoxing::foo
34
* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestIntBoxing::foob
35
* compiler.eliminateAutobox.TestIntBoxing
36
* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-EliminateAutoBox
37
* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestIntBoxing::dummy
38
* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestIntBoxing::foo
39
* -XX:CompileCommand=exclude,compiler.eliminateAutobox.TestIntBoxing::foob
40
* compiler.eliminateAutobox.TestIntBoxing
41
*/
42
43
package compiler.eliminateAutobox;
44
45
public class TestIntBoxing {
46
47
static final Integer ibc = new Integer(1);
48
49
//===============================================
50
// Non-inlined methods to test deoptimization info
51
static void dummy() { }
52
static int foo(int i) { return i; }
53
static Integer foob(int i) { return Integer.valueOf(i); }
54
55
56
static int simple(int i) {
57
Integer ib = new Integer(i);
58
return ib;
59
}
60
61
static int simpleb(int i) {
62
Integer ib = Integer.valueOf(i);
63
return ib;
64
}
65
66
static int simplec() {
67
Integer ib = ibc;
68
return ib;
69
}
70
71
static int simplef(int i) {
72
Integer ib = foob(i);
73
return ib;
74
}
75
76
static int simplep(Integer ib) {
77
return ib;
78
}
79
80
static int simple2(int i) {
81
Integer ib1 = new Integer(i);
82
Integer ib2 = new Integer(i+1);
83
return ib1 + ib2;
84
}
85
86
static int simpleb2(int i) {
87
Integer ib1 = Integer.valueOf(i);
88
Integer ib2 = Integer.valueOf(i+1);
89
return ib1 + ib2;
90
}
91
92
static int simplem2(int i) {
93
Integer ib1 = new Integer(i);
94
Integer ib2 = Integer.valueOf(i+1);
95
return ib1 + ib2;
96
}
97
98
static int simplep2(int i, Integer ib1) {
99
Integer ib2 = Integer.valueOf(i+1);
100
return ib1 + ib2;
101
}
102
103
static int simplec2(int i) {
104
Integer ib1 = ibc;
105
Integer ib2 = Integer.valueOf(i+1);
106
return ib1 + ib2;
107
}
108
109
//===============================================
110
static int test(int i) {
111
Integer ib = new Integer(i);
112
if ((i&1) == 0)
113
ib = i+1;
114
return ib;
115
}
116
117
static int testb(int i) {
118
Integer ib = i;
119
if ((i&1) == 0)
120
ib = (i+1);
121
return ib;
122
}
123
124
static int testm(int i) {
125
Integer ib = i;
126
if ((i&1) == 0)
127
ib = new Integer(i+1);
128
return ib;
129
}
130
131
static int testp(int i, Integer ib) {
132
if ((i&1) == 0)
133
ib = new Integer(i+1);
134
return ib;
135
}
136
137
static int testc(int i) {
138
Integer ib = ibc;
139
if ((i&1) == 0)
140
ib = new Integer(i+1);
141
return ib;
142
}
143
144
static int test2(int i) {
145
Integer ib1 = new Integer(i);
146
Integer ib2 = new Integer(i+1);
147
if ((i&1) == 0) {
148
ib1 = new Integer(i+1);
149
ib2 = new Integer(i+2);
150
}
151
return ib1+ib2;
152
}
153
154
static int testb2(int i) {
155
Integer ib1 = i;
156
Integer ib2 = i+1;
157
if ((i&1) == 0) {
158
ib1 = (i+1);
159
ib2 = (i+2);
160
}
161
return ib1+ib2;
162
}
163
164
static int testm2(int i) {
165
Integer ib1 = new Integer(i);
166
Integer ib2 = i+1;
167
if ((i&1) == 0) {
168
ib1 = new Integer(i+1);
169
ib2 = (i+2);
170
}
171
return ib1+ib2;
172
}
173
174
static int testp2(int i, Integer ib1) {
175
Integer ib2 = i+1;
176
if ((i&1) == 0) {
177
ib1 = new Integer(i+1);
178
ib2 = (i+2);
179
}
180
return ib1+ib2;
181
}
182
183
static int testc2(int i) {
184
Integer ib1 = ibc;
185
Integer ib2 = i+1;
186
if ((i&1) == 0) {
187
ib1 = (ibc+1);
188
ib2 = (i+2);
189
}
190
return ib1+ib2;
191
}
192
193
//===============================================
194
static int sum(int[] a) {
195
int result = 1;
196
for (Integer i : a)
197
result += i;
198
return result;
199
}
200
201
static int sumb(int[] a) {
202
Integer result = 1;
203
for (Integer i : a)
204
result += i;
205
return result;
206
}
207
208
static int sumc(int[] a) {
209
Integer result = ibc;
210
for (Integer i : a)
211
result += i;
212
return result;
213
}
214
215
static int sumf(int[] a) {
216
Integer result = foob(1);
217
for (Integer i : a)
218
result += i;
219
return result;
220
}
221
222
static int sump(int[] a, Integer result) {
223
for (Integer i : a)
224
result += i;
225
return result;
226
}
227
228
static int sum2(int[] a) {
229
int result1 = 1;
230
int result2 = 1;
231
for (Integer i : a) {
232
result1 += i;
233
result2 += i + 1;
234
}
235
return result1 + result2;
236
}
237
238
static int sumb2(int[] a) {
239
Integer result1 = 1;
240
Integer result2 = 1;
241
for (Integer i : a) {
242
result1 += i;
243
result2 += i + 1;
244
}
245
return result1 + result2;
246
}
247
248
static int summ2(int[] a) {
249
Integer result1 = 1;
250
Integer result2 = new Integer(1);
251
for (Integer i : a) {
252
result1 += i;
253
result2 += new Integer(i + 1);
254
}
255
return result1 + result2;
256
}
257
258
static int sump2(int[] a, Integer result2) {
259
Integer result1 = 1;
260
for (Integer i : a) {
261
result1 += i;
262
result2 += i + 1;
263
}
264
return result1 + result2;
265
}
266
267
static int sumc2(int[] a) {
268
Integer result1 = 1;
269
Integer result2 = ibc;
270
for (Integer i : a) {
271
result1 += i;
272
result2 += i + ibc;
273
}
274
return result1 + result2;
275
}
276
277
//===============================================
278
static int remi_sum() {
279
Integer j = new Integer(1);
280
for (int i = 0; i< 1000; i++) {
281
j = new Integer(j + 1);
282
}
283
return j;
284
}
285
286
static int remi_sumb() {
287
Integer j = Integer.valueOf(1);
288
for (int i = 0; i< 1000; i++) {
289
j = j + 1;
290
}
291
return j;
292
}
293
294
static int remi_sumf() {
295
Integer j = foob(1);
296
for (int i = 0; i< 1000; i++) {
297
j = j + 1;
298
}
299
return j;
300
}
301
302
static int remi_sump(Integer j) {
303
for (int i = 0; i< 1000; i++) {
304
j = new Integer(j + 1);
305
}
306
return j;
307
}
308
309
static int remi_sumc() {
310
Integer j = ibc;
311
for (int i = 0; i< 1000; i++) {
312
j = j + ibc;
313
}
314
return j;
315
}
316
317
static int remi_sum2() {
318
Integer j1 = new Integer(1);
319
Integer j2 = new Integer(1);
320
for (int i = 0; i< 1000; i++) {
321
j1 = new Integer(j1 + 1);
322
j2 = new Integer(j2 + 2);
323
}
324
return j1 + j2;
325
}
326
327
static int remi_sumb2() {
328
Integer j1 = Integer.valueOf(1);
329
Integer j2 = Integer.valueOf(1);
330
for (int i = 0; i< 1000; i++) {
331
j1 = j1 + 1;
332
j2 = j2 + 2;
333
}
334
return j1 + j2;
335
}
336
337
static int remi_summ2() {
338
Integer j1 = new Integer(1);
339
Integer j2 = Integer.valueOf(1);
340
for (int i = 0; i< 1000; i++) {
341
j1 = new Integer(j1 + 1);
342
j2 = j2 + 2;
343
}
344
return j1 + j2;
345
}
346
347
static int remi_sump2(Integer j1) {
348
Integer j2 = Integer.valueOf(1);
349
for (int i = 0; i< 1000; i++) {
350
j1 = new Integer(j1 + 1);
351
j2 = j2 + 2;
352
}
353
return j1 + j2;
354
}
355
356
static int remi_sumc2() {
357
Integer j1 = ibc;
358
Integer j2 = Integer.valueOf(1);
359
for (int i = 0; i< 1000; i++) {
360
j1 = j1 + ibc;
361
j2 = j2 + 2;
362
}
363
return j1 + j2;
364
}
365
366
367
//===============================================
368
// Safepointa and debug info for deoptimization
369
static int simple_deop(int i) {
370
Integer ib = new Integer(foo(i));
371
dummy();
372
return ib;
373
}
374
375
static int simpleb_deop(int i) {
376
Integer ib = Integer.valueOf(foo(i));
377
dummy();
378
return ib;
379
}
380
381
static int simplef_deop(int i) {
382
Integer ib = foob(i);
383
dummy();
384
return ib;
385
}
386
387
static int simplep_deop(Integer ib) {
388
dummy();
389
return ib;
390
}
391
392
static int simplec_deop(int i) {
393
Integer ib = ibc;
394
dummy();
395
return ib;
396
}
397
398
static int test_deop(int i) {
399
Integer ib = new Integer(foo(i));
400
if ((i&1) == 0)
401
ib = foo(i+1);
402
dummy();
403
return ib;
404
}
405
406
static int testb_deop(int i) {
407
Integer ib = foo(i);
408
if ((i&1) == 0)
409
ib = foo(i+1);
410
dummy();
411
return ib;
412
}
413
414
static int testf_deop(int i) {
415
Integer ib = foob(i);
416
if ((i&1) == 0)
417
ib = foo(i+1);
418
dummy();
419
return ib;
420
}
421
422
static int testp_deop(int i, Integer ib) {
423
if ((i&1) == 0)
424
ib = foo(i+1);
425
dummy();
426
return ib;
427
}
428
429
static int testc_deop(int i) {
430
Integer ib = ibc;
431
if ((i&1) == 0)
432
ib = foo(i+1);
433
dummy();
434
return ib;
435
}
436
437
static int sum_deop(int[] a) {
438
int result = 1;
439
for (Integer i : a)
440
result += foo(i);
441
dummy();
442
return result;
443
}
444
445
static int sumb_deop(int[] a) {
446
Integer result = 1;
447
for (Integer i : a)
448
result += foo(i);
449
dummy();
450
return result;
451
}
452
453
static int sumf_deop(int[] a) {
454
Integer result = 1;
455
for (Integer i : a)
456
result += foob(i);
457
dummy();
458
return result;
459
}
460
461
static int sump_deop(int[] a, Integer result) {
462
for (Integer i : a)
463
result += foob(i);
464
dummy();
465
return result;
466
}
467
468
static int sumc_deop(int[] a) {
469
Integer result = ibc;
470
for (Integer i : a)
471
result += foo(i);
472
dummy();
473
return result;
474
}
475
476
static int remi_sum_deop() {
477
Integer j = new Integer(foo(1));
478
for (int i = 0; i< 1000; i++) {
479
j = new Integer(foo(j + 1));
480
}
481
dummy();
482
return j;
483
}
484
485
static int remi_sumb_deop() {
486
Integer j = Integer.valueOf(foo(1));
487
for (int i = 0; i< 1000; i++) {
488
j = foo(j + 1);
489
}
490
dummy();
491
return j;
492
}
493
494
static int remi_sumf_deop() {
495
Integer j = foob(1);
496
for (int i = 0; i< 1000; i++) {
497
j = foo(j + 1);
498
}
499
dummy();
500
return j;
501
}
502
503
static int remi_sump_deop(Integer j) {
504
for (int i = 0; i< 1000; i++) {
505
j = foo(j + 1);
506
}
507
dummy();
508
return j;
509
}
510
511
static int remi_sumc_deop() {
512
Integer j = ibc;
513
for (int i = 0; i< 1000; i++) {
514
j = foo(j + 1);
515
}
516
dummy();
517
return j;
518
}
519
520
//===============================================
521
// Conditional increment
522
static int remi_sum_cond() {
523
Integer j = new Integer(1);
524
for (int i = 0; i< 1000; i++) {
525
if ((i&1) == 0) {
526
j = new Integer(j + 1);
527
}
528
}
529
return j;
530
}
531
532
static int remi_sumb_cond() {
533
Integer j = Integer.valueOf(1);
534
for (int i = 0; i< 1000; i++) {
535
if ((i&1) == 0) {
536
j = j + 1;
537
}
538
}
539
return j;
540
}
541
542
static int remi_sumf_cond() {
543
Integer j = foob(1);
544
for (int i = 0; i< 1000; i++) {
545
if ((i&1) == 0) {
546
j = j + 1;
547
}
548
}
549
return j;
550
}
551
552
static int remi_sump_cond(Integer j) {
553
for (int i = 0; i< 1000; i++) {
554
if ((i&1) == 0) {
555
j = j + 1;
556
}
557
}
558
return j;
559
}
560
561
static int remi_sumc_cond() {
562
Integer j = ibc;
563
for (int i = 0; i< 1000; i++) {
564
if ((i&1) == 0) {
565
j = j + ibc;
566
}
567
}
568
return j;
569
}
570
571
static int remi_sum2_cond() {
572
Integer j1 = new Integer(1);
573
Integer j2 = new Integer(1);
574
for (int i = 0; i< 1000; i++) {
575
if ((i&1) == 0) {
576
j1 = new Integer(j1 + 1);
577
} else {
578
j2 = new Integer(j2 + 2);
579
}
580
}
581
return j1 + j2;
582
}
583
584
static int remi_sumb2_cond() {
585
Integer j1 = Integer.valueOf(1);
586
Integer j2 = Integer.valueOf(1);
587
for (int i = 0; i< 1000; i++) {
588
if ((i&1) == 0) {
589
j1 = j1 + 1;
590
} else {
591
j2 = j2 + 2;
592
}
593
}
594
return j1 + j2;
595
}
596
597
static int remi_summ2_cond() {
598
Integer j1 = new Integer(1);
599
Integer j2 = Integer.valueOf(1);
600
for (int i = 0; i< 1000; i++) {
601
if ((i&1) == 0) {
602
j1 = new Integer(j1 + 1);
603
} else {
604
j2 = j2 + 2;
605
}
606
}
607
return j1 + j2;
608
}
609
610
static int remi_sump2_cond(Integer j1) {
611
Integer j2 = Integer.valueOf(1);
612
for (int i = 0; i< 1000; i++) {
613
if ((i&1) == 0) {
614
j1 = new Integer(j1 + 1);
615
} else {
616
j2 = j2 + 2;
617
}
618
}
619
return j1 + j2;
620
}
621
622
static int remi_sumc2_cond() {
623
Integer j1 = ibc;
624
Integer j2 = Integer.valueOf(1);
625
for (int i = 0; i< 1000; i++) {
626
if ((i&1) == 0) {
627
j1 = j1 + ibc;
628
} else {
629
j2 = j2 + 2;
630
}
631
}
632
return j1 + j2;
633
}
634
635
636
public static void main(String[] args) {
637
final int ntests = 70;
638
639
String[] test_name = new String[] {
640
"simple", "simpleb", "simplec", "simplef", "simplep",
641
"simple2", "simpleb2", "simplec2", "simplem2", "simplep2",
642
"simple_deop", "simpleb_deop", "simplec_deop", "simplef_deop", "simplep_deop",
643
"test", "testb", "testc", "testm", "testp",
644
"test2", "testb2", "testc2", "testm2", "testp2",
645
"test_deop", "testb_deop", "testc_deop", "testf_deop", "testp_deop",
646
"sum", "sumb", "sumc", "sumf", "sump",
647
"sum2", "sumb2", "sumc2", "summ2", "sump2",
648
"sum_deop", "sumb_deop", "sumc_deop", "sumf_deop", "sump_deop",
649
"remi_sum", "remi_sumb", "remi_sumc", "remi_sumf", "remi_sump",
650
"remi_sum2", "remi_sumb2", "remi_sumc2", "remi_summ2", "remi_sump2",
651
"remi_sum_deop", "remi_sumb_deop", "remi_sumc_deop", "remi_sumf_deop", "remi_sump_deop",
652
"remi_sum_cond", "remi_sumb_cond", "remi_sumc_cond", "remi_sumf_cond", "remi_sump_cond",
653
"remi_sum2_cond", "remi_sumb2_cond", "remi_sumc2_cond", "remi_summ2_cond", "remi_sump2_cond"
654
};
655
656
final int[] val = new int[] {
657
71994000, 71994000, 12000, 71994000, 71994000,
658
144000000, 144000000, 72018000, 144000000, 144000000,
659
71994000, 71994000, 12000, 71994000, 71994000,
660
72000000, 72000000, 36006000, 72000000, 72000000,
661
144012000, 144012000, 72030000, 144012000, 144012000,
662
72000000, 72000000, 36006000, 72000000, 72000000,
663
499501, 499501, 499501, 499501, 499501,
664
1000002, 1000002, 1000002, 1000002, 1000002,
665
499501, 499501, 499501, 499501, 499501,
666
1001, 1001, 1001, 1001, 1001,
667
3002, 3002, 3002, 3002, 3002,
668
1001, 1001, 1001, 1001, 1001,
669
501, 501, 501, 501, 501,
670
1502, 1502, 1502, 1502, 1502
671
};
672
673
int[] res = new int[ntests];
674
for (int i = 0; i < ntests; i++) {
675
res[i] = 0;
676
}
677
678
679
for (int i = 0; i < 12000; i++) {
680
res[0] += simple(i);
681
res[1] += simpleb(i);
682
res[2] += simplec();
683
res[3] += simplef(i);
684
res[4] += simplep(i);
685
686
res[5] += simple2(i);
687
res[6] += simpleb2(i);
688
res[7] += simplec2(i);
689
res[8] += simplem2(i);
690
res[9] += simplep2(i, i);
691
692
res[10] += simple_deop(i);
693
res[11] += simpleb_deop(i);
694
res[12] += simplec_deop(i);
695
res[13] += simplef_deop(i);
696
res[14] += simplep_deop(i);
697
698
res[15] += test(i);
699
res[16] += testb(i);
700
res[17] += testc(i);
701
res[18] += testm(i);
702
res[19] += testp(i, i);
703
704
res[20] += test2(i);
705
res[21] += testb2(i);
706
res[22] += testc2(i);
707
res[23] += testm2(i);
708
res[24] += testp2(i, i);
709
710
res[25] += test_deop(i);
711
res[26] += testb_deop(i);
712
res[27] += testc_deop(i);
713
res[28] += testf_deop(i);
714
res[29] += testp_deop(i, i);
715
}
716
717
int[] ia = new int[1000];
718
for (int i = 0; i < 1000; i++) {
719
ia[i] = i;
720
}
721
722
for (int i = 0; i < 100; i++) {
723
res[30] = sum(ia);
724
res[31] = sumb(ia);
725
res[32] = sumc(ia);
726
res[33] = sumf(ia);
727
res[34] = sump(ia, 1);
728
729
res[35] = sum2(ia);
730
res[36] = sumb2(ia);
731
res[37] = sumc2(ia);
732
res[38] = summ2(ia);
733
res[39] = sump2(ia, 1);
734
735
res[40] = sum_deop(ia);
736
res[41] = sumb_deop(ia);
737
res[42] = sumc_deop(ia);
738
res[43] = sumf_deop(ia);
739
res[44] = sump_deop(ia, 1);
740
741
res[45] = remi_sum();
742
res[46] = remi_sumb();
743
res[47] = remi_sumc();
744
res[48] = remi_sumf();
745
res[49] = remi_sump(1);
746
747
res[50] = remi_sum2();
748
res[51] = remi_sumb2();
749
res[52] = remi_sumc2();
750
res[53] = remi_summ2();
751
res[54] = remi_sump2(1);
752
753
res[55] = remi_sum_deop();
754
res[56] = remi_sumb_deop();
755
res[57] = remi_sumc_deop();
756
res[58] = remi_sumf_deop();
757
res[59] = remi_sump_deop(1);
758
759
res[60] = remi_sum_cond();
760
res[61] = remi_sumb_cond();
761
res[62] = remi_sumc_cond();
762
res[63] = remi_sumf_cond();
763
res[64] = remi_sump_cond(1);
764
765
res[65] = remi_sum2_cond();
766
res[66] = remi_sumb2_cond();
767
res[67] = remi_sumc2_cond();
768
res[68] = remi_summ2_cond();
769
res[69] = remi_sump2_cond(1);
770
}
771
772
int failed = 0;
773
for (int i = 0; i < ntests; i++) {
774
if (res[i] != val[i]) {
775
System.err.println(test_name[i] + ": " + res[i] + " != " + val[i]);
776
failed++;
777
}
778
}
779
if (failed > 0) {
780
System.err.println("Failed " + failed + " tests.");
781
throw new InternalError();
782
} else {
783
System.out.println("Passed.");
784
}
785
}
786
}
787
788