Path: blob/master/src/hotspot/share/compiler/compilerDefinitions.hpp
40930 views
/*1* Copyright (c) 2016, 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*22*/2324#ifndef SHARE_COMPILER_COMPILERDEFINITIONS_HPP25#define SHARE_COMPILER_COMPILERDEFINITIONS_HPP2627#include "compiler/compiler_globals.hpp"28#include "jvmci/jvmci_globals.hpp"29#include "memory/allocation.hpp"30#include "runtime/globals.hpp"3132// The (closed set) of concrete compiler classes.33enum CompilerType {34compiler_none,35compiler_c1,36compiler_c2,37compiler_jvmci,38compiler_number_of_types39};4041extern const char* compilertype2name_tab[compiler_number_of_types]; // Map CompilerType to its name42inline const char* compilertype2name(CompilerType t) { return (uint)t < compiler_number_of_types ? compilertype2name_tab[t] : NULL; }4344// Handy constants for deciding which compiler mode to use.45enum MethodCompilation {46InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation47BeforeBci = InvocationEntryBci,48AfterBci = -2,49UnwindBci = -3,50AfterExceptionBci = -4,51UnknownBci = -5,52InvalidFrameStateBci = -653};5455// Enumeration to distinguish tiers of compilation56enum CompLevel {57CompLevel_any = -1, // Used for querying the state58CompLevel_all = -1, // Used for changing the state59CompLevel_none = 0, // Interpreter60CompLevel_simple = 1, // C161CompLevel_limited_profile = 2, // C1, invocation & backedge counters62CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo63CompLevel_full_optimization = 4 // C2 or JVMCI64};6566class CompilationModeFlag : AllStatic {67enum class Mode {68NORMAL,69QUICK_ONLY,70HIGH_ONLY,71HIGH_ONLY_QUICK_INTERNAL72};73static Mode _mode;74static void print_error();75public:76static bool initialize();77static bool normal() { return _mode == Mode::NORMAL; }78static bool quick_only() { return _mode == Mode::QUICK_ONLY; }79static bool high_only() { return _mode == Mode::HIGH_ONLY; }80static bool high_only_quick_internal() { return _mode == Mode::HIGH_ONLY_QUICK_INTERNAL; }8182static bool disable_intermediate() { return high_only() || high_only_quick_internal(); }83static bool quick_internal() { return !high_only(); }8485static void set_high_only_quick_internal() { _mode = Mode::HIGH_ONLY_QUICK_INTERNAL; }86static void set_quick_only() { _mode = Mode::QUICK_ONLY; }87static void set_high_only() { _mode = Mode::HIGH_ONLY; }88};8990inline bool is_c1_compile(int comp_level) {91return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;92}9394inline bool is_c2_compile(int comp_level) {95return comp_level == CompLevel_full_optimization;96}9798inline bool is_compile(int comp_level) {99return is_c1_compile(comp_level) || is_c2_compile(comp_level);100}101102103// States of Restricted Transactional Memory usage.104enum RTMState {105NoRTM = 0x2, // Don't use RTM106UseRTM = 0x1, // Use RTM107ProfileRTM = 0x0 // Use RTM with abort ratio calculation108};109110#ifndef INCLUDE_RTM_OPT111#define INCLUDE_RTM_OPT 0112#endif113#if INCLUDE_RTM_OPT114#define RTM_OPT_ONLY(code) code115#else116#define RTM_OPT_ONLY(code)117#endif118119class CompilerConfig : public AllStatic {120public:121// Scale compile thresholds122// Returns threshold scaled with CompileThresholdScaling123static intx scaled_compile_threshold(intx threshold, double scale);124static intx scaled_compile_threshold(intx threshold);125126// Returns freq_log scaled with CompileThresholdScaling127static intx scaled_freq_log(intx freq_log, double scale);128static intx scaled_freq_log(intx freq_log);129130static bool check_args_consistency(bool status);131132static void ergo_initialize();133134// Which compilers are baked in?135constexpr static bool has_c1() { return COMPILER1_PRESENT(true) NOT_COMPILER1(false); }136constexpr static bool has_c2() { return COMPILER2_PRESENT(true) NOT_COMPILER2(false); }137constexpr static bool has_jvmci() { return JVMCI_ONLY(true) NOT_JVMCI(false); }138constexpr static bool has_tiered() { return has_c1() && (has_c2() || has_jvmci()); }139140static bool is_jvmci_compiler() { return JVMCI_ONLY(has_jvmci() && UseJVMCICompiler) NOT_JVMCI(false); }141static bool is_jvmci() { return JVMCI_ONLY(has_jvmci() && EnableJVMCI) NOT_JVMCI(false); }142static bool is_interpreter_only();143144// is_*_only() functions describe situations in which the JVM is in one way or another145// forced to use a particular compiler or their combination. The constraint functions146// deliberately ignore the fact that there may also be methods installed147// through JVMCI (where the JVMCI compiler was invoked not through the broker). Be sure148// to check for those (using is_jvmci()) in situations where it matters.149//150151// Is the JVM in a configuration that permits only c1-compiled methods (level 1,2,3)?152static bool is_c1_only() {153if (!is_interpreter_only() && has_c1()) {154const bool c1_only = !has_c2() && !is_jvmci_compiler();155const bool tiered_degraded_to_c1_only = TieredCompilation && TieredStopAtLevel >= CompLevel_simple && TieredStopAtLevel < CompLevel_full_optimization;156const bool c1_only_compilation_mode = CompilationModeFlag::quick_only();157return c1_only || tiered_degraded_to_c1_only || c1_only_compilation_mode;158}159return false;160}161162static bool is_c1_or_interpreter_only_no_jvmci() {163assert(is_jvmci_compiler() && is_jvmci() || !is_jvmci_compiler(), "JVMCI compiler implies enabled JVMCI");164return !is_jvmci() && (is_interpreter_only() || is_c1_only());165}166167static bool is_c1_only_no_jvmci() {168return is_c1_only() && !is_jvmci();169}170171// Is the JVM in a configuration that permits only c1-compiled methods at level 1?172static bool is_c1_simple_only() {173if (is_c1_only()) {174const bool tiered_degraded_to_level_1 = TieredCompilation && TieredStopAtLevel == CompLevel_simple;175const bool c1_only_compilation_mode = CompilationModeFlag::quick_only();176const bool tiered_off = !TieredCompilation;177return tiered_degraded_to_level_1 || c1_only_compilation_mode || tiered_off;178}179return false;180}181182static bool is_c2_enabled() {183return has_c2() && !is_interpreter_only() && !is_c1_only() && !is_jvmci_compiler();184}185186static bool is_jvmci_compiler_enabled() {187return is_jvmci_compiler() && !is_interpreter_only() && !is_c1_only();188}189// Is the JVM in a configuration that permits only c2-compiled methods?190static bool is_c2_only() {191if (is_c2_enabled()) {192const bool c2_only = !has_c1();193// There is no JVMCI compiler to replace C2 in the broker, and the user (or ergonomics)194// is forcing C1 off.195const bool c2_only_compilation_mode = CompilationModeFlag::high_only();196const bool tiered_off = !TieredCompilation;197return c2_only || c2_only_compilation_mode || tiered_off;198}199return false;200}201202// Is the JVM in a configuration that permits only jvmci-compiled methods?203static bool is_jvmci_compiler_only() {204if (is_jvmci_compiler_enabled()) {205const bool jvmci_compiler_only = !has_c1();206// JVMCI compiler replaced C2 and the user (or ergonomics) is forcing C1 off.207const bool jvmci_only_compilation_mode = CompilationModeFlag::high_only();208const bool tiered_off = !TieredCompilation;209return jvmci_compiler_only || jvmci_only_compilation_mode || tiered_off;210}211return false;212}213214static bool is_c2_or_jvmci_compiler_only() {215return is_c2_only() || is_jvmci_compiler_only();216}217218// Tiered is basically C1 & (C2 | JVMCI) minus all the odd cases with restrictions.219static bool is_tiered() {220assert(is_c1_simple_only() && is_c1_only() || !is_c1_simple_only(), "c1 simple mode must imply c1-only mode");221return has_tiered() && !is_interpreter_only() && !is_c1_only() && !is_c2_or_jvmci_compiler_only();222}223224static bool is_c1_enabled() {225return has_c1() && !is_interpreter_only() && !is_c2_or_jvmci_compiler_only();226}227228static bool is_c1_profiling() {229const bool c1_only_profiling = is_c1_only() && !is_c1_simple_only();230const bool tiered = is_tiered();231return c1_only_profiling || tiered;232}233234235static bool is_c2_or_jvmci_compiler_enabled() {236return is_c2_enabled() || is_jvmci_compiler_enabled();237}238239240private:241static bool is_compilation_mode_selected();242static void set_compilation_policy_flags();243static void set_jvmci_specific_flags();244static void set_legacy_emulation_flags();245static void set_client_emulation_mode_flags();246};247248#endif // SHARE_COMPILER_COMPILERDEFINITIONS_HPP249250251