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