compiler_options.h revision 5fdcc3c931b70204fd8c491afa66f57f8428490f
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_ 18#define ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_ 19 20#include <ostream> 21#include <string> 22#include <vector> 23 24#include "base/macros.h" 25#include "dex/pass_manager.h" 26#include "globals.h" 27#include "utils.h" 28 29namespace art { 30 31class CompilerOptions FINAL { 32 public: 33 enum CompilerFilter { 34 kVerifyNone, // Skip verification and compile nothing except JNI stubs. 35 kInterpretOnly, // Verify, and compile only JNI stubs. 36 kVerifyAtRuntime, // Only compile JNI stubs and verify at runtime. 37 kSpace, // Maximize space savings. 38 kBalanced, // Try to get the best performance return on compilation investment. 39 kSpeed, // Maximize runtime performance. 40 kEverything, // Force compilation of everything capable of being compiled. 41 kTime, // Compile methods, but minimize compilation time. 42 }; 43 44 // Guide heuristics to determine whether to compile method if profile data not available. 45 static const CompilerFilter kDefaultCompilerFilter = kSpeed; 46 static const size_t kDefaultHugeMethodThreshold = 10000; 47 static const size_t kDefaultLargeMethodThreshold = 600; 48 static const size_t kDefaultSmallMethodThreshold = 60; 49 static const size_t kDefaultTinyMethodThreshold = 20; 50 static const size_t kDefaultNumDexMethodsThreshold = 900; 51 static constexpr double kDefaultTopKProfileThreshold = 90.0; 52 static const bool kDefaultNativeDebuggable = false; 53 static const bool kDefaultGenerateDebugInfo = false; 54 static const bool kDefaultGenerateMiniDebugInfo = false; 55 static const bool kDefaultIncludePatchInformation = false; 56 static const size_t kDefaultInlineDepthLimit = 3; 57 static const size_t kDefaultInlineMaxCodeUnits = 32; 58 static constexpr size_t kUnsetInlineDepthLimit = -1; 59 static constexpr size_t kUnsetInlineMaxCodeUnits = -1; 60 61 // Default inlining settings when the space filter is used. 62 static constexpr size_t kSpaceFilterInlineDepthLimit = 3; 63 static constexpr size_t kSpaceFilterInlineMaxCodeUnits = 10; 64 65 CompilerOptions(); 66 ~CompilerOptions(); 67 68 CompilerOptions(CompilerFilter compiler_filter, 69 size_t huge_method_threshold, 70 size_t large_method_threshold, 71 size_t small_method_threshold, 72 size_t tiny_method_threshold, 73 size_t num_dex_methods_threshold, 74 size_t inline_depth_limit, 75 size_t inline_max_code_units, 76 const DexFile* no_inline_from, 77 bool include_patch_information, 78 double top_k_profile_threshold, 79 bool debuggable, 80 bool generate_debug_info, 81 bool implicit_null_checks, 82 bool implicit_so_checks, 83 bool implicit_suspend_checks, 84 bool compile_pic, 85 const std::vector<std::string>* verbose_methods, 86 std::ostream* init_failure_output, 87 bool abort_on_hard_verifier_failure, 88 const std::string& dump_cfg_file_name, 89 bool dump_cfg_append); 90 91 CompilerFilter GetCompilerFilter() const { 92 return compiler_filter_; 93 } 94 95 void SetCompilerFilter(CompilerFilter compiler_filter) { 96 compiler_filter_ = compiler_filter; 97 } 98 99 bool VerifyAtRuntime() const { 100 return compiler_filter_ == CompilerOptions::kVerifyAtRuntime; 101 } 102 103 bool IsCompilationEnabled() const { 104 return compiler_filter_ != CompilerOptions::kVerifyNone && 105 compiler_filter_ != CompilerOptions::kInterpretOnly && 106 compiler_filter_ != CompilerOptions::kVerifyAtRuntime; 107 } 108 109 bool IsVerificationEnabled() const { 110 return compiler_filter_ != CompilerOptions::kVerifyNone && 111 compiler_filter_ != CompilerOptions::kVerifyAtRuntime; 112 } 113 114 bool NeverVerify() const { 115 return compiler_filter_ == CompilerOptions::kVerifyNone; 116 } 117 118 size_t GetHugeMethodThreshold() const { 119 return huge_method_threshold_; 120 } 121 122 size_t GetLargeMethodThreshold() const { 123 return large_method_threshold_; 124 } 125 126 size_t GetSmallMethodThreshold() const { 127 return small_method_threshold_; 128 } 129 130 size_t GetTinyMethodThreshold() const { 131 return tiny_method_threshold_; 132 } 133 134 bool IsHugeMethod(size_t num_dalvik_instructions) const { 135 return num_dalvik_instructions > huge_method_threshold_; 136 } 137 138 bool IsLargeMethod(size_t num_dalvik_instructions) const { 139 return num_dalvik_instructions > large_method_threshold_; 140 } 141 142 bool IsSmallMethod(size_t num_dalvik_instructions) const { 143 return num_dalvik_instructions > small_method_threshold_; 144 } 145 146 bool IsTinyMethod(size_t num_dalvik_instructions) const { 147 return num_dalvik_instructions > tiny_method_threshold_; 148 } 149 150 size_t GetNumDexMethodsThreshold() const { 151 return num_dex_methods_threshold_; 152 } 153 154 size_t GetInlineDepthLimit() const { 155 return inline_depth_limit_; 156 } 157 158 size_t GetInlineMaxCodeUnits() const { 159 return inline_max_code_units_; 160 } 161 162 double GetTopKProfileThreshold() const { 163 return top_k_profile_threshold_; 164 } 165 166 bool GetDebuggable() const { 167 return debuggable_; 168 } 169 170 bool GetNativeDebuggable() const { 171 return native_debuggable_; 172 } 173 174 // This flag controls whether the compiler collects debugging information. 175 // The other flags control how the information is written to disk. 176 bool GenerateAnyDebugInfo() const { 177 return GetGenerateDebugInfo() || GetGenerateMiniDebugInfo(); 178 } 179 180 bool GetGenerateDebugInfo() const { 181 return generate_debug_info_; 182 } 183 184 bool GetGenerateMiniDebugInfo() const { 185 return generate_mini_debug_info_; 186 } 187 188 bool GetImplicitNullChecks() const { 189 return implicit_null_checks_; 190 } 191 192 bool GetImplicitStackOverflowChecks() const { 193 return implicit_so_checks_; 194 } 195 196 bool GetImplicitSuspendChecks() const { 197 return implicit_suspend_checks_; 198 } 199 200 bool GetIncludePatchInformation() const { 201 return include_patch_information_; 202 } 203 204 // Should the code be compiled as position independent? 205 bool GetCompilePic() const { 206 return compile_pic_; 207 } 208 209 bool HasVerboseMethods() const { 210 return verbose_methods_ != nullptr && !verbose_methods_->empty(); 211 } 212 213 bool IsVerboseMethod(const std::string& pretty_method) const { 214 for (const std::string& cur_method : *verbose_methods_) { 215 if (pretty_method.find(cur_method) != std::string::npos) { 216 return true; 217 } 218 } 219 return false; 220 } 221 222 std::ostream* GetInitFailureOutput() const { 223 return init_failure_output_.get(); 224 } 225 226 const PassManagerOptions* GetPassManagerOptions() const { 227 return &pass_manager_options_; 228 } 229 230 bool AbortOnHardVerifierFailure() const { 231 return abort_on_hard_verifier_failure_; 232 } 233 234 const DexFile* GetNoInlineFromDexFile() const { 235 return no_inline_from_; 236 } 237 238 bool ParseCompilerOption(const StringPiece& option, UsageFn Usage); 239 240 const std::string& GetDumpCfgFileName() const { 241 return dump_cfg_file_name_; 242 } 243 244 bool GetDumpCfgAppend() const { 245 return dump_cfg_append_; 246 } 247 248 private: 249 void ParseDumpInitFailures(const StringPiece& option, UsageFn Usage); 250 void ParsePassOptions(const StringPiece& option, UsageFn Usage); 251 void ParseDumpCfgPasses(const StringPiece& option, UsageFn Usage); 252 void ParsePrintPasses(const StringPiece& option, UsageFn Usage); 253 void ParseDisablePasses(const StringPiece& option, UsageFn Usage); 254 void ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage); 255 void ParseInlineDepthLimit(const StringPiece& option, UsageFn Usage); 256 void ParseNumDexMethods(const StringPiece& option, UsageFn Usage); 257 void ParseTinyMethodMax(const StringPiece& option, UsageFn Usage); 258 void ParseSmallMethodMax(const StringPiece& option, UsageFn Usage); 259 void ParseLargeMethodMax(const StringPiece& option, UsageFn Usage); 260 void ParseHugeMethodMax(const StringPiece& option, UsageFn Usage); 261 262 CompilerFilter compiler_filter_; 263 size_t huge_method_threshold_; 264 size_t large_method_threshold_; 265 size_t small_method_threshold_; 266 size_t tiny_method_threshold_; 267 size_t num_dex_methods_threshold_; 268 size_t inline_depth_limit_; 269 size_t inline_max_code_units_; 270 271 // A dex file from which we should not inline code. 272 const DexFile* no_inline_from_; 273 274 bool include_patch_information_; 275 // When using a profile file only the top K% of the profiled samples will be compiled. 276 double top_k_profile_threshold_; 277 bool debuggable_; 278 bool native_debuggable_; 279 bool generate_debug_info_; 280 bool generate_mini_debug_info_; 281 bool implicit_null_checks_; 282 bool implicit_so_checks_; 283 bool implicit_suspend_checks_; 284 bool compile_pic_; 285 286 // Vector of methods to have verbose output enabled for. 287 const std::vector<std::string>* verbose_methods_; 288 289 PassManagerOptions pass_manager_options_; 290 291 // Abort compilation with an error if we find a class that fails verification with a hard 292 // failure. 293 bool abort_on_hard_verifier_failure_; 294 295 // Log initialization of initialization failures to this stream if not null. 296 std::unique_ptr<std::ostream> init_failure_output_; 297 298 std::string dump_cfg_file_name_; 299 bool dump_cfg_append_; 300 301 friend class Dex2Oat; 302 303 DISALLOW_COPY_AND_ASSIGN(CompilerOptions); 304}; 305std::ostream& operator<<(std::ostream& os, const CompilerOptions::CompilerFilter& rhs); 306 307} // namespace art 308 309#endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_ 310