• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/mutex.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   // Return true if we should attempt to relocate to a random base address if we have not already
55   // done so. Return false if relocating in this way would be problematic.
56   virtual bool IsRelocationPossible() = 0;
57 
58   virtual verifier::VerifierDeps* GetVerifierDeps() const = 0;
SetVerifierDeps(verifier::VerifierDeps * deps ATTRIBUTE_UNUSED)59   virtual void SetVerifierDeps(verifier::VerifierDeps* deps ATTRIBUTE_UNUSED) {}
60 
61   // Return the class status of a previous stage of the compilation. This can be used, for example,
62   // when class unloading is enabled during multidex compilation.
GetPreviousClassState(ClassReference ref ATTRIBUTE_UNUSED)63   virtual ClassStatus GetPreviousClassState(ClassReference ref ATTRIBUTE_UNUSED) {
64     return ClassStatus::kNotReady;
65   }
66 
SetDoesClassUnloading(bool does_class_unloading ATTRIBUTE_UNUSED,CompilerDriver * compiler_driver ATTRIBUTE_UNUSED)67   virtual void SetDoesClassUnloading(bool does_class_unloading ATTRIBUTE_UNUSED,
68                                      CompilerDriver* compiler_driver ATTRIBUTE_UNUSED) {}
69 
IsBootImage()70   bool IsBootImage() {
71     return mode_ == CallbackMode::kCompileBootImage;
72   }
73 
UpdateClassState(ClassReference ref ATTRIBUTE_UNUSED,ClassStatus state ATTRIBUTE_UNUSED)74   virtual void UpdateClassState(ClassReference ref ATTRIBUTE_UNUSED,
75                                 ClassStatus state ATTRIBUTE_UNUSED) {}
76 
CanUseOatStatusForVerification(mirror::Class * klass ATTRIBUTE_UNUSED)77   virtual bool CanUseOatStatusForVerification(mirror::Class* klass ATTRIBUTE_UNUSED)
78       REQUIRES_SHARED(Locks::mutator_lock_) {
79     return false;
80   }
81 
82  protected:
CompilerCallbacks(CallbackMode mode)83   explicit CompilerCallbacks(CallbackMode mode) : mode_(mode) { }
84 
85  private:
86   // Whether the compiler is creating a boot image.
87   const CallbackMode mode_;
88 };
89 
90 }  // namespace art
91 
92 #endif  // ART_RUNTIME_COMPILER_CALLBACKS_H_
93