blob: 5466d4596a61b33ef6f4d184b26c1a3954e82fcb [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),
Nicolas Geoffray27e28d32015-01-23 09:36:52 +000067 implicit_null_checks_(true),
68 implicit_so_checks_(true),
Igor Murashkind6dee672014-10-16 18:36:16 -070069 implicit_suspend_checks_(false),
Ian Rogersc7dd2952014-10-21 23:31:19 -070070 compile_pic_(false),
Andreas Gampedbfe2542014-11-25 22:21:42 -080071 verbose_methods_(nullptr),
72 init_failure_output_(nullptr) {
Ian Rogersc7dd2952014-10-21 23:31:19 -070073 }
Brian Carlstrom6449c622014-02-10 23:48:36 -080074
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 Mendellae9fd932014-02-10 16:14:35 -080080 size_t num_dex_methods_threshold,
Calin Juravlec1b643c2014-05-30 23:44:11 +010081 bool generate_gdb_information,
Alex Light53cb16b2014-06-12 11:26:29 -070082 bool include_patch_information,
Alex Light78382fa2014-06-06 15:45:32 -070083 double top_k_profile_threshold,
Andreas Gampe5655e842014-06-17 16:36:07 -070084 bool include_debug_symbols,
Dave Allison69dfe512014-07-11 17:11:58 +000085 bool implicit_null_checks,
86 bool implicit_so_checks,
Igor Murashkind6dee672014-10-16 18:36:16 -070087 bool implicit_suspend_checks,
Ian Rogersc7dd2952014-10-21 23:31:19 -070088 bool compile_pic,
Andreas Gampedbfe2542014-11-25 22:21:42 -080089 const std::vector<std::string>* verbose_methods,
90 std::ostream* init_failure_output
Brian Carlstrom6449c622014-02-10 23:48:36 -080091 ) : // 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 Mendellae9fd932014-02-10 16:14:35 -080097 num_dex_methods_threshold_(num_dex_methods_threshold),
Calin Juravlec1b643c2014-05-30 23:44:11 +010098 generate_gdb_information_(generate_gdb_information),
Alex Light53cb16b2014-06-12 11:26:29 -070099 include_patch_information_(include_patch_information),
Alex Light78382fa2014-06-06 15:45:32 -0700100 top_k_profile_threshold_(top_k_profile_threshold),
Andreas Gampe5655e842014-06-17 16:36:07 -0700101 include_debug_symbols_(include_debug_symbols),
Dave Allison69dfe512014-07-11 17:11:58 +0000102 implicit_null_checks_(implicit_null_checks),
103 implicit_so_checks_(implicit_so_checks),
Igor Murashkind6dee672014-10-16 18:36:16 -0700104 implicit_suspend_checks_(implicit_suspend_checks),
Ian Rogersc7dd2952014-10-21 23:31:19 -0700105 compile_pic_(compile_pic),
Andreas Gampedbfe2542014-11-25 22:21:42 -0800106 verbose_methods_(verbose_methods),
107 init_failure_output_(init_failure_output) {
Ian Rogersc7dd2952014-10-21 23:31:19 -0700108 }
Brian Carlstrom6449c622014-02-10 23:48:36 -0800109
110 CompilerFilter GetCompilerFilter() const {
111 return compiler_filter_;
112 }
113
114 void SetCompilerFilter(CompilerFilter compiler_filter) {
115 compiler_filter_ = compiler_filter;
116 }
117
Jeff Hao4a200f52014-04-01 14:58:49 -0700118 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 Carlstrom6449c622014-02-10 23:48:36 -0800127 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 Juravlec1b643c2014-05-30 23:44:11 +0100163 double GetTopKProfileThreshold() const {
164 return top_k_profile_threshold_;
165 }
166
Alex Light78382fa2014-06-06 15:45:32 -0700167 bool GetIncludeDebugSymbols() const {
168 return include_debug_symbols_;
169 }
170
Dave Allison69dfe512014-07-11 17:11:58 +0000171 bool GetImplicitNullChecks() const {
172 return implicit_null_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700173 }
174
Dave Allison69dfe512014-07-11 17:11:58 +0000175 bool GetImplicitStackOverflowChecks() const {
176 return implicit_so_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700177 }
178
Dave Allison69dfe512014-07-11 17:11:58 +0000179 bool GetImplicitSuspendChecks() const {
180 return implicit_suspend_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700181 }
182
Mark Mendellae9fd932014-02-10 16:14:35 -0800183 bool GetGenerateGDBInformation() const {
184 return generate_gdb_information_;
185 }
186
Alex Light53cb16b2014-06-12 11:26:29 -0700187 bool GetIncludePatchInformation() const {
188 return include_patch_information_;
189 }
190
Igor Murashkind6dee672014-10-16 18:36:16 -0700191 // Should the code be compiled as position independent?
192 bool GetCompilePic() const {
193 return compile_pic_;
194 }
195
Ian Rogersc7dd2952014-10-21 23:31:19 -0700196 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 Gampedbfe2542014-11-25 22:21:42 -0800209 std::ostream* GetInitFailureOutput() const {
210 return init_failure_output_;
211 }
212
Brian Carlstrom6449c622014-02-10 23:48:36 -0800213 private:
214 CompilerFilter compiler_filter_;
Ian Rogersc7dd2952014-10-21 23:31:19 -0700215 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 Juravlec1b643c2014-05-30 23:44:11 +0100222 // When using a profile file only the top K% of the profiled samples will be compiled.
Ian Rogersc7dd2952014-10-21 23:31:19 -0700223 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 Rogersc7dd2952014-10-21 23:31:19 -0700230 // Vector of methods to have verbose output enabled for.
231 const std::vector<std::string>* const verbose_methods_;
232
Andreas Gampedbfe2542014-11-25 22:21:42 -0800233 // Log initialization of initialization failures to this stream if not null.
234 std::ostream* const init_failure_output_;
235
Ian Rogersc7dd2952014-10-21 23:31:19 -0700236 DISALLOW_COPY_AND_ASSIGN(CompilerOptions);
Brian Carlstrom6449c622014-02-10 23:48:36 -0800237};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700238std::ostream& operator<<(std::ostream& os, const CompilerOptions::CompilerFilter& rhs);
Brian Carlstrom6449c622014-02-10 23:48:36 -0800239
240} // namespace art
241
242#endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_