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