blob: ea38f4d5370e688183f314f88b89334c69db041f [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"
26#include "class_reference.h"
27#include "method_reference.h"
28#include "safe_map.h"
Mathieu Chartier9df89312016-11-23 13:28:16 -080029#include "utils/atomic_method_ref_map.h"
Vladimir Markoc7f83202014-01-24 17:55:18 +000030
31namespace art {
32
33namespace verifier {
34class MethodVerifier;
35} // namespace verifier
36
Brian Carlstrom6449c622014-02-10 23:48:36 -080037class CompilerOptions;
Vladimir Markoc7f83202014-01-24 17:55:18 +000038class VerifiedMethod;
39
Brian Carlstrom6449c622014-02-10 23:48:36 -080040// Used by CompilerCallbacks to track verification information from the Runtime.
Vladimir Markoc7f83202014-01-24 17:55:18 +000041class VerificationResults {
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080042 public:
43 explicit VerificationResults(const CompilerOptions* compiler_options);
44 ~VerificationResults();
Vladimir Markoc7f83202014-01-24 17:55:18 +000045
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080046 void ProcessVerifiedMethod(verifier::MethodVerifier* method_verifier)
47 REQUIRES_SHARED(Locks::mutator_lock_)
48 REQUIRES(!verified_methods_lock_);
Vladimir Markoc7f83202014-01-24 17:55:18 +000049
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080050 const VerifiedMethod* GetVerifiedMethod(MethodReference ref)
51 REQUIRES(!verified_methods_lock_);
Vladimir Markoc7f83202014-01-24 17:55:18 +000052
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080053 void AddRejectedClass(ClassReference ref) REQUIRES(!rejected_classes_lock_);
54 bool IsClassRejected(ClassReference ref) REQUIRES(!rejected_classes_lock_);
Vladimir Markoc7f83202014-01-24 17:55:18 +000055
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080056 bool IsCandidateForCompilation(MethodReference& method_ref, const uint32_t access_flags);
Vladimir Markoc7f83202014-01-24 17:55:18 +000057
Mathieu Chartier9df89312016-11-23 13:28:16 -080058 // Add a dex file to enable using the atomic map.
59 void AddDexFile(const DexFile* dex_file) REQUIRES(!verified_methods_lock_);
Ian Rogers1ff3c982014-08-12 02:30:58 -070060
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080061 private:
62 // Verified methods. The method array is fixed to avoid needing a lock to extend it.
Mathieu Chartier9df89312016-11-23 13:28:16 -080063 using AtomicMap = AtomicMethodRefMap<const VerifiedMethod*>;
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080064 using VerifiedMethodMap = SafeMap<MethodReference,
65 const VerifiedMethod*,
66 MethodReferenceComparator>;
Vladimir Markoc7f83202014-01-24 17:55:18 +000067
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080068 VerifiedMethodMap verified_methods_ GUARDED_BY(verified_methods_lock_);
69 const CompilerOptions* const compiler_options_;
70
Mathieu Chartier9df89312016-11-23 13:28:16 -080071 // Dex2oat can add dex files to atomic_verified_methods_ to avoid locking when calling
72 // GetVerifiedMethod.
73 AtomicMap atomic_verified_methods_;
Mathieu Chartierfc2dd612016-11-21 15:05:23 -080074
75 ReaderWriterMutex verified_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
76
77 // Rejected classes.
78 ReaderWriterMutex rejected_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
79 std::set<ClassReference> rejected_classes_ GUARDED_BY(rejected_classes_lock_);
Vladimir Markoc7f83202014-01-24 17:55:18 +000080};
81
82} // namespace art
83
84#endif // ART_COMPILER_DEX_VERIFICATION_RESULTS_H_