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_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 
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     kQuicken,             // Verify, quicken, and compile JNI stubs.
37     kSpaceProfile,        // Maximize space savings based on profile.
38     kSpace,               // Maximize space savings.
39     kSpeedProfile,        // Maximize runtime performance based on profile.
40     kSpeed,               // Maximize runtime performance.
41     kEverythingProfile,   // Compile everything capable of being compiled based on profile.
42     kEverything,          // Compile everything capable of being compiled.
43   };
44 
45   static const Filter kDefaultCompilerFilter = kSpeed;
46 
47   // Returns true if an oat file with this compiler filter contains
48   // compiled executable code for bytecode.
49   static bool IsAotCompilationEnabled(Filter filter);
50 
51   // Returns true if an oat file with this compiler filter contains
52   // compiled executable code for bytecode, JNI methods, or quickened dex
53   // bytecode.
54   static bool IsAnyCompilationEnabled(Filter filter);
55 
56   // Returns true if an oat file with this compiler filter contains
57   // compiled executable code for JNI methods.
58   static bool IsJniCompilationEnabled(Filter filter);
59 
60   // Returns true if an oat file with this compiler filter contains
61   // quickened dex bytecode.
62   static bool IsQuickeningCompilationEnabled(Filter filter);
63 
64   // Returns true if this compiler filter requires running verification.
65   static bool IsVerificationEnabled(Filter filter);
66 
67   // Returns true if an oat file with this compiler filter depends on the
68   // boot image checksum.
69   static bool DependsOnImageChecksum(Filter filter);
70 
71   // Returns true if an oat file with this compiler filter depends on a
72   // profile.
73   static bool DependsOnProfile(Filter filter);
74 
75   // Returns a non-profile-guided version of the given filter.
76   static Filter GetNonProfileDependentFilterFrom(Filter filter);
77 
78   // Returns a filter suitable for safe mode.
79   static Filter GetSafeModeFilterFrom(Filter filter);
80 
81   // Returns true if the 'current' compiler filter is considered at least as
82   // good as the 'target' compilation type.
83   // For example: kSpeed is as good as kInterpretOnly, but kInterpretOnly is
84   // not as good as kSpeed.
85   static bool IsAsGoodAs(Filter current, Filter target);
86 
87   // Returns true if 'current' compiler filter is better than 'target' compiler
88   // filter. Compared to IsAsGoodAs, this returns false if the compiler filters are
89   // equal.
90   static bool IsBetter(Filter current, Filter target);
91 
92   // Return the flag name of the given filter.
93   // For example: given kVerifyAtRuntime, returns "verify-at-runtime".
94   // The name returned corresponds to the name accepted by
95   // ParseCompilerFilter.
96   static std::string NameOfFilter(Filter filter);
97 
98   // Parse the compiler filter from the given name.
99   // Returns true and sets filter to the parsed value if name refers to a
100   // valid filter. Returns false if no filter matches that name.
101   // 'filter' must be non-null.
102   static bool ParseCompilerFilter(const char* name, /*out*/Filter* filter);
103 
104  private:
105   DISALLOW_COPY_AND_ASSIGN(CompilerFilter);
106 };
107 
108 std::ostream& operator<<(std::ostream& os, const CompilerFilter::Filter& rhs);
109 
110 }  // namespace art
111 
112 #endif  // ART_RUNTIME_COMPILER_FILTER_H_
113