class ArtField; class ArtMethod; class DexFile; class VariableIndentationOutputStream;
namespace mirror { classClass; class ClassLoader;
} // namespace mirror
namespace verifier {
class RegType;
// Verification dependencies collector class used by the MethodVerifier to record // resolution outcomes and type assignability tests of classes/methods/fields // not present in the set of compiled DEX files, that is classes/methods/fields // defined in the classpath. // The compilation driver initializes the class and registers all DEX files // which are being compiled. Classes defined in DEX files outside of this set // (or synthesized classes without associated DEX files) are considered being // in the classpath. // During code-flow verification, the MethodVerifier informs VerifierDeps // about the outcome of every resolution and assignability test, and // the VerifierDeps object records them if their outcome may change with // changes in the classpath. class VerifierDeps { public:
EXPORT explicit VerifierDeps(const std::vector<const DexFile*>& dex_files, bool output_only = true);
// Marker to know whether a class is verified. A non-verified class will have // this marker as its offset entry in the encoded data. static uint32_t constexpr kNotVerifiedMarker = std::numeric_limits<uint32_t>::max();
// Fill dependencies from stored data. Returns true on success, false on failure.
EXPORT bool ParseStoredData(const std::vector<const DexFile*>& dex_files,
ArrayRef<const uint8_t> data);
// Merge `other` into this `VerifierDeps`'. `other` and `this` must be for the // same set of dex files.
EXPORT void MergeWith(std::unique_ptr<VerifierDeps> other, const std::vector<const DexFile*>& dex_files);
// Record information that a class was verified. // Note that this function is different from MaybeRecordVerificationStatus() which // looks up thread-local VerifierDeps first. void RecordClassVerified(const DexFile& dex_file, const dex::ClassDef& class_def)
REQUIRES(!Locks::verifier_deps_lock_);
// Record the verification status of the class defined in `class_def`.
EXPORT staticvoid MaybeRecordVerificationStatus(VerifierDeps* verifier_deps, const DexFile& dex_file, const dex::ClassDef& class_def,
FailureKind failure_kind)
REQUIRES(!Locks::verifier_deps_lock_);
// Record the outcome `is_assignable` of type assignability test from `source` // to `destination` as defined by RegType::AssignableFrom. `dex_file` is the // owner of the method for which MethodVerifier performed the assignability test. staticvoid MaybeRecordAssignability(VerifierDeps* verifier_deps, const DexFile& dex_file, const dex::ClassDef& class_def,
ObjPtr<mirror::Class> destination,
ObjPtr<mirror::Class> source)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::verifier_deps_lock_);
// Record that `source` is assignable to `destination`. `dex_file` is the // owner of the method for which MethodVerifier performed the assignability test. staticvoid MaybeRecordAssignability(VerifierDeps* verifier_deps, const DexFile& dex_file, const dex::ClassDef& class_def, const RegType& destination, const RegType& source)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::verifier_deps_lock_);
// Serialize the recorded dependencies and store the data into `buffer`. // `dex_files` provides the order of the dex files in which the dependencies // should be emitted.
EXPORT void Encode(const std::vector<const DexFile*>& dex_files,
std::vector<uint8_t>* buffer) const;
// Verifies the encoded dependencies of this `VerifierDeps` are still valid. // Returns whether all dependencies were validated.
EXPORT bool ValidateDependenciesAndUpdateStatus(
Thread* self,
Handle<mirror::ClassLoader> class_loader, const std::vector<const DexFile*>& dex_files)
REQUIRES_SHARED(Locks::mutator_lock_);
// Whether this `verifier_deps` has recorded that the given class is verified. bool HasRecordedVerifiedStatus(const DexFile& dex_file, const dex::ClassDef& class_def)
REQUIRES(!Locks::verifier_deps_lock_);
// Parses raw VerifierDeps data to extract bitvectors of which class def indices // were verified or not. The given `dex_files` must match the order and count of // dex files used to create the VerifierDeps. staticbool ParseVerifiedClasses( const std::vector<const DexFile*>& dex_files,
ArrayRef<const uint8_t> data, /*out*/std::vector<std::vector<bool>>* verified_classes_per_dex);
private: // Data structure representing dependencies collected during verification of // methods inside one DexFile. struct DexFileDeps { explicit DexFileDeps(size_t num_class_defs)
: assignable_types_(num_class_defs),
verified_classes_(num_class_defs) {}
// Vector of strings which are not present in the corresponding DEX file. // These are referred to with ids starting with `NumStringIds()` of that DexFile.
std::vector<std::string> strings_;
// Vector that contains for each class def defined in a dex file, a set of class pairs recording // the outcome of assignability test from one of the two types to the other.
std::vector<std::set<TypeAssignability>> assignable_types_;
// Bit vector indexed by class def indices indicating whether the corresponding // class was successfully verified.
std::vector<bool> verified_classes_;
bool Equals(const DexFileDeps& rhs) const;
};
// Helper function to share DexFileDeps decoding code. // Returns true on success, false on failure. template <bool kOnlyVerifiedClasses> staticbool DecodeDexFileDeps(DexFileDeps& deps, const uint8_t** cursor, const uint8_t* data_start, const uint8_t* data_end,
size_t num_class_defs);
// Finds the DexFileDep instance associated with `dex_file`, or nullptr if // `dex_file` is not reported as being compiled.
DexFileDeps* GetDexFileDeps(const DexFile& dex_file);
// Returns the index of `str`. If it is defined in `dex_file_`, this is the dex // string ID. If not, an ID is assigned to the string and cached in `strings_` // of the corresponding DexFileDeps structure (either provided or inferred from // `dex_file`).
dex::StringIndex GetIdFromString(const DexFile& dex_file, const std::string& str)
REQUIRES(!Locks::verifier_deps_lock_);
// Returns the string represented by `string_idx`. constchar* GetStringFromIndex(const DexFile& dex_file,
dex::StringIndex string_idx, /*out*/ size_t* utf8_length = nullptr) const;
// Returns a string ID of the descriptor of the class.
dex::StringIndex GetClassDescriptorStringId(const DexFile& dex_file, ObjPtr<mirror::Class> klass)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::verifier_deps_lock_);
// Verify `dex_file` according to the `deps`, that is going over each // `DexFileDeps` field, and checking that the recorded information still // holds. // Returns whether all dependencies were validated. bool VerifyDexFileAndUpdateStatus(
Handle<mirror::ClassLoader> class_loader, const DexFile& dex_file,
DexFileDeps& deps,
Thread* self)
REQUIRES_SHARED(Locks::mutator_lock_);
// Iterates over `dex_files` and tries to find a class def matching `descriptor`. // Returns true if such class def is found. bool IsInDexFiles(constchar* descriptor,
size_t hash, const std::vector<const DexFile*>& dex_files, /* out */ const DexFile** cp_dex_file) const;
// Map from DexFiles into dependencies collected from verification of their methods.
std::map<const DexFile*, std::unique_ptr<DexFileDeps>> dex_deps_;
// Output only signifies if we are using the verifier deps to verify or just to generate them. constbool output_only_;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.