blob: 60975b04f7da83263fc2f0559520cacf4213957d [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 {
Nicolas Geoffray49cda062017-04-21 13:08:25 +010033 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.
Andreas Gampe29d38e72016-03-23 15:31:51 +000037 kSpaceProfile, // Maximize space savings based on profile.
38 kSpace, // Maximize space savings.
Andreas Gampe29d38e72016-03-23 15:31:51 +000039 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
Richard Uhlerf4b34872016-04-13 11:03:46 -070045 static const Filter kDefaultCompilerFilter = kSpeed;
46
Andreas Gampe29d38e72016-03-23 15:31:51 +000047 // Returns true if an oat file with this compiler filter contains
Vladimir Marko8c185bf2016-05-23 15:32:42 +010048 // compiled executable code for bytecode.
Nicolas Geoffray49cda062017-04-21 13:08:25 +010049 static bool IsAotCompilationEnabled(Filter filter);
Vladimir Marko8c185bf2016-05-23 15:32:42 +010050
51 // Returns true if an oat file with this compiler filter contains
Nicolas Geoffray60ca9492016-12-20 21:15:00 +000052 // compiled executable code for bytecode, JNI methods, or quickened dex
53 // bytecode.
Nicolas Geoffray49cda062017-04-21 13:08:25 +010054 static bool IsAnyCompilationEnabled(Filter filter);
Nicolas Geoffray60ca9492016-12-20 21:15:00 +000055
56 // Returns true if an oat file with this compiler filter contains
Vladimir Marko8c185bf2016-05-23 15:32:42 +010057 // compiled executable code for JNI methods.
58 static bool IsJniCompilationEnabled(Filter filter);
Andreas Gampe29d38e72016-03-23 15:31:51 +000059
Nicolas Geoffray49cda062017-04-21 13:08:25 +010060 // Returns true if an oat file with this compiler filter contains
61 // quickened dex bytecode.
62 static bool IsQuickeningCompilationEnabled(Filter filter);
63
Andreas Gampe29d38e72016-03-23 15:31:51 +000064 // 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
Andreas Gampe86a785d2016-03-30 17:19:48 -070075 // Returns a non-profile-guided version of the given filter.
76 static Filter GetNonProfileDependentFilterFrom(Filter filter);
77
Nicolas Geoffray741d4262017-05-03 13:08:36 +010078 // Returns a filter suitable for safe mode.
79 static Filter GetSafeModeFilterFrom(Filter filter);
80
Andreas Gampe29d38e72016-03-23 15:31:51 +000081 // 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
Shubham Ajmerae4e812a2017-05-25 20:09:58 -070087 // 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
Andreas Gampe29d38e72016-03-23 15:31:51 +000092 // 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
108std::ostream& operator<<(std::ostream& os, const CompilerFilter::Filter& rhs);
109
110} // namespace art
111
112#endif // ART_RUNTIME_COMPILER_FILTER_H_