• 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_NOOP_COMPILER_CALLBACKS_H_
18 #define ART_RUNTIME_NOOP_COMPILER_CALLBACKS_H_
19 
20 #include "base/macros.h"
21 #include "class_linker.h"
22 #include "compiler_callbacks.h"
23 
24 namespace art HIDDEN {
25 
26 // Used for tests and some tools that pretend to be a compiler (say, oatdump).
27 class NoopCompilerCallbacks final : public CompilerCallbacks {
28  public:
NoopCompilerCallbacks()29   NoopCompilerCallbacks() : CompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp) {}
~NoopCompilerCallbacks()30   ~NoopCompilerCallbacks() {}
31 
CreateAotClassLinker(InternTable * intern_table)32   ClassLinker* CreateAotClassLinker(InternTable* intern_table) override {
33     return new PermissiveClassLinker(intern_table);
34   }
35 
AddUncompilableMethod(MethodReference ref)36   void AddUncompilableMethod([[maybe_unused]] MethodReference ref) override {}
AddUncompilableClass(ClassReference ref)37   void AddUncompilableClass([[maybe_unused]] ClassReference ref) override {}
IsUncompilableMethod(MethodReference ref)38   bool IsUncompilableMethod([[maybe_unused]] MethodReference ref) override { return false; }
ClassRejected(ClassReference ref)39   void ClassRejected([[maybe_unused]] ClassReference ref) override {}
40 
GetVerifierDeps()41   verifier::VerifierDeps* GetVerifierDeps() const override { return nullptr; }
42 
43  private:
44   // When we supply compiler callbacks, we need an appropriate `ClassLinker` that can
45   // handle `SdkChecker`-related calls that are unimplemented in the base `ClassLinker`.
46   class PermissiveClassLinker : public ClassLinker {
47    public:
PermissiveClassLinker(InternTable * intern_table)48     explicit PermissiveClassLinker(InternTable* intern_table)
49         : ClassLinker(intern_table, /*fast_class_not_found_exceptions=*/ false) {}
50 
DenyAccessBasedOnPublicSdk(ArtMethod * art_method)51     bool DenyAccessBasedOnPublicSdk([[maybe_unused]] ArtMethod* art_method) const override
52         REQUIRES_SHARED(Locks::mutator_lock_) {
53       return false;
54     }
DenyAccessBasedOnPublicSdk(ArtField * art_field)55     bool DenyAccessBasedOnPublicSdk([[maybe_unused]] ArtField* art_field) const override
56         REQUIRES_SHARED(Locks::mutator_lock_) {
57       return false;
58     }
DenyAccessBasedOnPublicSdk(std::string_view type_descriptor)59     bool DenyAccessBasedOnPublicSdk(
60         [[maybe_unused]] std::string_view type_descriptor) const override {
61       return false;
62     }
SetEnablePublicSdkChecks(bool enabled)63     void SetEnablePublicSdkChecks([[maybe_unused]] bool enabled) override {}
64 
65     // Transaction-related virtual functions should not be called on `PermissiveClassLinker`.
66 
TransactionWriteConstraint(Thread * self,ObjPtr<mirror::Object> obj)67     bool TransactionWriteConstraint([[maybe_unused]] Thread* self,
68                                     [[maybe_unused]] ObjPtr<mirror::Object> obj) override
69         REQUIRES_SHARED(Locks::mutator_lock_) {
70       LOG(FATAL) << "UNREACHABLE";
71       UNREACHABLE();
72     }
73 
TransactionWriteValueConstraint(Thread * self,ObjPtr<mirror::Object> value)74     bool TransactionWriteValueConstraint([[maybe_unused]] Thread* self,
75                                          [[maybe_unused]] ObjPtr<mirror::Object> value) override
76         REQUIRES_SHARED(Locks::mutator_lock_) {
77       LOG(FATAL) << "UNREACHABLE";
78       UNREACHABLE();
79     }
80 
TransactionAllocationConstraint(Thread * self,ObjPtr<mirror::Class> klass)81     bool TransactionAllocationConstraint([[maybe_unused]] Thread* self,
82                                          [[maybe_unused]] ObjPtr<mirror::Class> klass) override
83         REQUIRES_SHARED(Locks::mutator_lock_) {
84       LOG(FATAL) << "UNREACHABLE";
85       UNREACHABLE();
86     }
87 
RecordWriteFieldBoolean(mirror::Object * obj,MemberOffset field_offset,uint8_t value,bool is_volatile)88     void RecordWriteFieldBoolean([[maybe_unused]] mirror::Object* obj,
89                                  [[maybe_unused]] MemberOffset field_offset,
90                                  [[maybe_unused]] uint8_t value,
91                                  [[maybe_unused]] bool is_volatile) override {
92       LOG(FATAL) << "UNREACHABLE";
93       UNREACHABLE();
94     }
95 
RecordWriteFieldByte(mirror::Object * obj,MemberOffset field_offset,int8_t value,bool is_volatile)96     void RecordWriteFieldByte([[maybe_unused]] mirror::Object* obj,
97                               [[maybe_unused]] MemberOffset field_offset,
98                               [[maybe_unused]] int8_t value,
99                               [[maybe_unused]] bool is_volatile) override {
100       LOG(FATAL) << "UNREACHABLE";
101       UNREACHABLE();
102     }
103 
RecordWriteFieldChar(mirror::Object * obj,MemberOffset field_offset,uint16_t value,bool is_volatile)104     void RecordWriteFieldChar([[maybe_unused]] mirror::Object* obj,
105                               [[maybe_unused]] MemberOffset field_offset,
106                               [[maybe_unused]] uint16_t value,
107                               [[maybe_unused]] bool is_volatile) override {
108       LOG(FATAL) << "UNREACHABLE";
109       UNREACHABLE();
110     }
111 
RecordWriteFieldShort(mirror::Object * obj,MemberOffset field_offset,int16_t value,bool is_volatile)112     void RecordWriteFieldShort([[maybe_unused]] mirror::Object* obj,
113                                [[maybe_unused]] MemberOffset field_offset,
114                                [[maybe_unused]] int16_t value,
115                                [[maybe_unused]] bool is_volatile) override {
116       LOG(FATAL) << "UNREACHABLE";
117       UNREACHABLE();
118     }
119 
RecordWriteField32(mirror::Object * obj,MemberOffset field_offset,uint32_t value,bool is_volatile)120     void RecordWriteField32([[maybe_unused]] mirror::Object* obj,
121                             [[maybe_unused]] MemberOffset field_offset,
122                             [[maybe_unused]] uint32_t value,
123                             [[maybe_unused]] bool is_volatile) override {
124       LOG(FATAL) << "UNREACHABLE";
125       UNREACHABLE();
126     }
127 
RecordWriteField64(mirror::Object * obj,MemberOffset field_offset,uint64_t value,bool is_volatile)128     void RecordWriteField64([[maybe_unused]] mirror::Object* obj,
129                             [[maybe_unused]] MemberOffset field_offset,
130                             [[maybe_unused]] uint64_t value,
131                             [[maybe_unused]] bool is_volatile) override {
132       LOG(FATAL) << "UNREACHABLE";
133       UNREACHABLE();
134     }
135 
RecordWriteFieldReference(mirror::Object * obj,MemberOffset field_offset,ObjPtr<mirror::Object> value,bool is_volatile)136     void RecordWriteFieldReference([[maybe_unused]] mirror::Object* obj,
137                                    [[maybe_unused]] MemberOffset field_offset,
138                                    [[maybe_unused]] ObjPtr<mirror::Object> value,
139                                    [[maybe_unused]] bool is_volatile) override
140         REQUIRES_SHARED(Locks::mutator_lock_) {
141       LOG(FATAL) << "UNREACHABLE";
142       UNREACHABLE();
143     }
144 
RecordWriteArray(mirror::Array * array,size_t index,uint64_t value)145     void RecordWriteArray([[maybe_unused]] mirror::Array* array,
146                           [[maybe_unused]] size_t index,
147                           [[maybe_unused]] uint64_t value) override
148         REQUIRES_SHARED(Locks::mutator_lock_) {
149       LOG(FATAL) << "UNREACHABLE";
150       UNREACHABLE();
151     }
152 
RecordStrongStringInsertion(ObjPtr<mirror::String> s)153     void RecordStrongStringInsertion([[maybe_unused]] ObjPtr<mirror::String> s) override
154         REQUIRES(Locks::intern_table_lock_) {
155       LOG(FATAL) << "UNREACHABLE";
156       UNREACHABLE();
157     }
158 
RecordWeakStringInsertion(ObjPtr<mirror::String> s)159     void RecordWeakStringInsertion([[maybe_unused]] ObjPtr<mirror::String> s) override
160         REQUIRES(Locks::intern_table_lock_) {
161       LOG(FATAL) << "UNREACHABLE";
162       UNREACHABLE();
163     }
164 
RecordStrongStringRemoval(ObjPtr<mirror::String> s)165     void RecordStrongStringRemoval([[maybe_unused]] ObjPtr<mirror::String> s) override
166         REQUIRES(Locks::intern_table_lock_) {
167       LOG(FATAL) << "UNREACHABLE";
168       UNREACHABLE();
169     }
170 
RecordWeakStringRemoval(ObjPtr<mirror::String> s)171     void RecordWeakStringRemoval([[maybe_unused]] ObjPtr<mirror::String> s) override
172         REQUIRES(Locks::intern_table_lock_) {
173       LOG(FATAL) << "UNREACHABLE";
174       UNREACHABLE();
175     }
176 
RecordResolveString(ObjPtr<mirror::DexCache> dex_cache,dex::StringIndex string_idx)177     void RecordResolveString([[maybe_unused]] ObjPtr<mirror::DexCache> dex_cache,
178                              [[maybe_unused]] dex::StringIndex string_idx) override
179         REQUIRES_SHARED(Locks::mutator_lock_) {
180       LOG(FATAL) << "UNREACHABLE";
181       UNREACHABLE();
182     }
183 
RecordResolveMethodType(ObjPtr<mirror::DexCache> dex_cache,dex::ProtoIndex proto_idx)184     void RecordResolveMethodType([[maybe_unused]] ObjPtr<mirror::DexCache> dex_cache,
185                                  [[maybe_unused]] dex::ProtoIndex proto_idx) override
186         REQUIRES_SHARED(Locks::mutator_lock_) {
187       LOG(FATAL) << "UNREACHABLE";
188       UNREACHABLE();
189     }
190 
ThrowTransactionAbortError(Thread * self)191     void ThrowTransactionAbortError([[maybe_unused]] Thread* self) override
192         REQUIRES_SHARED(Locks::mutator_lock_) {
193       LOG(FATAL) << "UNREACHABLE";
194       UNREACHABLE();
195     }
196 
AbortTransactionF(Thread * self,const char * fmt,...)197     void AbortTransactionF([[maybe_unused]] Thread* self,
198                            [[maybe_unused]] const char* fmt, ...) override
199         __attribute__((__format__(__printf__, 3, 4)))
200         REQUIRES_SHARED(Locks::mutator_lock_) {
201       LOG(FATAL) << "UNREACHABLE";
202       UNREACHABLE();
203     }
204 
AbortTransactionV(Thread * self,const char * fmt,va_list args)205     void AbortTransactionV([[maybe_unused]] Thread* self,
206                            [[maybe_unused]] const char* fmt,
207                            [[maybe_unused]] va_list args) override
208         REQUIRES_SHARED(Locks::mutator_lock_) {
209       LOG(FATAL) << "UNREACHABLE";
210       UNREACHABLE();
211     }
212 
IsTransactionAborted()213     bool IsTransactionAborted() const override {
214       LOG(FATAL) << "UNREACHABLE";
215       UNREACHABLE();
216     }
217 
VisitTransactionRoots(RootVisitor * visitor)218     void VisitTransactionRoots([[maybe_unused]] RootVisitor* visitor) override {
219       // Nothing to do for `PermissiveClassLinker`, only `AotClassLinker` handles transactions.
220     }
221 
GetTransactionalInterpreter()222     const void* GetTransactionalInterpreter() override {
223       LOG(FATAL) << "UNREACHABLE";
224       UNREACHABLE();
225     }
226   };
227 
228   DISALLOW_COPY_AND_ASSIGN(NoopCompilerCallbacks);
229 };
230 
231 }  // namespace art
232 
233 #endif  // ART_RUNTIME_NOOP_COMPILER_CALLBACKS_H_
234