• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "compiler_filter.h"
18 
19 #include <ostream>
20 
21 #include "base/utils.h"
22 
23 namespace art {
24 
IsAotCompilationEnabled(Filter filter)25 bool CompilerFilter::IsAotCompilationEnabled(Filter filter) {
26   switch (filter) {
27     case CompilerFilter::kAssumeVerified:
28     case CompilerFilter::kVerify: return false;
29 
30     case CompilerFilter::kSpaceProfile:
31     case CompilerFilter::kSpace:
32     case CompilerFilter::kSpeedProfile:
33     case CompilerFilter::kSpeed:
34     case CompilerFilter::kEverythingProfile:
35     case CompilerFilter::kEverything: return true;
36   }
37   UNREACHABLE();
38 }
39 
IsJniCompilationEnabled(Filter filter)40 bool CompilerFilter::IsJniCompilationEnabled(Filter filter) {
41   switch (filter) {
42     case CompilerFilter::kAssumeVerified:
43     case CompilerFilter::kVerify: return false;
44 
45     case CompilerFilter::kSpaceProfile:
46     case CompilerFilter::kSpace:
47     case CompilerFilter::kSpeedProfile:
48     case CompilerFilter::kSpeed:
49     case CompilerFilter::kEverythingProfile:
50     case CompilerFilter::kEverything: return true;
51   }
52   UNREACHABLE();
53 }
54 
IsAnyCompilationEnabled(Filter filter)55 bool CompilerFilter::IsAnyCompilationEnabled(Filter filter) {
56   return IsJniCompilationEnabled(filter) || IsAotCompilationEnabled(filter);
57 }
58 
IsVerificationEnabled(Filter filter)59 bool CompilerFilter::IsVerificationEnabled(Filter filter) {
60   switch (filter) {
61     case CompilerFilter::kAssumeVerified: return false;
62 
63     case CompilerFilter::kVerify:
64     case CompilerFilter::kSpaceProfile:
65     case CompilerFilter::kSpace:
66     case CompilerFilter::kSpeedProfile:
67     case CompilerFilter::kSpeed:
68     case CompilerFilter::kEverythingProfile:
69     case CompilerFilter::kEverything: return true;
70   }
71   UNREACHABLE();
72 }
73 
DependsOnImageChecksum(Filter filter)74 bool CompilerFilter::DependsOnImageChecksum(Filter filter) {
75   // We run dex2dex with verification, so the oat file will depend on the
76   // image checksum if verification is enabled.
77   return IsVerificationEnabled(filter);
78 }
79 
DependsOnProfile(Filter filter)80 bool CompilerFilter::DependsOnProfile(Filter filter) {
81   switch (filter) {
82     case CompilerFilter::kAssumeVerified:
83     case CompilerFilter::kVerify:
84     case CompilerFilter::kSpace:
85     case CompilerFilter::kSpeed:
86     case CompilerFilter::kEverything: return false;
87 
88     case CompilerFilter::kSpaceProfile:
89     case CompilerFilter::kSpeedProfile:
90     case CompilerFilter::kEverythingProfile: return true;
91   }
92   UNREACHABLE();
93 }
94 
GetNonProfileDependentFilterFrom(Filter filter)95 CompilerFilter::Filter CompilerFilter::GetNonProfileDependentFilterFrom(Filter filter) {
96   switch (filter) {
97     case CompilerFilter::kAssumeVerified:
98     case CompilerFilter::kVerify:
99     case CompilerFilter::kSpace:
100     case CompilerFilter::kSpeed:
101     case CompilerFilter::kEverything:
102       return filter;
103 
104     case CompilerFilter::kSpaceProfile:
105       return CompilerFilter::kSpace;
106 
107     case CompilerFilter::kSpeedProfile:
108       return CompilerFilter::kSpeed;
109 
110     case CompilerFilter::kEverythingProfile:
111       return CompilerFilter::kEverything;
112   }
113   UNREACHABLE();
114 }
115 
GetSafeModeFilterFrom(Filter filter)116 CompilerFilter::Filter CompilerFilter::GetSafeModeFilterFrom(Filter filter) {
117   // For safe mode, we should not return a filter that generates AOT compiled
118   // code.
119   switch (filter) {
120     case CompilerFilter::kAssumeVerified:
121     case CompilerFilter::kVerify:
122       return filter;
123 
124     case CompilerFilter::kSpace:
125     case CompilerFilter::kSpeed:
126     case CompilerFilter::kEverything:
127     case CompilerFilter::kSpaceProfile:
128     case CompilerFilter::kSpeedProfile:
129     case CompilerFilter::kEverythingProfile:
130       return CompilerFilter::kVerify;
131   }
132   UNREACHABLE();
133 }
134 
IsAsGoodAs(Filter current,Filter target)135 bool CompilerFilter::IsAsGoodAs(Filter current, Filter target) {
136   return current >= target;
137 }
138 
IsBetter(Filter current,Filter target)139 bool CompilerFilter::IsBetter(Filter current, Filter target) {
140   return current > target;
141 }
142 
NameOfFilter(Filter filter)143 std::string CompilerFilter::NameOfFilter(Filter filter) {
144   switch (filter) {
145     case CompilerFilter::kAssumeVerified: return "assume-verified";
146     case CompilerFilter::kVerify: return "verify";
147     case CompilerFilter::kSpaceProfile: return "space-profile";
148     case CompilerFilter::kSpace: return "space";
149     case CompilerFilter::kSpeedProfile: return "speed-profile";
150     case CompilerFilter::kSpeed: return "speed";
151     case CompilerFilter::kEverythingProfile: return "everything-profile";
152     case CompilerFilter::kEverything: return "everything";
153   }
154   UNREACHABLE();
155 }
156 
ParseCompilerFilter(const char * option,Filter * filter)157 bool CompilerFilter::ParseCompilerFilter(const char* option, Filter* filter) {
158   CHECK(filter != nullptr);
159 
160   if (strcmp(option, "verify-none") == 0) {
161     LOG(WARNING) << "'verify-none' is an obsolete compiler filter name that will be "
162                  << "removed in future releases, please use 'assume-verified' instead.";
163     *filter = kAssumeVerified;
164   } else if (strcmp(option, "interpret-only") == 0) {
165     LOG(WARNING) << "'interpret-only' is an obsolete compiler filter name that will be "
166                  << "removed in future releases, please use 'quicken' instead.";
167     *filter = kVerify;
168   } else if (strcmp(option, "verify-profile") == 0) {
169     LOG(WARNING) << "'verify-profile' is an obsolete compiler filter name that will be "
170                  << "removed in future releases, please use 'verify' instead.";
171     *filter = kVerify;
172   } else if (strcmp(option, "verify-at-runtime") == 0) {
173     LOG(WARNING) << "'verify-at-runtime' is an obsolete compiler filter name that will be "
174                  << "removed in future releases, please use 'verify' instead.";
175     *filter = kVerify;
176   } else if (strcmp(option, "balanced") == 0) {
177     LOG(WARNING) << "'balanced' is an obsolete compiler filter name that will be "
178                  << "removed in future releases, please use 'speed' instead.";
179     *filter = kSpeed;
180   } else if (strcmp(option, "time") == 0) {
181     LOG(WARNING) << "'time' is an obsolete compiler filter name that will be "
182                  << "removed in future releases, please use 'space' instead.";
183     *filter = kSpace;
184   } else if (strcmp(option, "extract") == 0) {
185     LOG(WARNING) << "'extract' is an obsolete compiler filter name that will be "
186                  << "removed in future releases, please use 'verify' instead.";
187     *filter = kVerify;
188   } else if (strcmp(option, "quicken") == 0) {
189     LOG(WARNING) << "'quicken' is an obsolete compiler filter name that will be "
190                  << "removed in future releases, please use 'verify' instead.";
191     *filter = kVerify;
192   } else if (strcmp(option, "assume-verified") == 0) {
193     *filter = kAssumeVerified;
194   } else if (strcmp(option, "verify") == 0) {
195     *filter = kVerify;
196   } else if (strcmp(option, "space") == 0) {
197     *filter = kSpace;
198   } else if (strcmp(option, "space-profile") == 0) {
199     *filter = kSpaceProfile;
200   } else if (strcmp(option, "speed") == 0) {
201     *filter = kSpeed;
202   } else if (strcmp(option, "speed-profile") == 0) {
203     *filter = kSpeedProfile;
204   } else if (strcmp(option, "everything") == 0) {
205     *filter = kEverything;
206   } else if (strcmp(option, "everything-profile") == 0) {
207     *filter = kEverythingProfile;
208   } else {
209     return false;
210   }
211   return true;
212 }
213 
DescribeOptions()214 const char* CompilerFilter::DescribeOptions() {
215   return "assume-verified|verify|space{,-profile}|speed{,-profile}|"
216           "everything{,-profile}";
217 }
218 
operator <<(std::ostream & os,const CompilerFilter::Filter & rhs)219 std::ostream& operator<<(std::ostream& os, const CompilerFilter::Filter& rhs) {
220   return os << CompilerFilter::NameOfFilter(rhs);
221 }
222 
223 }  // namespace art
224