Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/eliminateAutobox/TestSafepointDebugInfo.java
64474 views
1
/*
2
* Copyright (c) 2021, 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
* @key randomness
27
* @bug 8276112
28
* @summary Verify consistency of safepoint debug info when boxes are scalar
29
* replaced during incremental inlining.
30
* @library /test/lib
31
* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline
32
* -XX:CompileCommand=compileonly,compiler.eliminateAutobox.TestSafepointDebugInfo::test*
33
* compiler.eliminateAutobox.TestSafepointDebugInfo
34
*/
35
36
package compiler.eliminateAutobox;
37
38
import java.util.Random;
39
40
import jdk.test.lib.Asserts;
41
import jdk.test.lib.Utils;
42
43
public class TestSafepointDebugInfo {
44
45
private static final Random random = Utils.getRandomInstance();
46
47
static Integer fBox;
48
49
public static Integer helper(int i) {
50
return Integer.valueOf(i);
51
}
52
53
// assert(local) failed: use _top instead of null
54
public static int test1(int i) {
55
Integer box = helper(i);
56
fBox = Integer.valueOf(i);
57
return box.intValue();
58
}
59
60
// Wrong execution, same types
61
public static int test2(int i1, int i2) {
62
Integer box1 = helper(i1);
63
Integer box2 = Integer.valueOf(i2);
64
fBox = Integer.valueOf(i1);
65
return box1.intValue() + box2.intValue();
66
}
67
68
// Wrong execution, different types
69
public static long test3(int i1, long i2) {
70
Integer box1 = helper(i1);
71
Long box2 = Long.valueOf(i2);
72
fBox = Integer.valueOf(i1);
73
return box1.intValue() + box2.longValue();
74
}
75
76
// assert(i < _max) failed: oob: i=16, _max=16
77
public static int test4(int i1, int i2) {
78
Integer box1 = helper(i1);
79
Integer box2 = helper(i2);
80
fBox = Integer.valueOf(i1);
81
return box1.intValue() + box2.intValue();
82
}
83
84
public static Integer test5_helper(int i1, int i2) {
85
Integer box1 = helper(i1);
86
Integer box2 = helper(i2);
87
fBox = Integer.valueOf(i1);
88
return box1.intValue() + box2.intValue();
89
}
90
91
// assert(local) failed: use _top instead of null
92
// Variant with deeper inlining
93
public static int test5(int i1, int i2) {
94
return test5_helper(i1, i2);
95
}
96
97
public static int test6_helper(int i1, int i2) {
98
Integer box = helper(i1);
99
fBox = Integer.valueOf(i2);
100
return box.intValue();
101
}
102
103
// Wrong execution, variant with more arguments
104
public static int test6(int i1, int i2, int i3, int i4) {
105
Integer box1 = helper(i1);
106
Integer box2 = helper(i2);
107
int res = test6_helper(i3, i4);
108
res += box1.intValue() + box2.intValue();
109
return res;
110
}
111
112
public static void main(String[] args) {
113
// Warmup
114
for (int i = 0; i < 100_000; ++i) {
115
int val = (i % 10);
116
Asserts.assertEquals(test1(val), val);
117
Asserts.assertEquals(fBox, val);
118
Asserts.assertEquals(test2(val, val), 2*val);
119
Asserts.assertEquals(fBox, val);
120
Asserts.assertEquals(test3(val, val), 2L*val);
121
Asserts.assertEquals(fBox, val);
122
Asserts.assertEquals(test4(val, val), 2*val);
123
Asserts.assertEquals(fBox, val);
124
Asserts.assertEquals(test5(val, val), 2*val);
125
Asserts.assertEquals(fBox, val);
126
Asserts.assertEquals(test6(val, val, val, val), 3*val);
127
Asserts.assertEquals(fBox, val);
128
}
129
130
// Trigger deoptimization by choosing a value that does not
131
// fit in the Integer cache and check the result.
132
int val = 4000;
133
Asserts.assertEquals(test1(val), val);
134
switch (random.nextInt(3)) {
135
case 0:
136
Asserts.assertEquals(test2(val, 1), val + 1);
137
Asserts.assertEquals(fBox, val);
138
Asserts.assertEquals(test3(val, 1), (long)val + 1);
139
Asserts.assertEquals(fBox, val);
140
Asserts.assertEquals(test4(val, 1), val + 1);
141
Asserts.assertEquals(fBox, val);
142
Asserts.assertEquals(test5(val, 1), val + 1);
143
Asserts.assertEquals(fBox, val);
144
Asserts.assertEquals(test6(val, 1, 2, 3), val + 3);
145
Asserts.assertEquals(fBox, 3);
146
break;
147
case 1:
148
Asserts.assertEquals(test2(1, val), val + 1);
149
Asserts.assertEquals(fBox, 1);
150
Asserts.assertEquals(test3(1, val), (long)val + 1);
151
Asserts.assertEquals(fBox, 1);
152
Asserts.assertEquals(test4(1, val), val + 1);
153
Asserts.assertEquals(fBox, 1);
154
Asserts.assertEquals(test5(1, val), val + 1);
155
Asserts.assertEquals(fBox, 1);
156
Asserts.assertEquals(test6(1, val, 2, 3), val + 3);
157
Asserts.assertEquals(fBox, 3);
158
break;
159
case 2:
160
Asserts.assertEquals(test2(1, 2), 3);
161
Asserts.assertEquals(fBox, 1);
162
Asserts.assertEquals(test3(1, 2), 3L);
163
Asserts.assertEquals(fBox, 1);
164
Asserts.assertEquals(test4(1, 2), 3);
165
Asserts.assertEquals(fBox, 1);
166
Asserts.assertEquals(test5(1, 2), 3);
167
Asserts.assertEquals(fBox, 1);
168
Asserts.assertEquals(test6(1, 2, 3, val), 6);
169
Asserts.assertEquals(fBox, val);
170
break;
171
}
172
}
173
}
174
175