Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 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 | |
Andreas Gampe | dbfe254 | 2014-11-25 22:21:42 -0800 | [diff] [blame] | 20 | #include <ostream> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include "base/macros.h" |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 25 | #include "globals.h" |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 26 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 27 | namespace art { |
| 28 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 29 | class CompilerOptions FINAL { |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 30 | public: |
| 31 | enum CompilerFilter { |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 32 | kVerifyNone, // Skip verification and compile nothing except JNI stubs. |
| 33 | kInterpretOnly, // Compile nothing except JNI stubs. |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 34 | kSpace, // Maximize space savings. |
| 35 | kBalanced, // Try to get the best performance return on compilation investment. |
| 36 | kSpeed, // Maximize runtime performance. |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 37 | kEverything, // Force compilation (Note: excludes compilation of class initializers). |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 38 | kTime, // Compile methods, but minimize compilation time. |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | // Guide heuristics to determine whether to compile method if profile data not available. |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 42 | #if ART_SMALL_MODE |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 43 | static const CompilerFilter kDefaultCompilerFilter = kInterpretOnly; |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 44 | #else |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 45 | static const CompilerFilter kDefaultCompilerFilter = kSpeed; |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 46 | #endif |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 47 | static const size_t kDefaultHugeMethodThreshold = 10000; |
| 48 | static const size_t kDefaultLargeMethodThreshold = 600; |
| 49 | static const size_t kDefaultSmallMethodThreshold = 60; |
| 50 | static const size_t kDefaultTinyMethodThreshold = 20; |
| 51 | static const size_t kDefaultNumDexMethodsThreshold = 900; |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 52 | static constexpr double kDefaultTopKProfileThreshold = 90.0; |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 53 | static const bool kDefaultIncludeDebugSymbols = kIsDebugBuild; |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 54 | static const bool kDefaultIncludePatchInformation = false; |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 55 | |
| 56 | CompilerOptions() : |
| 57 | compiler_filter_(kDefaultCompilerFilter), |
| 58 | huge_method_threshold_(kDefaultHugeMethodThreshold), |
| 59 | large_method_threshold_(kDefaultLargeMethodThreshold), |
| 60 | small_method_threshold_(kDefaultSmallMethodThreshold), |
| 61 | tiny_method_threshold_(kDefaultTinyMethodThreshold), |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 62 | num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold), |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 63 | generate_gdb_information_(false), |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 64 | include_patch_information_(kDefaultIncludePatchInformation), |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 65 | top_k_profile_threshold_(kDefaultTopKProfileThreshold), |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 66 | include_debug_symbols_(kDefaultIncludeDebugSymbols), |
Nicolas Geoffray | 27e28d3 | 2015-01-23 09:36:52 +0000 | [diff] [blame] | 67 | implicit_null_checks_(true), |
| 68 | implicit_so_checks_(true), |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 69 | implicit_suspend_checks_(false), |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 70 | compile_pic_(false), |
Andreas Gampe | dbfe254 | 2014-11-25 22:21:42 -0800 | [diff] [blame] | 71 | verbose_methods_(nullptr), |
| 72 | init_failure_output_(nullptr) { |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 73 | } |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 74 | |
| 75 | CompilerOptions(CompilerFilter compiler_filter, |
| 76 | size_t huge_method_threshold, |
| 77 | size_t large_method_threshold, |
| 78 | size_t small_method_threshold, |
| 79 | size_t tiny_method_threshold, |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 80 | size_t num_dex_methods_threshold, |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 81 | bool generate_gdb_information, |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 82 | bool include_patch_information, |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 83 | double top_k_profile_threshold, |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 84 | bool include_debug_symbols, |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 85 | bool implicit_null_checks, |
| 86 | bool implicit_so_checks, |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 87 | bool implicit_suspend_checks, |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 88 | bool compile_pic, |
Andreas Gampe | dbfe254 | 2014-11-25 22:21:42 -0800 | [diff] [blame] | 89 | const std::vector<std::string>* verbose_methods, |
| 90 | std::ostream* init_failure_output |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 91 | ) : // NOLINT(whitespace/parens) |
| 92 | compiler_filter_(compiler_filter), |
| 93 | huge_method_threshold_(huge_method_threshold), |
| 94 | large_method_threshold_(large_method_threshold), |
| 95 | small_method_threshold_(small_method_threshold), |
| 96 | tiny_method_threshold_(tiny_method_threshold), |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 97 | num_dex_methods_threshold_(num_dex_methods_threshold), |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 98 | generate_gdb_information_(generate_gdb_information), |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 99 | include_patch_information_(include_patch_information), |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 100 | top_k_profile_threshold_(top_k_profile_threshold), |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 101 | include_debug_symbols_(include_debug_symbols), |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 102 | implicit_null_checks_(implicit_null_checks), |
| 103 | implicit_so_checks_(implicit_so_checks), |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 104 | implicit_suspend_checks_(implicit_suspend_checks), |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 105 | compile_pic_(compile_pic), |
Andreas Gampe | dbfe254 | 2014-11-25 22:21:42 -0800 | [diff] [blame] | 106 | verbose_methods_(verbose_methods), |
| 107 | init_failure_output_(init_failure_output) { |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 108 | } |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 109 | |
| 110 | CompilerFilter GetCompilerFilter() const { |
| 111 | return compiler_filter_; |
| 112 | } |
| 113 | |
| 114 | void SetCompilerFilter(CompilerFilter compiler_filter) { |
| 115 | compiler_filter_ = compiler_filter; |
| 116 | } |
| 117 | |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 118 | bool IsCompilationEnabled() const { |
| 119 | return ((compiler_filter_ != CompilerOptions::kVerifyNone) && |
| 120 | (compiler_filter_ != CompilerOptions::kInterpretOnly)); |
| 121 | } |
| 122 | |
| 123 | bool IsVerificationEnabled() const { |
| 124 | return (compiler_filter_ != CompilerOptions::kVerifyNone); |
| 125 | } |
| 126 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 127 | size_t GetHugeMethodThreshold() const { |
| 128 | return huge_method_threshold_; |
| 129 | } |
| 130 | |
| 131 | size_t GetLargeMethodThreshold() const { |
| 132 | return large_method_threshold_; |
| 133 | } |
| 134 | |
| 135 | size_t GetSmallMethodThreshold() const { |
| 136 | return small_method_threshold_; |
| 137 | } |
| 138 | |
| 139 | size_t GetTinyMethodThreshold() const { |
| 140 | return tiny_method_threshold_; |
| 141 | } |
| 142 | |
| 143 | bool IsHugeMethod(size_t num_dalvik_instructions) const { |
| 144 | return num_dalvik_instructions > huge_method_threshold_; |
| 145 | } |
| 146 | |
| 147 | bool IsLargeMethod(size_t num_dalvik_instructions) const { |
| 148 | return num_dalvik_instructions > large_method_threshold_; |
| 149 | } |
| 150 | |
| 151 | bool IsSmallMethod(size_t num_dalvik_instructions) const { |
| 152 | return num_dalvik_instructions > small_method_threshold_; |
| 153 | } |
| 154 | |
| 155 | bool IsTinyMethod(size_t num_dalvik_instructions) const { |
| 156 | return num_dalvik_instructions > tiny_method_threshold_; |
| 157 | } |
| 158 | |
| 159 | size_t GetNumDexMethodsThreshold() const { |
| 160 | return num_dex_methods_threshold_; |
| 161 | } |
| 162 | |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 163 | double GetTopKProfileThreshold() const { |
| 164 | return top_k_profile_threshold_; |
| 165 | } |
| 166 | |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 167 | bool GetIncludeDebugSymbols() const { |
| 168 | return include_debug_symbols_; |
| 169 | } |
| 170 | |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 171 | bool GetImplicitNullChecks() const { |
| 172 | return implicit_null_checks_; |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 175 | bool GetImplicitStackOverflowChecks() const { |
| 176 | return implicit_so_checks_; |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 179 | bool GetImplicitSuspendChecks() const { |
| 180 | return implicit_suspend_checks_; |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 183 | bool GetGenerateGDBInformation() const { |
| 184 | return generate_gdb_information_; |
| 185 | } |
| 186 | |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 187 | bool GetIncludePatchInformation() const { |
| 188 | return include_patch_information_; |
| 189 | } |
| 190 | |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 191 | // Should the code be compiled as position independent? |
| 192 | bool GetCompilePic() const { |
| 193 | return compile_pic_; |
| 194 | } |
| 195 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 196 | bool HasVerboseMethods() const { |
| 197 | return verbose_methods_ != nullptr && !verbose_methods_->empty(); |
| 198 | } |
| 199 | |
| 200 | bool IsVerboseMethod(const std::string& pretty_method) const { |
| 201 | for (const std::string& cur_method : *verbose_methods_) { |
| 202 | if (pretty_method.find(cur_method) != std::string::npos) { |
| 203 | return true; |
| 204 | } |
| 205 | } |
| 206 | return false; |
| 207 | } |
| 208 | |
Andreas Gampe | dbfe254 | 2014-11-25 22:21:42 -0800 | [diff] [blame] | 209 | std::ostream* GetInitFailureOutput() const { |
| 210 | return init_failure_output_; |
| 211 | } |
| 212 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 213 | private: |
| 214 | CompilerFilter compiler_filter_; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 215 | const size_t huge_method_threshold_; |
| 216 | const size_t large_method_threshold_; |
| 217 | const size_t small_method_threshold_; |
| 218 | const size_t tiny_method_threshold_; |
| 219 | const size_t num_dex_methods_threshold_; |
| 220 | const bool generate_gdb_information_; |
| 221 | const bool include_patch_information_; |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 222 | // When using a profile file only the top K% of the profiled samples will be compiled. |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 223 | const double top_k_profile_threshold_; |
| 224 | const bool include_debug_symbols_; |
| 225 | const bool implicit_null_checks_; |
| 226 | const bool implicit_so_checks_; |
| 227 | const bool implicit_suspend_checks_; |
| 228 | const bool compile_pic_; |
| 229 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 230 | // Vector of methods to have verbose output enabled for. |
| 231 | const std::vector<std::string>* const verbose_methods_; |
| 232 | |
Andreas Gampe | dbfe254 | 2014-11-25 22:21:42 -0800 | [diff] [blame] | 233 | // Log initialization of initialization failures to this stream if not null. |
| 234 | std::ostream* const init_failure_output_; |
| 235 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 236 | DISALLOW_COPY_AND_ASSIGN(CompilerOptions); |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 237 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 238 | std::ostream& operator<<(std::ostream& os, const CompilerOptions::CompilerFilter& rhs); |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 239 | |
| 240 | } // namespace art |
| 241 | |
| 242 | #endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_ |