Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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_COMPILER_DEX_VERIFICATION_RESULTS_H_ |
| 18 | #define ART_COMPILER_DEX_VERIFICATION_RESULTS_H_ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <set> |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 22 | |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 23 | #include "base/dchecked_vector.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 24 | #include "base/macros.h" |
| 25 | #include "base/mutex.h" |
| 26 | #include "class_reference.h" |
| 27 | #include "method_reference.h" |
| 28 | #include "safe_map.h" |
Mathieu Chartier | 9df8931 | 2016-11-23 13:28:16 -0800 | [diff] [blame] | 29 | #include "utils/atomic_method_ref_map.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | |
| 33 | namespace verifier { |
| 34 | class MethodVerifier; |
Nicolas Geoffray | 1d0ae3f | 2016-12-06 13:40:16 +0000 | [diff] [blame] | 35 | class VerifierDepsTest; |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 36 | } // namespace verifier |
| 37 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 38 | class CompilerOptions; |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 39 | class VerifiedMethod; |
| 40 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 41 | // Used by CompilerCallbacks to track verification information from the Runtime. |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 42 | class VerificationResults { |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 43 | public: |
| 44 | explicit VerificationResults(const CompilerOptions* compiler_options); |
| 45 | ~VerificationResults(); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 46 | |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 47 | void ProcessVerifiedMethod(verifier::MethodVerifier* method_verifier) |
| 48 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 49 | REQUIRES(!verified_methods_lock_); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 50 | |
Nicolas Geoffray | 51c17fa | 2016-11-25 15:56:12 +0000 | [diff] [blame] | 51 | void CreateVerifiedMethodFor(MethodReference ref) |
| 52 | REQUIRES(!verified_methods_lock_); |
| 53 | |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 54 | const VerifiedMethod* GetVerifiedMethod(MethodReference ref) |
| 55 | REQUIRES(!verified_methods_lock_); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 56 | |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 57 | void AddRejectedClass(ClassReference ref) REQUIRES(!rejected_classes_lock_); |
| 58 | bool IsClassRejected(ClassReference ref) REQUIRES(!rejected_classes_lock_); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 59 | |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 60 | bool IsCandidateForCompilation(MethodReference& method_ref, const uint32_t access_flags); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 61 | |
Mathieu Chartier | 9df8931 | 2016-11-23 13:28:16 -0800 | [diff] [blame] | 62 | // Add a dex file to enable using the atomic map. |
| 63 | void AddDexFile(const DexFile* dex_file) REQUIRES(!verified_methods_lock_); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 64 | |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 65 | private: |
| 66 | // Verified methods. The method array is fixed to avoid needing a lock to extend it. |
Mathieu Chartier | 9df8931 | 2016-11-23 13:28:16 -0800 | [diff] [blame] | 67 | using AtomicMap = AtomicMethodRefMap<const VerifiedMethod*>; |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 68 | using VerifiedMethodMap = SafeMap<MethodReference, |
| 69 | const VerifiedMethod*, |
| 70 | MethodReferenceComparator>; |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 71 | |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 72 | VerifiedMethodMap verified_methods_ GUARDED_BY(verified_methods_lock_); |
| 73 | const CompilerOptions* const compiler_options_; |
| 74 | |
Mathieu Chartier | 9df8931 | 2016-11-23 13:28:16 -0800 | [diff] [blame] | 75 | // Dex2oat can add dex files to atomic_verified_methods_ to avoid locking when calling |
| 76 | // GetVerifiedMethod. |
| 77 | AtomicMap atomic_verified_methods_; |
Mathieu Chartier | fc2dd61 | 2016-11-21 15:05:23 -0800 | [diff] [blame] | 78 | |
| 79 | ReaderWriterMutex verified_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 80 | |
| 81 | // Rejected classes. |
| 82 | ReaderWriterMutex rejected_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 83 | std::set<ClassReference> rejected_classes_ GUARDED_BY(rejected_classes_lock_); |
Nicolas Geoffray | 1d0ae3f | 2016-12-06 13:40:16 +0000 | [diff] [blame] | 84 | |
| 85 | friend class verifier::VerifierDepsTest; |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | } // namespace art |
| 89 | |
| 90 | #endif // ART_COMPILER_DEX_VERIFICATION_RESULTS_H_ |