1 /*
  2  * Copyright (c) 1998, 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_COMPILERORACLE_HPP
 26 #define SHARE_COMPILER_COMPILERORACLE_HPP
 27 
 28 #include "memory/allStatic.hpp"
 29 #include "oops/oopsHierarchy.hpp"
 30 
 31 class methodHandle;
 32 
 33 
 34 // CompilerOracle is an interface for turning on and off compilation
 35 // for some methods
 36 
 37 //       OPTION_TYPES: type, name
 38 #define OPTION_TYPES(type) \
 39   type(Intx, "intx") \
 40   type(Uintx, "uintx") \
 41   type(Bool, "bool") \
 42   type(Ccstr, "ccstr") \
 43   type(Ccstrlist, "ccstrlist") \
 44   type(Double, "double")
 45 
 46 //       COMPILECOMMAND_OPTIONS: option, name, variant, type
 47 #define COMPILECOMMAND_OPTIONS(option) \
 48   option(Help,  "help",  Unknown) \
 49   option(Quiet, "quiet", Unknown) \
 50   option(Log, "log", Bool) \
 51   option(Print, "print", Bool) \
 52   option(Inline,  "inline", Bool) \
 53   option(DontInline,  "dontinline", Bool) \
 54   option(Blackhole,  "blackhole", Bool) \
 55   option(CompileOnly, "compileonly", Bool)\
 56   option(Exclude, "exclude", Bool) \
 57   option(Break, "break", Bool) \
 58   option(BreakAtExecute, "BreakAtExecute", Bool) \
 59   option(BreakAtCompile, "BreakAtCompile", Bool) \
 60   option(MemLimit, "MemLimit", Intx) \
 61   option(MemStat, "MemStat", Uintx) \
 62   option(PrintAssembly, "PrintAssembly", Bool) \
 63   option(PrintCompilation, "PrintCompilation", Bool) \
 64   option(PrintInlining, "PrintInlining", Bool) \
 65   option(PrintIntrinsics, "PrintIntrinsics", Bool) \
 66   option(PrintNMethods, "PrintNMethods", Bool)   \
 67   option(PrintOptoAssembly, "PrintOptoAssembly", Bool) \
 68   option(PrintDebugInfo,    "PrintDebugInfo",    Bool) \
 69   option(PrintRelocations,  "PrintRelocations",  Bool) \
 70   option(PrintDependencies, "PrintDependencies", Bool) \
 71   option(BackgroundCompilation, "BackgroundCompilation", Bool) \
 72   option(RepeatCompilation, "RepeatCompilation", Intx) \
 73   option(ReplayInline,   "ReplayInline", Bool) \
 74   option(DumpReplay,     "DumpReplay", Bool) \
 75   option(DumpInline,     "DumpInline", Bool) \
 76   option(CompileThresholdScaling, "CompileThresholdScaling", Double) \
 77   option(ControlIntrinsic,  "ControlIntrinsic",  Ccstrlist) \
 78   option(DisableIntrinsic,  "DisableIntrinsic",  Ccstrlist) \
 79   option(NoRTMLockEliding,  "NoRTMLockEliding",  Bool) \
 80   option(UseRTMLockEliding, "UseRTMLockEliding", Bool) \
 81   option(BlockLayoutByFrequency, "BlockLayoutByFrequency", Bool) \
 82   option(TraceOptoPipelining, "TraceOptoPipelining", Bool) \
 83   option(TraceOptoOutput, "TraceOptoOutput", Bool) \
 84   option(TraceSpilling, "TraceSpilling", Bool) \
 85 NOT_PRODUCT(option(TraceEscapeAnalysis, "TraceEscapeAnalysis", Bool)) \
 86 NOT_PRODUCT(option(PrintIdeal, "PrintIdeal", Bool))  \
 87 NOT_PRODUCT(option(PrintIdealPhase, "PrintIdealPhase", Ccstrlist)) \
 88 NOT_PRODUCT(option(IGVPrintLevel, "IGVPrintLevel", Intx)) \
 89 NOT_PRODUCT(option(TraceAutoVectorization, "TraceAutoVectorization", Ccstrlist)) \
 90   option(Vectorize, "Vectorize", Bool) \
 91   option(CloneMapDebug, "CloneMapDebug", Bool) \
 92   option(IncrementalInlineForceCleanup, "IncrementalInlineForceCleanup", Bool) \
 93   option(MaxNodeLimit, "MaxNodeLimit", Intx)  \
 94   option(PrecompileRecorded, "PrecompileRecorded", Uintx) \
 95   option(DontPrecompile, "DontPrecompile", Bool) \
 96   option(DontPreload, "DontPreload", Bool) \
 97   option(IgnorePrecompiled, "IgnorePrecompiled", Bool) \
 98   option(IgnoreRecordedProfile, "IgnoreRecordedProfile", Bool) \
 99   option(TooManyTrapsAtBCI, "TooManyTrapsAtBCI", Ccstrlist) \
100 NOT_PRODUCT(option(TestOptionInt,    "TestOptionInt",    Intx)) \
101 NOT_PRODUCT(option(TestOptionUint,   "TestOptionUint",   Uintx)) \
102 NOT_PRODUCT(option(TestOptionBool,   "TestOptionBool",   Bool)) \
103 NOT_PRODUCT(option(TestOptionBool2,  "TestOptionBool2",  Bool)) \
104 NOT_PRODUCT(option(TestOptionStr,    "TestOptionStr",    Ccstr)) \
105 NOT_PRODUCT(option(TestOptionList,   "TestOptionList",   Ccstrlist)) \
106 NOT_PRODUCT(option(TestOptionDouble, "TestOptionDouble", Double)) \
107   option(Option, "option", Unknown) \
108   option(Unknown, "unknown", Unknown)
109 
110 enum class CompileCommand {
111   #define enum_of_options(option, name, ctype) option,
112     COMPILECOMMAND_OPTIONS(enum_of_options)
113   #undef enum_of_options
114   Count
115 };
116 
117 enum class OptionType {
118 #define enum_of_types(type, name) type,
119     OPTION_TYPES(enum_of_types)
120 #undef enum_of_types
121     Unknown
122 };
123 
124 enum class MemStatAction {
125   collect = 1, print = 2
126 };
127 
128 class CompilerOracle : AllStatic {
129  private:
130   static bool _quiet;
131   static void print_parse_error(char* error_msg, char* original_line);
132   static void print_command(enum CompileCommand option, const char* name, enum OptionType type);
133 
134  public:
135   // True if the command file has been specified or is implicit
136   static bool has_command_file();
137 
138   // Reads from file and adds to lists
139   static bool parse_from_file();
140 
141   // Tells whether we to exclude compilation of method
142   static bool should_exclude(const methodHandle& method);
143   static bool be_quiet() { return _quiet; }
144 
145   // Tells whether we want to inline this method
146   static bool should_inline(const methodHandle& method);
147 
148   // Tells whether we want to disallow inlining of this method
149   static bool should_not_inline(const methodHandle& method);
150 
151   // Tells whether this method changes Thread.currentThread()
152   static bool changes_current_thread(const methodHandle& method);
153 
154   // Tells whether we should print the assembly for this method
155   static bool should_print(const methodHandle& method);
156 
157   // Tells whether we should log the compilation data for this method
158   static bool should_log(const methodHandle& method);
159 
160   // Tells whether to break when compiling method
161   static bool should_break_at(const methodHandle& method);
162 
163   // Tells whether there are any methods to print for print_method_statistics()
164   static bool should_print_methods();
165 
166   // Tells whether there are any methods to (collect|collect+print) memory statistics for
167   static bool should_collect_memstat();
168   static bool should_print_final_memstat_report();
169 
170   // Tags the method as blackhole candidate, if possible.
171   static void tag_blackhole_if_possible(const methodHandle& method);
172 
173   // A wrapper for checking bool options
174   static bool has_option(const methodHandle& method, enum CompileCommand option);
175 
176   // Check if method has option and value set. If yes, overwrite value and return true,
177   // otherwise leave value unchanged and return false.
178   template<typename T>
179   static bool has_option_value(const methodHandle& method, enum CompileCommand option, T& value);
180 
181   // This check is currently only needed by whitebox API
182   template<typename T>
183   static bool option_matches_type(enum CompileCommand option, T& value);
184 
185   // Reads from string instead of file
186   static bool parse_from_string(const char* option_string, bool (*parser)(char*));
187   static bool parse_from_line(char* line);
188   static bool parse_compile_only(char* line);
189 
190   // Fast check if there is any option set that compile control needs to know about
191   static bool has_any_command_set();
192 
193   // convert a string to a proper compilecommand option - used from whitebox.
194   // returns CompileCommand::Unknown on names not matching an option.
195   static enum CompileCommand string_to_option(const char* name);
196 
197   // convert a string to a proper compilecommand option
198   // returns CompileCommand::Unknown if name is not an option.
199   static enum CompileCommand parse_option_name(const char* name);
200 
201   // convert a string to a proper option type
202   // returns OptionType::Unknown on strings not matching an option type.
203   static enum OptionType parse_option_type(const char* type_str);
204 };
205 
206 #endif // SHARE_COMPILER_COMPILERORACLE_HPP