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