- Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathCompLevel.java
171 lines (157 loc) · 6.07 KB
/
CompLevel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
packagecompiler.lib.ir_framework;
importcompiler.lib.ir_framework.shared.TestFrameworkException;
importcompiler.lib.ir_framework.shared.TestRun;
importcompiler.lib.ir_framework.shared.TestRunException;
importcompiler.lib.ir_framework.test.TestVM;
importjdk.test.lib.Utils;
importjava.lang.reflect.Executable;
importjava.util.HashMap;
importjava.util.Map;
/**
* Compilation levels used by the framework to initiate a compilation of a method. The compilation levels map to the used
* levels in HotSpot (apart from the framework specific values {@link #SKIP} and {@link #WAIT_FOR_COMPILATION} that cannot
* be found in HotSpot). The HotSpot specific levels must be in sync with hotspot/share/compiler/compilerDefinitions.hpp.
*
* <p>
* The compilation levels can be specified in the {@link Test}, {@link ForceCompile}, and
* {@link ForceCompileClassInitializer} annotation.
*
* @see Test
* @see ForceCompile
* @see ForceCompileClassInitializer
*/
publicenumCompLevel {
/**
* Can only be used at {@link Test#compLevel()}. After the warm-up, the framework keeps invoking the test over a span
* of 10s (configurable by setting the property flag {@code -DWaitForCompilationTimeout}) until HotSpot compiles the
* {@link Test} method. If the method was not compiled after 10s, an exception is thrown. The framework does not wait
* for the compilation if the test VM is run with {@code -Xcomp}, {@code -XX:-UseCompiler}, or
* {@code -DExcludeRandom=true}.
*/
WAIT_FOR_COMPILATION(-4),
/**
* Can only be used at {@link Test#compLevel()}. Skip a compilation of the {@link Test @Test} method completely.
*/
SKIP(-3),
/**
* Use any compilation level depending on the usage:
* <ul>
* <li><p>{@link Test @Test}, {@link ForceCompile @ForceCompile}: Use the highest available compilation level
* which is usually C2.</li>
* <li><p>{@link DontCompile @DontCompile}: Prevents any compilation of the associated helper method.</li>
* </ul>
*/
ANY(-1),
/**
* Compilation level 1: C1 compilation without any profile information.
*/
C1_SIMPLE(1),
/**
* Compilation level 2: C1 compilation with limited profile information: Includes Invocation and backedge counters.
*/
C1_LIMITED_PROFILE(2),
/**
* Compilation level 3: C1 compilation with full profile information: Includes Invocation and backedge counters with MDO.
*/
C1_FULL_PROFILE(3),
/**
* Compilation level 4: C2 compilation with full optimizations.
*/
C2(4),
;
privatestaticfinalMap<Integer, CompLevel> TYPES_BY_VALUE = newHashMap<>();
privatefinalintvalue;
static {
for (CompLevellevel : CompLevel.values()) {
TYPES_BY_VALUE.put(level.value, level);
}
}
CompLevel(intlevel) {
this.value = level;
}
/**
* Get the compilation level as integer value. These will match the levels specified in HotSpot (if available).
*
* @return the compilation level as integer.
*/
publicintgetValue() {
returnvalue;
}
/**
* Get the compilation level enum from the specified integer.
*
* @param value the compilation level as integer.
* @throws TestRunException if {@code value} does not specify a valid compilation level.
* @return the compilation level enum for {@code value}.
*/
publicstaticCompLevelforValue(intvalue) {
CompLevellevel = TYPES_BY_VALUE.get(value);
TestRun.check(level != null, "Invalid compilation level " + value);
returnlevel;
}
/**
* Called by {@link TestFramework} to check if this compilation level is not part of the compiler.
*/
publicbooleanisNotCompilationLevelOfCompiler(Compilerc) {
returnswitch (c) {
caseC1 -> !isC1();
caseC2 -> this != C2;
default -> thrownewTestFrameworkException("Should not be called with compiler " + c);
};
}
/**
* Called by {@link TestFramework} to flip compilation levels.
*/
publicCompLevelflipCompLevel() {
switch (this) {
caseC1_SIMPLE, C1_LIMITED_PROFILE, C1_FULL_PROFILE -> {
returnCompLevel.C2;
}
caseC2 -> {
returnCompLevel.C1_SIMPLE;
}
}
returnthis;
}
/**
* Called by {@link TestFramework}. Return the compilation level when only allowing a compilation with the specified
* compiler.
*/
publicCompLevelexcludeCompilationRandomly(Executableex) {
if (Utils.getRandomInstance().nextBoolean()) {
// No exclusion
returnthis;
}
Compilercompiler = TestVM.excludeRandomly(ex);
returnswitch (compiler) {
caseANY -> SKIP;
caseC1 -> isC1() ? SKIP : this;
caseC2 -> this == C2 ? SKIP : this;
};
}
privatebooleanisC1() {
returnthis == C1_SIMPLE || this == C1_LIMITED_PROFILE || this == C1_FULL_PROFILE;
}
}