blob: 781d43aa6e492b579a5ad31746605941f5c375d7 [file] [log] [blame]
Andreas Gampe29d38e72016-03-23 15:31:51 +00001/*
2 * Copyright (C) 2016 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_RUNTIME_COMPILER_FILTER_H_
18#define ART_RUNTIME_COMPILER_FILTER_H_
19
20#include <ostream>
21#include <string>
22#include <vector>
23
24#include "base/macros.h"
25
26namespace art {
27
28class CompilerFilter FINAL {
29 public:
30 // Note: Order here matters. Later filter choices are considered "as good
31 // as" earlier filter choices.
32 enum Filter {
Vladimir Marko8c185bf2016-05-23 15:32:42 +010033 kVerifyNone, // Skip verification but mark all classes as verified anyway.
34 kVerifyAtRuntime, // Delay verication to runtime, do not compile anything.
35 kVerifyProfile, // Verify only the classes in the profile, compile only JNI stubs.
36 kInterpretOnly, // Verify everything, compile only JNI stubs.
Andreas Gampe29d38e72016-03-23 15:31:51 +000037 kTime, // Compile methods, but minimize compilation time.
38 kSpaceProfile, // Maximize space savings based on profile.
39 kSpace, // Maximize space savings.
40 kBalanced, // Good performance return on compilation investment.
41 kSpeedProfile, // Maximize runtime performance based on profile.
Jeff Hao608f2ce2016-10-19 11:17:11 -070042 kLayoutProfile, // Temporary filter for dexlayout. Will be merged with kSpeedProfile.
Andreas Gampe29d38e72016-03-23 15:31:51 +000043 kSpeed, // Maximize runtime performance.
44 kEverythingProfile, // Compile everything capable of being compiled based on profile.
45 kEverything, // Compile everything capable of being compiled.
46 };
47
Richard Uhlerf4b34872016-04-13 11:03:46 -070048 static const Filter kDefaultCompilerFilter = kSpeed;
49
Andreas Gampe29d38e72016-03-23 15:31:51 +000050 // Returns true if an oat file with this compiler filter contains
Vladimir Marko8c185bf2016-05-23 15:32:42 +010051 // compiled executable code for bytecode.
52 static bool IsBytecodeCompilationEnabled(Filter filter);
53
54 // Returns true if an oat file with this compiler filter contains
55 // compiled executable code for JNI methods.
56 static bool IsJniCompilationEnabled(Filter filter);
Andreas Gampe29d38e72016-03-23 15:31:51 +000057
58 // Returns true if this compiler filter requires running verification.
59 static bool IsVerificationEnabled(Filter filter);
60
61 // Returns true if an oat file with this compiler filter depends on the
62 // boot image checksum.
63 static bool DependsOnImageChecksum(Filter filter);
64
65 // Returns true if an oat file with this compiler filter depends on a
66 // profile.
67 static bool DependsOnProfile(Filter filter);
68
Andreas Gampe86a785d2016-03-30 17:19:48 -070069 // Returns a non-profile-guided version of the given filter.
70 static Filter GetNonProfileDependentFilterFrom(Filter filter);
71
Andreas Gampe29d38e72016-03-23 15:31:51 +000072 // Returns true if the 'current' compiler filter is considered at least as
73 // good as the 'target' compilation type.
74 // For example: kSpeed is as good as kInterpretOnly, but kInterpretOnly is
75 // not as good as kSpeed.
76 static bool IsAsGoodAs(Filter current, Filter target);
77
78 // Return the flag name of the given filter.
79 // For example: given kVerifyAtRuntime, returns "verify-at-runtime".
80 // The name returned corresponds to the name accepted by
81 // ParseCompilerFilter.
82 static std::string NameOfFilter(Filter filter);
83
84 // Parse the compiler filter from the given name.
85 // Returns true and sets filter to the parsed value if name refers to a
86 // valid filter. Returns false if no filter matches that name.
87 // 'filter' must be non-null.
88 static bool ParseCompilerFilter(const char* name, /*out*/Filter* filter);
89
90 private:
91 DISALLOW_COPY_AND_ASSIGN(CompilerFilter);
92};
93
94std::ostream& operator<<(std::ostream& os, const CompilerFilter::Filter& rhs);
95
96} // namespace art
97
98#endif // ART_RUNTIME_COMPILER_FILTER_H_