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 #ifndef ART_RUNTIME_COMPILER_CALLBACKS_H_
18 #define ART_RUNTIME_COMPILER_CALLBACKS_H_
19 
20 #include "base/locks.h"
21 #include "dex/class_reference.h"
22 #include "class_status.h"
23 
24 namespace art {
25 
26 class CompilerDriver;
27 
28 namespace mirror {
29 
30 class Class;
31 
32 }  // namespace mirror
33 
34 namespace verifier {
35 
36 class MethodVerifier;
37 class VerifierDeps;
38 
39 }  // namespace verifier
40 
41 class CompilerCallbacks {
42  public:
43   enum class CallbackMode {  // private
44     kCompileBootImage,
45     kCompileApp
46   };
47 
~CompilerCallbacks()48   virtual ~CompilerCallbacks() { }
49 
50   virtual void MethodVerified(verifier::MethodVerifier* verifier)
51       REQUIRES_SHARED(Locks::mutator_lock_) = 0;
52   virtual void ClassRejected(ClassReference ref) = 0;
53 
54   virtual verifier::VerifierDeps* GetVerifierDeps() const = 0;
SetVerifierDeps(verifier::VerifierDeps * deps ATTRIBUTE_UNUSED)55   virtual void SetVerifierDeps(verifier::VerifierDeps* deps ATTRIBUTE_UNUSED) {}
56 
57   // Return the class status of a previous stage of the compilation. This can be used, for example,
58   // when class unloading is enabled during multidex compilation.
GetPreviousClassState(ClassReference ref ATTRIBUTE_UNUSED)59   virtual ClassStatus GetPreviousClassState(ClassReference ref ATTRIBUTE_UNUSED) {
60     return ClassStatus::kNotReady;
61   }
62 
SetDoesClassUnloading(bool does_class_unloading ATTRIBUTE_UNUSED,CompilerDriver * compiler_driver ATTRIBUTE_UNUSED)63   virtual void SetDoesClassUnloading(bool does_class_unloading ATTRIBUTE_UNUSED,
64                                      CompilerDriver* compiler_driver ATTRIBUTE_UNUSED) {}
65 
IsBootImage()66   bool IsBootImage() {
67     return mode_ == CallbackMode::kCompileBootImage;
68   }
69 
UpdateClassState(ClassReference ref ATTRIBUTE_UNUSED,ClassStatus state ATTRIBUTE_UNUSED)70   virtual void UpdateClassState(ClassReference ref ATTRIBUTE_UNUSED,
71                                 ClassStatus state ATTRIBUTE_UNUSED) {}
72 
CanUseOatStatusForVerification(mirror::Class * klass ATTRIBUTE_UNUSED)73   virtual bool CanUseOatStatusForVerification(mirror::Class* klass ATTRIBUTE_UNUSED)
74       REQUIRES_SHARED(Locks::mutator_lock_) {
75     return false;
76   }
77 
78  protected:
CompilerCallbacks(CallbackMode mode)79   explicit CompilerCallbacks(CallbackMode mode) : mode_(mode) { }
80 
81  private:
82   // Whether the compiler is creating a boot image.
83   const CallbackMode mode_;
84 };
85 
86 }  // namespace art
87 
88 #endif  // ART_RUNTIME_COMPILER_CALLBACKS_H_
89