David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 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_VERIFIER_VERIFIER_DEPS_H_ |
| 18 | #define ART_RUNTIME_VERIFIER_VERIFIER_DEPS_H_ |
| 19 | |
| 20 | #include <map> |
| 21 | #include <set> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include "art_field.h" |
| 25 | #include "art_method.h" |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 26 | #include "base/array_ref.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 27 | #include "base/mutex.h" |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 28 | #include "indenter.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 29 | #include "method_resolution_kind.h" |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 30 | #include "method_verifier.h" // For MethodVerifier::FailureKind. |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 31 | #include "obj_ptr.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 32 | #include "os.h" |
| 33 | |
| 34 | namespace art { |
| 35 | namespace verifier { |
| 36 | |
| 37 | // Verification dependencies collector class used by the MethodVerifier to record |
| 38 | // resolution outcomes and type assignability tests of classes/methods/fields |
| 39 | // not present in the set of compiled DEX files, that is classes/methods/fields |
| 40 | // defined in the classpath. |
| 41 | // The compilation driver initializes the class and registers all DEX files |
| 42 | // which are being compiled. Classes defined in DEX files outside of this set |
| 43 | // (or synthesized classes without associated DEX files) are considered being |
| 44 | // in the classpath. |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 45 | // During code-flow verification, the MethodVerifier informs VerifierDeps |
| 46 | // about the outcome of every resolution and assignability test, and |
| 47 | // the VerifierDeps object records them if their outcome may change with |
| 48 | // changes in the classpath. |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 49 | class VerifierDeps { |
| 50 | public: |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 51 | explicit VerifierDeps(const std::vector<const DexFile*>& dex_files); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 52 | |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 53 | VerifierDeps(const std::vector<const DexFile*>& dex_files, ArrayRef<const uint8_t> data); |
| 54 | |
| 55 | // Merge `other` into this `VerifierDeps`'. `other` and `this` must be for the |
| 56 | // same set of dex files. |
| 57 | void MergeWith(const VerifierDeps& other, const std::vector<const DexFile*>& dex_files); |
Nicolas Geoffray | e70dd56 | 2016-10-30 21:03:35 +0000 | [diff] [blame] | 58 | |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 59 | // Record the verification status of the class at `type_idx`. |
| 60 | static void MaybeRecordVerificationStatus(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 61 | dex::TypeIndex type_idx, |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 62 | MethodVerifier::FailureKind failure_kind) |
| 63 | REQUIRES(!Locks::verifier_deps_lock_); |
| 64 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 65 | // Record the outcome `klass` of resolving type `type_idx` from `dex_file`. |
| 66 | // If `klass` is null, the class is assumed unresolved. |
| 67 | static void MaybeRecordClassResolution(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 68 | dex::TypeIndex type_idx, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 69 | mirror::Class* klass) |
| 70 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 71 | REQUIRES(!Locks::verifier_deps_lock_); |
| 72 | |
| 73 | // Record the outcome `field` of resolving field `field_idx` from `dex_file`. |
| 74 | // If `field` is null, the field is assumed unresolved. |
| 75 | static void MaybeRecordFieldResolution(const DexFile& dex_file, |
| 76 | uint32_t field_idx, |
| 77 | ArtField* field) |
| 78 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 79 | REQUIRES(!Locks::verifier_deps_lock_); |
| 80 | |
| 81 | // Record the outcome `method` of resolving method `method_idx` from `dex_file` |
| 82 | // using `res_kind` kind of method resolution algorithm. If `method` is null, |
| 83 | // the method is assumed unresolved. |
| 84 | static void MaybeRecordMethodResolution(const DexFile& dex_file, |
| 85 | uint32_t method_idx, |
| 86 | MethodResolutionKind res_kind, |
| 87 | ArtMethod* method) |
| 88 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 89 | REQUIRES(!Locks::verifier_deps_lock_); |
| 90 | |
| 91 | // Record the outcome `is_assignable` of type assignability test from `source` |
| 92 | // to `destination` as defined by RegType::AssignableFrom. `dex_file` is the |
| 93 | // owner of the method for which MethodVerifier performed the assignability test. |
| 94 | static void MaybeRecordAssignability(const DexFile& dex_file, |
| 95 | mirror::Class* destination, |
| 96 | mirror::Class* source, |
| 97 | bool is_strict, |
| 98 | bool is_assignable) |
| 99 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 100 | REQUIRES(!Locks::verifier_deps_lock_); |
| 101 | |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 102 | // Serialize the recorded dependencies and store the data into `buffer`. |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 103 | // `dex_files` provides the order of the dex files in which the dependencies |
| 104 | // should be emitted. |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 105 | void Encode(const std::vector<const DexFile*>& dex_files, std::vector<uint8_t>* buffer) const; |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 106 | |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 107 | void Dump(VariableIndentationOutputStream* vios) const; |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 108 | |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 109 | // Verify the encoded dependencies of this `VerifierDeps` are still valid. |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 110 | bool ValidateDependencies(Handle<mirror::ClassLoader> class_loader, Thread* self) const |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 111 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 112 | |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 113 | const std::vector<dex::TypeIndex>& GetUnverifiedClasses(const DexFile& dex_file) const { |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 114 | return GetDexFileDeps(dex_file)->unverified_classes_; |
| 115 | } |
| 116 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 117 | private: |
| 118 | static constexpr uint16_t kUnresolvedMarker = static_cast<uint16_t>(-1); |
| 119 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 120 | using ClassResolutionBase = std::tuple<dex::TypeIndex, uint16_t>; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 121 | struct ClassResolution : public ClassResolutionBase { |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 122 | ClassResolution() = default; |
| 123 | ClassResolution(const ClassResolution&) = default; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 124 | ClassResolution(dex::TypeIndex type_idx, uint16_t access_flags) |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 125 | : ClassResolutionBase(type_idx, access_flags) {} |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 126 | |
| 127 | bool IsResolved() const { return GetAccessFlags() != kUnresolvedMarker; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 128 | dex::TypeIndex GetDexTypeIndex() const { return std::get<0>(*this); } |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 129 | uint16_t GetAccessFlags() const { return std::get<1>(*this); } |
| 130 | }; |
| 131 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 132 | using FieldResolutionBase = std::tuple<uint32_t, uint16_t, dex::StringIndex>; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 133 | struct FieldResolution : public FieldResolutionBase { |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 134 | FieldResolution() = default; |
| 135 | FieldResolution(const FieldResolution&) = default; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 136 | FieldResolution(uint32_t field_idx, uint16_t access_flags, dex::StringIndex declaring_class_idx) |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 137 | : FieldResolutionBase(field_idx, access_flags, declaring_class_idx) {} |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 138 | |
| 139 | bool IsResolved() const { return GetAccessFlags() != kUnresolvedMarker; } |
| 140 | uint32_t GetDexFieldIndex() const { return std::get<0>(*this); } |
| 141 | uint16_t GetAccessFlags() const { return std::get<1>(*this); } |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 142 | dex::StringIndex GetDeclaringClassIndex() const { return std::get<2>(*this); } |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 143 | }; |
| 144 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 145 | using MethodResolutionBase = std::tuple<uint32_t, uint16_t, dex::StringIndex>; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 146 | struct MethodResolution : public MethodResolutionBase { |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 147 | MethodResolution() = default; |
| 148 | MethodResolution(const MethodResolution&) = default; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 149 | MethodResolution(uint32_t method_idx, |
| 150 | uint16_t access_flags, |
| 151 | dex::StringIndex declaring_class_idx) |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 152 | : MethodResolutionBase(method_idx, access_flags, declaring_class_idx) {} |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 153 | |
| 154 | bool IsResolved() const { return GetAccessFlags() != kUnresolvedMarker; } |
| 155 | uint32_t GetDexMethodIndex() const { return std::get<0>(*this); } |
| 156 | uint16_t GetAccessFlags() const { return std::get<1>(*this); } |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 157 | dex::StringIndex GetDeclaringClassIndex() const { return std::get<2>(*this); } |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 160 | using TypeAssignabilityBase = std::tuple<dex::StringIndex, dex::StringIndex>; |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 161 | struct TypeAssignability : public TypeAssignabilityBase { |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 162 | TypeAssignability() = default; |
| 163 | TypeAssignability(const TypeAssignability&) = default; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 164 | TypeAssignability(dex::StringIndex destination_idx, dex::StringIndex source_idx) |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 165 | : TypeAssignabilityBase(destination_idx, source_idx) {} |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 166 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 167 | dex::StringIndex GetDestination() const { return std::get<0>(*this); } |
| 168 | dex::StringIndex GetSource() const { return std::get<1>(*this); } |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | // Data structure representing dependencies collected during verification of |
| 172 | // methods inside one DexFile. |
| 173 | struct DexFileDeps { |
| 174 | // Vector of strings which are not present in the corresponding DEX file. |
| 175 | // These are referred to with ids starting with `NumStringIds()` of that DexFile. |
| 176 | std::vector<std::string> strings_; |
| 177 | |
| 178 | // Set of class pairs recording the outcome of assignability test from one |
| 179 | // of the two types to the other. |
| 180 | std::set<TypeAssignability> assignable_types_; |
| 181 | std::set<TypeAssignability> unassignable_types_; |
| 182 | |
| 183 | // Sets of recorded class/field/method resolutions. |
| 184 | std::set<ClassResolution> classes_; |
| 185 | std::set<FieldResolution> fields_; |
| 186 | std::set<MethodResolution> direct_methods_; |
| 187 | std::set<MethodResolution> virtual_methods_; |
| 188 | std::set<MethodResolution> interface_methods_; |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 189 | |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 190 | // List of classes that were not fully verified in that dex file. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 191 | std::vector<dex::TypeIndex> unverified_classes_; |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 192 | |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 193 | bool Equals(const DexFileDeps& rhs) const; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | // Finds the DexFileDep instance associated with `dex_file`, or nullptr if |
| 197 | // `dex_file` is not reported as being compiled. |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 198 | DexFileDeps* GetDexFileDeps(const DexFile& dex_file); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 199 | |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 200 | const DexFileDeps* GetDexFileDeps(const DexFile& dex_file) const; |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 201 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 202 | // Returns true if `klass` is null or not defined in any of dex files which |
| 203 | // were reported as being compiled. |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 204 | bool IsInClassPath(ObjPtr<mirror::Class> klass) const |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 205 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 206 | |
| 207 | // Returns the index of `str`. If it is defined in `dex_file_`, this is the dex |
| 208 | // string ID. If not, an ID is assigned to the string and cached in `strings_` |
| 209 | // of the corresponding DexFileDeps structure (either provided or inferred from |
| 210 | // `dex_file`). |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 211 | dex::StringIndex GetIdFromString(const DexFile& dex_file, const std::string& str) |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 212 | REQUIRES(!Locks::verifier_deps_lock_); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 213 | |
| 214 | // Returns the string represented by `id`. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 215 | std::string GetStringFromId(const DexFile& dex_file, dex::StringIndex string_id) const; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 216 | |
| 217 | // Returns the bytecode access flags of `element` (bottom 16 bits), or |
| 218 | // `kUnresolvedMarker` if `element` is null. |
| 219 | template <typename T> |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 220 | static uint16_t GetAccessFlags(T* element) |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 221 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 222 | |
| 223 | // Returns a string ID of the descriptor of the declaring class of `element`, |
| 224 | // or `kUnresolvedMarker` if `element` is null. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 225 | dex::StringIndex GetMethodDeclaringClassStringId(const DexFile& dex_file, |
| 226 | uint32_t dex_method_idx, |
| 227 | ArtMethod* method) |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 228 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 229 | dex::StringIndex GetFieldDeclaringClassStringId(const DexFile& dex_file, |
| 230 | uint32_t dex_field_idx, |
| 231 | ArtField* field) |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 232 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 32b5030 | 2016-11-17 13:08:35 -0800 | [diff] [blame] | 233 | |
| 234 | // Returns a string ID of the descriptor of the class. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 235 | dex::StringIndex GetClassDescriptorStringId(const DexFile& dex_file, ObjPtr<mirror::Class> klass) |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 236 | REQUIRES_SHARED(Locks::mutator_lock_) |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 237 | REQUIRES(!Locks::verifier_deps_lock_); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 238 | |
| 239 | void AddClassResolution(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 240 | dex::TypeIndex type_idx, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 241 | mirror::Class* klass) |
| 242 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 243 | REQUIRES(!Locks::verifier_deps_lock_); |
| 244 | |
| 245 | void AddFieldResolution(const DexFile& dex_file, |
| 246 | uint32_t field_idx, |
| 247 | ArtField* field) |
| 248 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 249 | REQUIRES(!Locks::verifier_deps_lock_); |
| 250 | |
| 251 | void AddMethodResolution(const DexFile& dex_file, |
| 252 | uint32_t method_idx, |
| 253 | MethodResolutionKind res_kind, |
| 254 | ArtMethod* method) |
| 255 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 256 | REQUIRES(!Locks::verifier_deps_lock_); |
| 257 | |
| 258 | void AddAssignability(const DexFile& dex_file, |
| 259 | mirror::Class* destination, |
| 260 | mirror::Class* source, |
| 261 | bool is_strict, |
| 262 | bool is_assignable) |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 263 | REQUIRES_SHARED(Locks::mutator_lock_); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 264 | |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 265 | bool Equals(const VerifierDeps& rhs) const; |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 266 | |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 267 | // Verify `dex_file` according to the `deps`, that is going over each |
| 268 | // `DexFileDeps` field, and checking that the recorded information still |
| 269 | // holds. |
| 270 | bool VerifyDexFile(Handle<mirror::ClassLoader> class_loader, |
| 271 | const DexFile& dex_file, |
| 272 | const DexFileDeps& deps, |
| 273 | Thread* self) const |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 274 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 275 | |
| 276 | bool VerifyAssignability(Handle<mirror::ClassLoader> class_loader, |
| 277 | const DexFile& dex_file, |
| 278 | const std::set<TypeAssignability>& assignables, |
| 279 | bool expected_assignability, |
| 280 | Thread* self) const |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 281 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 282 | |
| 283 | // Verify that the set of resolved classes at the point of creation |
| 284 | // of this `VerifierDeps` is still the same. |
| 285 | bool VerifyClasses(Handle<mirror::ClassLoader> class_loader, |
| 286 | const DexFile& dex_file, |
| 287 | const std::set<ClassResolution>& classes, |
| 288 | Thread* self) const |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 289 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 290 | |
| 291 | // Verify that the set of resolved fields at the point of creation |
| 292 | // of this `VerifierDeps` is still the same, and each field resolves to the |
| 293 | // same field holder and access flags. |
| 294 | bool VerifyFields(Handle<mirror::ClassLoader> class_loader, |
| 295 | const DexFile& dex_file, |
| 296 | const std::set<FieldResolution>& classes, |
| 297 | Thread* self) const |
| 298 | REQUIRES_SHARED(Locks::mutator_lock_) |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 299 | REQUIRES(!Locks::verifier_deps_lock_); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 300 | |
| 301 | // Verify that the set of resolved methods at the point of creation |
| 302 | // of this `VerifierDeps` is still the same, and each method resolves to the |
| 303 | // same method holder, access flags, and invocation kind. |
| 304 | bool VerifyMethods(Handle<mirror::ClassLoader> class_loader, |
| 305 | const DexFile& dex_file, |
| 306 | const std::set<MethodResolution>& methods, |
| 307 | MethodResolutionKind kind, |
| 308 | Thread* self) const |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 309 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 310 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 311 | // Map from DexFiles into dependencies collected from verification of their methods. |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 312 | std::map<const DexFile*, std::unique_ptr<DexFileDeps>> dex_deps_; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 313 | |
| 314 | friend class VerifierDepsTest; |
| 315 | ART_FRIEND_TEST(VerifierDepsTest, StringToId); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 316 | ART_FRIEND_TEST(VerifierDepsTest, EncodeDecode); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 317 | ART_FRIEND_TEST(VerifierDepsTest, EncodeDecodeMulti); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 318 | ART_FRIEND_TEST(VerifierDepsTest, VerifyDeps); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 319 | ART_FRIEND_TEST(VerifierDepsTest, CompilerDriver); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 320 | }; |
| 321 | |
| 322 | } // namespace verifier |
| 323 | } // namespace art |
| 324 | |
| 325 | #endif // ART_RUNTIME_VERIFIER_VERIFIER_DEPS_H_ |