Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/lib/sun/hotspot/code/Compiler.java
41149 views
1
/*
2
* Copyright (c) 2018, 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 sun.hotspot.code;
25
26
import java.lang.reflect.Executable;
27
import sun.hotspot.WhiteBox;
28
29
/**
30
* API to obtain information about enabled JIT compilers
31
* retrieved from the VM with the WhiteBox API.
32
*/
33
public class Compiler {
34
35
private static final WhiteBox WB = WhiteBox.getWhiteBox();
36
37
/**
38
* Check if C2 or JVMCI were included in the VM build
39
*
40
* @return true if either C2 or JVMCI were included in the VM build.
41
*/
42
public static boolean isC2OrJVMCIIncluded() {
43
return WB.isC2OrJVMCIIncluded();
44
}
45
46
/**
47
* Check if JVMCI is enabled.
48
*
49
* @return true if JVMCI is enabled
50
*/
51
public static boolean isJVMCIEnabled() {
52
Boolean enableJvmci = WB.getBooleanVMFlag("EnableJVMCI");
53
if (enableJvmci == null || !enableJvmci) {
54
return false;
55
}
56
57
return true;
58
}
59
60
/**
61
* Check if Graal is used as JIT compiler.
62
*
63
* Graal is enabled if following conditions are true:
64
* - we are not in Interpreter mode
65
* - UseJVMCICompiler flag is true
66
* - jvmci.Compiler variable is equal to 'graal'
67
* - TieredCompilation is not used or TieredStopAtLevel is greater than 3
68
* No need to check client mode because it set UseJVMCICompiler to false.
69
*
70
* @return true if Graal is used as JIT compiler.
71
*/
72
public static boolean isGraalEnabled() {
73
Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");
74
if (useCompiler == null || !useCompiler) {
75
return false;
76
}
77
Boolean useJvmciComp = WB.getBooleanVMFlag("UseJVMCICompiler");
78
if (useJvmciComp == null || !useJvmciComp) {
79
return false;
80
}
81
82
Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");
83
Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");
84
// if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used
85
if (tieredCompilation != null && tieredCompilation &&
86
compLevel != null && compLevel <= 3) {
87
return false;
88
}
89
return true;
90
}
91
92
/**
93
* Check if C2 is used as JIT compiler.
94
*
95
* C2 is enabled if following conditions are true:
96
* - we are not in Interpreter mode
97
* - we are in Server compilation mode
98
* - TieredCompilation is not used or TieredStopAtLevel is greater than 3
99
* - Graal is not used
100
*
101
* @return true if C2 is used as JIT compiler.
102
*/
103
public static boolean isC2Enabled() {
104
Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");
105
if (useCompiler == null || !useCompiler) {
106
return false;
107
}
108
Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");
109
if (serverMode == null || !serverMode) {
110
return false;
111
}
112
113
Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");
114
Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");
115
// if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used
116
if (tieredCompilation != null && tieredCompilation &&
117
compLevel != null && compLevel <= 3) {
118
return false;
119
}
120
121
if (isGraalEnabled()) {
122
return false;
123
}
124
125
return true;
126
}
127
128
/*
129
* Check if C1 is used as JIT compiler.
130
*
131
* C1 is enabled if following conditions are true:
132
* - we are not in Interpreter mode
133
* - we are not in Server compilation mode
134
* - TieredCompilation is used in Server mode
135
*
136
* @return true if C1 is used as JIT compiler.
137
*/
138
public static boolean isC1Enabled() {
139
Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");
140
if (useCompiler == null || !useCompiler) {
141
return false;
142
}
143
Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");
144
if (serverMode == null || !serverMode) {
145
return true; // Client mode
146
}
147
148
Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");
149
// C1 is not used in server mode if TieredCompilation is off.
150
if (tieredCompilation != null && !tieredCompilation) {
151
return false;
152
}
153
return true;
154
}
155
156
/*
157
* Determine if the compiler corresponding to the compilation level 'compLevel'
158
* provides an intrinsic for 'class'.'method'.
159
*/
160
public static boolean isIntrinsicAvailable(int compLevel, String klass, String method, Class<?>... parameterTypes) {
161
Executable intrinsicMethod;
162
try {
163
intrinsicMethod = Class.forName(klass).getDeclaredMethod(method, parameterTypes);
164
} catch (NoSuchMethodException e) {
165
throw new RuntimeException("Test bug, '" + method + "' method unavailable. " + e);
166
} catch (ClassNotFoundException e) {
167
throw new RuntimeException("Test bug, '" + klass + "' class unavailable. " + e);
168
}
169
return WB.isIntrinsicAvailable(intrinsicMethod, compLevel);
170
}
171
}
172
173