1 /*
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_LIBARTBASE_BASE_COMPILER_FILTER_H_
18 #define ART_LIBARTBASE_BASE_COMPILER_FILTER_H_
19 
20 #include <iosfwd>
21 #include <string>
22 #include <vector>
23 
24 #include "base/macros.h"
25 
26 namespace art {
27 
28 class CompilerFilter final {
29  public:
30   // Note: Order here matters. Later filter choices are considered "as good
31   // as" earlier filter choices.
32   enum Filter {
33     kAssumeVerified,      // Skip verification but mark all classes as verified anyway.
34     kExtract,             // Delay verication to runtime, do not compile anything.
35     kVerify,              // Only verify classes.
36     kSpaceProfile,        // Maximize space savings based on profile.
37     kSpace,               // Maximize space savings.
38     kSpeedProfile,        // Maximize runtime performance based on profile.
39     kSpeed,               // Maximize runtime performance.
40     kEverythingProfile,   // Compile everything capable of being compiled based on profile.
41     kEverything,          // Compile everything capable of being compiled.
42   };
43 
44   static const Filter kDefaultCompilerFilter = kSpeed;
45 
46   // Returns true if an oat file with this compiler filter contains
47   // compiled executable code for bytecode.
48   static bool IsAotCompilationEnabled(Filter filter);
49 
50   // Returns true if an oat file with this compiler filter contains
51   // compiled executable code for bytecode, JNI methods, or quickened dex
52   // bytecode.
53   static bool IsAnyCompilationEnabled(Filter filter);
54 
55   // Returns true if an oat file with this compiler filter contains
56   // compiled executable code for JNI methods.
57   static bool IsJniCompilationEnabled(Filter filter);
58 
59   // Returns true if this compiler filter requires running verification.
60   static bool IsVerificationEnabled(Filter filter);
61 
62   // Returns true if an oat file with this compiler filter depends on the
63   // boot image checksum.
64   static bool DependsOnImageChecksum(Filter filter);
65 
66   // Returns true if an oat file with this compiler filter depends on a
67   // profile.
68   static bool DependsOnProfile(Filter filter);
69 
70   // Returns a non-profile-guided version of the given filter.
71   static Filter GetNonProfileDependentFilterFrom(Filter filter);
72 
73   // Returns a filter suitable for safe mode.
74   static Filter GetSafeModeFilterFrom(Filter filter);
75 
76   // Returns true if the 'current' compiler filter is considered at least as
77   // good as the 'target' compilation type.
78   // For example: kSpeed is as good as kInterpretOnly, but kInterpretOnly is
79   // not as good as kSpeed.
80   static bool IsAsGoodAs(Filter current, Filter target);
81 
82   // Returns true if 'current' compiler filter is better than 'target' compiler
83   // filter. Compared to IsAsGoodAs, this returns false if the compiler filters are
84   // equal.
85   static bool IsBetter(Filter current, Filter target);
86 
87   // Return the flag name of the given filter.
88   // For example: given kVerifyAtRuntime, returns "verify-at-runtime".
89   // The name returned corresponds to the name accepted by
90   // ParseCompilerFilter.
91   static std::string NameOfFilter(Filter filter);
92 
93   // Parse the compiler filter from the given name.
94   // Returns true and sets filter to the parsed value if name refers to a
95   // valid filter. Returns false if no filter matches that name.
96   // 'filter' must be non-null.
97   static bool ParseCompilerFilter(const char* name, /*out*/Filter* filter);
98 
99   static const char* DescribeOptions();
100 
101  private:
102   DISALLOW_COPY_AND_ASSIGN(CompilerFilter);
103 };
104 
105 std::ostream& operator<<(std::ostream& os, const CompilerFilter::Filter& rhs);
106 
107 }  // namespace art
108 
109 #endif  // ART_LIBARTBASE_BASE_COMPILER_FILTER_H_
110