Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/RunInfo.java
64507 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
package compiler.lib.ir_framework;
25
26
import compiler.lib.ir_framework.test.DeclaredTest;
27
import compiler.lib.ir_framework.shared.TestRunException;
28
import compiler.lib.ir_framework.test.TestVM;
29
30
import java.lang.reflect.Method;
31
import java.util.HashMap;
32
import java.util.List;
33
import java.util.Map;
34
35
/**
36
* Test info class which provides some useful utility methods and information about a <b>custom run test</b>.
37
*
38
* @see Run
39
*/
40
public class RunInfo extends AbstractInfo {
41
private final Method testMethod;
42
private final DeclaredTest test;
43
private final Map<String, DeclaredTest> tests;
44
private final boolean hasMultipleTests;
45
46
public RunInfo(List<DeclaredTest> tests) {
47
super(tests.get(0).getTestMethod().getDeclaringClass());
48
this.test = tests.get(0);
49
this.testMethod = test.getTestMethod();
50
this.hasMultipleTests = tests.size() != 1;
51
if (hasMultipleTests) {
52
this.tests = new HashMap<>();
53
for (DeclaredTest test : tests) {
54
this.tests.put(test.getTestMethod().getName(), test);
55
}
56
} else {
57
this.tests = null;
58
}
59
}
60
61
/**
62
* Get the associated test method object of this custom run test. This method can only be called if <i>one</i> test
63
* method is specified in the custom run test ({@link Run#test()}). Otherwise, use {@link #getTest(String)}.
64
*
65
* @return the associated test method object.
66
* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.
67
*/
68
public Method getTest() {
69
checkSingleTest("getTest");
70
return testMethod;
71
}
72
73
/**
74
* Get the associated method object of the test method with the name {@code testName}. This method can only be called
75
* if the custom run test specifies more than one test method in ({@link Run#test()}). Otherwise, use {@link #getTest()}.
76
*
77
* @param testName the test method for which the method object should be returned.
78
* @return the associated test method object with the name {@code testName}.
79
* @throws TestRunException if there is no test method with the name {@code testName} or if called with only
80
* <i>one</i> associated test method.
81
*/
82
public Method getTest(String testName) {
83
checkMultipleTests("getTest");
84
return getMethod(testName);
85
}
86
87
/**
88
* Return a boolean indicating if the framework skipped a compilation of the associated test method after the warm-up
89
* due to VM flags not allowing a compilation on the requested level in {@link Test#compLevel()}. This method can only
90
* be called if <i>one</i> test method is specified in the custom run test ({@link Run#test()}). Otherwise, use
91
* {@link #isCompilationSkipped(String)}.
92
*
93
* @return {@code true} if the framework skipped compilation of the test;
94
* {@code false} otherwise.
95
* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.
96
*/
97
public boolean isCompilationSkipped() {
98
checkSingleTest("isCompilationSkipped");
99
return test.getCompLevel() == CompLevel.SKIP;
100
}
101
102
/**
103
* Return a boolean indicating if the framework skipped a compilation of the associated test method with the name
104
* {@code testName} after the warm-up due to VM flags not allowing a compilation on the requested level in
105
* {@link Test#compLevel()}. This method can only be called if the custom run test specifies more than one test method
106
* in ({@link Run#test()}). Otherwise, use {@link #isCompilationSkipped()}.
107
*
108
* @param testName the test method for which the method object should be returned.
109
* @return {@code true} if the framework skipped compilation of the test;
110
* {@code false} otherwise.
111
* @throws TestRunException if there is no test method with the name {@code testName} or if called with only
112
* <i>one</i> associated test method.
113
*/
114
public boolean isCompilationSkipped(String testName) {
115
checkMultipleTests("isCompilationSkipped");
116
return getDeclaredTest(testName).getCompLevel() == CompLevel.SKIP;
117
}
118
119
/**
120
* Returns a boolean indicating if the associated test method is C1 compiled. This method can only be called if
121
* <i>one</i> test method is specified in the custom run test ({@link Run#test()}). Otherwise, use
122
* {@link #isTestC1Compiled(String)}.
123
*
124
* @return {@code true} if the associated test method is C1 compiled;
125
* {@code false} otherwise.
126
* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.
127
*/
128
public boolean isTestC1Compiled() {
129
checkSingleTest("isTestC1Compiled");
130
return TestVM.isC1Compiled(testMethod);
131
}
132
133
/**
134
* Returns a boolean indicating if the associated test method with the name {@code testName} is C1 compiled.
135
* This method can only be called if the custom run test specifies more than one test method in ({@link Run#test()}).
136
* Otherwise, use {@link #isTestC1Compiled()}.
137
*
138
* @param testName the name of the test method.
139
* @return {@code true} if the test method with the name {@code testName} is C1 compiled;
140
* {@code false} otherwise.
141
* @throws TestRunException if there is no test method with the name {@code testName} or if called with only
142
* <i>one</i> associated test method.
143
*/
144
public boolean isTestC1Compiled(String testName) {
145
checkMultipleTests("isTestC1Compiled");
146
return TestVM.isC1Compiled(getMethod(testName));
147
}
148
149
/**
150
* Returns a boolean indicating if the associated test method is C2 compiled. This method can only be called if
151
* <i>one</i> test method is specified in the custom run test ({@link Run#test()}). Otherwise, use
152
* {@link #isTestC2Compiled(String)}.
153
*
154
* @return {@code true} if the associated test method is C2 compiled;
155
* {@code false} otherwise.
156
* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.
157
*/
158
public boolean isTestC2Compiled() {
159
checkSingleTest("isTestC2Compiled");
160
return TestVM.isC2Compiled(testMethod);
161
}
162
163
/**
164
* Returns a boolean indicating if the associated test method with the name {@code testName} is C2 compiled.
165
* This method can only be called if the custom run test specifies more than one test method in ({@link Run#test()}).
166
* Otherwise, use {@link #isTestC2Compiled()}.
167
*
168
* @param testName the name of the test method.
169
* @return {@code true} if the test method with the name {@code testName} is C2 compiled;
170
* {@code false} otherwise.
171
* @throws TestRunException if there is no test method with the name {@code testName} or if called with only
172
* <i>one</i> associated test method.
173
*/
174
public boolean isTestC2Compiled(String testName) {
175
checkMultipleTests("isTestC2Compiled");
176
return TestVM.isC2Compiled(getMethod(testName));
177
}
178
179
/**
180
* Returns a boolean indicating if the associated test method is compiled at {@code compLevel}. This method can only
181
* be called if <i>one</i> test method is specified in the custom run test ({@link Run#test()}).
182
* Otherwise, use {@link #isTestCompiledAtLevel(String, CompLevel)}.
183
*
184
* @param compLevel the compilation level
185
* @return {@code true} if the associated test method is compiled at {@code compLevel};
186
* {@code false} otherwise.
187
* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.
188
*/
189
public boolean isTestCompiledAtLevel(CompLevel compLevel) {
190
checkSingleTest("isTestCompiledAtLevel");
191
return TestVM.isCompiledAtLevel(testMethod, compLevel);
192
}
193
194
/**
195
* Returns a boolean indicating if the associated test method with the name {@code testName} is compiled at
196
* {@code compLevel}. This method can only be called if the custom run test specifies more than one test method
197
* in ({@link Run#test()}). Otherwise, use {@link #isTestCompiledAtLevel(CompLevel)}.
198
*
199
* @param testName the name of the test method.
200
* @param compLevel the compilation level.
201
* @return {@code true} if the test method with the name {@code testName} is compiled at {@code compLevel};
202
* {@code false} otherwise.
203
* @throws TestRunException if there is no test method with the name {@code testName} oor if called with only
204
* <i>one</i> associated test method.
205
*/
206
public boolean isTestCompiledAtLevel(String testName, CompLevel compLevel) {
207
checkMultipleTests("isTestCompiledAtLevel");
208
return TestVM.isCompiledAtLevel(getMethod(testName), compLevel);
209
}
210
211
private void checkSingleTest(String calledMethod) {
212
if (hasMultipleTests) {
213
throw new TestRunException("Use " + calledMethod + "(String) with testName String argument in @Run method " +
214
"for custom run test that specifies more than one @Test method.");
215
}
216
}
217
218
private void checkMultipleTests(String calledMethod) {
219
if (!hasMultipleTests) {
220
throw new TestRunException("Use " + calledMethod + "() without testName String argument in @Run method " +
221
"for custom run test that specifies exactly one @Test method.");
222
}
223
}
224
225
private DeclaredTest getDeclaredTest(String testName) {
226
DeclaredTest test = tests.get(testName);
227
if (test == null) {
228
throw new TestRunException("Could not find @Test \"" + testName + "\" in " + testClass + " being associated with" +
229
" corresponding @Run method.");
230
}
231
return test;
232
}
233
234
private Method getMethod(String testName) {
235
return getDeclaredTest(testName).getTestMethod();
236
}
237
}
238
239