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 #ifndef ART_DEX2OAT_DEX_QUICK_COMPILER_CALLBACKS_H_
18 #define ART_DEX2OAT_DEX_QUICK_COMPILER_CALLBACKS_H_
19 
20 #include "compiler_callbacks.h"
21 #include "verifier/verifier_deps.h"
22 
23 namespace art {
24 
25 class CompilerDriver;
26 class DexFile;
27 class VerificationResults;
28 
29 class QuickCompilerCallbacks final : public CompilerCallbacks {
30  public:
QuickCompilerCallbacks(CompilerCallbacks::CallbackMode mode)31   explicit QuickCompilerCallbacks(CompilerCallbacks::CallbackMode mode)
32       : CompilerCallbacks(mode), dex_files_(nullptr) {}
33 
~QuickCompilerCallbacks()34   ~QuickCompilerCallbacks() { }
35 
36   void MethodVerified(verifier::MethodVerifier* verifier)
37       REQUIRES_SHARED(Locks::mutator_lock_) override;
38 
39   void ClassRejected(ClassReference ref) override;
40 
GetVerifierDeps()41   verifier::VerifierDeps* GetVerifierDeps() const override {
42     return verifier_deps_.get();
43   }
44 
SetVerifierDeps(verifier::VerifierDeps * deps)45   void SetVerifierDeps(verifier::VerifierDeps* deps) override {
46     verifier_deps_.reset(deps);
47   }
48 
SetVerificationResults(VerificationResults * verification_results)49   void SetVerificationResults(VerificationResults* verification_results) {
50     verification_results_ = verification_results;
51   }
52 
53   ClassStatus GetPreviousClassState(ClassReference ref) override;
54 
SetDoesClassUnloading(bool does_class_unloading,CompilerDriver * compiler_driver)55   void SetDoesClassUnloading(bool does_class_unloading, CompilerDriver* compiler_driver)
56       override {
57     does_class_unloading_ = does_class_unloading;
58     compiler_driver_ = compiler_driver;
59     DCHECK(!does_class_unloading || compiler_driver_ != nullptr);
60   }
61 
62   void UpdateClassState(ClassReference ref, ClassStatus state) override;
63 
64   bool CanUseOatStatusForVerification(mirror::Class* klass) override
65       REQUIRES_SHARED(Locks::mutator_lock_);
66 
SetDexFiles(const std::vector<const DexFile * > * dex_files)67   void SetDexFiles(const std::vector<const DexFile*>* dex_files) {
68     dex_files_ = dex_files;
69   }
70 
71  private:
72   VerificationResults* verification_results_ = nullptr;
73   bool does_class_unloading_ = false;
74   CompilerDriver* compiler_driver_ = nullptr;
75   std::unique_ptr<verifier::VerifierDeps> verifier_deps_;
76   const std::vector<const DexFile*>* dex_files_;
77 };
78 
79 }  // namespace art
80 
81 #endif  // ART_DEX2OAT_DEX_QUICK_COMPILER_CALLBACKS_H_
82