129d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe/* 229d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * Copyright (C) 2016 The Android Open Source Project 329d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * 429d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * Licensed under the Apache License, Version 2.0 (the "License"); 529d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * you may not use this file except in compliance with the License. 629d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * You may obtain a copy of the License at 729d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * 829d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * http://www.apache.org/licenses/LICENSE-2.0 929d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * 1029d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * Unless required by applicable law or agreed to in writing, software 1129d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * distributed under the License is distributed on an "AS IS" BASIS, 1229d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1329d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * See the License for the specific language governing permissions and 1429d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe * limitations under the License. 1529d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe */ 1629d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 1729d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe#ifndef ART_RUNTIME_COMPILER_FILTER_H_ 1829d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe#define ART_RUNTIME_COMPILER_FILTER_H_ 1929d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 2029d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe#include <ostream> 2129d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe#include <string> 2229d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe#include <vector> 2329d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 2429d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe#include "base/macros.h" 2529d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 2629d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampenamespace art { 2729d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 2829d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampeclass CompilerFilter FINAL { 2929d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe public: 3029d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // Note: Order here matters. Later filter choices are considered "as good 3129d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // as" earlier filter choices. 3229d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe enum Filter { 33a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray kAssumeVerified, // Skip verification but mark all classes as verified anyway. 34a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray kExtract, // Delay verication to runtime, do not compile anything. 35a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray kVerify, // Only verify classes. 36a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray kQuicken, // Verify, quicken, and compile JNI stubs. 3729d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe kSpaceProfile, // Maximize space savings based on profile. 3829d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe kSpace, // Maximize space savings. 3929d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe kSpeedProfile, // Maximize runtime performance based on profile. 4029d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe kSpeed, // Maximize runtime performance. 4129d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe kEverythingProfile, // Compile everything capable of being compiled based on profile. 4229d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe kEverything, // Compile everything capable of being compiled. 4329d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe }; 4429d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 45f4b3487ee77e3c2e3d5372ae9e857cd3429bb808Richard Uhler static const Filter kDefaultCompilerFilter = kSpeed; 46f4b3487ee77e3c2e3d5372ae9e857cd3429bb808Richard Uhler 4729d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // Returns true if an oat file with this compiler filter contains 488c185bf0c6f18a5349bc87a7e3751ba06d90f461Vladimir Marko // compiled executable code for bytecode. 49a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray static bool IsAotCompilationEnabled(Filter filter); 508c185bf0c6f18a5349bc87a7e3751ba06d90f461Vladimir Marko 518c185bf0c6f18a5349bc87a7e3751ba06d90f461Vladimir Marko // Returns true if an oat file with this compiler filter contains 5260ca949cc39936b1f18853922d0dcafdda3b9322Nicolas Geoffray // compiled executable code for bytecode, JNI methods, or quickened dex 5360ca949cc39936b1f18853922d0dcafdda3b9322Nicolas Geoffray // bytecode. 54a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray static bool IsAnyCompilationEnabled(Filter filter); 5560ca949cc39936b1f18853922d0dcafdda3b9322Nicolas Geoffray 5660ca949cc39936b1f18853922d0dcafdda3b9322Nicolas Geoffray // Returns true if an oat file with this compiler filter contains 578c185bf0c6f18a5349bc87a7e3751ba06d90f461Vladimir Marko // compiled executable code for JNI methods. 588c185bf0c6f18a5349bc87a7e3751ba06d90f461Vladimir Marko static bool IsJniCompilationEnabled(Filter filter); 5929d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 60a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray // Returns true if an oat file with this compiler filter contains 61a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray // quickened dex bytecode. 62a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray static bool IsQuickeningCompilationEnabled(Filter filter); 63a10ac2ac733a9dc07962cfea2502605141e61953Nicolas Geoffray 6429d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // Returns true if this compiler filter requires running verification. 6529d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe static bool IsVerificationEnabled(Filter filter); 6629d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 6729d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // Returns true if an oat file with this compiler filter depends on the 6829d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // boot image checksum. 6929d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe static bool DependsOnImageChecksum(Filter filter); 7029d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 7129d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // Returns true if an oat file with this compiler filter depends on a 7229d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // profile. 7329d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe static bool DependsOnProfile(Filter filter); 7429d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 7586a785d23ba3956b78c33aa3b623df4b6ec8b901Andreas Gampe // Returns a non-profile-guided version of the given filter. 7686a785d23ba3956b78c33aa3b623df4b6ec8b901Andreas Gampe static Filter GetNonProfileDependentFilterFrom(Filter filter); 7786a785d23ba3956b78c33aa3b623df4b6ec8b901Andreas Gampe 78d0faf8cedf65afd6b642ebdfb894736c6e224e6aNicolas Geoffray // Returns a filter suitable for safe mode. 79d0faf8cedf65afd6b642ebdfb894736c6e224e6aNicolas Geoffray static Filter GetSafeModeFilterFrom(Filter filter); 80d0faf8cedf65afd6b642ebdfb894736c6e224e6aNicolas Geoffray 8129d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // Returns true if the 'current' compiler filter is considered at least as 8229d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // good as the 'target' compilation type. 8329d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // For example: kSpeed is as good as kInterpretOnly, but kInterpretOnly is 8429d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // not as good as kSpeed. 8529d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe static bool IsAsGoodAs(Filter current, Filter target); 8629d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 8729d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // Return the flag name of the given filter. 8829d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // For example: given kVerifyAtRuntime, returns "verify-at-runtime". 8929d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // The name returned corresponds to the name accepted by 9029d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // ParseCompilerFilter. 9129d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe static std::string NameOfFilter(Filter filter); 9229d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 9329d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // Parse the compiler filter from the given name. 9429d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // Returns true and sets filter to the parsed value if name refers to a 9529d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // valid filter. Returns false if no filter matches that name. 9629d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe // 'filter' must be non-null. 9729d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe static bool ParseCompilerFilter(const char* name, /*out*/Filter* filter); 9829d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 9929d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe private: 10029d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe DISALLOW_COPY_AND_ASSIGN(CompilerFilter); 10129d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe}; 10229d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 10329d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampestd::ostream& operator<<(std::ostream& os, const CompilerFilter::Filter& rhs); 10429d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 10529d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe} // namespace art 10629d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe 10729d38e77c553c6cf71fc4dafe2d22b4e3f814872Andreas Gampe#endif // ART_RUNTIME_COMPILER_FILTER_H_ 108