Path: blob/master/test/lib/sun/hotspot/code/Compiler.java
41149 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package sun.hotspot.code;2425import java.lang.reflect.Executable;26import sun.hotspot.WhiteBox;2728/**29* API to obtain information about enabled JIT compilers30* retrieved from the VM with the WhiteBox API.31*/32public class Compiler {3334private static final WhiteBox WB = WhiteBox.getWhiteBox();3536/**37* Check if C2 or JVMCI were included in the VM build38*39* @return true if either C2 or JVMCI were included in the VM build.40*/41public static boolean isC2OrJVMCIIncluded() {42return WB.isC2OrJVMCIIncluded();43}4445/**46* Check if JVMCI is enabled.47*48* @return true if JVMCI is enabled49*/50public static boolean isJVMCIEnabled() {51Boolean enableJvmci = WB.getBooleanVMFlag("EnableJVMCI");52if (enableJvmci == null || !enableJvmci) {53return false;54}5556return true;57}5859/**60* Check if Graal is used as JIT compiler.61*62* Graal is enabled if following conditions are true:63* - we are not in Interpreter mode64* - UseJVMCICompiler flag is true65* - jvmci.Compiler variable is equal to 'graal'66* - TieredCompilation is not used or TieredStopAtLevel is greater than 367* No need to check client mode because it set UseJVMCICompiler to false.68*69* @return true if Graal is used as JIT compiler.70*/71public static boolean isGraalEnabled() {72Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");73if (useCompiler == null || !useCompiler) {74return false;75}76Boolean useJvmciComp = WB.getBooleanVMFlag("UseJVMCICompiler");77if (useJvmciComp == null || !useJvmciComp) {78return false;79}8081Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");82Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");83// if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used84if (tieredCompilation != null && tieredCompilation &&85compLevel != null && compLevel <= 3) {86return false;87}88return true;89}9091/**92* Check if C2 is used as JIT compiler.93*94* C2 is enabled if following conditions are true:95* - we are not in Interpreter mode96* - we are in Server compilation mode97* - TieredCompilation is not used or TieredStopAtLevel is greater than 398* - Graal is not used99*100* @return true if C2 is used as JIT compiler.101*/102public static boolean isC2Enabled() {103Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");104if (useCompiler == null || !useCompiler) {105return false;106}107Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");108if (serverMode == null || !serverMode) {109return false;110}111112Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");113Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");114// if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used115if (tieredCompilation != null && tieredCompilation &&116compLevel != null && compLevel <= 3) {117return false;118}119120if (isGraalEnabled()) {121return false;122}123124return true;125}126127/*128* Check if C1 is used as JIT compiler.129*130* C1 is enabled if following conditions are true:131* - we are not in Interpreter mode132* - we are not in Server compilation mode133* - TieredCompilation is used in Server mode134*135* @return true if C1 is used as JIT compiler.136*/137public static boolean isC1Enabled() {138Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");139if (useCompiler == null || !useCompiler) {140return false;141}142Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");143if (serverMode == null || !serverMode) {144return true; // Client mode145}146147Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");148// C1 is not used in server mode if TieredCompilation is off.149if (tieredCompilation != null && !tieredCompilation) {150return false;151}152return true;153}154155/*156* Determine if the compiler corresponding to the compilation level 'compLevel'157* provides an intrinsic for 'class'.'method'.158*/159public static boolean isIntrinsicAvailable(int compLevel, String klass, String method, Class<?>... parameterTypes) {160Executable intrinsicMethod;161try {162intrinsicMethod = Class.forName(klass).getDeclaredMethod(method, parameterTypes);163} catch (NoSuchMethodException e) {164throw new RuntimeException("Test bug, '" + method + "' method unavailable. " + e);165} catch (ClassNotFoundException e) {166throw new RuntimeException("Test bug, '" + klass + "' class unavailable. " + e);167}168return WB.isIntrinsicAvailable(intrinsicMethod, compLevel);169}170}171172173