1 /* 2 * Copyright (c) 2016, 2024, 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 25 #ifndef SHARE_COMPILER_COMPILERDEFINITIONS_HPP 26 #define SHARE_COMPILER_COMPILERDEFINITIONS_HPP 27 28 #include "memory/allStatic.hpp" 29 #include "utilities/globalDefinitions.hpp" 30 31 // The (closed set) of concrete compiler classes. 32 enum CompilerType : u1 { 33 compiler_none, 34 compiler_c1, 35 compiler_c2, 36 compiler_jvmci, 37 compiler_number_of_types 38 }; 39 40 extern const char* compilertype2name_tab[compiler_number_of_types]; // Map CompilerType to its name 41 inline const char* compilertype2name(CompilerType t) { return (uint)t < compiler_number_of_types ? compilertype2name_tab[t] : "invalid"; } 42 43 // Handy constants for deciding which compiler mode to use. 44 enum MethodCompilation { 45 InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation 46 BeforeBci = InvocationEntryBci, 47 AfterBci = -2, 48 UnwindBci = -3, 49 AfterExceptionBci = -4, 50 UnknownBci = -5, 51 InvalidFrameStateBci = -6 52 }; 53 54 // Enumeration to distinguish tiers of compilation 55 enum CompLevel : s1 { 56 CompLevel_any = -1, // Used for querying the state 57 CompLevel_all = -1, // Used for changing the state 58 CompLevel_none = 0, // Interpreter 59 CompLevel_simple = 1, // C1 60 CompLevel_limited_profile = 2, // C1, invocation & backedge counters 61 CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo 62 CompLevel_full_optimization = 4, // C2 or JVMCI 63 CompLevel_count = 4 64 }; 65 66 class CompilationModeFlag : AllStatic { 67 enum class Mode { 68 NORMAL, 69 QUICK_ONLY, 70 HIGH_ONLY, 71 HIGH_ONLY_QUICK_INTERNAL 72 }; 73 static Mode _mode; 74 static void print_error(); 75 public: 76 static bool initialize(); 77 static bool normal() { return _mode == Mode::NORMAL; } 78 static bool quick_only() { return _mode == Mode::QUICK_ONLY; } 79 static bool high_only() { return _mode == Mode::HIGH_ONLY; } 80 static bool high_only_quick_internal() { return _mode == Mode::HIGH_ONLY_QUICK_INTERNAL; } 81 82 static bool disable_intermediate() { return high_only() || high_only_quick_internal(); } 83 static bool quick_internal() { return !high_only(); } 84 85 static void set_high_only_quick_internal() { _mode = Mode::HIGH_ONLY_QUICK_INTERNAL; } 86 static void set_quick_only() { _mode = Mode::QUICK_ONLY; } 87 static void set_high_only() { _mode = Mode::HIGH_ONLY; } 88 }; 89 90 inline bool is_c1_compile(int comp_level) { 91 return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization; 92 } 93 94 inline bool is_c2_compile(int comp_level) { 95 return comp_level == CompLevel_full_optimization; 96 } 97 98 inline bool is_compile(int comp_level) { 99 return is_c1_compile(comp_level) || is_c2_compile(comp_level); 100 } 101 102 class CompilerConfig : public AllStatic { 103 public: 104 // Scale compile thresholds 105 // Returns threshold scaled with CompileThresholdScaling 106 static intx scaled_compile_threshold(intx threshold, double scale); 107 static intx scaled_compile_threshold(intx threshold); 108 static intx jvmflag_scaled_compile_threshold(intx threshold); 109 110 // Returns freq_log scaled with CompileThresholdScaling 111 static intx scaled_freq_log(intx freq_log, double scale); 112 static intx scaled_freq_log(intx freq_log); 113 static intx jvmflag_scaled_freq_log(intx freq_log); 114 115 static bool check_args_consistency(bool status); 116 117 static void ergo_initialize(); 118 119 // Which compilers are baked in? 120 constexpr static bool has_c1() { return COMPILER1_PRESENT(true) NOT_COMPILER1(false); } 121 constexpr static bool has_c2() { return COMPILER2_PRESENT(true) NOT_COMPILER2(false); } 122 constexpr static bool has_jvmci() { return JVMCI_ONLY(true) NOT_JVMCI(false); } 123 constexpr static bool has_tiered() { return has_c1() && (has_c2() || has_jvmci()); } 124 125 inline static bool is_jvmci_compiler(); 126 inline static bool is_jvmci(); 127 inline static bool is_interpreter_only(); 128 129 // is_*_only() functions describe situations in which the JVM is in one way or another 130 // forced to use a particular compiler or their combination. The constraint functions 131 // deliberately ignore the fact that there may also be methods installed 132 // through JVMCI (where the JVMCI compiler was invoked not through the broker). Be sure 133 // to check for those (using is_jvmci()) in situations where it matters. 134 135 inline static bool is_tiered(); 136 137 inline static bool is_c1_enabled(); 138 inline static bool is_c1_only(); 139 inline static bool is_c1_simple_only(); 140 inline static bool is_c1_or_interpreter_only_no_jvmci(); 141 inline static bool is_c1_only_no_jvmci(); 142 inline static bool is_c1_profiling(); 143 144 inline static bool is_jvmci_compiler_enabled(); 145 inline static bool is_jvmci_compiler_only(); 146 147 inline static bool is_c2_only(); 148 inline static bool is_c2_enabled(); 149 inline static bool is_c2_or_jvmci_compiler_only(); 150 inline static bool is_c2_or_jvmci_compiler_enabled(); 151 152 inline static size_t min_code_cache_size(); 153 154 private: 155 static bool is_compilation_mode_selected(); 156 static void set_compilation_policy_flags(); 157 static void set_jvmci_specific_flags(); 158 static void set_legacy_emulation_flags(); 159 static void set_client_emulation_mode_flags(); 160 }; 161 162 #endif // SHARE_COMPILER_COMPILERDEFINITIONS_HPP