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 namespace art { 21 22 class CompilerOptions { 23 public: 24 enum CompilerFilter { 25 kVerifyNone, // Skip verification and compile nothing except JNI stubs. 26 kInterpretOnly, // Compile nothing except JNI stubs. 27 kSpace, // Maximize space savings. 28 kBalanced, // Try to get the best performance return on compilation investment. 29 kSpeed, // Maximize runtime performance. 30 kEverything, // Force compilation (Note: excludes compilaton of class initializers). 31 }; 32 33 // Guide heuristics to determine whether to compile method if profile data not available. 34 #if ART_SMALL_MODE 35 static const CompilerFilter kDefaultCompilerFilter = kInterpretOnly; 36 #else 37 static const CompilerFilter kDefaultCompilerFilter = kSpeed; 38 #endif 39 static const size_t kDefaultHugeMethodThreshold = 10000; 40 static const size_t kDefaultLargeMethodThreshold = 600; 41 static const size_t kDefaultSmallMethodThreshold = 60; 42 static const size_t kDefaultTinyMethodThreshold = 20; 43 static const size_t kDefaultNumDexMethodsThreshold = 900; 44 static constexpr double kDefaultTopKProfileThreshold = 90.0; 45 static const bool kDefaultIncludeDebugSymbols = kIsDebugBuild; 46 static const bool kDefaultIncludePatchInformation = false; 47 48 CompilerOptions() : 49 compiler_filter_(kDefaultCompilerFilter), 50 huge_method_threshold_(kDefaultHugeMethodThreshold), 51 large_method_threshold_(kDefaultLargeMethodThreshold), 52 small_method_threshold_(kDefaultSmallMethodThreshold), 53 tiny_method_threshold_(kDefaultTinyMethodThreshold), 54 num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold), 55 generate_gdb_information_(false), 56 include_patch_information_(kDefaultIncludePatchInformation), 57 top_k_profile_threshold_(kDefaultTopKProfileThreshold), 58 include_debug_symbols_(kDefaultIncludeDebugSymbols), 59 implicit_null_checks_(false), 60 implicit_so_checks_(false), 61 implicit_suspend_checks_(false), 62 compile_pic_(false) 63 #ifdef ART_SEA_IR_MODE 64 , sea_ir_mode_(false) 65 #endif 66 {} 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 bool generate_gdb_information, 75 bool include_patch_information, 76 double top_k_profile_threshold, 77 bool include_debug_symbols, 78 bool implicit_null_checks, 79 bool implicit_so_checks, 80 bool implicit_suspend_checks, 81 bool compile_pic 82 #ifdef ART_SEA_IR_MODE 83 , bool sea_ir_mode 84 #endif 85 ) : // NOLINT(whitespace/parens) 86 compiler_filter_(compiler_filter), 87 huge_method_threshold_(huge_method_threshold), 88 large_method_threshold_(large_method_threshold), 89 small_method_threshold_(small_method_threshold), 90 tiny_method_threshold_(tiny_method_threshold), 91 num_dex_methods_threshold_(num_dex_methods_threshold), 92 generate_gdb_information_(generate_gdb_information), 93 include_patch_information_(include_patch_information), 94 top_k_profile_threshold_(top_k_profile_threshold), 95 include_debug_symbols_(include_debug_symbols), 96 implicit_null_checks_(implicit_null_checks), 97 implicit_so_checks_(implicit_so_checks), 98 implicit_suspend_checks_(implicit_suspend_checks), 99 compile_pic_(compile_pic) 100 #ifdef ART_SEA_IR_MODE 101 , sea_ir_mode_(sea_ir_mode) 102 #endif 103 {} 104 105 CompilerFilter GetCompilerFilter() const { 106 return compiler_filter_; 107 } 108 109 void SetCompilerFilter(CompilerFilter compiler_filter) { 110 compiler_filter_ = compiler_filter; 111 } 112 113 bool IsCompilationEnabled() const { 114 return ((compiler_filter_ != CompilerOptions::kVerifyNone) && 115 (compiler_filter_ != CompilerOptions::kInterpretOnly)); 116 } 117 118 bool IsVerificationEnabled() const { 119 return (compiler_filter_ != CompilerOptions::kVerifyNone); 120 } 121 122 size_t GetHugeMethodThreshold() const { 123 return huge_method_threshold_; 124 } 125 126 size_t GetLargeMethodThreshold() const { 127 return large_method_threshold_; 128 } 129 130 size_t GetSmallMethodThreshold() const { 131 return small_method_threshold_; 132 } 133 134 size_t GetTinyMethodThreshold() const { 135 return tiny_method_threshold_; 136 } 137 138 bool IsHugeMethod(size_t num_dalvik_instructions) const { 139 return num_dalvik_instructions > huge_method_threshold_; 140 } 141 142 bool IsLargeMethod(size_t num_dalvik_instructions) const { 143 return num_dalvik_instructions > large_method_threshold_; 144 } 145 146 bool IsSmallMethod(size_t num_dalvik_instructions) const { 147 return num_dalvik_instructions > small_method_threshold_; 148 } 149 150 bool IsTinyMethod(size_t num_dalvik_instructions) const { 151 return num_dalvik_instructions > tiny_method_threshold_; 152 } 153 154 size_t GetNumDexMethodsThreshold() const { 155 return num_dex_methods_threshold_; 156 } 157 158 double GetTopKProfileThreshold() const { 159 return top_k_profile_threshold_; 160 } 161 162 bool GetIncludeDebugSymbols() const { 163 return include_debug_symbols_; 164 } 165 166 bool GetImplicitNullChecks() const { 167 return implicit_null_checks_; 168 } 169 170 void SetImplicitNullChecks(bool new_val) { 171 implicit_null_checks_ = new_val; 172 } 173 174 bool GetImplicitStackOverflowChecks() const { 175 return implicit_so_checks_; 176 } 177 178 void SetImplicitStackOverflowChecks(bool new_val) { 179 implicit_so_checks_ = new_val; 180 } 181 182 bool GetImplicitSuspendChecks() const { 183 return implicit_suspend_checks_; 184 } 185 186 void SetImplicitSuspendChecks(bool new_val) { 187 implicit_suspend_checks_ = new_val; 188 } 189 190 #ifdef ART_SEA_IR_MODE 191 bool GetSeaIrMode(); 192 #endif 193 194 bool GetGenerateGDBInformation() const { 195 return generate_gdb_information_; 196 } 197 198 bool GetIncludePatchInformation() const { 199 return include_patch_information_; 200 } 201 202 // Should the code be compiled as position independent? 203 bool GetCompilePic() const { 204 return compile_pic_; 205 } 206 207 private: 208 CompilerFilter compiler_filter_; 209 size_t huge_method_threshold_; 210 size_t large_method_threshold_; 211 size_t small_method_threshold_; 212 size_t tiny_method_threshold_; 213 size_t num_dex_methods_threshold_; 214 bool generate_gdb_information_; 215 bool include_patch_information_; 216 // When using a profile file only the top K% of the profiled samples will be compiled. 217 double top_k_profile_threshold_; 218 bool include_debug_symbols_; 219 bool implicit_null_checks_; 220 bool implicit_so_checks_; 221 bool implicit_suspend_checks_; 222 bool compile_pic_; 223 #ifdef ART_SEA_IR_MODE 224 bool sea_ir_mode_; 225 #endif 226 }; 227 228 } // namespace art 229 230 #endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_ 231