blob: 04c4fa65e6b9e13e4882b542332a54154d40fe4f [file] [log] [blame]
Vladimir Markoc7f83202014-01-24 17:55:18 +00001/*
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 Markoc7f83202014-01-24 17:55:18 +000022
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080023#include "base/dchecked_vector.h"
Vladimir Markoc7f83202014-01-24 17:55:18 +000024#include "base/macros.h"
25#include "base/mutex.h"
David Sehr67bf42e2018-02-26 16:43:04 -080026#include "base/safe_map.h"
David Sehr312f3b22018-03-19 08:39:26 -070027#include "dex/class_reference.h"
28#include "dex/method_reference.h"
Mathieu Chartier93764b82017-07-17 14:51:53 -070029#include "utils/atomic_dex_ref_map.h"
Vladimir Markoc7f83202014-01-24 17:55:18 +000030
31namespace art {
32
33namespace verifier {
34class MethodVerifier;
Nicolas Geoffray1d0ae3f2016-12-06 13:40:16 +000035class VerifierDepsTest;
Vladimir Markoc7f83202014-01-24 17:55:18 +000036} // namespace verifier
37
Brian Carlstrom6449c622014-02-10 23:48:36 -080038class CompilerOptions;
Vladimir Markoc7f83202014-01-24 17:55:18 +000039class VerifiedMethod;
40
Brian Carlstrom6449c622014-02-10 23:48:36 -080041// Used by CompilerCallbacks to track verification information from the Runtime.
Vladimir Markoc7f83202014-01-24 17:55:18 +000042class VerificationResults {
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080043 public:
44 explicit VerificationResults(const CompilerOptions* compiler_options);
45 ~VerificationResults();
Vladimir Markoc7f83202014-01-24 17:55:18 +000046
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080047 void ProcessVerifiedMethod(verifier::MethodVerifier* method_verifier)
48 REQUIRES_SHARED(Locks::mutator_lock_)
49 REQUIRES(!verified_methods_lock_);
Vladimir Markoc7f83202014-01-24 17:55:18 +000050
Nicolas Geoffray51c17fa2016-11-25 15:56:12 +000051 void CreateVerifiedMethodFor(MethodReference ref)
52 REQUIRES(!verified_methods_lock_);
53
Vladimir Marko2afaff72018-11-30 17:01:50 +000054 const VerifiedMethod* GetVerifiedMethod(MethodReference ref) const
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080055 REQUIRES(!verified_methods_lock_);
Vladimir Markoc7f83202014-01-24 17:55:18 +000056
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080057 void AddRejectedClass(ClassReference ref) REQUIRES(!rejected_classes_lock_);
Vladimir Marko2afaff72018-11-30 17:01:50 +000058 bool IsClassRejected(ClassReference ref) const REQUIRES(!rejected_classes_lock_);
Vladimir Markoc7f83202014-01-24 17:55:18 +000059
Vladimir Marko2afaff72018-11-30 17:01:50 +000060 bool IsCandidateForCompilation(MethodReference& method_ref, const uint32_t access_flags) const;
Vladimir Markoc7f83202014-01-24 17:55:18 +000061
Mathieu Chartier9df89312016-11-23 13:28:16 -080062 // Add a dex file to enable using the atomic map.
63 void AddDexFile(const DexFile* dex_file) REQUIRES(!verified_methods_lock_);
Ian Rogers1ff3c982014-08-12 02:30:58 -070064
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080065 private:
66 // Verified methods. The method array is fixed to avoid needing a lock to extend it.
Mathieu Chartierfc8b4222017-09-17 13:44:24 -070067 using AtomicMap = AtomicDexRefMap<MethodReference, const VerifiedMethod*>;
68 using VerifiedMethodMap = SafeMap<MethodReference, const VerifiedMethod*>;
Vladimir Markoc7f83202014-01-24 17:55:18 +000069
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080070 VerifiedMethodMap verified_methods_ GUARDED_BY(verified_methods_lock_);
71 const CompilerOptions* const compiler_options_;
72
Mathieu Chartier9df89312016-11-23 13:28:16 -080073 // Dex2oat can add dex files to atomic_verified_methods_ to avoid locking when calling
74 // GetVerifiedMethod.
75 AtomicMap atomic_verified_methods_;
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080076
Vladimir Marko2afaff72018-11-30 17:01:50 +000077 // TODO: External locking during CompilerDriver::PreCompile(), no locking during compilation.
78 mutable ReaderWriterMutex verified_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080079
80 // Rejected classes.
Vladimir Marko2afaff72018-11-30 17:01:50 +000081 // TODO: External locking during CompilerDriver::PreCompile(), no locking during compilation.
82 mutable ReaderWriterMutex rejected_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080083 std::set<ClassReference> rejected_classes_ GUARDED_BY(rejected_classes_lock_);
Nicolas Geoffray1d0ae3f2016-12-06 13:40:16 +000084
85 friend class verifier::VerifierDepsTest;
Vladimir Markoc7f83202014-01-24 17:55:18 +000086};
87
88} // namespace art
89
90#endif // ART_COMPILER_DEX_VERIFICATION_RESULTS_H_