Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/CompLevel.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.TestFrameworkException;
27
import compiler.lib.ir_framework.shared.TestRun;
28
import compiler.lib.ir_framework.shared.TestRunException;
29
import compiler.lib.ir_framework.test.TestVM;
30
import jdk.test.lib.Utils;
31
32
import java.lang.reflect.Executable;
33
import java.util.HashMap;
34
import java.util.Map;
35
36
/**
37
* Compilation levels used by the framework to initiate a compilation of a method. The compilation levels map to the used
38
* levels in HotSpot (apart from the framework specific values {@link #SKIP} and {@link #WAIT_FOR_COMPILATION} that cannot
39
* be found in HotSpot). The HotSpot specific levels must be in sync with hotspot/share/compiler/compilerDefinitions.hpp.
40
*
41
* <p>
42
* The compilation levels can be specified in the {@link Test}, {@link ForceCompile}, and
43
* {@link ForceCompileClassInitializer} annotation.
44
*
45
* @see Test
46
* @see ForceCompile
47
* @see ForceCompileClassInitializer
48
*/
49
public enum CompLevel {
50
/**
51
* Can only be used at {@link Test#compLevel()}. After the warm-up, the framework keeps invoking the test over a span
52
* of 10s (configurable by setting the property flag {@code -DWaitForCompilationTimeout}) until HotSpot compiles the
53
* {@link Test} method. If the method was not compiled after 10s, an exception is thrown. The framework does not wait
54
* for the compilation if the test VM is run with {@code -Xcomp}, {@code -XX:-UseCompiler}, or
55
* {@code -DExcludeRandom=true}.
56
*/
57
WAIT_FOR_COMPILATION(-4),
58
/**
59
* Can only be used at {@link Test#compLevel()}. Skip a compilation of the {@link Test @Test} method completely.
60
*/
61
SKIP(-3),
62
/**
63
* Use any compilation level depending on the usage:
64
* <ul>
65
* <li><p>{@link Test @Test}, {@link ForceCompile @ForceCompile}: Use the highest available compilation level
66
* which is usually C2.</li>
67
* <li><p>{@link DontCompile @DontCompile}: Prevents any compilation of the associated helper method.</li>
68
* </ul>
69
*/
70
ANY(-1),
71
/**
72
* Compilation level 1: C1 compilation without any profile information.
73
*/
74
C1_SIMPLE(1),
75
/**
76
* Compilation level 2: C1 compilation with limited profile information: Includes Invocation and backedge counters.
77
*/
78
C1_LIMITED_PROFILE(2),
79
/**
80
* Compilation level 3: C1 compilation with full profile information: Includes Invocation and backedge counters with MDO.
81
*/
82
C1_FULL_PROFILE(3),
83
/**
84
* Compilation level 4: C2 compilation with full optimizations.
85
*/
86
C2(4),
87
88
;
89
90
private static final Map<Integer, CompLevel> TYPES_BY_VALUE = new HashMap<>();
91
private final int value;
92
93
static {
94
for (CompLevel level : CompLevel.values()) {
95
TYPES_BY_VALUE.put(level.value, level);
96
}
97
}
98
99
CompLevel(int level) {
100
this.value = level;
101
}
102
103
/**
104
* Get the compilation level as integer value. These will match the levels specified in HotSpot (if available).
105
*
106
* @return the compilation level as integer.
107
*/
108
public int getValue() {
109
return value;
110
}
111
112
/**
113
* Get the compilation level enum from the specified integer.
114
*
115
* @param value the compilation level as integer.
116
* @throws TestRunException if {@code value} does not specify a valid compilation level.
117
* @return the compilation level enum for {@code value}.
118
*/
119
public static CompLevel forValue(int value) {
120
CompLevel level = TYPES_BY_VALUE.get(value);
121
TestRun.check(level != null, "Invalid compilation level " + value);
122
return level;
123
}
124
125
/**
126
* Called by {@link TestFramework} to check if this compilation level is not part of the compiler.
127
*/
128
public boolean isNotCompilationLevelOfCompiler(Compiler c) {
129
return switch (c) {
130
case C1 -> !isC1();
131
case C2 -> this != C2;
132
default -> throw new TestFrameworkException("Should not be called with compiler " + c);
133
};
134
}
135
136
/**
137
* Called by {@link TestFramework} to flip compilation levels.
138
*/
139
public CompLevel flipCompLevel() {
140
switch (this) {
141
case C1_SIMPLE, C1_LIMITED_PROFILE, C1_FULL_PROFILE -> {
142
return CompLevel.C2;
143
}
144
case C2 -> {
145
return CompLevel.C1_SIMPLE;
146
}
147
}
148
return this;
149
}
150
151
/**
152
* Called by {@link TestFramework}. Return the compilation level when only allowing a compilation with the specified
153
* compiler.
154
*/
155
public CompLevel excludeCompilationRandomly(Executable ex) {
156
if (Utils.getRandomInstance().nextBoolean()) {
157
// No exclusion
158
return this;
159
}
160
Compiler compiler = TestVM.excludeRandomly(ex);
161
return switch (compiler) {
162
case ANY -> SKIP;
163
case C1 -> isC1() ? SKIP : this;
164
case C2 -> this == C2 ? SKIP : this;
165
};
166
}
167
168
private boolean isC1() {
169
return this == C1_SIMPLE || this == C1_LIMITED_PROFILE || this == C1_FULL_PROFILE;
170
}
171
}
172
173