xref: /aosp_15_r20/art/dex2oat/dex/verification_results.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2013 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #include "verification_results.h"
18*795d594fSAndroid Build Coastguard Worker 
19*795d594fSAndroid Build Coastguard Worker #include <android-base/logging.h>
20*795d594fSAndroid Build Coastguard Worker 
21*795d594fSAndroid Build Coastguard Worker #include "base/mutex-inl.h"
22*795d594fSAndroid Build Coastguard Worker #include "base/stl_util.h"
23*795d594fSAndroid Build Coastguard Worker #include "dex/class_accessor-inl.h"
24*795d594fSAndroid Build Coastguard Worker #include "runtime.h"
25*795d594fSAndroid Build Coastguard Worker #include "thread-current-inl.h"
26*795d594fSAndroid Build Coastguard Worker #include "thread.h"
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker namespace art {
29*795d594fSAndroid Build Coastguard Worker 
VerificationResults()30*795d594fSAndroid Build Coastguard Worker VerificationResults::VerificationResults()
31*795d594fSAndroid Build Coastguard Worker     : uncompilable_methods_lock_("compiler uncompilable methods lock"),
32*795d594fSAndroid Build Coastguard Worker       rejected_classes_lock_("compiler rejected classes lock") {}
33*795d594fSAndroid Build Coastguard Worker 
34*795d594fSAndroid Build Coastguard Worker // Non-inline version of the destructor, as it does some implicit work not worth
35*795d594fSAndroid Build Coastguard Worker // inlining.
~VerificationResults()36*795d594fSAndroid Build Coastguard Worker VerificationResults::~VerificationResults() {}
37*795d594fSAndroid Build Coastguard Worker 
AddRejectedClass(ClassReference ref)38*795d594fSAndroid Build Coastguard Worker void VerificationResults::AddRejectedClass(ClassReference ref) {
39*795d594fSAndroid Build Coastguard Worker   {
40*795d594fSAndroid Build Coastguard Worker     WriterMutexLock mu(Thread::Current(), rejected_classes_lock_);
41*795d594fSAndroid Build Coastguard Worker     rejected_classes_.insert(ref);
42*795d594fSAndroid Build Coastguard Worker   }
43*795d594fSAndroid Build Coastguard Worker   DCHECK(IsClassRejected(ref));
44*795d594fSAndroid Build Coastguard Worker }
45*795d594fSAndroid Build Coastguard Worker 
IsClassRejected(ClassReference ref) const46*795d594fSAndroid Build Coastguard Worker bool VerificationResults::IsClassRejected(ClassReference ref) const {
47*795d594fSAndroid Build Coastguard Worker   ReaderMutexLock mu(Thread::Current(), rejected_classes_lock_);
48*795d594fSAndroid Build Coastguard Worker   return rejected_classes_.find(ref) != rejected_classes_.end();
49*795d594fSAndroid Build Coastguard Worker }
50*795d594fSAndroid Build Coastguard Worker 
AddUncompilableMethod(MethodReference ref)51*795d594fSAndroid Build Coastguard Worker void VerificationResults::AddUncompilableMethod(MethodReference ref) {
52*795d594fSAndroid Build Coastguard Worker   {
53*795d594fSAndroid Build Coastguard Worker     WriterMutexLock mu(Thread::Current(), uncompilable_methods_lock_);
54*795d594fSAndroid Build Coastguard Worker     uncompilable_methods_.insert(ref);
55*795d594fSAndroid Build Coastguard Worker   }
56*795d594fSAndroid Build Coastguard Worker   DCHECK(IsUncompilableMethod(ref));
57*795d594fSAndroid Build Coastguard Worker }
58*795d594fSAndroid Build Coastguard Worker 
AddUncompilableClass(ClassReference ref)59*795d594fSAndroid Build Coastguard Worker void VerificationResults::AddUncompilableClass(ClassReference ref) {
60*795d594fSAndroid Build Coastguard Worker   const DexFile& dex_file = *ref.dex_file;
61*795d594fSAndroid Build Coastguard Worker   const dex::ClassDef& class_def = dex_file.GetClassDef(ref.ClassDefIdx());
62*795d594fSAndroid Build Coastguard Worker   WriterMutexLock mu(Thread::Current(), uncompilable_methods_lock_);
63*795d594fSAndroid Build Coastguard Worker   ClassAccessor accessor(dex_file, class_def);
64*795d594fSAndroid Build Coastguard Worker   for (const ClassAccessor::Method& method : accessor.GetMethods()) {
65*795d594fSAndroid Build Coastguard Worker     MethodReference method_ref(&dex_file, method.GetIndex());
66*795d594fSAndroid Build Coastguard Worker     uncompilable_methods_.insert(method_ref);
67*795d594fSAndroid Build Coastguard Worker   }
68*795d594fSAndroid Build Coastguard Worker }
69*795d594fSAndroid Build Coastguard Worker 
IsUncompilableMethod(MethodReference ref) const70*795d594fSAndroid Build Coastguard Worker bool VerificationResults::IsUncompilableMethod(MethodReference ref) const {
71*795d594fSAndroid Build Coastguard Worker   ReaderMutexLock mu(Thread::Current(), uncompilable_methods_lock_);
72*795d594fSAndroid Build Coastguard Worker   return uncompilable_methods_.find(ref) != uncompilable_methods_.end();
73*795d594fSAndroid Build Coastguard Worker }
74*795d594fSAndroid Build Coastguard Worker 
75*795d594fSAndroid Build Coastguard Worker 
76*795d594fSAndroid Build Coastguard Worker }  // namespace art
77