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
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 {
33    kVerifyNone,          // Skip verification but mark all classes as verified anyway.
34    kVerifyAtRuntime,     // Delay verication to runtime, do not compile anything.
35    kVerifyProfile,       // Verify only the classes in the profile, compile only JNI stubs.
36    kInterpretOnly,       // Verify everything, compile only JNI stubs.
37    kTime,                // Compile methods, but minimize compilation time.
38    kSpaceProfile,        // Maximize space savings based on profile.
39    kSpace,               // Maximize space savings.
40    kBalanced,            // Good performance return on compilation investment.
41    kSpeedProfile,        // Maximize runtime performance based on profile.
42    kSpeed,               // Maximize runtime performance.
43    kEverythingProfile,   // Compile everything capable of being compiled based on profile.
44    kEverything,          // Compile everything capable of being compiled.
45  };
46
47  // Returns true if an oat file with this compiler filter contains
48  // compiled executable code for bytecode.
49  static bool IsBytecodeCompilationEnabled(Filter filter);
50
51  // Returns true if an oat file with this compiler filter contains
52  // compiled executable code for JNI methods.
53  static bool IsJniCompilationEnabled(Filter filter);
54
55  // Returns true if this compiler filter requires running verification.
56  static bool IsVerificationEnabled(Filter filter);
57
58  // Returns true if an oat file with this compiler filter depends on the
59  // boot image checksum.
60  static bool DependsOnImageChecksum(Filter filter);
61
62  // Returns true if an oat file with this compiler filter depends on a
63  // profile.
64  static bool DependsOnProfile(Filter filter);
65
66  // Returns a non-profile-guided version of the given filter.
67  static Filter GetNonProfileDependentFilterFrom(Filter filter);
68
69  // Returns true if the 'current' compiler filter is considered at least as
70  // good as the 'target' compilation type.
71  // For example: kSpeed is as good as kInterpretOnly, but kInterpretOnly is
72  // not as good as kSpeed.
73  static bool IsAsGoodAs(Filter current, Filter target);
74
75  // Return the flag name of the given filter.
76  // For example: given kVerifyAtRuntime, returns "verify-at-runtime".
77  // The name returned corresponds to the name accepted by
78  // ParseCompilerFilter.
79  static std::string NameOfFilter(Filter filter);
80
81  // Parse the compiler filter from the given name.
82  // Returns true and sets filter to the parsed value if name refers to a
83  // valid filter. Returns false if no filter matches that name.
84  // 'filter' must be non-null.
85  static bool ParseCompilerFilter(const char* name, /*out*/Filter* filter);
86
87 private:
88  DISALLOW_COPY_AND_ASSIGN(CompilerFilter);
89};
90
91std::ostream& operator<<(std::ostream& os, const CompilerFilter::Filter& rhs);
92
93}  // namespace art
94
95#endif  // ART_RUNTIME_COMPILER_FILTER_H_
96