Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/lib/sun/hotspot/code/Compiler.java
38853 views
/*1* Copyright (c) 2018, 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 sun.hotspot.WhiteBox;2627/**28* API to obtain information about enabled JIT compilers29* retrieved from the VM with the WhiteBox API.30*/31public class Compiler {3233private static final WhiteBox WB = WhiteBox.getWhiteBox();3435/**36* Check if Graal is used as JIT compiler.37*38* Graal is enabled if following conditions are true:39* - we are not in Interpreter mode40* - UseJVMCICompiler flag is true41* - jvmci.Compiler variable is equal to 'graal'42* - TieredCompilation is not used or TieredStopAtLevel is greater than 343* No need to check client mode because it set UseJVMCICompiler to false.44*45* @return true if Graal is used as JIT compiler.46*/47public static boolean isGraalEnabled() {48Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");49if (useCompiler == null || !useCompiler) {50return false;51}52Boolean useJvmciComp = WB.getBooleanVMFlag("UseJVMCICompiler");53if (useJvmciComp == null || !useJvmciComp) {54return false;55}56// This check might be redundant but let's keep it for now.57String jvmciCompiler = System.getProperty("jvmci.Compiler");58if (jvmciCompiler == null || !jvmciCompiler.equals("graal")) {59return false;60}6162Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");63Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");64// if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used65if (tieredCompilation != null && tieredCompilation &&66compLevel != null && compLevel <= 3) {67return false;68}69return true;70}7172/**73* Check if C2 is used as JIT compiler.74*75* C2 is enabled if following conditions are true:76* - we are not in Interpreter mode77* - we are in Server compilation mode78* - TieredCompilation is not used or TieredStopAtLevel is greater than 379* - Graal is not used80*81* @return true if C2 is used as JIT compiler.82*/83public static boolean isC2Enabled() {84Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");85if (useCompiler == null || !useCompiler) {86return false;87}88Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");89if (serverMode == null || !serverMode) {90return false;91}9293Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");94Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");95// if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used96if (tieredCompilation != null && tieredCompilation &&97compLevel != null && compLevel <= 3) {98return false;99}100101if (isGraalEnabled()) {102return false;103}104105return true;106}107108/*109* Check if C1 is used as JIT compiler.110*111* C1 is enabled if following conditions are true:112* - we are not in Interpreter mode113* - we are not in Server compilation mode114* - TieredCompilation is used in Server mode115*116* @return true if C1 is used as JIT compiler.117*/118public static boolean isC1Enabled() {119Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");120if (useCompiler == null || !useCompiler) {121return false;122}123Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");124if (serverMode == null || !serverMode) {125return true; // Client mode126}127128Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");129// C1 is not used in server mode if TieredCompilation is off.130if (tieredCompilation != null && !tieredCompilation) {131return false;132}133return true;134}135}136137138