Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/AbstractInfo.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.shared.TestRunException;
27
import compiler.lib.ir_framework.test.TestVM;
28
import jdk.test.lib.Utils;
29
30
import java.lang.reflect.Method;
31
import java.util.Arrays;
32
import java.util.Random;
33
import java.util.stream.Collectors;
34
35
/**
36
* Base info class which provides some useful utility methods and information about a test.
37
* <p>
38
* <b>Base tests</b> and <b>checked tests</b> use {@link TestInfo} while <b>custom run tests</b> use {@link RunInfo}.
39
*
40
* @see Test
41
* @see Check
42
* @see Run
43
*/
44
abstract public class AbstractInfo {
45
private static final Random RANDOM = Utils.getRandomInstance();
46
47
protected final Class<?> testClass;
48
private boolean onWarmUp = true;
49
50
AbstractInfo(Class<?> testClass) {
51
this.testClass = testClass;
52
}
53
54
/**
55
* Get the initialized {@link Random} object.
56
*
57
* @return the random object.
58
*/
59
public Random getRandom() {
60
return RANDOM;
61
}
62
63
/**
64
* Returns a boolean indicating if the framework is currently warming up the associated test.
65
*
66
* @return the warm-up status of the associated test.
67
*
68
* @see Warmup
69
*/
70
public boolean isWarmUp() {
71
return onWarmUp;
72
}
73
74
/**
75
* Get the method object of the method {@code name} of class {@code c} with arguments {@code args}.
76
*
77
* @param c the class containing the method.
78
* @param name the name of the method.
79
* @param args the arguments of the method, leave empty if no arguments.
80
*
81
* @return the method object of the requested method.
82
*/
83
public Method getMethod(Class<?> c, String name, Class<?>... args) {
84
try {
85
return c.getMethod(name, args);
86
} catch (NoSuchMethodException e) {
87
String parameters = args == null || args.length == 0 ? "" :
88
" with arguments [" + Arrays.stream(args).map(Class::getName).collect(Collectors.joining(",")) + "]";
89
throw new TestRunException("Could not find method " + name + " in " + c + parameters, e);
90
}
91
}
92
93
/**
94
* Get the method object of the method {@code name} of the test class with arguments {@code args}.
95
*
96
* @param name the name of the method in the test class.
97
* @param args the arguments of the method, leave empty if no arguments.
98
*
99
* @return the method object of the requested method in the test class.
100
*/
101
public Method getTestClassMethod(String name, Class<?>... args) {
102
return getMethod(testClass, name, args);
103
}
104
105
/**
106
* Returns a boolean indicating if the test VM runs with flags that allow C2 compilations.
107
*
108
* @return {@code true} if C2 compilations are allowed;
109
* {@code false} otherwise (run with {@code -XX:TieredStopAtLevel={1,2,3}, -XX:-UseCompiler}).
110
*/
111
public boolean isC2CompilationEnabled() {
112
return TestVM.USE_COMPILER && !TestVM.TEST_C1;
113
}
114
115
/**
116
* Called by {@link TestFramework} when the warm-up is finished. Should not be called by user code.
117
*/
118
public void setWarmUpFinished() {
119
onWarmUp = false;
120
}
121
}
122
123