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 #include "verification_results.h"
18
19 #include <android-base/logging.h>
20
21 #include "base/mutex-inl.h"
22 #include "base/stl_util.h"
23 #include "dex/class_accessor-inl.h"
24 #include "runtime.h"
25 #include "thread-current-inl.h"
26 #include "thread.h"
27
28 namespace art {
29
VerificationResults()30 VerificationResults::VerificationResults()
31 : uncompilable_methods_lock_("compiler uncompilable methods lock"),
32 rejected_classes_lock_("compiler rejected classes lock") {}
33
34 // Non-inline version of the destructor, as it does some implicit work not worth
35 // inlining.
~VerificationResults()36 VerificationResults::~VerificationResults() {}
37
AddRejectedClass(ClassReference ref)38 void VerificationResults::AddRejectedClass(ClassReference ref) {
39 {
40 WriterMutexLock mu(Thread::Current(), rejected_classes_lock_);
41 rejected_classes_.insert(ref);
42 }
43 DCHECK(IsClassRejected(ref));
44 }
45
IsClassRejected(ClassReference ref) const46 bool VerificationResults::IsClassRejected(ClassReference ref) const {
47 ReaderMutexLock mu(Thread::Current(), rejected_classes_lock_);
48 return rejected_classes_.find(ref) != rejected_classes_.end();
49 }
50
AddUncompilableMethod(MethodReference ref)51 void VerificationResults::AddUncompilableMethod(MethodReference ref) {
52 {
53 WriterMutexLock mu(Thread::Current(), uncompilable_methods_lock_);
54 uncompilable_methods_.insert(ref);
55 }
56 DCHECK(IsUncompilableMethod(ref));
57 }
58
AddUncompilableClass(ClassReference ref)59 void VerificationResults::AddUncompilableClass(ClassReference ref) {
60 const DexFile& dex_file = *ref.dex_file;
61 const dex::ClassDef& class_def = dex_file.GetClassDef(ref.ClassDefIdx());
62 WriterMutexLock mu(Thread::Current(), uncompilable_methods_lock_);
63 ClassAccessor accessor(dex_file, class_def);
64 for (const ClassAccessor::Method& method : accessor.GetMethods()) {
65 MethodReference method_ref(&dex_file, method.GetIndex());
66 uncompilable_methods_.insert(method_ref);
67 }
68 }
69
IsUncompilableMethod(MethodReference ref) const70 bool VerificationResults::IsUncompilableMethod(MethodReference ref) const {
71 ReaderMutexLock mu(Thread::Current(), uncompilable_methods_lock_);
72 return uncompilable_methods_.find(ref) != uncompilable_methods_.end();
73 }
74
75
76 } // namespace art
77