blob: aec7d241f5a676bf6d677cd9c1cf285066b98ace [file] [log] [blame]
Brian Carlstrom6449c622014-02-10 23:48:36 -08001/*
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 Gampedbfe2542014-11-25 22:21:42 -080020#include <ostream>
Ian Rogersc7dd2952014-10-21 23:31:19 -070021#include <string>
22#include <vector>
23
24#include "base/macros.h"
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070025#include "globals.h"
Ian Rogersc7dd2952014-10-21 23:31:19 -070026
Brian Carlstrom6449c622014-02-10 23:48:36 -080027namespace art {
28
Ian Rogersc7dd2952014-10-21 23:31:19 -070029class CompilerOptions FINAL {
Brian Carlstrom6449c622014-02-10 23:48:36 -080030 public:
31 enum CompilerFilter {
Jeff Hao4a200f52014-04-01 14:58:49 -070032 kVerifyNone, // Skip verification and compile nothing except JNI stubs.
33 kInterpretOnly, // Compile nothing except JNI stubs.
Brian Carlstrom6449c622014-02-10 23:48:36 -080034 kSpace, // Maximize space savings.
35 kBalanced, // Try to get the best performance return on compilation investment.
36 kSpeed, // Maximize runtime performance.
Nicolas Geoffray88157ef2014-09-12 10:29:53 +010037 kEverything, // Force compilation (Note: excludes compilation of class initializers).
Igor Murashkind6dee672014-10-16 18:36:16 -070038 kTime, // Compile methods, but minimize compilation time.
Brian Carlstrom6449c622014-02-10 23:48:36 -080039 };
40
41 // Guide heuristics to determine whether to compile method if profile data not available.
Dave Allison39c3bfb2014-01-28 18:33:52 -080042#if ART_SMALL_MODE
Calin Juravlec1b643c2014-05-30 23:44:11 +010043 static const CompilerFilter kDefaultCompilerFilter = kInterpretOnly;
Dave Allison39c3bfb2014-01-28 18:33:52 -080044#else
Brian Carlstrom6449c622014-02-10 23:48:36 -080045 static const CompilerFilter kDefaultCompilerFilter = kSpeed;
Dave Allison39c3bfb2014-01-28 18:33:52 -080046#endif
Brian Carlstrom6449c622014-02-10 23:48:36 -080047 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 Juravlec1b643c2014-05-30 23:44:11 +010052 static constexpr double kDefaultTopKProfileThreshold = 90.0;
Alex Light78382fa2014-06-06 15:45:32 -070053 static const bool kDefaultIncludeDebugSymbols = kIsDebugBuild;
Alex Light53cb16b2014-06-12 11:26:29 -070054 static const bool kDefaultIncludePatchInformation = false;
Brian Carlstrom6449c622014-02-10 23:48:36 -080055
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 Mendellae9fd932014-02-10 16:14:35 -080062 num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold),
Calin Juravlec1b643c2014-05-30 23:44:11 +010063 generate_gdb_information_(false),
Alex Light53cb16b2014-06-12 11:26:29 -070064 include_patch_information_(kDefaultIncludePatchInformation),
Alex Light78382fa2014-06-06 15:45:32 -070065 top_k_profile_threshold_(kDefaultTopKProfileThreshold),
Andreas Gampe5655e842014-06-17 16:36:07 -070066 include_debug_symbols_(kDefaultIncludeDebugSymbols),
Dave Allison69dfe512014-07-11 17:11:58 +000067 implicit_null_checks_(false),
68 implicit_so_checks_(false),
Igor Murashkind6dee672014-10-16 18:36:16 -070069 implicit_suspend_checks_(false),
Ian Rogersc7dd2952014-10-21 23:31:19 -070070 compile_pic_(false),
Brian Carlstrom6449c622014-02-10 23:48:36 -080071#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -070072 sea_ir_mode_(false),
Brian Carlstrom6449c622014-02-10 23:48:36 -080073#endif
Andreas Gampedbfe2542014-11-25 22:21:42 -080074 verbose_methods_(nullptr),
75 init_failure_output_(nullptr) {
Ian Rogersc7dd2952014-10-21 23:31:19 -070076 }
Brian Carlstrom6449c622014-02-10 23:48:36 -080077
78 CompilerOptions(CompilerFilter compiler_filter,
79 size_t huge_method_threshold,
80 size_t large_method_threshold,
81 size_t small_method_threshold,
82 size_t tiny_method_threshold,
Mark Mendellae9fd932014-02-10 16:14:35 -080083 size_t num_dex_methods_threshold,
Calin Juravlec1b643c2014-05-30 23:44:11 +010084 bool generate_gdb_information,
Alex Light53cb16b2014-06-12 11:26:29 -070085 bool include_patch_information,
Alex Light78382fa2014-06-06 15:45:32 -070086 double top_k_profile_threshold,
Andreas Gampe5655e842014-06-17 16:36:07 -070087 bool include_debug_symbols,
Dave Allison69dfe512014-07-11 17:11:58 +000088 bool implicit_null_checks,
89 bool implicit_so_checks,
Igor Murashkind6dee672014-10-16 18:36:16 -070090 bool implicit_suspend_checks,
Ian Rogersc7dd2952014-10-21 23:31:19 -070091 bool compile_pic,
Brian Carlstrom6449c622014-02-10 23:48:36 -080092#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -070093 bool sea_ir_mode,
Brian Carlstrom6449c622014-02-10 23:48:36 -080094#endif
Andreas Gampedbfe2542014-11-25 22:21:42 -080095 const std::vector<std::string>* verbose_methods,
96 std::ostream* init_failure_output
Brian Carlstrom6449c622014-02-10 23:48:36 -080097 ) : // NOLINT(whitespace/parens)
98 compiler_filter_(compiler_filter),
99 huge_method_threshold_(huge_method_threshold),
100 large_method_threshold_(large_method_threshold),
101 small_method_threshold_(small_method_threshold),
102 tiny_method_threshold_(tiny_method_threshold),
Mark Mendellae9fd932014-02-10 16:14:35 -0800103 num_dex_methods_threshold_(num_dex_methods_threshold),
Calin Juravlec1b643c2014-05-30 23:44:11 +0100104 generate_gdb_information_(generate_gdb_information),
Alex Light53cb16b2014-06-12 11:26:29 -0700105 include_patch_information_(include_patch_information),
Alex Light78382fa2014-06-06 15:45:32 -0700106 top_k_profile_threshold_(top_k_profile_threshold),
Andreas Gampe5655e842014-06-17 16:36:07 -0700107 include_debug_symbols_(include_debug_symbols),
Dave Allison69dfe512014-07-11 17:11:58 +0000108 implicit_null_checks_(implicit_null_checks),
109 implicit_so_checks_(implicit_so_checks),
Igor Murashkind6dee672014-10-16 18:36:16 -0700110 implicit_suspend_checks_(implicit_suspend_checks),
Ian Rogersc7dd2952014-10-21 23:31:19 -0700111 compile_pic_(compile_pic),
Brian Carlstrom6449c622014-02-10 23:48:36 -0800112#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -0700113 sea_ir_mode_(sea_ir_mode),
Brian Carlstrom6449c622014-02-10 23:48:36 -0800114#endif
Andreas Gampedbfe2542014-11-25 22:21:42 -0800115 verbose_methods_(verbose_methods),
116 init_failure_output_(init_failure_output) {
Ian Rogersc7dd2952014-10-21 23:31:19 -0700117 }
Brian Carlstrom6449c622014-02-10 23:48:36 -0800118
119 CompilerFilter GetCompilerFilter() const {
120 return compiler_filter_;
121 }
122
123 void SetCompilerFilter(CompilerFilter compiler_filter) {
124 compiler_filter_ = compiler_filter;
125 }
126
Jeff Hao4a200f52014-04-01 14:58:49 -0700127 bool IsCompilationEnabled() const {
128 return ((compiler_filter_ != CompilerOptions::kVerifyNone) &&
129 (compiler_filter_ != CompilerOptions::kInterpretOnly));
130 }
131
132 bool IsVerificationEnabled() const {
133 return (compiler_filter_ != CompilerOptions::kVerifyNone);
134 }
135
Brian Carlstrom6449c622014-02-10 23:48:36 -0800136 size_t GetHugeMethodThreshold() const {
137 return huge_method_threshold_;
138 }
139
140 size_t GetLargeMethodThreshold() const {
141 return large_method_threshold_;
142 }
143
144 size_t GetSmallMethodThreshold() const {
145 return small_method_threshold_;
146 }
147
148 size_t GetTinyMethodThreshold() const {
149 return tiny_method_threshold_;
150 }
151
152 bool IsHugeMethod(size_t num_dalvik_instructions) const {
153 return num_dalvik_instructions > huge_method_threshold_;
154 }
155
156 bool IsLargeMethod(size_t num_dalvik_instructions) const {
157 return num_dalvik_instructions > large_method_threshold_;
158 }
159
160 bool IsSmallMethod(size_t num_dalvik_instructions) const {
161 return num_dalvik_instructions > small_method_threshold_;
162 }
163
164 bool IsTinyMethod(size_t num_dalvik_instructions) const {
165 return num_dalvik_instructions > tiny_method_threshold_;
166 }
167
168 size_t GetNumDexMethodsThreshold() const {
169 return num_dex_methods_threshold_;
170 }
171
Calin Juravlec1b643c2014-05-30 23:44:11 +0100172 double GetTopKProfileThreshold() const {
173 return top_k_profile_threshold_;
174 }
175
Alex Light78382fa2014-06-06 15:45:32 -0700176 bool GetIncludeDebugSymbols() const {
177 return include_debug_symbols_;
178 }
179
Dave Allison69dfe512014-07-11 17:11:58 +0000180 bool GetImplicitNullChecks() const {
181 return implicit_null_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700182 }
183
Dave Allison69dfe512014-07-11 17:11:58 +0000184 bool GetImplicitStackOverflowChecks() const {
185 return implicit_so_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700186 }
187
Dave Allison69dfe512014-07-11 17:11:58 +0000188 bool GetImplicitSuspendChecks() const {
189 return implicit_suspend_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700190 }
191
Brian Carlstrom6449c622014-02-10 23:48:36 -0800192#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -0700193 bool GetSeaIrMode() const {
194 return sea_ir_mode_;
195 }
Brian Carlstrom6449c622014-02-10 23:48:36 -0800196#endif
197
Mark Mendellae9fd932014-02-10 16:14:35 -0800198 bool GetGenerateGDBInformation() const {
199 return generate_gdb_information_;
200 }
201
Alex Light53cb16b2014-06-12 11:26:29 -0700202 bool GetIncludePatchInformation() const {
203 return include_patch_information_;
204 }
205
Igor Murashkind6dee672014-10-16 18:36:16 -0700206 // Should the code be compiled as position independent?
207 bool GetCompilePic() const {
208 return compile_pic_;
209 }
210
Ian Rogersc7dd2952014-10-21 23:31:19 -0700211 bool HasVerboseMethods() const {
212 return verbose_methods_ != nullptr && !verbose_methods_->empty();
213 }
214
215 bool IsVerboseMethod(const std::string& pretty_method) const {
216 for (const std::string& cur_method : *verbose_methods_) {
217 if (pretty_method.find(cur_method) != std::string::npos) {
218 return true;
219 }
220 }
221 return false;
222 }
223
Andreas Gampedbfe2542014-11-25 22:21:42 -0800224 std::ostream* GetInitFailureOutput() const {
225 return init_failure_output_;
226 }
227
Brian Carlstrom6449c622014-02-10 23:48:36 -0800228 private:
229 CompilerFilter compiler_filter_;
Ian Rogersc7dd2952014-10-21 23:31:19 -0700230 const size_t huge_method_threshold_;
231 const size_t large_method_threshold_;
232 const size_t small_method_threshold_;
233 const size_t tiny_method_threshold_;
234 const size_t num_dex_methods_threshold_;
235 const bool generate_gdb_information_;
236 const bool include_patch_information_;
Calin Juravlec1b643c2014-05-30 23:44:11 +0100237 // When using a profile file only the top K% of the profiled samples will be compiled.
Ian Rogersc7dd2952014-10-21 23:31:19 -0700238 const double top_k_profile_threshold_;
239 const bool include_debug_symbols_;
240 const bool implicit_null_checks_;
241 const bool implicit_so_checks_;
242 const bool implicit_suspend_checks_;
243 const bool compile_pic_;
244
Brian Carlstrom6449c622014-02-10 23:48:36 -0800245#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -0700246 const bool sea_ir_mode_;
Brian Carlstrom6449c622014-02-10 23:48:36 -0800247#endif
Ian Rogersc7dd2952014-10-21 23:31:19 -0700248
249 // Vector of methods to have verbose output enabled for.
250 const std::vector<std::string>* const verbose_methods_;
251
Andreas Gampedbfe2542014-11-25 22:21:42 -0800252 // Log initialization of initialization failures to this stream if not null.
253 std::ostream* const init_failure_output_;
254
Ian Rogersc7dd2952014-10-21 23:31:19 -0700255 DISALLOW_COPY_AND_ASSIGN(CompilerOptions);
Brian Carlstrom6449c622014-02-10 23:48:36 -0800256};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700257std::ostream& operator<<(std::ostream& os, const CompilerOptions::CompilerFilter& rhs);
Brian Carlstrom6449c622014-02-10 23:48:36 -0800258
259} // namespace art
260
261#endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_