blob: 0a7b1bc2e7ba2ed28435ef21a4aa6487af4fdf7c [file] [log] [blame]
Martin Stjernholm4fb51112021-04-30 11:53:52 +01001/*
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
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.
Fairphone ODM25c12f52023-12-15 17:24:06 +080032 // Keep supported filters in sync with `ArtShellCommand.printHelp` in
33 // art/libartservice/service/java/com/android/server/art/ArtShellCommand.java.
Martin Stjernholm4fb51112021-04-30 11:53:52 +010034 enum Filter {
35 kAssumeVerified, // Skip verification but mark all classes as verified anyway.
Martin Stjernholm4fb51112021-04-30 11:53:52 +010036 kVerify, // Only verify classes.
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 this compiler filter requires running verification.
61 static bool IsVerificationEnabled(Filter filter);
62
63 // Returns true if an oat file with this compiler filter depends on the
64 // boot image checksum.
65 static bool DependsOnImageChecksum(Filter filter);
66
67 // Returns true if an oat file with this compiler filter depends on a
68 // profile.
69 static bool DependsOnProfile(Filter filter);
70
71 // Returns a non-profile-guided version of the given filter.
72 static Filter GetNonProfileDependentFilterFrom(Filter filter);
73
74 // Returns a filter suitable for safe mode.
75 static Filter GetSafeModeFilterFrom(Filter filter);
76
77 // Returns true if the 'current' compiler filter is considered at least as
78 // good as the 'target' compilation type.
79 // For example: kSpeed is as good as kInterpretOnly, but kInterpretOnly is
80 // not as good as kSpeed.
81 static bool IsAsGoodAs(Filter current, Filter target);
82
83 // Returns true if 'current' compiler filter is better than 'target' compiler
84 // filter. Compared to IsAsGoodAs, this returns false if the compiler filters are
85 // equal.
86 static bool IsBetter(Filter current, Filter target);
87
88 // Return the flag name of the given filter.
89 // For example: given kVerifyAtRuntime, returns "verify-at-runtime".
90 // The name returned corresponds to the name accepted by
91 // ParseCompilerFilter.
92 static std::string NameOfFilter(Filter filter);
93
94 // Parse the compiler filter from the given name.
95 // Returns true and sets filter to the parsed value if name refers to a
96 // valid filter. Returns false if no filter matches that name.
97 // 'filter' must be non-null.
98 static bool ParseCompilerFilter(const char* name, /*out*/Filter* filter);
99
100 static const char* DescribeOptions();
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(CompilerFilter);
104};
105
106std::ostream& operator<<(std::ostream& os, const CompilerFilter::Filter& rhs);
107
108} // namespace art
109
110#endif // ART_LIBARTBASE_BASE_COMPILER_FILTER_H_