• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 "quick_compiler_callbacks.h"
18 
19 #include "aot_class_linker.h"
20 #include "dex/verification_results.h"
21 #include "driver/compiler_driver.h"
22 #include "mirror/class-inl.h"
23 
24 namespace art {
25 
CreateAotClassLinker(InternTable * intern_table)26 ClassLinker* QuickCompilerCallbacks::CreateAotClassLinker(InternTable* intern_table) {
27   return new AotClassLinker(intern_table);
28 }
29 
AddUncompilableMethod(MethodReference ref)30 void QuickCompilerCallbacks::AddUncompilableMethod(MethodReference ref) {
31   if (verification_results_ != nullptr) {
32     verification_results_->AddUncompilableMethod(ref);
33   }
34 }
35 
AddUncompilableClass(ClassReference ref)36 void QuickCompilerCallbacks::AddUncompilableClass(ClassReference ref) {
37   if (verification_results_ != nullptr) {
38     verification_results_->AddUncompilableClass(ref);
39   }
40 }
41 
ClassRejected(ClassReference ref)42 void QuickCompilerCallbacks::ClassRejected(ClassReference ref) {
43   if (verification_results_ != nullptr) {
44     verification_results_->AddRejectedClass(ref);
45   }
46 }
47 
IsUncompilableMethod(MethodReference ref)48 bool QuickCompilerCallbacks::IsUncompilableMethod(MethodReference ref) {
49   if (verification_results_ != nullptr) {
50     return verification_results_->IsUncompilableMethod(ref);
51   }
52   return false;
53 }
54 
GetPreviousClassState(ClassReference ref)55 ClassStatus QuickCompilerCallbacks::GetPreviousClassState(ClassReference ref) {
56   // If we don't have class unloading enabled in the compiler, we will never see class that were
57   // previously verified. Return false to avoid overhead from the lookup in the compiler driver.
58   if (!does_class_unloading_) {
59     return ClassStatus::kNotReady;
60   }
61   DCHECK(compiler_driver_ != nullptr);
62   // In the case of the verify filter, avoiding verifiying twice.
63   return compiler_driver_->GetClassStatus(ref);
64 }
65 
UpdateClassState(ClassReference ref,ClassStatus status)66 void QuickCompilerCallbacks::UpdateClassState(ClassReference ref, ClassStatus status) {
67   // Driver is null when bootstrapping the runtime.
68   if (compiler_driver_ != nullptr) {
69     compiler_driver_->RecordClassStatus(ref, status);
70   }
71 }
72 
CanUseOatStatusForVerification(mirror::Class * klass)73 bool QuickCompilerCallbacks::CanUseOatStatusForVerification(mirror::Class* klass) {
74   // No dex files: conservatively false.
75   if (dex_files_ == nullptr) {
76     return false;
77   }
78 
79   // If the class isn't from one of the dex files, accept oat file data.
80   const DexFile* dex_file = &klass->GetDexFile();
81   return std::find(dex_files_->begin(), dex_files_->end(), dex_file) == dex_files_->end();
82 }
83 
84 }  // namespace art
85