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_RUNTIME_CLASS_LINKER_H_ 18 #define ART_RUNTIME_CLASS_LINKER_H_ 19 20 #include <list> 21 #include <map> 22 #include <set> 23 #include <string> 24 #include <type_traits> 25 #include <utility> 26 #include <vector> 27 28 #include "base/enums.h" 29 #include "base/hash_map.h" 30 #include "base/mutex.h" 31 #include "base/intrusive_forward_list.h" 32 #include "base/locks.h" 33 #include "base/macros.h" 34 #include "dex/class_accessor.h" 35 #include "dex/dex_file_types.h" 36 #include "gc_root.h" 37 #include "handle.h" 38 #include "jni.h" 39 #include "mirror/class.h" 40 #include "mirror/object.h" 41 #include "verifier/verifier_enums.h" 42 43 namespace art { 44 45 class ArtField; 46 class ArtMethod; 47 class ClassHierarchyAnalysis; 48 enum class ClassRoot : uint32_t; 49 class ClassTable; 50 class DexFile; 51 template<class T> class Handle; 52 class ImtConflictTable; 53 template<typename T> class LengthPrefixedArray; 54 template<class T> class MutableHandle; 55 class InternTable; 56 class LinearAlloc; 57 class OatFile; 58 template<class T> class ObjectLock; 59 class Runtime; 60 class ScopedObjectAccessAlreadyRunnable; 61 class SdkChecker; 62 template<size_t kNumReferences> class PACKED(4) StackHandleScope; 63 class Thread; 64 65 enum VisitRootFlags : uint8_t; 66 67 namespace dex { 68 struct ClassDef; 69 struct MethodHandleItem; 70 } // namespace dex 71 72 namespace gc { 73 namespace space { 74 class ImageSpace; 75 } // namespace space 76 } // namespace gc 77 78 namespace linker { 79 struct CompilationHelper; 80 class ImageWriter; 81 class OatWriter; 82 } // namespace linker 83 84 namespace mirror { 85 class ClassLoader; 86 class DexCache; 87 class DexCachePointerArray; 88 class DexCacheMethodHandlesTest_Open_Test; 89 class DexCacheTest_Open_Test; 90 class IfTable; 91 class MethodHandle; 92 class MethodHandlesLookup; 93 class MethodType; 94 template<class T> class ObjectArray; 95 class StackTraceElement; 96 template <typename T> struct NativeDexCachePair; 97 using MethodDexCachePair = NativeDexCachePair<ArtMethod>; 98 using MethodDexCacheType = std::atomic<MethodDexCachePair>; 99 } // namespace mirror 100 101 namespace verifier { 102 class VerifierDeps; 103 } 104 105 class ClassVisitor { 106 public: ~ClassVisitor()107 virtual ~ClassVisitor() {} 108 // Return true to continue visiting. 109 virtual bool operator()(ObjPtr<mirror::Class> klass) = 0; 110 }; 111 112 template <typename Func> 113 class ClassFuncVisitor final : public ClassVisitor { 114 public: ClassFuncVisitor(Func func)115 explicit ClassFuncVisitor(Func func) : func_(func) {} operator()116 bool operator()(ObjPtr<mirror::Class> klass) override REQUIRES_SHARED(Locks::mutator_lock_) { 117 return func_(klass); 118 } 119 120 private: 121 Func func_; 122 }; 123 124 class ClassLoaderVisitor { 125 public: ~ClassLoaderVisitor()126 virtual ~ClassLoaderVisitor() {} 127 virtual void Visit(ObjPtr<mirror::ClassLoader> class_loader) 128 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_) = 0; 129 }; 130 131 template <typename Func> 132 class ClassLoaderFuncVisitor final : public ClassLoaderVisitor { 133 public: ClassLoaderFuncVisitor(Func func)134 explicit ClassLoaderFuncVisitor(Func func) : func_(func) {} Visit(ObjPtr<mirror::ClassLoader> cl)135 void Visit(ObjPtr<mirror::ClassLoader> cl) override REQUIRES_SHARED(Locks::mutator_lock_) { 136 func_(cl); 137 } 138 139 private: 140 Func func_; 141 }; 142 143 class AllocatorVisitor { 144 public: ~AllocatorVisitor()145 virtual ~AllocatorVisitor() {} 146 // Return true to continue visiting. 147 virtual bool Visit(LinearAlloc* alloc) 148 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_) = 0; 149 }; 150 151 class ClassLinker { 152 public: 153 static constexpr bool kAppImageMayContainStrings = true; 154 155 explicit ClassLinker(InternTable* intern_table, 156 bool fast_class_not_found_exceptions = true); 157 virtual ~ClassLinker(); 158 159 // Initialize class linker by bootstraping from dex files. 160 bool InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> boot_class_path, 161 std::string* error_msg) 162 REQUIRES_SHARED(Locks::mutator_lock_) 163 REQUIRES(!Locks::dex_lock_); 164 165 // Initialize class linker from one or more boot images. 166 bool InitFromBootImage(std::string* error_msg) 167 REQUIRES_SHARED(Locks::mutator_lock_) 168 REQUIRES(!Locks::dex_lock_); 169 170 // Add boot class path dex files that were not included in the boot image. 171 // ClassLinker takes ownership of these dex files. 172 void AddExtraBootDexFiles(Thread* self, 173 std::vector<std::unique_ptr<const DexFile>>&& additional_dex_files) 174 REQUIRES_SHARED(Locks::mutator_lock_); 175 176 // Add an image space to the class linker, may fix up classloader fields and dex cache fields. 177 // The dex files that were newly opened for the space are placed in the out argument 178 // out_dex_files. Returns true if the operation succeeded. 179 // The space must be already added to the heap before calling AddImageSpace since we need to 180 // properly handle read barriers and object marking. 181 bool AddImageSpace(gc::space::ImageSpace* space, 182 Handle<mirror::ClassLoader> class_loader, 183 std::vector<std::unique_ptr<const DexFile>>* out_dex_files, 184 std::string* error_msg) 185 REQUIRES(!Locks::dex_lock_) 186 REQUIRES_SHARED(Locks::mutator_lock_); 187 188 bool OpenImageDexFiles(gc::space::ImageSpace* space, 189 std::vector<std::unique_ptr<const DexFile>>* out_dex_files, 190 std::string* error_msg) 191 REQUIRES(!Locks::dex_lock_) 192 REQUIRES_SHARED(Locks::mutator_lock_); 193 194 // Finds a class by its descriptor, loading it if necessary. 195 // If class_loader is null, searches boot_class_path_. 196 ObjPtr<mirror::Class> FindClass(Thread* self, 197 const char* descriptor, 198 Handle<mirror::ClassLoader> class_loader) 199 REQUIRES_SHARED(Locks::mutator_lock_) 200 REQUIRES(!Locks::dex_lock_); 201 202 // Finds a class by its descriptor using the "system" class loader, ie by searching the 203 // boot_class_path_. FindSystemClass(Thread * self,const char * descriptor)204 ObjPtr<mirror::Class> FindSystemClass(Thread* self, const char* descriptor) 205 REQUIRES_SHARED(Locks::mutator_lock_) 206 REQUIRES(!Locks::dex_lock_) { 207 return FindClass(self, descriptor, ScopedNullHandle<mirror::ClassLoader>()); 208 } 209 210 // Finds the array class given for the element class. 211 ObjPtr<mirror::Class> FindArrayClass(Thread* self, ObjPtr<mirror::Class> element_class) 212 REQUIRES_SHARED(Locks::mutator_lock_) 213 REQUIRES(!Locks::dex_lock_); 214 215 // Returns true if the class linker is initialized. IsInitialized()216 bool IsInitialized() const { 217 return init_done_; 218 } 219 220 // Define a new a class based on a ClassDef from a DexFile 221 ObjPtr<mirror::Class> DefineClass(Thread* self, 222 const char* descriptor, 223 size_t hash, 224 Handle<mirror::ClassLoader> class_loader, 225 const DexFile& dex_file, 226 const dex::ClassDef& dex_class_def) 227 REQUIRES_SHARED(Locks::mutator_lock_) 228 REQUIRES(!Locks::dex_lock_); 229 230 // Finds a class by its descriptor, returning null if it isn't wasn't loaded 231 // by the given 'class_loader'. 232 ObjPtr<mirror::Class> LookupClass(Thread* self, 233 const char* descriptor, 234 ObjPtr<mirror::ClassLoader> class_loader) 235 REQUIRES(!Locks::classlinker_classes_lock_) 236 REQUIRES_SHARED(Locks::mutator_lock_); 237 238 // Finds all the classes with the given descriptor, regardless of ClassLoader. 239 void LookupClasses(const char* descriptor, std::vector<ObjPtr<mirror::Class>>& classes) 240 REQUIRES(!Locks::classlinker_classes_lock_) 241 REQUIRES_SHARED(Locks::mutator_lock_); 242 243 ObjPtr<mirror::Class> LookupPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_); 244 ObjPtr<mirror::Class> FindPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_); 245 246 void DumpForSigQuit(std::ostream& os) REQUIRES(!Locks::classlinker_classes_lock_); 247 248 size_t NumLoadedClasses() 249 REQUIRES(!Locks::classlinker_classes_lock_) 250 REQUIRES_SHARED(Locks::mutator_lock_); 251 252 // Resolve a String with the given index from the DexFile associated with the given `referrer`, 253 // storing the result in the DexCache. The `referrer` is used to identify the target DexCache 254 // to use for resolution. 255 ObjPtr<mirror::String> ResolveString(dex::StringIndex string_idx, 256 ArtField* referrer) 257 REQUIRES_SHARED(Locks::mutator_lock_); 258 ObjPtr<mirror::String> ResolveString(dex::StringIndex string_idx, 259 ArtMethod* referrer) 260 REQUIRES_SHARED(Locks::mutator_lock_); 261 262 // Resolve a String with the given index from the DexFile associated with the given DexCache, 263 // storing the result in the DexCache. 264 ObjPtr<mirror::String> ResolveString(dex::StringIndex string_idx, 265 Handle<mirror::DexCache> dex_cache) 266 REQUIRES_SHARED(Locks::mutator_lock_); 267 268 // Find a String with the given index from the DexFile associated with the given DexCache, 269 // storing the result in the DexCache if found. Return null if not found. 270 ObjPtr<mirror::String> LookupString(dex::StringIndex string_idx, 271 ObjPtr<mirror::DexCache> dex_cache) 272 REQUIRES_SHARED(Locks::mutator_lock_); 273 274 // Resolve a Type with the given index from the DexFile associated with the given `referrer`, 275 // storing the result in the DexCache. The `referrer` is used to identify the target DexCache 276 // and ClassLoader to use for resolution. 277 ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ObjPtr<mirror::Class> referrer) 278 REQUIRES_SHARED(Locks::mutator_lock_) 279 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 280 ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ArtField* referrer) 281 REQUIRES_SHARED(Locks::mutator_lock_) 282 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 283 ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer) 284 REQUIRES_SHARED(Locks::mutator_lock_) 285 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 286 287 // Resolve a type with the given index from the DexFile associated with the given DexCache 288 // and ClassLoader, storing the result in DexCache. The ClassLoader is used to search for 289 // the type, since it may be referenced from but not contained within the DexFile. 290 ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, 291 Handle<mirror::DexCache> dex_cache, 292 Handle<mirror::ClassLoader> class_loader) 293 REQUIRES_SHARED(Locks::mutator_lock_) 294 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 295 296 // Look up a resolved type with the given index from the DexFile associated with the given 297 // `referrer`, storing the result in the DexCache. The `referrer` is used to identify the 298 // target DexCache and ClassLoader to use for lookup. 299 ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, 300 ObjPtr<mirror::Class> referrer) 301 REQUIRES_SHARED(Locks::mutator_lock_); 302 ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, ArtField* referrer) 303 REQUIRES_SHARED(Locks::mutator_lock_); 304 ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, ArtMethod* referrer) 305 REQUIRES_SHARED(Locks::mutator_lock_); 306 307 // Look up a resolved type with the given index from the DexFile associated with the given 308 // DexCache and ClassLoader. The ClassLoader is used to search for the type, since it may 309 // be referenced from but not contained within the DexFile. 310 ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, 311 ObjPtr<mirror::DexCache> dex_cache, 312 ObjPtr<mirror::ClassLoader> class_loader) 313 REQUIRES_SHARED(Locks::mutator_lock_); 314 315 // Look up a resolved type with the given descriptor associated with the given ClassLoader. 316 ObjPtr<mirror::Class> LookupResolvedType(const char* descriptor, 317 ObjPtr<mirror::ClassLoader> class_loader) 318 REQUIRES_SHARED(Locks::mutator_lock_); 319 320 // Determine whether a dex cache result should be trusted, or an IncompatibleClassChangeError 321 // check and IllegalAccessError check should be performed even after a hit. 322 enum class ResolveMode { // private. 323 kNoChecks, 324 kCheckICCEAndIAE 325 }; 326 327 // Look up a previously resolved method with the given index. 328 ArtMethod* LookupResolvedMethod(uint32_t method_idx, 329 ObjPtr<mirror::DexCache> dex_cache, 330 ObjPtr<mirror::ClassLoader> class_loader) 331 REQUIRES_SHARED(Locks::mutator_lock_); 332 333 // Find a method with the given index from class `klass`, and update the dex cache. 334 ArtMethod* FindResolvedMethod(ObjPtr<mirror::Class> klass, 335 ObjPtr<mirror::DexCache> dex_cache, 336 ObjPtr<mirror::ClassLoader> class_loader, 337 uint32_t method_idx) 338 REQUIRES_SHARED(Locks::mutator_lock_); 339 340 // Find a method using the wrong lookup mechanism. If `klass` is an interface, 341 // search for a class method. If it is a class, search for an interface method. 342 // This is useful when throwing IncompatibleClassChangeError. 343 ArtMethod* FindIncompatibleMethod(ObjPtr<mirror::Class> klass, 344 ObjPtr<mirror::DexCache> dex_cache, 345 ObjPtr<mirror::ClassLoader> class_loader, 346 uint32_t method_idx) 347 REQUIRES_SHARED(Locks::mutator_lock_); 348 349 // Resolve a method with a given ID from the DexFile associated with the given DexCache 350 // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader are 351 // used as in ResolveType. What is unique is the method type argument which is used to 352 // determine if this method is a direct, static, or virtual method. 353 template <ResolveMode kResolveMode> 354 ArtMethod* ResolveMethod(uint32_t method_idx, 355 Handle<mirror::DexCache> dex_cache, 356 Handle<mirror::ClassLoader> class_loader, 357 ArtMethod* referrer, 358 InvokeType type) 359 REQUIRES_SHARED(Locks::mutator_lock_) 360 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 361 362 template <InvokeType type, ResolveMode kResolveMode> 363 ArtMethod* GetResolvedMethod(uint32_t method_idx, ArtMethod* referrer) 364 REQUIRES_SHARED(Locks::mutator_lock_); 365 366 template <ResolveMode kResolveMode> 367 ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, ArtMethod* referrer, InvokeType type) 368 REQUIRES_SHARED(Locks::mutator_lock_) 369 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 370 ArtMethod* ResolveMethodWithoutInvokeType(uint32_t method_idx, 371 Handle<mirror::DexCache> dex_cache, 372 Handle<mirror::ClassLoader> class_loader) 373 REQUIRES_SHARED(Locks::mutator_lock_) 374 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 375 376 ArtField* LookupResolvedField(uint32_t field_idx, ArtMethod* referrer, bool is_static) 377 REQUIRES_SHARED(Locks::mutator_lock_); 378 ArtField* ResolveField(uint32_t field_idx, ArtMethod* referrer, bool is_static) 379 REQUIRES_SHARED(Locks::mutator_lock_) 380 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 381 382 // Resolve a field with a given ID from the DexFile associated with the given DexCache 383 // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader 384 // are used as in ResolveType. What is unique is the is_static argument which is used 385 // to determine if we are resolving a static or non-static field. 386 ArtField* ResolveField(uint32_t field_idx, 387 Handle<mirror::DexCache> dex_cache, 388 Handle<mirror::ClassLoader> class_loader, 389 bool is_static) 390 REQUIRES_SHARED(Locks::mutator_lock_) 391 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 392 393 // Resolve a field with a given ID from the DexFile associated with the given DexCache 394 // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader 395 // are used as in ResolveType. No is_static argument is provided so that Java 396 // field resolution semantics are followed. 397 ArtField* ResolveFieldJLS(uint32_t field_idx, 398 Handle<mirror::DexCache> dex_cache, 399 Handle<mirror::ClassLoader> class_loader) 400 REQUIRES_SHARED(Locks::mutator_lock_) 401 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 402 403 // Find a field with a given ID from the DexFile associated with the given DexCache 404 // and ClassLoader, storing the result in DexCache. The declaring class is assumed 405 // to have been already resolved into `klass`. The `is_static` argument is used to 406 // determine if we are resolving a static or non-static field. 407 ArtField* FindResolvedField(ObjPtr<mirror::Class> klass, 408 ObjPtr<mirror::DexCache> dex_cache, 409 ObjPtr<mirror::ClassLoader> class_loader, 410 uint32_t field_idx, 411 bool is_static) 412 REQUIRES_SHARED(Locks::mutator_lock_); 413 414 // Find a field with a given ID from the DexFile associated with the given DexCache 415 // and ClassLoader, storing the result in DexCache. The declaring class is assumed 416 // to have been already resolved into `klass`. No is_static argument is provided 417 // so that Java field resolution semantics are followed. 418 ArtField* FindResolvedFieldJLS(ObjPtr<mirror::Class> klass, 419 ObjPtr<mirror::DexCache> dex_cache, 420 ObjPtr<mirror::ClassLoader> class_loader, 421 uint32_t field_idx) 422 REQUIRES_SHARED(Locks::mutator_lock_); 423 424 // Resolve a method type with a given ID from the DexFile associated with a given DexCache 425 // and ClassLoader, storing the result in the DexCache. 426 ObjPtr<mirror::MethodType> ResolveMethodType(Thread* self, 427 dex::ProtoIndex proto_idx, 428 Handle<mirror::DexCache> dex_cache, 429 Handle<mirror::ClassLoader> class_loader) 430 REQUIRES_SHARED(Locks::mutator_lock_) 431 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 432 433 ObjPtr<mirror::MethodType> ResolveMethodType(Thread* self, 434 dex::ProtoIndex proto_idx, 435 ArtMethod* referrer) 436 REQUIRES_SHARED(Locks::mutator_lock_); 437 438 // Resolve a method handle with a given ID from the DexFile. The 439 // result is not cached in the DexCache as the instance will only be 440 // used once in most circumstances. 441 ObjPtr<mirror::MethodHandle> ResolveMethodHandle(Thread* self, 442 uint32_t method_handle_idx, 443 ArtMethod* referrer) 444 REQUIRES_SHARED(Locks::mutator_lock_); 445 446 // Returns true on success, false if there's an exception pending. 447 // can_run_clinit=false allows the compiler to attempt to init a class, 448 // given the restriction that no <clinit> execution is possible. 449 bool EnsureInitialized(Thread* self, 450 Handle<mirror::Class> c, 451 bool can_init_fields, 452 bool can_init_parents) 453 REQUIRES_SHARED(Locks::mutator_lock_) 454 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 455 456 // Initializes classes that have instances in the image but that have 457 // <clinit> methods so they could not be initialized by the compiler. 458 void RunRootClinits(Thread* self) 459 REQUIRES_SHARED(Locks::mutator_lock_) 460 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 461 462 // Directly register an already existing dex cache. RegisterDexFile should be preferred since that 463 // reduplicates DexCaches when possible. The DexCache given to this function must already be fully 464 // initialized and not already registered. 465 void RegisterExistingDexCache(ObjPtr<mirror::DexCache> cache, 466 ObjPtr<mirror::ClassLoader> class_loader) 467 REQUIRES(!Locks::dex_lock_) 468 REQUIRES_SHARED(Locks::mutator_lock_); 469 ObjPtr<mirror::DexCache> RegisterDexFile(const DexFile& dex_file, 470 ObjPtr<mirror::ClassLoader> class_loader) 471 REQUIRES(!Locks::dex_lock_) 472 REQUIRES_SHARED(Locks::mutator_lock_); 473 GetBootClassPath()474 const std::vector<const DexFile*>& GetBootClassPath() { 475 return boot_class_path_; 476 } 477 478 void VisitClasses(ClassVisitor* visitor) 479 REQUIRES(!Locks::classlinker_classes_lock_) 480 REQUIRES_SHARED(Locks::mutator_lock_); 481 482 // Less efficient variant of VisitClasses that copies the class_table_ into secondary storage 483 // so that it can visit individual classes without holding the doesn't hold the 484 // Locks::classlinker_classes_lock_. As the Locks::classlinker_classes_lock_ isn't held this code 485 // can race with insertion and deletion of classes while the visitor is being called. 486 void VisitClassesWithoutClassesLock(ClassVisitor* visitor) 487 REQUIRES_SHARED(Locks::mutator_lock_) 488 REQUIRES(!Locks::dex_lock_); 489 490 void VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags) 491 REQUIRES(!Locks::classlinker_classes_lock_, !Locks::trace_lock_) 492 REQUIRES_SHARED(Locks::mutator_lock_); 493 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags) 494 REQUIRES(!Locks::dex_lock_, !Locks::classlinker_classes_lock_, !Locks::trace_lock_) 495 REQUIRES_SHARED(Locks::mutator_lock_); 496 // Visits all dex-files accessible by any class-loader or the BCP. 497 template<typename Visitor> 498 void VisitKnownDexFiles(Thread* self, Visitor visitor) REQUIRES(Locks::mutator_lock_); 499 500 bool IsDexFileRegistered(Thread* self, const DexFile& dex_file) 501 REQUIRES(!Locks::dex_lock_) 502 REQUIRES_SHARED(Locks::mutator_lock_); 503 ObjPtr<mirror::DexCache> FindDexCache(Thread* self, const DexFile& dex_file) 504 REQUIRES(!Locks::dex_lock_) 505 REQUIRES_SHARED(Locks::mutator_lock_); 506 ClassTable* FindClassTable(Thread* self, ObjPtr<mirror::DexCache> dex_cache) 507 REQUIRES(!Locks::dex_lock_) 508 REQUIRES_SHARED(Locks::mutator_lock_); 509 510 LengthPrefixedArray<ArtField>* AllocArtFieldArray(Thread* self, 511 LinearAlloc* allocator, 512 size_t length); 513 514 LengthPrefixedArray<ArtMethod>* AllocArtMethodArray(Thread* self, 515 LinearAlloc* allocator, 516 size_t length); 517 518 // Convenience AllocClass() overload that uses mirror::Class::InitializeClassVisitor 519 // for the class initialization and uses the `java_lang_Class` from class roots 520 // instead of an explicit argument. 521 ObjPtr<mirror::Class> AllocClass(Thread* self, uint32_t class_size) 522 REQUIRES_SHARED(Locks::mutator_lock_) 523 REQUIRES(!Roles::uninterruptible_); 524 525 // Setup the classloader, class def index, type idx so that we can insert this class in the class 526 // table. 527 void SetupClass(const DexFile& dex_file, 528 const dex::ClassDef& dex_class_def, 529 Handle<mirror::Class> klass, 530 ObjPtr<mirror::ClassLoader> class_loader) 531 REQUIRES_SHARED(Locks::mutator_lock_); 532 533 void LoadClass(Thread* self, 534 const DexFile& dex_file, 535 const dex::ClassDef& dex_class_def, 536 Handle<mirror::Class> klass) 537 REQUIRES_SHARED(Locks::mutator_lock_); 538 539 // Link the class and place it into the class-table using the given descriptor. NB if the 540 // descriptor is null the class will not be placed in any class-table. This is useful implementing 541 // obsolete classes and should not be used otherwise. 542 bool LinkClass(Thread* self, 543 const char* descriptor, 544 Handle<mirror::Class> klass, 545 Handle<mirror::ObjectArray<mirror::Class>> interfaces, 546 MutableHandle<mirror::Class>* h_new_class_out) 547 REQUIRES_SHARED(Locks::mutator_lock_) 548 REQUIRES(!Locks::classlinker_classes_lock_); 549 550 ObjPtr<mirror::PointerArray> AllocPointerArray(Thread* self, size_t length) 551 REQUIRES_SHARED(Locks::mutator_lock_) 552 REQUIRES(!Roles::uninterruptible_); 553 554 ObjPtr<mirror::IfTable> AllocIfTable(Thread* self, size_t ifcount) 555 REQUIRES_SHARED(Locks::mutator_lock_) 556 REQUIRES(!Roles::uninterruptible_); 557 558 ObjPtr<mirror::ObjectArray<mirror::StackTraceElement>> AllocStackTraceElementArray(Thread* self, 559 size_t length) 560 REQUIRES_SHARED(Locks::mutator_lock_) 561 REQUIRES(!Roles::uninterruptible_); 562 563 verifier::FailureKind VerifyClass( 564 Thread* self, 565 verifier::VerifierDeps* verifier_deps, 566 Handle<mirror::Class> klass, 567 verifier::HardFailLogMode log_level = verifier::HardFailLogMode::kLogNone) 568 REQUIRES_SHARED(Locks::mutator_lock_) 569 REQUIRES(!Locks::dex_lock_); 570 bool VerifyClassUsingOatFile(Thread* self, 571 const DexFile& dex_file, 572 Handle<mirror::Class> klass, 573 ClassStatus& oat_file_class_status) 574 REQUIRES_SHARED(Locks::mutator_lock_) 575 REQUIRES(!Locks::dex_lock_); 576 void ResolveClassExceptionHandlerTypes(Handle<mirror::Class> klass) 577 REQUIRES_SHARED(Locks::mutator_lock_) 578 REQUIRES(!Locks::dex_lock_); 579 void ResolveMethodExceptionHandlerTypes(ArtMethod* klass) 580 REQUIRES_SHARED(Locks::mutator_lock_) 581 REQUIRES(!Locks::dex_lock_); 582 583 ObjPtr<mirror::Class> CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, 584 jstring name, 585 jobjectArray interfaces, 586 jobject loader, 587 jobjectArray methods, 588 jobjectArray throws) 589 REQUIRES_SHARED(Locks::mutator_lock_); 590 591 // Get the oat code for a method when its class isn't yet initialized. 592 const void* GetQuickOatCodeFor(ArtMethod* method) 593 REQUIRES_SHARED(Locks::mutator_lock_); 594 595 pid_t GetClassesLockOwner(); // For SignalCatcher. 596 pid_t GetDexLockOwner(); // For SignalCatcher. 597 598 // Is the given entry point quick code to run the resolution stub? 599 bool IsQuickResolutionStub(const void* entry_point) const; 600 601 // Is the given entry point quick code to bridge into the interpreter? 602 bool IsQuickToInterpreterBridge(const void* entry_point) const; 603 604 // Is the given entry point quick code to run the generic JNI stub? 605 bool IsQuickGenericJniStub(const void* entry_point) const; 606 607 // Is the given entry point the JNI dlsym lookup stub? 608 bool IsJniDlsymLookupStub(const void* entry_point) const; 609 610 // Is the given entry point the JNI dlsym lookup critical stub? 611 bool IsJniDlsymLookupCriticalStub(const void* entry_point) const; 612 613 // Is the given entry point the nterp trampoline? IsNterpTrampoline(const void * entry_point)614 bool IsNterpTrampoline(const void* entry_point) const { 615 return nterp_trampoline_ == entry_point; 616 } 617 GetQuickToInterpreterBridgeTrampoline()618 const void* GetQuickToInterpreterBridgeTrampoline() const { 619 return quick_to_interpreter_bridge_trampoline_; 620 } 621 GetInternTable()622 InternTable* GetInternTable() const { 623 return intern_table_; 624 } 625 626 // Set the entrypoints up for method to the enter the interpreter. 627 void SetEntryPointsToInterpreter(ArtMethod* method) const 628 REQUIRES_SHARED(Locks::mutator_lock_); 629 630 // Set the entrypoints up for an obsolete method. 631 void SetEntryPointsForObsoleteMethod(ArtMethod* method) const 632 REQUIRES_SHARED(Locks::mutator_lock_); 633 634 // Attempts to insert a class into a class table. Returns null if 635 // the class was inserted, otherwise returns an existing class with 636 // the same descriptor and ClassLoader. 637 ObjPtr<mirror::Class> InsertClass(const char* descriptor, 638 ObjPtr<mirror::Class> klass, 639 size_t hash) 640 REQUIRES(!Locks::classlinker_classes_lock_) 641 REQUIRES_SHARED(Locks::mutator_lock_); 642 643 // Add an oat file with .bss GC roots to be visited again at the end of GC 644 // for collector types that need it. 645 void WriteBarrierForBootOatFileBssRoots(const OatFile* oat_file) 646 REQUIRES(!Locks::classlinker_classes_lock_) 647 REQUIRES_SHARED(Locks::mutator_lock_); 648 649 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 650 ObjPtr<mirror::ObjectArray<mirror::Class>> GetClassRoots() REQUIRES_SHARED(Locks::mutator_lock_); 651 652 // Move the class table to the pre-zygote table to reduce memory usage. This works by ensuring 653 // that no more classes are ever added to the pre zygote table which makes it that the pages 654 // always remain shared dirty instead of private dirty. 655 void MoveClassTableToPreZygote() 656 REQUIRES(!Locks::classlinker_classes_lock_) 657 REQUIRES_SHARED(Locks::mutator_lock_); 658 659 // Creates a GlobalRef PathClassLoader or DelegateLastClassLoader (specified by loader_class) 660 // that can be used to load classes from the given dex files. The parent of the class loader 661 // will be set to `parent_loader`. If `parent_loader` is null the parent will be 662 // the boot class loader. 663 // If class_loader points to a different class than PathClassLoader or DelegateLastClassLoader 664 // this method will abort. 665 // Note: the objects are not completely set up. Do not use this outside of tests and the compiler. 666 jobject CreateWellKnownClassLoader(Thread* self, 667 const std::vector<const DexFile*>& dex_files, 668 jclass loader_class, 669 jobject parent_loader, 670 jobject shared_libraries = nullptr) 671 REQUIRES_SHARED(Locks::mutator_lock_) 672 REQUIRES(!Locks::dex_lock_); 673 674 // Calls CreateWellKnownClassLoader(self, 675 // dex_files, 676 // WellKnownClasses::dalvik_system_PathClassLoader, 677 // nullptr) 678 jobject CreatePathClassLoader(Thread* self, const std::vector<const DexFile*>& dex_files) 679 REQUIRES_SHARED(Locks::mutator_lock_) 680 REQUIRES(!Locks::dex_lock_); 681 682 // Non-GlobalRef version of CreateWellKnownClassLoader 683 ObjPtr<mirror::ClassLoader> CreateWellKnownClassLoader( 684 Thread* self, 685 const std::vector<const DexFile*>& dex_files, 686 Handle<mirror::Class> loader_class, 687 Handle<mirror::ClassLoader> parent_loader, 688 Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries) 689 REQUIRES_SHARED(Locks::mutator_lock_) 690 REQUIRES(!Locks::dex_lock_); 691 GetImagePointerSize()692 PointerSize GetImagePointerSize() const { 693 return image_pointer_size_; 694 } 695 696 // Clear the ArrayClass cache. This is necessary when cleaning up for the image, as the cache 697 // entries are roots, but potentially not image classes. 698 void DropFindArrayClassCache() REQUIRES_SHARED(Locks::mutator_lock_); 699 700 // Clean up class loaders, this needs to happen after JNI weak globals are cleared. 701 void CleanupClassLoaders() 702 REQUIRES(!Locks::classlinker_classes_lock_) 703 REQUIRES_SHARED(Locks::mutator_lock_); 704 705 // Unlike GetOrCreateAllocatorForClassLoader, GetAllocatorForClassLoader asserts that the 706 // allocator for this class loader is already created. 707 LinearAlloc* GetAllocatorForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 708 REQUIRES_SHARED(Locks::mutator_lock_); 709 710 // Return the linear alloc for a class loader if it is already allocated, otherwise allocate and 711 // set it. TODO: Consider using a lock other than classlinker_classes_lock_. 712 LinearAlloc* GetOrCreateAllocatorForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 713 REQUIRES(!Locks::classlinker_classes_lock_) 714 REQUIRES_SHARED(Locks::mutator_lock_); 715 716 // May be called with null class_loader due to legacy code. b/27954959 717 void InsertDexFileInToClassLoader(ObjPtr<mirror::Object> dex_file, 718 ObjPtr<mirror::ClassLoader> class_loader) 719 REQUIRES(!Locks::classlinker_classes_lock_) 720 REQUIRES_SHARED(Locks::mutator_lock_); 721 722 static bool ShouldUseInterpreterEntrypoint(ArtMethod* method, const void* quick_code) 723 REQUIRES_SHARED(Locks::mutator_lock_); 724 725 static bool IsBootClassLoader(ScopedObjectAccessAlreadyRunnable& soa, 726 ObjPtr<mirror::ClassLoader> class_loader) 727 REQUIRES_SHARED(Locks::mutator_lock_); 728 729 ArtMethod* AddMethodToConflictTable(ObjPtr<mirror::Class> klass, 730 ArtMethod* conflict_method, 731 ArtMethod* interface_method, 732 ArtMethod* method) 733 REQUIRES_SHARED(Locks::mutator_lock_); 734 735 // Create a conflict table with a specified capacity. 736 ImtConflictTable* CreateImtConflictTable(size_t count, LinearAlloc* linear_alloc); 737 738 // Static version for when the class linker is not yet created. 739 static ImtConflictTable* CreateImtConflictTable(size_t count, 740 LinearAlloc* linear_alloc, 741 PointerSize pointer_size); 742 743 744 // Create the IMT and conflict tables for a class. 745 void FillIMTAndConflictTables(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_); 746 747 // Visit all of the class tables. This is used by dex2oat to allow pruning dex caches. 748 template <class Visitor> 749 void VisitClassTables(const Visitor& visitor) 750 REQUIRES(!Locks::classlinker_classes_lock_) 751 REQUIRES_SHARED(Locks::mutator_lock_); 752 753 // Visit all of the allocators that belong to classloaders except boot classloader. 754 // This is used by 616-cha-unloading test to confirm memory reuse. 755 void VisitAllocators(AllocatorVisitor* visitor) const 756 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_); 757 758 // Throw the class initialization failure recorded when first trying to initialize the given 759 // class. 760 void ThrowEarlierClassFailure(ObjPtr<mirror::Class> c, 761 bool wrap_in_no_class_def = false, 762 bool log = false) 763 REQUIRES_SHARED(Locks::mutator_lock_) 764 REQUIRES(!Locks::dex_lock_); 765 766 // Get the actual holding class for a copied method. Pretty slow, don't call often. 767 ObjPtr<mirror::Class> GetHoldingClassOfCopiedMethod(ArtMethod* method) 768 REQUIRES_SHARED(Locks::mutator_lock_); 769 770 // Returns null if not found. 771 // This returns a pointer to the class-table, without requiring any locking - including the 772 // boot class-table. It is the caller's responsibility to access this under lock, if required. 773 ClassTable* ClassTableForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 774 REQUIRES_SHARED(Locks::mutator_lock_) 775 NO_THREAD_SAFETY_ANALYSIS; 776 777 void AppendToBootClassPath(Thread* self, const DexFile* dex_file) 778 REQUIRES_SHARED(Locks::mutator_lock_) 779 REQUIRES(!Locks::dex_lock_); 780 781 // Visit all of the class loaders in the class linker. 782 void VisitClassLoaders(ClassLoaderVisitor* visitor) const 783 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_); 784 785 // Checks that a class and its superclass from another class loader have the same virtual methods. 786 bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass) 787 REQUIRES_SHARED(Locks::mutator_lock_); 788 GetClassHierarchyAnalysis()789 ClassHierarchyAnalysis* GetClassHierarchyAnalysis() { 790 return cha_.get(); 791 } 792 793 void MakeInitializedClassesVisiblyInitialized(Thread* self, bool wait); 794 795 // Registers the native method and returns the new entry point. NB The returned entry point 796 // might be different from the native_method argument if some MethodCallback modifies it. 797 const void* RegisterNative(Thread* self, ArtMethod* method, const void* native_method) 798 REQUIRES_SHARED(Locks::mutator_lock_) WARN_UNUSED; 799 800 // Unregister native code for a method. 801 void UnregisterNative(Thread* self, ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); 802 803 // Get the registered native method entrypoint, if any, otherwise null. 804 const void* GetRegisteredNative(Thread* self, ArtMethod* method) 805 REQUIRES_SHARED(Locks::mutator_lock_) 806 REQUIRES(!critical_native_code_with_clinit_check_lock_); 807 808 struct DexCacheData { 809 // Construct an invalid data object. DexCacheDataDexCacheData810 DexCacheData() 811 : weak_root(nullptr), 812 dex_file(nullptr), 813 class_table(nullptr) { } 814 815 // Check if the data is valid. IsValidDexCacheData816 bool IsValid() const { 817 return dex_file != nullptr; 818 } 819 820 // Weak root to the DexCache. Note: Do not decode this unnecessarily or else class unloading may 821 // not work properly. 822 jweak weak_root; 823 // The following field caches the DexCache's field here to avoid unnecessary jweak decode that 824 // triggers read barriers (and marks them alive unnecessarily and messes with class unloading.) 825 const DexFile* dex_file; 826 // Identify the associated class loader's class table. This is used to make sure that 827 // the Java call to native DexCache.setResolvedType() inserts the resolved type in that 828 // class table. It is also used to make sure we don't register the same dex cache with 829 // multiple class loaders. 830 ClassTable* class_table; 831 }; 832 833 // Forces a class to be marked as initialized without actually running initializers. Should only 834 // be used by plugin code when creating new classes directly. 835 void ForceClassInitialized(Thread* self, Handle<mirror::Class> klass) 836 REQUIRES_SHARED(Locks::mutator_lock_) 837 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 838 839 // Verifies if the method is accesible according to the SdkChecker (if installed). 840 virtual bool DenyAccessBasedOnPublicSdk(ArtMethod* art_method) const 841 REQUIRES_SHARED(Locks::mutator_lock_); 842 // Verifies if the field is accesible according to the SdkChecker (if installed). 843 virtual bool DenyAccessBasedOnPublicSdk(ArtField* art_field) const 844 REQUIRES_SHARED(Locks::mutator_lock_); 845 // Verifies if the descriptor is accesible according to the SdkChecker (if installed). 846 virtual bool DenyAccessBasedOnPublicSdk(const char* type_descriptor) const; 847 // Enable or disable public sdk checks. 848 virtual void SetEnablePublicSdkChecks(bool enabled); 849 850 protected: 851 virtual bool InitializeClass(Thread* self, 852 Handle<mirror::Class> klass, 853 bool can_run_clinit, 854 bool can_init_parents) 855 REQUIRES_SHARED(Locks::mutator_lock_) 856 REQUIRES(!Locks::dex_lock_); 857 858 virtual verifier::FailureKind PerformClassVerification(Thread* self, 859 verifier::VerifierDeps* verifier_deps, 860 Handle<mirror::Class> klass, 861 verifier::HardFailLogMode log_level, 862 std::string* error_msg) 863 REQUIRES_SHARED(Locks::mutator_lock_); 864 CanAllocClass()865 virtual bool CanAllocClass() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_) { 866 return true; 867 } 868 869 virtual bool IsUpdatableBootClassPathDescriptor(const char* descriptor); 870 871 private: 872 class LinkFieldsHelper; 873 class LinkInterfaceMethodsHelper; 874 class MethodTranslation; 875 class VisiblyInitializedCallback; 876 877 struct ClassLoaderData { 878 jweak weak_root; // Weak root to enable class unloading. 879 ClassTable* class_table; 880 LinearAlloc* allocator; 881 }; 882 883 void VisiblyInitializedCallbackDone(Thread* self, VisiblyInitializedCallback* callback); 884 VisiblyInitializedCallback* MarkClassInitialized(Thread* self, Handle<mirror::Class> klass) 885 REQUIRES_SHARED(Locks::mutator_lock_); 886 887 // Ensures that the supertype of 'klass' ('supertype') is verified. Returns false and throws 888 // appropriate exceptions if verification failed hard. Returns true for successful verification or 889 // soft-failures. 890 bool AttemptSupertypeVerification(Thread* self, 891 verifier::VerifierDeps* verifier_deps, 892 Handle<mirror::Class> klass, 893 Handle<mirror::Class> supertype) 894 REQUIRES(!Locks::dex_lock_) 895 REQUIRES_SHARED(Locks::mutator_lock_); 896 897 void DeleteClassLoader(Thread* self, const ClassLoaderData& data, bool cleanup_cha) 898 REQUIRES_SHARED(Locks::mutator_lock_); 899 900 void VisitClassesInternal(ClassVisitor* visitor) 901 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_); 902 903 // Returns the number of zygote and image classes. 904 size_t NumZygoteClasses() const 905 REQUIRES(Locks::classlinker_classes_lock_) 906 REQUIRES_SHARED(Locks::mutator_lock_); 907 908 // Returns the number of non zygote nor image classes. 909 size_t NumNonZygoteClasses() const 910 REQUIRES(Locks::classlinker_classes_lock_) 911 REQUIRES_SHARED(Locks::mutator_lock_); 912 913 void FinishInit(Thread* self) 914 REQUIRES_SHARED(Locks::mutator_lock_) 915 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 916 917 // If we do not allow moving classes (`art::kMovingClass` is false) or if 918 // parameter `kMovable` is false (or both), the class object is allocated in 919 // the non-moving space. 920 template <bool kMovable = true, class PreFenceVisitor> 921 ObjPtr<mirror::Class> AllocClass(Thread* self, 922 ObjPtr<mirror::Class> java_lang_Class, 923 uint32_t class_size, 924 const PreFenceVisitor& pre_fence_visitor) 925 REQUIRES_SHARED(Locks::mutator_lock_) 926 REQUIRES(!Roles::uninterruptible_); 927 928 // Convenience AllocClass() overload that uses mirror::Class::InitializeClassVisitor 929 // for the class initialization. 930 template <bool kMovable = true> 931 ObjPtr<mirror::Class> AllocClass(Thread* self, 932 ObjPtr<mirror::Class> java_lang_Class, 933 uint32_t class_size) 934 REQUIRES_SHARED(Locks::mutator_lock_) 935 REQUIRES(!Roles::uninterruptible_); 936 937 // Allocate a primitive array class and store it in appropriate class root. 938 void AllocPrimitiveArrayClass(Thread* self, 939 ClassRoot primitive_root, 940 ClassRoot array_root) 941 REQUIRES_SHARED(Locks::mutator_lock_) 942 REQUIRES(!Roles::uninterruptible_); 943 944 // Finish setup of an array class. 945 void FinishArrayClassSetup(ObjPtr<mirror::Class> array_class) 946 REQUIRES_SHARED(Locks::mutator_lock_) 947 REQUIRES(!Roles::uninterruptible_); 948 949 // Finish setup of a core array class (Object[], Class[], String[] and 950 // primitive arrays) and insert it into the class table. 951 void FinishCoreArrayClassSetup(ClassRoot array_root) 952 REQUIRES_SHARED(Locks::mutator_lock_) 953 REQUIRES(!Roles::uninterruptible_); 954 955 ObjPtr<mirror::DexCache> AllocDexCache(Thread* self, const DexFile& dex_file) 956 REQUIRES_SHARED(Locks::mutator_lock_) 957 REQUIRES(!Roles::uninterruptible_); 958 959 // Used for tests and AppendToBootClassPath. 960 ObjPtr<mirror::DexCache> AllocAndInitializeDexCache(Thread* self, 961 const DexFile& dex_file, 962 LinearAlloc* linear_alloc) 963 REQUIRES_SHARED(Locks::mutator_lock_) 964 REQUIRES(!Locks::dex_lock_) 965 REQUIRES(!Roles::uninterruptible_); 966 967 // Create a primitive class and store it in the appropriate class root. 968 void CreatePrimitiveClass(Thread* self, Primitive::Type type, ClassRoot primitive_root) 969 REQUIRES_SHARED(Locks::mutator_lock_) 970 REQUIRES(!Roles::uninterruptible_); 971 972 ObjPtr<mirror::Class> CreateArrayClass(Thread* self, 973 const char* descriptor, 974 size_t hash, 975 Handle<mirror::ClassLoader> class_loader) 976 REQUIRES_SHARED(Locks::mutator_lock_) 977 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 978 979 void AppendToBootClassPath(const DexFile* dex_file, ObjPtr<mirror::DexCache> dex_cache) 980 REQUIRES_SHARED(Locks::mutator_lock_) 981 REQUIRES(!Locks::dex_lock_); 982 983 // Precomputes size needed for Class, in the case of a non-temporary class this size must be 984 // sufficient to hold all static fields. 985 uint32_t SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file, 986 const dex::ClassDef& dex_class_def); 987 988 void LoadField(const ClassAccessor::Field& field, Handle<mirror::Class> klass, ArtField* dst) 989 REQUIRES_SHARED(Locks::mutator_lock_); 990 991 void LoadMethod(const DexFile& dex_file, 992 const ClassAccessor::Method& method, 993 Handle<mirror::Class> klass, 994 ArtMethod* dst) 995 REQUIRES_SHARED(Locks::mutator_lock_); 996 997 void FixupStaticTrampolines(Thread* self, ObjPtr<mirror::Class> klass) 998 REQUIRES_SHARED(Locks::mutator_lock_); 999 1000 // Finds a class in a Path- or DexClassLoader, loading it if necessary without using JNI. Hash 1001 // function is supposed to be ComputeModifiedUtf8Hash(descriptor). Returns true if the 1002 // class-loader chain could be handled, false otherwise, i.e., a non-supported class-loader 1003 // was encountered while walking the parent chain (currently only BootClassLoader and 1004 // PathClassLoader are supported). 1005 bool FindClassInBaseDexClassLoader(ScopedObjectAccessAlreadyRunnable& soa, 1006 Thread* self, 1007 const char* descriptor, 1008 size_t hash, 1009 Handle<mirror::ClassLoader> class_loader, 1010 /*out*/ ObjPtr<mirror::Class>* result) 1011 REQUIRES_SHARED(Locks::mutator_lock_) 1012 REQUIRES(!Locks::dex_lock_); 1013 1014 bool FindClassInSharedLibraries(ScopedObjectAccessAlreadyRunnable& soa, 1015 Thread* self, 1016 const char* descriptor, 1017 size_t hash, 1018 Handle<mirror::ClassLoader> class_loader, 1019 /*out*/ ObjPtr<mirror::Class>* result) 1020 REQUIRES_SHARED(Locks::mutator_lock_) 1021 REQUIRES(!Locks::dex_lock_); 1022 1023 // Finds the class in the classpath of the given class loader. It only searches the class loader 1024 // dex files and does not recurse into its parent. 1025 // The method checks that the provided class loader is either a PathClassLoader or a 1026 // DexClassLoader. 1027 // If the class is found the method updates `result`. 1028 // The method always returns true, to notify to the caller a 1029 // BaseDexClassLoader has a known lookup. 1030 bool FindClassInBaseDexClassLoaderClassPath( 1031 ScopedObjectAccessAlreadyRunnable& soa, 1032 const char* descriptor, 1033 size_t hash, 1034 Handle<mirror::ClassLoader> class_loader, 1035 /*out*/ ObjPtr<mirror::Class>* result) 1036 REQUIRES_SHARED(Locks::mutator_lock_) 1037 REQUIRES(!Locks::dex_lock_); 1038 1039 // Finds the class in the boot class loader. 1040 // If the class is found the method updates `result`. 1041 // The method always returns true, to notify to the caller the 1042 // boot class loader has a known lookup. 1043 bool FindClassInBootClassLoaderClassPath(Thread* self, 1044 const char* descriptor, 1045 size_t hash, 1046 /*out*/ ObjPtr<mirror::Class>* result) 1047 REQUIRES_SHARED(Locks::mutator_lock_) 1048 REQUIRES(!Locks::dex_lock_); 1049 1050 // Implementation of LookupResolvedType() called when the type was not found in the dex cache. 1051 ObjPtr<mirror::Class> DoLookupResolvedType(dex::TypeIndex type_idx, 1052 ObjPtr<mirror::Class> referrer) 1053 REQUIRES_SHARED(Locks::mutator_lock_); 1054 ObjPtr<mirror::Class> DoLookupResolvedType(dex::TypeIndex type_idx, 1055 ObjPtr<mirror::DexCache> dex_cache, 1056 ObjPtr<mirror::ClassLoader> class_loader) 1057 REQUIRES_SHARED(Locks::mutator_lock_); 1058 1059 // Implementation of ResolveString() called when the string was not found in the dex cache. 1060 ObjPtr<mirror::String> DoResolveString(dex::StringIndex string_idx, 1061 ObjPtr<mirror::DexCache> dex_cache) 1062 REQUIRES_SHARED(Locks::mutator_lock_); 1063 ObjPtr<mirror::String> DoResolveString(dex::StringIndex string_idx, 1064 Handle<mirror::DexCache> dex_cache) 1065 REQUIRES_SHARED(Locks::mutator_lock_); 1066 1067 // Implementation of LookupString() called when the string was not found in the dex cache. 1068 ObjPtr<mirror::String> DoLookupString(dex::StringIndex string_idx, 1069 ObjPtr<mirror::DexCache> dex_cache) 1070 REQUIRES_SHARED(Locks::mutator_lock_); 1071 1072 // Implementation of ResolveType() called when the type was not found in the dex cache. May be 1073 // used with ArtField*, ArtMethod* or ObjPtr<Class>. 1074 template <typename RefType> 1075 ObjPtr<mirror::Class> DoResolveType(dex::TypeIndex type_idx, RefType referrer) 1076 REQUIRES_SHARED(Locks::mutator_lock_) 1077 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 1078 ObjPtr<mirror::Class> DoResolveType(dex::TypeIndex type_idx, 1079 Handle<mirror::DexCache> dex_cache, 1080 Handle<mirror::ClassLoader> class_loader) 1081 REQUIRES_SHARED(Locks::mutator_lock_) 1082 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 1083 1084 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded 1085 // by the given 'class_loader'. Uses the provided hash for the descriptor. 1086 ObjPtr<mirror::Class> LookupClass(Thread* self, 1087 const char* descriptor, 1088 size_t hash, 1089 ObjPtr<mirror::ClassLoader> class_loader) 1090 REQUIRES(!Locks::classlinker_classes_lock_) 1091 REQUIRES_SHARED(Locks::mutator_lock_); 1092 1093 // Find a field by its field index. 1094 ArtField* LookupResolvedField(uint32_t field_idx, 1095 ObjPtr<mirror::DexCache> dex_cache, 1096 ObjPtr<mirror::ClassLoader> class_loader, 1097 bool is_static) 1098 REQUIRES_SHARED(Locks::mutator_lock_); 1099 1100 void RegisterDexFileLocked(const DexFile& dex_file, 1101 ObjPtr<mirror::DexCache> dex_cache, 1102 ObjPtr<mirror::ClassLoader> class_loader) 1103 REQUIRES(Locks::dex_lock_) 1104 REQUIRES_SHARED(Locks::mutator_lock_); 1105 const DexCacheData* FindDexCacheDataLocked(const DexFile& dex_file) 1106 REQUIRES(Locks::dex_lock_) 1107 REQUIRES_SHARED(Locks::mutator_lock_); 1108 static ObjPtr<mirror::DexCache> DecodeDexCacheLocked(Thread* self, const DexCacheData* data) 1109 REQUIRES_SHARED(Locks::dex_lock_, Locks::mutator_lock_); 1110 bool IsSameClassLoader(ObjPtr<mirror::DexCache> dex_cache, 1111 const DexCacheData* data, 1112 ObjPtr<mirror::ClassLoader> class_loader) 1113 REQUIRES_SHARED(Locks::dex_lock_, Locks::mutator_lock_); 1114 1115 bool InitializeDefaultInterfaceRecursive(Thread* self, 1116 Handle<mirror::Class> klass, 1117 bool can_run_clinit, 1118 bool can_init_parents) 1119 REQUIRES(!Locks::dex_lock_) 1120 REQUIRES_SHARED(Locks::mutator_lock_); 1121 bool WaitForInitializeClass(Handle<mirror::Class> klass, 1122 Thread* self, 1123 ObjectLock<mirror::Class>& lock); 1124 1125 bool IsSameDescriptorInDifferentClassContexts(Thread* self, 1126 const char* descriptor, 1127 Handle<mirror::ClassLoader> class_loader1, 1128 Handle<mirror::ClassLoader> class_loader2) 1129 REQUIRES_SHARED(Locks::mutator_lock_); 1130 1131 bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, 1132 ArtMethod* method, 1133 ObjPtr<mirror::Class> klass1, 1134 ObjPtr<mirror::Class> klass2) 1135 REQUIRES_SHARED(Locks::mutator_lock_); 1136 1137 bool LinkSuperClass(Handle<mirror::Class> klass) 1138 REQUIRES_SHARED(Locks::mutator_lock_); 1139 1140 bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file) 1141 REQUIRES_SHARED(Locks::mutator_lock_) 1142 REQUIRES(!Locks::dex_lock_); 1143 1144 bool LinkMethods(Thread* self, 1145 Handle<mirror::Class> klass, 1146 Handle<mirror::ObjectArray<mirror::Class>> interfaces, 1147 bool* out_new_conflict, 1148 ArtMethod** out_imt) 1149 REQUIRES_SHARED(Locks::mutator_lock_); 1150 1151 ObjPtr<mirror::MethodHandle> ResolveMethodHandleForField( 1152 Thread* self, 1153 const dex::MethodHandleItem& method_handle, 1154 ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_); 1155 1156 ObjPtr<mirror::MethodHandle> ResolveMethodHandleForMethod( 1157 Thread* self, 1158 const dex::MethodHandleItem& method_handle, 1159 ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_); 1160 1161 // Links the virtual methods for the given class and records any default methods that will need to 1162 // be updated later. 1163 // 1164 // Arguments: 1165 // * self - The current thread. 1166 // * klass - class, whose vtable will be filled in. 1167 // * default_translations - Vtable index to new method map. 1168 // Any vtable entries that need to be updated with new default methods 1169 // are stored into the default_translations map. The default_translations 1170 // map is keyed on the vtable index that needs to be updated. We use this 1171 // map because if we override a default method with another default 1172 // method we need to update the vtable to point to the new method. 1173 // Unfortunately since we copy the ArtMethod* we cannot just do a simple 1174 // scan, we therefore store the vtable index's that might need to be 1175 // updated with the method they will turn into. 1176 // TODO This whole default_translations thing is very dirty. There should be a better way. 1177 bool LinkVirtualMethods( 1178 Thread* self, 1179 Handle<mirror::Class> klass, 1180 /*out*/HashMap<size_t, MethodTranslation>* default_translations) 1181 REQUIRES_SHARED(Locks::mutator_lock_); 1182 1183 // Sets up the interface lookup table (IFTable) in the correct order to allow searching for 1184 // default methods. 1185 bool SetupInterfaceLookupTable(Thread* self, 1186 Handle<mirror::Class> klass, 1187 Handle<mirror::ObjectArray<mirror::Class>> interfaces) 1188 REQUIRES_SHARED(Locks::mutator_lock_); 1189 1190 1191 enum class DefaultMethodSearchResult { 1192 kDefaultFound, 1193 kAbstractFound, 1194 kDefaultConflict 1195 }; 1196 1197 // Find the default method implementation for 'interface_method' in 'klass', if one exists. 1198 // 1199 // Arguments: 1200 // * self - The current thread. 1201 // * target_method - The method we are trying to find a default implementation for. 1202 // * klass - The class we are searching for a definition of target_method. 1203 // * out_default_method - The pointer we will store the found default method to on success. 1204 // 1205 // Return value: 1206 // * kDefaultFound - There were no conflicting method implementations found in the class while 1207 // searching for target_method. The default method implementation is stored into 1208 // out_default_method. 1209 // * kAbstractFound - There were no conflicting method implementations found in the class while 1210 // searching for target_method but no default implementation was found either. 1211 // out_default_method is set to null and the method should be considered not 1212 // implemented. 1213 // * kDefaultConflict - Conflicting method implementations were found when searching for 1214 // target_method. The value of *out_default_method is null. 1215 DefaultMethodSearchResult FindDefaultMethodImplementation( 1216 Thread* self, 1217 ArtMethod* target_method, 1218 Handle<mirror::Class> klass, 1219 /*out*/ArtMethod** out_default_method) const 1220 REQUIRES_SHARED(Locks::mutator_lock_); 1221 1222 // Sets the imt entries and fixes up the vtable for the given class by linking all the interface 1223 // methods. See LinkVirtualMethods for an explanation of what default_translations is. 1224 bool LinkInterfaceMethods( 1225 Thread* self, 1226 Handle<mirror::Class> klass, 1227 const HashMap<size_t, MethodTranslation>& default_translations, 1228 bool* out_new_conflict, 1229 ArtMethod** out_imt) 1230 REQUIRES_SHARED(Locks::mutator_lock_); 1231 1232 bool LinkStaticFields(Thread* self, Handle<mirror::Class> klass, size_t* class_size) 1233 REQUIRES_SHARED(Locks::mutator_lock_); 1234 bool LinkInstanceFields(Thread* self, Handle<mirror::Class> klass) 1235 REQUIRES_SHARED(Locks::mutator_lock_); 1236 void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass) 1237 REQUIRES_SHARED(Locks::mutator_lock_); 1238 1239 void CheckProxyConstructor(ArtMethod* constructor) const 1240 REQUIRES_SHARED(Locks::mutator_lock_); 1241 void CheckProxyMethod(ArtMethod* method, ArtMethod* prototype) const 1242 REQUIRES_SHARED(Locks::mutator_lock_); 1243 GetDexCacheCount()1244 size_t GetDexCacheCount() REQUIRES_SHARED(Locks::mutator_lock_, Locks::dex_lock_) { 1245 return dex_caches_.size(); 1246 } GetDexCachesData()1247 const std::list<DexCacheData>& GetDexCachesData() 1248 REQUIRES_SHARED(Locks::mutator_lock_, Locks::dex_lock_) { 1249 return dex_caches_; 1250 } 1251 1252 void CreateProxyConstructor(Handle<mirror::Class> klass, ArtMethod* out) 1253 REQUIRES_SHARED(Locks::mutator_lock_); 1254 void CreateProxyMethod(Handle<mirror::Class> klass, ArtMethod* prototype, ArtMethod* out) 1255 REQUIRES_SHARED(Locks::mutator_lock_); 1256 1257 // Register a class loader and create its class table and allocator. Should not be called if 1258 // these are already created. 1259 void RegisterClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 1260 REQUIRES_SHARED(Locks::mutator_lock_) 1261 REQUIRES(Locks::classlinker_classes_lock_); 1262 1263 // Insert a new class table if not found. 1264 ClassTable* InsertClassTableForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 1265 REQUIRES_SHARED(Locks::mutator_lock_) 1266 REQUIRES(Locks::classlinker_classes_lock_); 1267 1268 // EnsureResolved is called to make sure that a class in the class_table_ has been resolved 1269 // before returning it to the caller. Its the responsibility of the thread that placed the class 1270 // in the table to make it resolved. The thread doing resolution must notify on the class' lock 1271 // when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may 1272 // retire a class, the version of the class in the table is returned and this may differ from 1273 // the class passed in. 1274 ObjPtr<mirror::Class> EnsureResolved(Thread* self, 1275 const char* descriptor, 1276 ObjPtr<mirror::Class> klass) 1277 WARN_UNUSED 1278 REQUIRES_SHARED(Locks::mutator_lock_) 1279 REQUIRES(!Locks::dex_lock_); 1280 1281 void FixupTemporaryDeclaringClass(ObjPtr<mirror::Class> temp_class, 1282 ObjPtr<mirror::Class> new_class) 1283 REQUIRES_SHARED(Locks::mutator_lock_); 1284 1285 void SetClassRoot(ClassRoot class_root, ObjPtr<mirror::Class> klass) 1286 REQUIRES_SHARED(Locks::mutator_lock_); 1287 1288 // Return the quick generic JNI stub for testing. 1289 const void* GetRuntimeQuickGenericJniStub() const; 1290 1291 bool CanWeInitializeClass(ObjPtr<mirror::Class> klass, 1292 bool can_init_statics, 1293 bool can_init_parents) 1294 REQUIRES_SHARED(Locks::mutator_lock_); 1295 1296 void UpdateClassMethods(ObjPtr<mirror::Class> klass, 1297 LengthPrefixedArray<ArtMethod>* new_methods) 1298 REQUIRES_SHARED(Locks::mutator_lock_) 1299 REQUIRES(!Locks::classlinker_classes_lock_); 1300 1301 // Check that c1 == FindSystemClass(self, descriptor). Abort with class dumps otherwise. 1302 void CheckSystemClass(Thread* self, Handle<mirror::Class> c1, const char* descriptor) 1303 REQUIRES(!Locks::dex_lock_) 1304 REQUIRES_SHARED(Locks::mutator_lock_); 1305 1306 // Allocate method arrays for interfaces. 1307 bool AllocateIfTableMethodArrays(Thread* self, 1308 Handle<mirror::Class> klass, 1309 Handle<mirror::IfTable> iftable) 1310 REQUIRES_SHARED(Locks::mutator_lock_); 1311 1312 // Sets imt_ref appropriately for LinkInterfaceMethods. 1313 // If there is no method in the imt location of imt_ref it will store the given method there. 1314 // Otherwise it will set the conflict method which will figure out which method to use during 1315 // runtime. 1316 void SetIMTRef(ArtMethod* unimplemented_method, 1317 ArtMethod* imt_conflict_method, 1318 ArtMethod* current_method, 1319 /*out*/bool* new_conflict, 1320 /*out*/ArtMethod** imt_ref) REQUIRES_SHARED(Locks::mutator_lock_); 1321 1322 void FillIMTFromIfTable(ObjPtr<mirror::IfTable> if_table, 1323 ArtMethod* unimplemented_method, 1324 ArtMethod* imt_conflict_method, 1325 ObjPtr<mirror::Class> klass, 1326 bool create_conflict_tables, 1327 bool ignore_copied_methods, 1328 /*out*/bool* new_conflict, 1329 /*out*/ArtMethod** imt) REQUIRES_SHARED(Locks::mutator_lock_); 1330 1331 void FillImtFromSuperClass(Handle<mirror::Class> klass, 1332 ArtMethod* unimplemented_method, 1333 ArtMethod* imt_conflict_method, 1334 bool* new_conflict, 1335 ArtMethod** imt) REQUIRES_SHARED(Locks::mutator_lock_); 1336 1337 // Check invoke type against the referenced class. Throws IncompatibleClassChangeError 1338 // (if `kThrowOnError`) and returns true on mismatch (kInterface on a non-interface class, 1339 // kVirtual on interface, kDefault on interface for dex files not supporting default methods), 1340 // otherwise returns false. 1341 template <bool kThrowOnError, typename ClassGetter> 1342 static bool CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache, 1343 InvokeType type, 1344 ClassGetter class_getter) 1345 REQUIRES_SHARED(Locks::mutator_lock_); 1346 // Helper that feeds the above function with `ClassGetter` doing `LookupResolvedType()`. 1347 template <bool kThrow> 1348 bool CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache, 1349 InvokeType type, 1350 uint32_t method_idx, 1351 ObjPtr<mirror::ClassLoader> class_loader) 1352 REQUIRES_SHARED(Locks::mutator_lock_); 1353 1354 ObjPtr<mirror::IfTable> GetArrayIfTable() REQUIRES_SHARED(Locks::mutator_lock_); 1355 1356 std::vector<const DexFile*> boot_class_path_; 1357 std::vector<std::unique_ptr<const DexFile>> boot_dex_files_; 1358 1359 // JNI weak globals and side data to allow dex caches to get unloaded. We lazily delete weak 1360 // globals when we register new dex files. 1361 std::list<DexCacheData> dex_caches_ GUARDED_BY(Locks::dex_lock_); 1362 1363 // This contains the class loaders which have class tables. It is populated by 1364 // InsertClassTableForClassLoader. 1365 std::list<ClassLoaderData> class_loaders_ 1366 GUARDED_BY(Locks::classlinker_classes_lock_); 1367 1368 // Boot class path table. Since the class loader for this is null. 1369 std::unique_ptr<ClassTable> boot_class_table_ GUARDED_BY(Locks::classlinker_classes_lock_); 1370 1371 // New class roots, only used by CMS since the GC needs to mark these in the pause. 1372 std::vector<GcRoot<mirror::Class>> new_class_roots_ GUARDED_BY(Locks::classlinker_classes_lock_); 1373 1374 // Boot image oat files with new .bss GC roots to be visited in the pause by CMS. 1375 std::vector<const OatFile*> new_bss_roots_boot_oat_files_ 1376 GUARDED_BY(Locks::classlinker_classes_lock_); 1377 1378 // Number of times we've searched dex caches for a class. After a certain number of misses we move 1379 // the classes into the class_table_ to avoid dex cache based searches. 1380 Atomic<uint32_t> failed_dex_cache_class_lookups_; 1381 1382 // Well known mirror::Class roots. 1383 GcRoot<mirror::ObjectArray<mirror::Class>> class_roots_; 1384 1385 // Method hashes for virtual methods from java.lang.Object used 1386 // to avoid recalculating them for each class we link. 1387 uint32_t object_virtual_method_hashes_[mirror::Object::kVTableLength]; 1388 1389 // A cache of the last FindArrayClass results. The cache serves to avoid creating array class 1390 // descriptors for the sake of performing FindClass. 1391 static constexpr size_t kFindArrayCacheSize = 16; 1392 GcRoot<mirror::Class> find_array_class_cache_[kFindArrayCacheSize]; 1393 size_t find_array_class_cache_next_victim_; 1394 1395 bool init_done_; 1396 bool log_new_roots_ GUARDED_BY(Locks::classlinker_classes_lock_); 1397 1398 InternTable* intern_table_; 1399 1400 const bool fast_class_not_found_exceptions_; 1401 1402 // Trampolines within the image the bounce to runtime entrypoints. Done so that there is a single 1403 // patch point within the image. TODO: make these proper relocations. 1404 const void* jni_dlsym_lookup_trampoline_; 1405 const void* jni_dlsym_lookup_critical_trampoline_; 1406 const void* quick_resolution_trampoline_; 1407 const void* quick_imt_conflict_trampoline_; 1408 const void* quick_generic_jni_trampoline_; 1409 const void* quick_to_interpreter_bridge_trampoline_; 1410 const void* nterp_trampoline_; 1411 1412 // Image pointer size. 1413 PointerSize image_pointer_size_; 1414 1415 // Classes to transition from ClassStatus::kInitialized to ClassStatus::kVisiblyInitialized. 1416 Mutex visibly_initialized_callback_lock_; 1417 std::unique_ptr<VisiblyInitializedCallback> visibly_initialized_callback_ 1418 GUARDED_BY(visibly_initialized_callback_lock_); 1419 IntrusiveForwardList<VisiblyInitializedCallback> running_visibly_initialized_callbacks_ 1420 GUARDED_BY(visibly_initialized_callback_lock_); 1421 1422 // Registered native code for @CriticalNative methods of classes that are not visibly 1423 // initialized. These code pointers cannot be stored in ArtMethod as that would risk 1424 // skipping the class initialization check for direct calls from compiled code. 1425 Mutex critical_native_code_with_clinit_check_lock_; 1426 std::map<ArtMethod*, void*> critical_native_code_with_clinit_check_ 1427 GUARDED_BY(critical_native_code_with_clinit_check_lock_); 1428 1429 std::unique_ptr<ClassHierarchyAnalysis> cha_; 1430 1431 class FindVirtualMethodHolderVisitor; 1432 1433 friend class AppImageLoadingHelper; 1434 friend class ImageDumper; // for DexLock 1435 friend struct linker::CompilationHelper; // For Compile in ImageTest. 1436 friend class linker::ImageWriter; // for GetClassRoots 1437 friend class JniCompilerTest; // for GetRuntimeQuickGenericJniStub 1438 friend class JniInternalTest; // for GetRuntimeQuickGenericJniStub 1439 friend class VMClassLoader; // for LookupClass and FindClassInBaseDexClassLoader. 1440 ART_FRIEND_TEST(ClassLinkerTest, RegisterDexFileName); // for DexLock, and RegisterDexFileLocked 1441 ART_FRIEND_TEST(mirror::DexCacheMethodHandlesTest, Open); // for AllocDexCache 1442 ART_FRIEND_TEST(mirror::DexCacheTest, Open); // for AllocDexCache 1443 DISALLOW_COPY_AND_ASSIGN(ClassLinker); 1444 }; 1445 1446 class ClassLoadCallback { 1447 public: ~ClassLoadCallback()1448 virtual ~ClassLoadCallback() {} 1449 1450 // Called immediately before beginning class-definition and immediately before returning from it. BeginDefineClass()1451 virtual void BeginDefineClass() REQUIRES_SHARED(Locks::mutator_lock_) {} EndDefineClass()1452 virtual void EndDefineClass() REQUIRES_SHARED(Locks::mutator_lock_) {} 1453 1454 // If set we will replace initial_class_def & initial_dex_file with the final versions. The 1455 // callback author is responsible for ensuring these are allocated in such a way they can be 1456 // cleaned up if another transformation occurs. Note that both must be set or null/unchanged on 1457 // return. 1458 // Note: the class may be temporary, in which case a following ClassPrepare event will be a 1459 // different object. It is the listener's responsibility to handle this. 1460 // Note: This callback is rarely useful so a default implementation has been given that does 1461 // nothing. ClassPreDefine(const char * descriptor ATTRIBUTE_UNUSED,Handle<mirror::Class> klass ATTRIBUTE_UNUSED,Handle<mirror::ClassLoader> class_loader ATTRIBUTE_UNUSED,const DexFile & initial_dex_file ATTRIBUTE_UNUSED,const dex::ClassDef & initial_class_def ATTRIBUTE_UNUSED,DexFile const ** final_dex_file ATTRIBUTE_UNUSED,dex::ClassDef const ** final_class_def ATTRIBUTE_UNUSED)1462 virtual void ClassPreDefine(const char* descriptor ATTRIBUTE_UNUSED, 1463 Handle<mirror::Class> klass ATTRIBUTE_UNUSED, 1464 Handle<mirror::ClassLoader> class_loader ATTRIBUTE_UNUSED, 1465 const DexFile& initial_dex_file ATTRIBUTE_UNUSED, 1466 const dex::ClassDef& initial_class_def ATTRIBUTE_UNUSED, 1467 /*out*/DexFile const** final_dex_file ATTRIBUTE_UNUSED, 1468 /*out*/dex::ClassDef const** final_class_def ATTRIBUTE_UNUSED) 1469 REQUIRES_SHARED(Locks::mutator_lock_) {} 1470 1471 // A class has been loaded. 1472 // Note: the class may be temporary, in which case a following ClassPrepare event will be a 1473 // different object. It is the listener's responsibility to handle this. 1474 virtual void ClassLoad(Handle<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) = 0; 1475 1476 // A class has been prepared, i.e., resolved. As the ClassLoad event might have been for a 1477 // temporary class, provide both the former and the current class. 1478 virtual void ClassPrepare(Handle<mirror::Class> temp_klass, 1479 Handle<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) = 0; 1480 }; 1481 1482 } // namespace art 1483 1484 #endif // ART_RUNTIME_CLASS_LINKER_H_ 1485