Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/conversions/TestMoveConvI2LOrCastIIThruAddIs.java
41149 views
1
/*
2
* Copyright (c) 2020, 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.conversions;
25
26
import java.util.Objects;
27
import java.util.Random;
28
import jdk.test.lib.Asserts;
29
30
/*
31
* @test
32
* @bug 8254317 8256730
33
* @requires vm.compiler2.enabled
34
* @summary Exercises the optimization that moves integer-to-long conversions
35
* upwards through different shapes of integer addition
36
* subgraphs. Contains three small functional tests and two stress
37
* tests that resulted in a compilation time and memory explosion
38
* before fixing bug 8254317. The stress tests run with -Xbatch to wait
39
* for C2, so that a timeout or an out-of-memory error is triggered if
40
* there was an explosion. These tests use a timeout of 30s to catch
41
* the explosion earlier.
42
* @library /test/lib /
43
* @run main/othervm
44
* compiler.conversions.TestMoveConvI2LOrCastIIThruAddIs functional
45
* @run main/othervm/timeout=30 -Xbatch
46
* compiler.conversions.TestMoveConvI2LOrCastIIThruAddIs stress1
47
* @run main/othervm/timeout=30 -Xbatch
48
* compiler.conversions.TestMoveConvI2LOrCastIIThruAddIs stress2
49
* @run main/othervm/timeout=30 -Xbatch
50
* compiler.conversions.TestMoveConvI2LOrCastIIThruAddIs stress3
51
* @run main/othervm/timeout=30 -Xbatch
52
* compiler.conversions.TestMoveConvI2LOrCastIIThruAddIs stress4
53
*/
54
55
public class TestMoveConvI2LOrCastIIThruAddIs {
56
57
// Number of repetitions of each test. Should be sufficiently large for the
58
// method under test to be compiled with C2.
59
static final int N = 100_000;
60
61
// Chain-shaped functional test.
62
static long testChain(boolean cnd) {
63
int a = cnd ? 1 : 2;
64
int b = a + a;
65
int c = b + b;
66
int d = c + c;
67
return d;
68
}
69
70
// Tree-shaped functional test.
71
static long testTree(boolean cnd) {
72
int a0 = cnd ? 1 : 2;
73
int a1 = cnd ? 1 : 2;
74
int a2 = cnd ? 1 : 2;
75
int a3 = cnd ? 1 : 2;
76
int a4 = cnd ? 1 : 2;
77
int a5 = cnd ? 1 : 2;
78
int a6 = cnd ? 1 : 2;
79
int a7 = cnd ? 1 : 2;
80
int b0 = a0 + a1;
81
int b1 = a2 + a3;
82
int b2 = a4 + a5;
83
int b3 = a6 + a7;
84
int c0 = b0 + b1;
85
int c1 = b2 + b3;
86
int d = c0 + c1;
87
return d;
88
}
89
90
// DAG-shaped functional test.
91
static long testDAG(boolean cnd) {
92
int a0 = cnd ? 1 : 2;
93
int a1 = cnd ? 1 : 2;
94
int a2 = cnd ? 1 : 2;
95
int a3 = cnd ? 1 : 2;
96
int b0 = a0 + a1;
97
int b1 = a1 + a2;
98
int b2 = a2 + a3;
99
int c0 = b0 + b1;
100
int c1 = b1 + b2;
101
int d = c0 + c1;
102
return d;
103
}
104
105
// Chain-shaped stress test. Before fixing bug 8254317, this test would
106
// result in an out-of-memory error after minutes running.
107
static long testStress1(boolean cnd) {
108
// C2 infers a finite, small value range for a. Note that there are
109
// different ways to achieve this, for example a might take the value of
110
// the induction variable in an outer counted loop.
111
int a = cnd ? 1 : 2;
112
// C2 fully unrolls this loop, creating a long chain of AddIs.
113
for (int i = 0; i < 28; i++) {
114
a = a + a;
115
}
116
// C2 places a ConvI2L at the end of the AddI chain.
117
return a;
118
}
119
120
// DAG-shaped stress test. Before fixing bug 8254317, this test would result
121
// in an out-of-memory error after minutes running.
122
static long testStress2(boolean cnd) {
123
int a = cnd ? 1 : 2;
124
int b = a;
125
int c = a + a;
126
for (int i = 0; i < 20; i++) {
127
b = b + c;
128
c = b + c;
129
}
130
int d = b + c;
131
return d;
132
}
133
134
// Same as testStress1 for CastII
135
static long testStress3(int a) {
136
Objects.checkIndex(a, 2);
137
for (int i = 0; i < 28; i++) {
138
a = a + a;
139
}
140
return Objects.checkIndex(a, 2);
141
}
142
143
// Same as testStress2 for CastII
144
static long testStress4(int a) {
145
a = Objects.checkIndex(a, 2);
146
int b = a;
147
int c = a + a;
148
for (int i = 0; i < 20; i++) {
149
b = b + c;
150
c = b + c;
151
}
152
int d = b + c;
153
return Objects.checkIndex(d, 2);
154
}
155
156
public static void main(String[] args) {
157
// We use a random number generator to avoid constant propagation in C2
158
// and produce a variable ("a" in the different tests) with a finite,
159
// small value range.
160
Random rnd = new Random();
161
switch(args[0]) {
162
case "functional":
163
// Small, functional tests.
164
for (int i = 0; i < N; i++) {
165
boolean cnd = rnd.nextBoolean();
166
Asserts.assertEQ(testChain(cnd), cnd ? 8L : 16L);
167
Asserts.assertEQ(testTree(cnd), cnd ? 8L : 16L);
168
Asserts.assertEQ(testDAG(cnd), cnd ? 8L : 16L);
169
}
170
break;
171
case "stress1":
172
// Chain-shaped stress test.
173
for (int i = 0; i < N; i++) {
174
boolean cnd = rnd.nextBoolean();
175
Asserts.assertEQ(testStress1(cnd),
176
cnd ? 268435456L : 536870912L);
177
}
178
break;
179
case "stress2":
180
// DAG-shaped stress test.
181
for (int i = 0; i < N; i++) {
182
boolean cnd = rnd.nextBoolean();
183
Asserts.assertEQ(testStress2(cnd),
184
cnd ? 701408733L : 1402817466L);
185
}
186
break;
187
case "stress3":
188
for (int i = 0; i < N; i++) {
189
testStress3(0);
190
}
191
break;
192
case "stress4":
193
// DAG-shaped stress test.
194
for (int i = 0; i < N; i++) {
195
testStress4(0);
196
}
197
break;
198
default:
199
System.out.println("invalid mode");
200
}
201
}
202
}
203
204