class_linker.h revision c5798bf82fc0ccd0bb90e0813d8e63df4d0576cc
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 <set> 21#include <string> 22#include <unordered_map> 23#include <unordered_set> 24#include <utility> 25#include <vector> 26 27#include "base/allocator.h" 28#include "base/enums.h" 29#include "base/hash_set.h" 30#include "base/macros.h" 31#include "base/mutex.h" 32#include "class_table.h" 33#include "dex_cache_resolved_classes.h" 34#include "dex_file.h" 35#include "dex_file_types.h" 36#include "gc_root.h" 37#include "jni.h" 38#include "mirror/class.h" 39#include "object_callbacks.h" 40#include "verifier/method_verifier.h" 41#include "verifier/verifier_log_mode.h" 42 43namespace art { 44 45namespace gc { 46namespace space { 47 class ImageSpace; 48} // namespace space 49} // namespace gc 50namespace mirror { 51 class ClassLoader; 52 class DexCache; 53 class DexCachePointerArray; 54 class DexCacheMethodHandlesTest_Open_Test; 55 class DexCacheTest_Open_Test; 56 class IfTable; 57 class MethodType; 58 template<class T> class ObjectArray; 59 class StackTraceElement; 60} // namespace mirror 61 62template<class T> class Handle; 63class ImtConflictTable; 64template<typename T> class LengthPrefixedArray; 65template<class T> class MutableHandle; 66class InternTable; 67template<class T> class ObjectLock; 68class Runtime; 69class ScopedObjectAccessAlreadyRunnable; 70template<size_t kNumReferences> class PACKED(4) StackHandleScope; 71 72enum VisitRootFlags : uint8_t; 73 74class ClassVisitor { 75 public: 76 virtual ~ClassVisitor() {} 77 // Return true to continue visiting. 78 virtual bool operator()(ObjPtr<mirror::Class> klass) = 0; 79}; 80 81class ClassLoaderVisitor { 82 public: 83 virtual ~ClassLoaderVisitor() {} 84 virtual void Visit(ObjPtr<mirror::ClassLoader> class_loader) 85 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_) = 0; 86}; 87 88class ClassLinker { 89 public: 90 // Well known mirror::Class roots accessed via GetClassRoot. 91 enum ClassRoot { 92 kJavaLangClass, 93 kJavaLangObject, 94 kClassArrayClass, 95 kObjectArrayClass, 96 kJavaLangString, 97 kJavaLangDexCache, 98 kJavaLangRefReference, 99 kJavaLangReflectConstructor, 100 kJavaLangReflectField, 101 kJavaLangReflectMethod, 102 kJavaLangReflectProxy, 103 kJavaLangStringArrayClass, 104 kJavaLangReflectConstructorArrayClass, 105 kJavaLangReflectFieldArrayClass, 106 kJavaLangReflectMethodArrayClass, 107 kJavaLangInvokeMethodHandleImpl, 108 kJavaLangInvokeMethodType, 109 kJavaLangClassLoader, 110 kJavaLangThrowable, 111 kJavaLangClassNotFoundException, 112 kJavaLangStackTraceElement, 113 kDalvikSystemEmulatedStackFrame, 114 kPrimitiveBoolean, 115 kPrimitiveByte, 116 kPrimitiveChar, 117 kPrimitiveDouble, 118 kPrimitiveFloat, 119 kPrimitiveInt, 120 kPrimitiveLong, 121 kPrimitiveShort, 122 kPrimitiveVoid, 123 kBooleanArrayClass, 124 kByteArrayClass, 125 kCharArrayClass, 126 kDoubleArrayClass, 127 kFloatArrayClass, 128 kIntArrayClass, 129 kLongArrayClass, 130 kShortArrayClass, 131 kJavaLangStackTraceElementArrayClass, 132 kDalvikSystemClassExt, 133 kClassRootsMax, 134 }; 135 136 explicit ClassLinker(InternTable* intern_table); 137 ~ClassLinker(); 138 139 // Initialize class linker by bootstraping from dex files. 140 bool InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> boot_class_path, 141 std::string* error_msg) 142 REQUIRES_SHARED(Locks::mutator_lock_) 143 REQUIRES(!Locks::dex_lock_); 144 145 // Initialize class linker from one or more boot images. 146 bool InitFromBootImage(std::string* error_msg) 147 REQUIRES_SHARED(Locks::mutator_lock_) 148 REQUIRES(!Locks::dex_lock_); 149 150 // Add an image space to the class linker, may fix up classloader fields and dex cache fields. 151 // The dex files that were newly opened for the space are placed in the out argument 152 // out_dex_files. Returns true if the operation succeeded. 153 // The space must be already added to the heap before calling AddImageSpace since we need to 154 // properly handle read barriers and object marking. 155 bool AddImageSpace(gc::space::ImageSpace* space, 156 Handle<mirror::ClassLoader> class_loader, 157 jobjectArray dex_elements, 158 const char* dex_location, 159 std::vector<std::unique_ptr<const DexFile>>* out_dex_files, 160 std::string* error_msg) 161 REQUIRES(!Locks::dex_lock_) 162 REQUIRES_SHARED(Locks::mutator_lock_); 163 164 bool OpenImageDexFiles(gc::space::ImageSpace* space, 165 std::vector<std::unique_ptr<const DexFile>>* out_dex_files, 166 std::string* error_msg) 167 REQUIRES(!Locks::dex_lock_) 168 REQUIRES_SHARED(Locks::mutator_lock_); 169 170 // Finds a class by its descriptor, loading it if necessary. 171 // If class_loader is null, searches boot_class_path_. 172 mirror::Class* FindClass(Thread* self, 173 const char* descriptor, 174 Handle<mirror::ClassLoader> class_loader) 175 REQUIRES_SHARED(Locks::mutator_lock_) 176 REQUIRES(!Locks::dex_lock_); 177 178 // Finds a class by its descriptor using the "system" class loader, ie by searching the 179 // boot_class_path_. 180 mirror::Class* FindSystemClass(Thread* self, const char* descriptor) 181 REQUIRES_SHARED(Locks::mutator_lock_) 182 REQUIRES(!Locks::dex_lock_); 183 184 // Finds the array class given for the element class. 185 mirror::Class* FindArrayClass(Thread* self, ObjPtr<mirror::Class>* element_class) 186 REQUIRES_SHARED(Locks::mutator_lock_) 187 REQUIRES(!Locks::dex_lock_); 188 189 // Returns true if the class linker is initialized. 190 bool IsInitialized() const { 191 return init_done_; 192 } 193 194 // Define a new a class based on a ClassDef from a DexFile 195 mirror::Class* DefineClass(Thread* self, 196 const char* descriptor, 197 size_t hash, 198 Handle<mirror::ClassLoader> class_loader, 199 const DexFile& dex_file, 200 const DexFile::ClassDef& dex_class_def) 201 REQUIRES_SHARED(Locks::mutator_lock_) 202 REQUIRES(!Locks::dex_lock_); 203 204 // Finds a class by its descriptor, returning null if it isn't wasn't loaded 205 // by the given 'class_loader'. 206 mirror::Class* LookupClass(Thread* self, 207 const char* descriptor, 208 ObjPtr<mirror::ClassLoader> class_loader) 209 REQUIRES(!Locks::classlinker_classes_lock_) 210 REQUIRES_SHARED(Locks::mutator_lock_) { 211 return LookupClass(self, descriptor, ComputeModifiedUtf8Hash(descriptor), class_loader); 212 } 213 214 // Finds all the classes with the given descriptor, regardless of ClassLoader. 215 void LookupClasses(const char* descriptor, std::vector<ObjPtr<mirror::Class>>& classes) 216 REQUIRES(!Locks::classlinker_classes_lock_) 217 REQUIRES_SHARED(Locks::mutator_lock_); 218 219 mirror::Class* FindPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_); 220 221 void DumpForSigQuit(std::ostream& os) REQUIRES(!Locks::classlinker_classes_lock_); 222 223 size_t NumLoadedClasses() 224 REQUIRES(!Locks::classlinker_classes_lock_) 225 REQUIRES_SHARED(Locks::mutator_lock_); 226 227 // Resolve a String with the given index from the DexFile, storing the 228 // result in the DexCache. The referrer is used to identify the 229 // target DexCache and ClassLoader to use for resolution. 230 mirror::String* ResolveString(dex::StringIndex string_idx, ArtMethod* referrer) 231 REQUIRES_SHARED(Locks::mutator_lock_); 232 233 // Resolve a String with the given index from the DexFile, storing the 234 // result in the DexCache. 235 mirror::String* ResolveString(const DexFile& dex_file, 236 dex::StringIndex string_idx, 237 Handle<mirror::DexCache> dex_cache) 238 REQUIRES_SHARED(Locks::mutator_lock_); 239 240 // Find a String with the given index from the DexFile, storing the 241 // result in the DexCache if found. Return null if not found. 242 mirror::String* LookupString(const DexFile& dex_file, 243 dex::StringIndex string_idx, 244 Handle<mirror::DexCache> dex_cache) 245 REQUIRES_SHARED(Locks::mutator_lock_); 246 247 // Resolve a Type with the given index from the DexFile, storing the 248 // result in the DexCache. The referrer is used to identify the 249 // target DexCache and ClassLoader to use for resolution. 250 mirror::Class* ResolveType(const DexFile& dex_file, 251 dex::TypeIndex type_idx, 252 ObjPtr<mirror::Class> referrer) 253 REQUIRES_SHARED(Locks::mutator_lock_) 254 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 255 256 // Resolve a Type with the given index from the DexFile, storing the 257 // result in the DexCache. The referrer is used to identify the 258 // target DexCache and ClassLoader to use for resolution. 259 mirror::Class* ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer) 260 REQUIRES_SHARED(Locks::mutator_lock_) 261 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 262 263 mirror::Class* ResolveType(dex::TypeIndex type_idx, ArtField* referrer) 264 REQUIRES_SHARED(Locks::mutator_lock_) 265 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 266 267 // Look up a resolved type with the given ID from the DexFile. The ClassLoader is used to search 268 // for the type, since it may be referenced from but not contained within the given DexFile. 269 ObjPtr<mirror::Class> LookupResolvedType(const DexFile& dex_file, 270 dex::TypeIndex type_idx, 271 ObjPtr<mirror::DexCache> dex_cache, 272 ObjPtr<mirror::ClassLoader> class_loader) 273 REQUIRES_SHARED(Locks::mutator_lock_); 274 275 // Resolve a type with the given ID from the DexFile, storing the 276 // result in DexCache. The ClassLoader is used to search for the 277 // type, since it may be referenced from but not contained within 278 // the given DexFile. 279 mirror::Class* ResolveType(const DexFile& dex_file, 280 dex::TypeIndex type_idx, 281 Handle<mirror::DexCache> dex_cache, 282 Handle<mirror::ClassLoader> class_loader) 283 REQUIRES_SHARED(Locks::mutator_lock_) 284 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 285 286 // Determine whether a dex cache result should be trusted, or an IncompatibleClassChangeError 287 // check should be performed even after a hit. 288 enum ResolveMode { // private. 289 kNoICCECheckForCache, 290 kForceICCECheck 291 }; 292 293 // Resolve a method with a given ID from the DexFile, storing the 294 // result in DexCache. The ClassLinker and ClassLoader are used as 295 // in ResolveType. What is unique is the method type argument which 296 // is used to determine if this method is a direct, static, or 297 // virtual method. 298 template <ResolveMode kResolveMode> 299 ArtMethod* ResolveMethod(const DexFile& dex_file, 300 uint32_t method_idx, 301 Handle<mirror::DexCache> dex_cache, 302 Handle<mirror::ClassLoader> class_loader, 303 ArtMethod* referrer, 304 InvokeType type) 305 REQUIRES_SHARED(Locks::mutator_lock_) 306 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 307 308 ArtMethod* GetResolvedMethod(uint32_t method_idx, ArtMethod* referrer) 309 REQUIRES_SHARED(Locks::mutator_lock_); 310 311 // This returns the class referred to by GetMethodId(method_idx).class_idx_. This might be 312 // different then the declaring class of the resolved method due to copied 313 // miranda/default/conflict methods. 314 mirror::Class* ResolveReferencedClassOfMethod(uint32_t method_idx, 315 Handle<mirror::DexCache> dex_cache, 316 Handle<mirror::ClassLoader> class_loader) 317 REQUIRES_SHARED(Locks::mutator_lock_) 318 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 319 template <ResolveMode kResolveMode> 320 ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, ArtMethod* referrer, InvokeType type) 321 REQUIRES_SHARED(Locks::mutator_lock_) 322 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 323 ArtMethod* ResolveMethodWithoutInvokeType(const DexFile& dex_file, 324 uint32_t method_idx, 325 Handle<mirror::DexCache> dex_cache, 326 Handle<mirror::ClassLoader> class_loader) 327 REQUIRES_SHARED(Locks::mutator_lock_) 328 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 329 330 ArtField* GetResolvedField(uint32_t field_idx, ObjPtr<mirror::Class> field_declaring_class) 331 REQUIRES_SHARED(Locks::mutator_lock_); 332 ArtField* GetResolvedField(uint32_t field_idx, ObjPtr<mirror::DexCache> dex_cache) 333 REQUIRES_SHARED(Locks::mutator_lock_); 334 ArtField* ResolveField(uint32_t field_idx, ArtMethod* referrer, bool is_static) 335 REQUIRES_SHARED(Locks::mutator_lock_) 336 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 337 338 // Resolve a field with a given ID from the DexFile, storing the 339 // result in DexCache. The ClassLinker and ClassLoader are used as 340 // in ResolveType. What is unique is the is_static argument which is 341 // used to determine if we are resolving a static or non-static 342 // field. 343 ArtField* ResolveField(const DexFile& dex_file, uint32_t field_idx, 344 Handle<mirror::DexCache> dex_cache, 345 Handle<mirror::ClassLoader> class_loader, bool is_static) 346 REQUIRES_SHARED(Locks::mutator_lock_) 347 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 348 349 // Resolve a field with a given ID from the DexFile, storing the 350 // result in DexCache. The ClassLinker and ClassLoader are used as 351 // in ResolveType. No is_static argument is provided so that Java 352 // field resolution semantics are followed. 353 ArtField* ResolveFieldJLS(const DexFile& dex_file, 354 uint32_t field_idx, 355 Handle<mirror::DexCache> dex_cache, 356 Handle<mirror::ClassLoader> class_loader) 357 REQUIRES_SHARED(Locks::mutator_lock_) 358 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 359 360 // Resolve a method type with a given ID from the DexFile, storing 361 // the result in the DexCache. 362 mirror::MethodType* ResolveMethodType(const DexFile& dex_file, 363 uint32_t proto_idx, 364 Handle<mirror::DexCache> dex_cache, 365 Handle<mirror::ClassLoader> class_loader) 366 REQUIRES_SHARED(Locks::mutator_lock_) 367 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 368 369 // Returns true on success, false if there's an exception pending. 370 // can_run_clinit=false allows the compiler to attempt to init a class, 371 // given the restriction that no <clinit> execution is possible. 372 bool EnsureInitialized(Thread* self, 373 Handle<mirror::Class> c, 374 bool can_init_fields, 375 bool can_init_parents) 376 REQUIRES_SHARED(Locks::mutator_lock_) 377 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 378 379 // Initializes classes that have instances in the image but that have 380 // <clinit> methods so they could not be initialized by the compiler. 381 void RunRootClinits() 382 REQUIRES_SHARED(Locks::mutator_lock_) 383 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 384 385 mirror::DexCache* RegisterDexFile(const DexFile& dex_file, 386 ObjPtr<mirror::ClassLoader> class_loader) 387 REQUIRES(!Locks::dex_lock_) 388 REQUIRES_SHARED(Locks::mutator_lock_); 389 void RegisterDexFile(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache) 390 REQUIRES(!Locks::dex_lock_) 391 REQUIRES_SHARED(Locks::mutator_lock_); 392 393 const std::vector<const DexFile*>& GetBootClassPath() { 394 return boot_class_path_; 395 } 396 397 void VisitClasses(ClassVisitor* visitor) 398 REQUIRES(!Locks::classlinker_classes_lock_) 399 REQUIRES_SHARED(Locks::mutator_lock_); 400 401 // Less efficient variant of VisitClasses that copies the class_table_ into secondary storage 402 // so that it can visit individual classes without holding the doesn't hold the 403 // Locks::classlinker_classes_lock_. As the Locks::classlinker_classes_lock_ isn't held this code 404 // can race with insertion and deletion of classes while the visitor is being called. 405 void VisitClassesWithoutClassesLock(ClassVisitor* visitor) 406 REQUIRES_SHARED(Locks::mutator_lock_) 407 REQUIRES(!Locks::dex_lock_); 408 409 void VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags) 410 REQUIRES(!Locks::classlinker_classes_lock_, !Locks::trace_lock_) 411 REQUIRES_SHARED(Locks::mutator_lock_); 412 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags) 413 REQUIRES(!Locks::dex_lock_, !Locks::classlinker_classes_lock_, !Locks::trace_lock_) 414 REQUIRES_SHARED(Locks::mutator_lock_); 415 416 mirror::DexCache* FindDexCache(Thread* self, 417 const DexFile& dex_file, 418 bool allow_failure = false) 419 REQUIRES(!Locks::dex_lock_) 420 REQUIRES_SHARED(Locks::mutator_lock_); 421 void FixupDexCaches(ArtMethod* resolution_method) 422 REQUIRES(!Locks::dex_lock_) 423 REQUIRES_SHARED(Locks::mutator_lock_); 424 425 // Allocate an instance of a java.lang.Object. 426 mirror::Object* AllocObject(Thread* self) 427 REQUIRES_SHARED(Locks::mutator_lock_) 428 REQUIRES(!Roles::uninterruptible_); 429 430 // TODO: replace this with multiple methods that allocate the correct managed type. 431 template <class T> 432 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length) 433 REQUIRES_SHARED(Locks::mutator_lock_) 434 REQUIRES(!Roles::uninterruptible_); 435 436 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length) 437 REQUIRES_SHARED(Locks::mutator_lock_) 438 REQUIRES(!Roles::uninterruptible_); 439 440 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length) 441 REQUIRES_SHARED(Locks::mutator_lock_) 442 REQUIRES(!Roles::uninterruptible_); 443 444 LengthPrefixedArray<ArtField>* AllocArtFieldArray(Thread* self, 445 LinearAlloc* allocator, 446 size_t length); 447 448 LengthPrefixedArray<ArtMethod>* AllocArtMethodArray(Thread* self, 449 LinearAlloc* allocator, 450 size_t length); 451 452 mirror::PointerArray* AllocPointerArray(Thread* self, size_t length) 453 REQUIRES_SHARED(Locks::mutator_lock_) 454 REQUIRES(!Roles::uninterruptible_); 455 456 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount) 457 REQUIRES_SHARED(Locks::mutator_lock_) 458 REQUIRES(!Roles::uninterruptible_); 459 460 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self, 461 size_t length) 462 REQUIRES_SHARED(Locks::mutator_lock_) 463 REQUIRES(!Roles::uninterruptible_); 464 465 verifier::MethodVerifier::FailureKind VerifyClass( 466 Thread* self, 467 Handle<mirror::Class> klass, 468 verifier::HardFailLogMode log_level = verifier::HardFailLogMode::kLogNone) 469 REQUIRES_SHARED(Locks::mutator_lock_) 470 REQUIRES(!Locks::dex_lock_); 471 bool VerifyClassUsingOatFile(const DexFile& dex_file, 472 ObjPtr<mirror::Class> klass, 473 mirror::Class::Status& oat_file_class_status) 474 REQUIRES_SHARED(Locks::mutator_lock_) 475 REQUIRES(!Locks::dex_lock_); 476 void ResolveClassExceptionHandlerTypes(Handle<mirror::Class> klass) 477 REQUIRES_SHARED(Locks::mutator_lock_) 478 REQUIRES(!Locks::dex_lock_); 479 void ResolveMethodExceptionHandlerTypes(ArtMethod* klass) 480 REQUIRES_SHARED(Locks::mutator_lock_) 481 REQUIRES(!Locks::dex_lock_); 482 483 mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, 484 jstring name, 485 jobjectArray interfaces, 486 jobject loader, 487 jobjectArray methods, 488 jobjectArray throws) 489 REQUIRES_SHARED(Locks::mutator_lock_); 490 std::string GetDescriptorForProxy(ObjPtr<mirror::Class> proxy_class) 491 REQUIRES_SHARED(Locks::mutator_lock_); 492 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> 493 ArtMethod* FindMethodForProxy(ObjPtr<mirror::Class> proxy_class, ArtMethod* proxy_method) 494 REQUIRES(!Locks::dex_lock_) 495 REQUIRES_SHARED(Locks::mutator_lock_); 496 497 // Get the oat code for a method when its class isn't yet initialized. 498 const void* GetQuickOatCodeFor(ArtMethod* method) 499 REQUIRES_SHARED(Locks::mutator_lock_); 500 501 pid_t GetClassesLockOwner(); // For SignalCatcher. 502 pid_t GetDexLockOwner(); // For SignalCatcher. 503 504 mirror::Class* GetClassRoot(ClassRoot class_root) REQUIRES_SHARED(Locks::mutator_lock_); 505 506 static const char* GetClassRootDescriptor(ClassRoot class_root); 507 508 // Is the given entry point quick code to run the resolution stub? 509 bool IsQuickResolutionStub(const void* entry_point) const; 510 511 // Is the given entry point quick code to bridge into the interpreter? 512 bool IsQuickToInterpreterBridge(const void* entry_point) const; 513 514 // Is the given entry point quick code to run the generic JNI stub? 515 bool IsQuickGenericJniStub(const void* entry_point) const; 516 517 const void* GetQuickToInterpreterBridgeTrampoline() const { 518 return quick_to_interpreter_bridge_trampoline_; 519 } 520 521 InternTable* GetInternTable() const { 522 return intern_table_; 523 } 524 525 // Set the entrypoints up for method to the given code. 526 void SetEntryPointsToCompiledCode(ArtMethod* method, const void* method_code) const 527 REQUIRES_SHARED(Locks::mutator_lock_); 528 529 // Set the entrypoints up for method to the enter the interpreter. 530 void SetEntryPointsToInterpreter(ArtMethod* method) const 531 REQUIRES_SHARED(Locks::mutator_lock_); 532 533 // Attempts to insert a class into a class table. Returns null if 534 // the class was inserted, otherwise returns an existing class with 535 // the same descriptor and ClassLoader. 536 mirror::Class* InsertClass(const char* descriptor, ObjPtr<mirror::Class> klass, size_t hash) 537 REQUIRES(!Locks::classlinker_classes_lock_) 538 REQUIRES_SHARED(Locks::mutator_lock_); 539 540 mirror::ObjectArray<mirror::Class>* GetClassRoots() REQUIRES_SHARED(Locks::mutator_lock_) { 541 mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read(); 542 DCHECK(class_roots != nullptr); 543 return class_roots; 544 } 545 546 // Move the class table to the pre-zygote table to reduce memory usage. This works by ensuring 547 // that no more classes are ever added to the pre zygote table which makes it that the pages 548 // always remain shared dirty instead of private dirty. 549 void MoveClassTableToPreZygote() 550 REQUIRES(!Locks::classlinker_classes_lock_) 551 REQUIRES_SHARED(Locks::mutator_lock_); 552 553 // Creates a GlobalRef PathClassLoader that can be used to load classes from the given dex files. 554 // Note: the objects are not completely set up. Do not use this outside of tests and the compiler. 555 jobject CreatePathClassLoader(Thread* self, const std::vector<const DexFile*>& dex_files) 556 REQUIRES_SHARED(Locks::mutator_lock_) 557 REQUIRES(!Locks::dex_lock_); 558 559 PointerSize GetImagePointerSize() const { 560 return image_pointer_size_; 561 } 562 563 // Used by image writer for checking. 564 bool ClassInClassTable(ObjPtr<mirror::Class> klass) 565 REQUIRES(Locks::classlinker_classes_lock_) 566 REQUIRES_SHARED(Locks::mutator_lock_); 567 568 // Clear the ArrayClass cache. This is necessary when cleaning up for the image, as the cache 569 // entries are roots, but potentially not image classes. 570 void DropFindArrayClassCache() REQUIRES_SHARED(Locks::mutator_lock_); 571 572 // Clean up class loaders, this needs to happen after JNI weak globals are cleared. 573 void CleanupClassLoaders() 574 REQUIRES(!Locks::classlinker_classes_lock_) 575 REQUIRES_SHARED(Locks::mutator_lock_); 576 577 // Unlike GetOrCreateAllocatorForClassLoader, GetAllocatorForClassLoader asserts that the 578 // allocator for this class loader is already created. 579 LinearAlloc* GetAllocatorForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 580 REQUIRES_SHARED(Locks::mutator_lock_); 581 582 // Return the linear alloc for a class loader if it is already allocated, otherwise allocate and 583 // set it. TODO: Consider using a lock other than classlinker_classes_lock_. 584 LinearAlloc* GetOrCreateAllocatorForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 585 REQUIRES(!Locks::classlinker_classes_lock_) 586 REQUIRES_SHARED(Locks::mutator_lock_); 587 588 // May be called with null class_loader due to legacy code. b/27954959 589 void InsertDexFileInToClassLoader(ObjPtr<mirror::Object> dex_file, 590 ObjPtr<mirror::ClassLoader> class_loader) 591 REQUIRES(!Locks::classlinker_classes_lock_) 592 REQUIRES_SHARED(Locks::mutator_lock_); 593 594 static bool ShouldUseInterpreterEntrypoint(ArtMethod* method, const void* quick_code) 595 REQUIRES_SHARED(Locks::mutator_lock_); 596 597 std::set<DexCacheResolvedClasses> GetResolvedClasses(bool ignore_boot_classes) 598 REQUIRES(!Locks::dex_lock_); 599 600 std::unordered_set<std::string> GetClassDescriptorsForProfileKeys( 601 const std::set<DexCacheResolvedClasses>& classes) 602 REQUIRES(!Locks::dex_lock_); 603 604 static bool IsBootClassLoader(ScopedObjectAccessAlreadyRunnable& soa, 605 ObjPtr<mirror::ClassLoader> class_loader) 606 REQUIRES_SHARED(Locks::mutator_lock_); 607 608 ArtMethod* AddMethodToConflictTable(ObjPtr<mirror::Class> klass, 609 ArtMethod* conflict_method, 610 ArtMethod* interface_method, 611 ArtMethod* method, 612 bool force_new_conflict_method) 613 REQUIRES_SHARED(Locks::mutator_lock_); 614 615 // Create a conflict table with a specified capacity. 616 ImtConflictTable* CreateImtConflictTable(size_t count, LinearAlloc* linear_alloc); 617 618 // Static version for when the class linker is not yet created. 619 static ImtConflictTable* CreateImtConflictTable(size_t count, 620 LinearAlloc* linear_alloc, 621 PointerSize pointer_size); 622 623 624 // Create the IMT and conflict tables for a class. 625 void FillIMTAndConflictTables(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_); 626 627 // Clear class table strong roots (other than classes themselves). This is done by dex2oat to 628 // allow pruning dex caches. 629 void ClearClassTableStrongRoots() const 630 REQUIRES(!Locks::classlinker_classes_lock_) 631 REQUIRES_SHARED(Locks::mutator_lock_); 632 633 // Throw the class initialization failure recorded when first trying to initialize the given 634 // class. 635 void ThrowEarlierClassFailure(ObjPtr<mirror::Class> c, bool wrap_in_no_class_def = false) 636 REQUIRES_SHARED(Locks::mutator_lock_) 637 REQUIRES(!Locks::dex_lock_); 638 639 // Get the actual holding class for a copied method. Pretty slow, don't call often. 640 mirror::Class* GetHoldingClassOfCopiedMethod(ArtMethod* method) 641 REQUIRES_SHARED(Locks::mutator_lock_); 642 643 struct DexCacheData { 644 // Weak root to the DexCache. Note: Do not decode this unnecessarily or else class unloading may 645 // not work properly. 646 jweak weak_root; 647 // The following two fields are caches to the DexCache's fields and here to avoid unnecessary 648 // jweak decode that triggers read barriers (and mark them alive unnecessarily and mess with 649 // class unloading.) 650 const DexFile* dex_file; 651 GcRoot<mirror::Class>* resolved_types; 652 }; 653 654 private: 655 struct ClassLoaderData { 656 jweak weak_root; // Weak root to enable class unloading. 657 ClassTable* class_table; 658 LinearAlloc* allocator; 659 }; 660 661 // Ensures that the supertype of 'klass' ('supertype') is verified. Returns false and throws 662 // appropriate exceptions if verification failed hard. Returns true for successful verification or 663 // soft-failures. 664 bool AttemptSupertypeVerification(Thread* self, 665 Handle<mirror::Class> klass, 666 Handle<mirror::Class> supertype) 667 REQUIRES(!Locks::dex_lock_) 668 REQUIRES_SHARED(Locks::mutator_lock_); 669 670 static void DeleteClassLoader(Thread* self, const ClassLoaderData& data) 671 REQUIRES_SHARED(Locks::mutator_lock_); 672 673 void VisitClassLoaders(ClassLoaderVisitor* visitor) const 674 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_); 675 676 void VisitClassesInternal(ClassVisitor* visitor) 677 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_); 678 679 // Returns the number of zygote and image classes. 680 size_t NumZygoteClasses() const 681 REQUIRES(Locks::classlinker_classes_lock_) 682 REQUIRES_SHARED(Locks::mutator_lock_); 683 684 // Returns the number of non zygote nor image classes. 685 size_t NumNonZygoteClasses() const 686 REQUIRES(Locks::classlinker_classes_lock_) 687 REQUIRES_SHARED(Locks::mutator_lock_); 688 689 void FinishInit(Thread* self) 690 REQUIRES_SHARED(Locks::mutator_lock_) 691 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 692 693 // For early bootstrapping by Init 694 mirror::Class* AllocClass(Thread* self, 695 ObjPtr<mirror::Class> java_lang_Class, 696 uint32_t class_size) 697 REQUIRES_SHARED(Locks::mutator_lock_) 698 REQUIRES(!Roles::uninterruptible_); 699 700 // Alloc* convenience functions to avoid needing to pass in mirror::Class* 701 // values that are known to the ClassLinker such as 702 // kObjectArrayClass and kJavaLangString etc. 703 mirror::Class* AllocClass(Thread* self, uint32_t class_size) 704 REQUIRES_SHARED(Locks::mutator_lock_) 705 REQUIRES(!Roles::uninterruptible_); 706 707 mirror::DexCache* AllocDexCache(ObjPtr<mirror::String>* out_location, 708 Thread* self, 709 const DexFile& dex_file) 710 REQUIRES_SHARED(Locks::mutator_lock_) 711 REQUIRES(!Roles::uninterruptible_); 712 713 // Used for tests and AppendToBootClassPath. 714 mirror::DexCache* AllocAndInitializeDexCache(Thread* self, 715 const DexFile& dex_file, 716 LinearAlloc* linear_alloc) 717 REQUIRES_SHARED(Locks::mutator_lock_) 718 REQUIRES(!Locks::dex_lock_) 719 REQUIRES(!Roles::uninterruptible_); 720 721 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type) 722 REQUIRES_SHARED(Locks::mutator_lock_) 723 REQUIRES(!Roles::uninterruptible_); 724 mirror::Class* InitializePrimitiveClass(ObjPtr<mirror::Class> primitive_class, 725 Primitive::Type type) 726 REQUIRES_SHARED(Locks::mutator_lock_) 727 REQUIRES(!Roles::uninterruptible_); 728 729 mirror::Class* CreateArrayClass(Thread* self, 730 const char* descriptor, 731 size_t hash, 732 Handle<mirror::ClassLoader> class_loader) 733 REQUIRES_SHARED(Locks::mutator_lock_) 734 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); 735 736 void AppendToBootClassPath(Thread* self, const DexFile& dex_file) 737 REQUIRES_SHARED(Locks::mutator_lock_) 738 REQUIRES(!Locks::dex_lock_); 739 void AppendToBootClassPath(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache) 740 REQUIRES_SHARED(Locks::mutator_lock_) 741 REQUIRES(!Locks::dex_lock_); 742 743 // Precomputes size needed for Class, in the case of a non-temporary class this size must be 744 // sufficient to hold all static fields. 745 uint32_t SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file, 746 const DexFile::ClassDef& dex_class_def); 747 748 // Setup the classloader, class def index, type idx so that we can insert this class in the class 749 // table. 750 void SetupClass(const DexFile& dex_file, 751 const DexFile::ClassDef& dex_class_def, 752 Handle<mirror::Class> klass, 753 ObjPtr<mirror::ClassLoader> class_loader) 754 REQUIRES_SHARED(Locks::mutator_lock_); 755 756 void LoadClass(Thread* self, 757 const DexFile& dex_file, 758 const DexFile::ClassDef& dex_class_def, 759 Handle<mirror::Class> klass) 760 REQUIRES_SHARED(Locks::mutator_lock_); 761 void LoadClassMembers(Thread* self, 762 const DexFile& dex_file, 763 const uint8_t* class_data, 764 Handle<mirror::Class> klass) 765 REQUIRES_SHARED(Locks::mutator_lock_); 766 767 void LoadField(const ClassDataItemIterator& it, Handle<mirror::Class> klass, ArtField* dst) 768 REQUIRES_SHARED(Locks::mutator_lock_); 769 770 void LoadMethod(const DexFile& dex_file, 771 const ClassDataItemIterator& it, 772 Handle<mirror::Class> klass, ArtMethod* dst) 773 REQUIRES_SHARED(Locks::mutator_lock_); 774 775 void FixupStaticTrampolines(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_); 776 777 // Finds a class in a Path- or DexClassLoader, loading it if necessary without using JNI. Hash 778 // function is supposed to be ComputeModifiedUtf8Hash(descriptor). Returns true if the 779 // class-loader chain could be handled, false otherwise, i.e., a non-supported class-loader 780 // was encountered while walking the parent chain (currently only BootClassLoader and 781 // PathClassLoader are supported). 782 bool FindClassInBaseDexClassLoader(ScopedObjectAccessAlreadyRunnable& soa, 783 Thread* self, 784 const char* descriptor, 785 size_t hash, 786 Handle<mirror::ClassLoader> class_loader, 787 ObjPtr<mirror::Class>* result) 788 REQUIRES_SHARED(Locks::mutator_lock_) 789 REQUIRES(!Locks::dex_lock_); 790 791 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded 792 // by the given 'class_loader'. Uses the provided hash for the descriptor. 793 mirror::Class* LookupClass(Thread* self, 794 const char* descriptor, 795 size_t hash, 796 ObjPtr<mirror::ClassLoader> class_loader) 797 REQUIRES(!Locks::classlinker_classes_lock_) 798 REQUIRES_SHARED(Locks::mutator_lock_); 799 800 void RegisterDexFileLocked(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache) 801 REQUIRES(Locks::dex_lock_) 802 REQUIRES_SHARED(Locks::mutator_lock_); 803 mirror::DexCache* FindDexCacheLocked(Thread* self, const DexFile& dex_file, bool allow_failure) 804 REQUIRES(Locks::dex_lock_) 805 REQUIRES_SHARED(Locks::mutator_lock_); 806 807 bool InitializeClass(Thread* self, 808 Handle<mirror::Class> klass, 809 bool can_run_clinit, 810 bool can_init_parents) 811 REQUIRES_SHARED(Locks::mutator_lock_) 812 REQUIRES(!Locks::dex_lock_); 813 bool InitializeDefaultInterfaceRecursive(Thread* self, 814 Handle<mirror::Class> klass, 815 bool can_run_clinit, 816 bool can_init_parents) 817 REQUIRES(!Locks::dex_lock_) 818 REQUIRES_SHARED(Locks::mutator_lock_); 819 bool WaitForInitializeClass(Handle<mirror::Class> klass, 820 Thread* self, 821 ObjectLock<mirror::Class>& lock); 822 bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass) 823 REQUIRES_SHARED(Locks::mutator_lock_); 824 825 bool IsSameDescriptorInDifferentClassContexts(Thread* self, 826 const char* descriptor, 827 Handle<mirror::ClassLoader> class_loader1, 828 Handle<mirror::ClassLoader> class_loader2) 829 REQUIRES_SHARED(Locks::mutator_lock_); 830 831 bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, 832 ArtMethod* method, 833 ObjPtr<mirror::Class> klass1, 834 ObjPtr<mirror::Class> klass2) 835 REQUIRES_SHARED(Locks::mutator_lock_); 836 837 bool LinkClass(Thread* self, 838 const char* descriptor, 839 Handle<mirror::Class> klass, 840 Handle<mirror::ObjectArray<mirror::Class>> interfaces, 841 MutableHandle<mirror::Class>* h_new_class_out) 842 REQUIRES_SHARED(Locks::mutator_lock_) 843 REQUIRES(!Locks::classlinker_classes_lock_); 844 845 bool LinkSuperClass(Handle<mirror::Class> klass) 846 REQUIRES_SHARED(Locks::mutator_lock_); 847 848 bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file) 849 REQUIRES_SHARED(Locks::mutator_lock_) 850 REQUIRES(!Locks::dex_lock_); 851 852 bool LinkMethods(Thread* self, 853 Handle<mirror::Class> klass, 854 Handle<mirror::ObjectArray<mirror::Class>> interfaces, 855 bool* out_new_conflict, 856 ArtMethod** out_imt) 857 REQUIRES_SHARED(Locks::mutator_lock_); 858 859 // A wrapper class representing the result of a method translation used for linking methods and 860 // updating superclass default methods. For each method in a classes vtable there are 4 states it 861 // could be in: 862 // 1) No translation is necessary. In this case there is no MethodTranslation object for it. This 863 // is the standard case and is true when the method is not overridable by a default method, 864 // the class defines a concrete implementation of the method, the default method implementation 865 // remains the same, or an abstract method stayed abstract. 866 // 2) The method must be translated to a different default method. We note this with 867 // CreateTranslatedMethod. 868 // 3) The method must be replaced with a conflict method. This happens when a superclass 869 // implements an interface with a default method and this class implements an unrelated 870 // interface that also defines that default method. We note this with CreateConflictingMethod. 871 // 4) The method must be replaced with an abstract miranda method. This happens when a superclass 872 // implements an interface with a default method and this class implements a subinterface of 873 // the superclass's interface which declares the default method abstract. We note this with 874 // CreateAbstractMethod. 875 // 876 // When a method translation is unnecessary (case #1), we don't put it into the 877 // default_translation maps. So an instance of MethodTranslation must be in one of #2-#4. 878 class MethodTranslation { 879 public: 880 // This slot must become a default conflict method. 881 static MethodTranslation CreateConflictingMethod() { 882 return MethodTranslation(Type::kConflict, /*translation*/nullptr); 883 } 884 885 // This slot must become an abstract method. 886 static MethodTranslation CreateAbstractMethod() { 887 return MethodTranslation(Type::kAbstract, /*translation*/nullptr); 888 } 889 890 // Use the given method as the current value for this vtable slot during translation. 891 static MethodTranslation CreateTranslatedMethod(ArtMethod* new_method) { 892 return MethodTranslation(Type::kTranslation, new_method); 893 } 894 895 // Returns true if this is a method that must become a conflict method. 896 bool IsInConflict() const { 897 return type_ == Type::kConflict; 898 } 899 900 // Returns true if this is a method that must become an abstract method. 901 bool IsAbstract() const { 902 return type_ == Type::kAbstract; 903 } 904 905 // Returns true if this is a method that must become a different method. 906 bool IsTranslation() const { 907 return type_ == Type::kTranslation; 908 } 909 910 // Get the translated version of this method. 911 ArtMethod* GetTranslation() const { 912 DCHECK(IsTranslation()); 913 DCHECK(translation_ != nullptr); 914 return translation_; 915 } 916 917 private: 918 enum class Type { 919 kTranslation, 920 kConflict, 921 kAbstract, 922 }; 923 924 MethodTranslation(Type type, ArtMethod* translation) 925 : translation_(translation), type_(type) {} 926 927 ArtMethod* const translation_; 928 const Type type_; 929 }; 930 931 // Links the virtual methods for the given class and records any default methods that will need to 932 // be updated later. 933 // 934 // Arguments: 935 // * self - The current thread. 936 // * klass - class, whose vtable will be filled in. 937 // * default_translations - Vtable index to new method map. 938 // Any vtable entries that need to be updated with new default methods 939 // are stored into the default_translations map. The default_translations 940 // map is keyed on the vtable index that needs to be updated. We use this 941 // map because if we override a default method with another default 942 // method we need to update the vtable to point to the new method. 943 // Unfortunately since we copy the ArtMethod* we cannot just do a simple 944 // scan, we therefore store the vtable index's that might need to be 945 // updated with the method they will turn into. 946 // TODO This whole default_translations thing is very dirty. There should be a better way. 947 bool LinkVirtualMethods( 948 Thread* self, 949 Handle<mirror::Class> klass, 950 /*out*/std::unordered_map<size_t, MethodTranslation>* default_translations) 951 REQUIRES_SHARED(Locks::mutator_lock_); 952 953 // Sets up the interface lookup table (IFTable) in the correct order to allow searching for 954 // default methods. 955 bool SetupInterfaceLookupTable(Thread* self, 956 Handle<mirror::Class> klass, 957 Handle<mirror::ObjectArray<mirror::Class>> interfaces) 958 REQUIRES_SHARED(Locks::mutator_lock_); 959 960 961 enum class DefaultMethodSearchResult { 962 kDefaultFound, 963 kAbstractFound, 964 kDefaultConflict 965 }; 966 967 // Find the default method implementation for 'interface_method' in 'klass', if one exists. 968 // 969 // Arguments: 970 // * self - The current thread. 971 // * target_method - The method we are trying to find a default implementation for. 972 // * klass - The class we are searching for a definition of target_method. 973 // * out_default_method - The pointer we will store the found default method to on success. 974 // 975 // Return value: 976 // * kDefaultFound - There were no conflicting method implementations found in the class while 977 // searching for target_method. The default method implementation is stored into 978 // out_default_method. 979 // * kAbstractFound - There were no conflicting method implementations found in the class while 980 // searching for target_method but no default implementation was found either. 981 // out_default_method is set to null and the method should be considered not 982 // implemented. 983 // * kDefaultConflict - Conflicting method implementations were found when searching for 984 // target_method. The value of *out_default_method is null. 985 DefaultMethodSearchResult FindDefaultMethodImplementation( 986 Thread* self, 987 ArtMethod* target_method, 988 Handle<mirror::Class> klass, 989 /*out*/ArtMethod** out_default_method) const 990 REQUIRES_SHARED(Locks::mutator_lock_); 991 992 // Sets the imt entries and fixes up the vtable for the given class by linking all the interface 993 // methods. See LinkVirtualMethods for an explanation of what default_translations is. 994 bool LinkInterfaceMethods( 995 Thread* self, 996 Handle<mirror::Class> klass, 997 const std::unordered_map<size_t, MethodTranslation>& default_translations, 998 bool* out_new_conflict, 999 ArtMethod** out_imt) 1000 REQUIRES_SHARED(Locks::mutator_lock_); 1001 1002 bool LinkStaticFields(Thread* self, Handle<mirror::Class> klass, size_t* class_size) 1003 REQUIRES_SHARED(Locks::mutator_lock_); 1004 bool LinkInstanceFields(Thread* self, Handle<mirror::Class> klass) 1005 REQUIRES_SHARED(Locks::mutator_lock_); 1006 bool LinkFields(Thread* self, Handle<mirror::Class> klass, bool is_static, size_t* class_size) 1007 REQUIRES_SHARED(Locks::mutator_lock_); 1008 void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass) 1009 REQUIRES_SHARED(Locks::mutator_lock_); 1010 1011 void CheckProxyConstructor(ArtMethod* constructor) const 1012 REQUIRES_SHARED(Locks::mutator_lock_); 1013 void CheckProxyMethod(ArtMethod* method, ArtMethod* prototype) const 1014 REQUIRES_SHARED(Locks::mutator_lock_); 1015 1016 size_t GetDexCacheCount() REQUIRES_SHARED(Locks::mutator_lock_, Locks::dex_lock_) { 1017 return dex_caches_.size(); 1018 } 1019 const std::list<DexCacheData>& GetDexCachesData() 1020 REQUIRES_SHARED(Locks::mutator_lock_, Locks::dex_lock_) { 1021 return dex_caches_; 1022 } 1023 1024 void CreateProxyConstructor(Handle<mirror::Class> klass, ArtMethod* out) 1025 REQUIRES_SHARED(Locks::mutator_lock_); 1026 void CreateProxyMethod(Handle<mirror::Class> klass, ArtMethod* prototype, ArtMethod* out) 1027 REQUIRES_SHARED(Locks::mutator_lock_); 1028 1029 // Register a class loader and create its class table and allocator. Should not be called if 1030 // these are already created. 1031 void RegisterClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 1032 REQUIRES_SHARED(Locks::mutator_lock_) 1033 REQUIRES(Locks::classlinker_classes_lock_); 1034 1035 // Returns null if not found. 1036 ClassTable* ClassTableForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 1037 REQUIRES_SHARED(Locks::mutator_lock_); 1038 1039 // Insert a new class table if not found. 1040 ClassTable* InsertClassTableForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) 1041 REQUIRES_SHARED(Locks::mutator_lock_) 1042 REQUIRES(Locks::classlinker_classes_lock_); 1043 1044 // EnsureResolved is called to make sure that a class in the class_table_ has been resolved 1045 // before returning it to the caller. Its the responsibility of the thread that placed the class 1046 // in the table to make it resolved. The thread doing resolution must notify on the class' lock 1047 // when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may 1048 // retire a class, the version of the class in the table is returned and this may differ from 1049 // the class passed in. 1050 mirror::Class* EnsureResolved(Thread* self, const char* descriptor, ObjPtr<mirror::Class> klass) 1051 WARN_UNUSED 1052 REQUIRES_SHARED(Locks::mutator_lock_) 1053 REQUIRES(!Locks::dex_lock_); 1054 1055 void FixupTemporaryDeclaringClass(ObjPtr<mirror::Class> temp_class, 1056 ObjPtr<mirror::Class> new_class) 1057 REQUIRES_SHARED(Locks::mutator_lock_); 1058 1059 void SetClassRoot(ClassRoot class_root, ObjPtr<mirror::Class> klass) 1060 REQUIRES_SHARED(Locks::mutator_lock_); 1061 1062 // Return the quick generic JNI stub for testing. 1063 const void* GetRuntimeQuickGenericJniStub() const; 1064 1065 bool CanWeInitializeClass(ObjPtr<mirror::Class> klass, 1066 bool can_init_statics, 1067 bool can_init_parents) 1068 REQUIRES_SHARED(Locks::mutator_lock_); 1069 1070 void UpdateClassMethods(ObjPtr<mirror::Class> klass, 1071 LengthPrefixedArray<ArtMethod>* new_methods) 1072 REQUIRES_SHARED(Locks::mutator_lock_) 1073 REQUIRES(!Locks::classlinker_classes_lock_); 1074 1075 // new_class_set is the set of classes that were read from the class table section in the image. 1076 // If there was no class table section, it is null. 1077 bool UpdateAppImageClassLoadersAndDexCaches( 1078 gc::space::ImageSpace* space, 1079 Handle<mirror::ClassLoader> class_loader, 1080 Handle<mirror::ObjectArray<mirror::DexCache>> dex_caches, 1081 ClassTable::ClassSet* new_class_set, 1082 bool* out_forward_dex_cache_array, 1083 std::string* out_error_msg) 1084 REQUIRES(!Locks::dex_lock_) 1085 REQUIRES_SHARED(Locks::mutator_lock_); 1086 1087 // Check that c1 == FindSystemClass(self, descriptor). Abort with class dumps otherwise. 1088 void CheckSystemClass(Thread* self, Handle<mirror::Class> c1, const char* descriptor) 1089 REQUIRES(!Locks::dex_lock_) 1090 REQUIRES_SHARED(Locks::mutator_lock_); 1091 1092 // Sets imt_ref appropriately for LinkInterfaceMethods. 1093 // If there is no method in the imt location of imt_ref it will store the given method there. 1094 // Otherwise it will set the conflict method which will figure out which method to use during 1095 // runtime. 1096 void SetIMTRef(ArtMethod* unimplemented_method, 1097 ArtMethod* imt_conflict_method, 1098 ArtMethod* current_method, 1099 /*out*/bool* new_conflict, 1100 /*out*/ArtMethod** imt_ref) REQUIRES_SHARED(Locks::mutator_lock_); 1101 1102 void FillIMTFromIfTable(ObjPtr<mirror::IfTable> if_table, 1103 ArtMethod* unimplemented_method, 1104 ArtMethod* imt_conflict_method, 1105 ObjPtr<mirror::Class> klass, 1106 bool create_conflict_tables, 1107 bool ignore_copied_methods, 1108 /*out*/bool* new_conflict, 1109 /*out*/ArtMethod** imt) REQUIRES_SHARED(Locks::mutator_lock_); 1110 1111 void FillImtFromSuperClass(Handle<mirror::Class> klass, 1112 ArtMethod* unimplemented_method, 1113 ArtMethod* imt_conflict_method, 1114 bool* new_conflict, 1115 ArtMethod** imt) REQUIRES_SHARED(Locks::mutator_lock_); 1116 1117 std::vector<const DexFile*> boot_class_path_; 1118 std::vector<std::unique_ptr<const DexFile>> boot_dex_files_; 1119 1120 // JNI weak globals and side data to allow dex caches to get unloaded. We lazily delete weak 1121 // globals when we register new dex files. 1122 std::list<DexCacheData> dex_caches_ GUARDED_BY(Locks::dex_lock_); 1123 1124 // This contains the class loaders which have class tables. It is populated by 1125 // InsertClassTableForClassLoader. 1126 std::list<ClassLoaderData> class_loaders_ 1127 GUARDED_BY(Locks::classlinker_classes_lock_); 1128 1129 // Boot class path table. Since the class loader for this is null. 1130 ClassTable boot_class_table_ GUARDED_BY(Locks::classlinker_classes_lock_); 1131 1132 // New class roots, only used by CMS since the GC needs to mark these in the pause. 1133 std::vector<GcRoot<mirror::Class>> new_class_roots_ GUARDED_BY(Locks::classlinker_classes_lock_); 1134 1135 // Number of times we've searched dex caches for a class. After a certain number of misses we move 1136 // the classes into the class_table_ to avoid dex cache based searches. 1137 Atomic<uint32_t> failed_dex_cache_class_lookups_; 1138 1139 // Well known mirror::Class roots. 1140 GcRoot<mirror::ObjectArray<mirror::Class>> class_roots_; 1141 1142 // The interface table used by all arrays. 1143 GcRoot<mirror::IfTable> array_iftable_; 1144 1145 // A cache of the last FindArrayClass results. The cache serves to avoid creating array class 1146 // descriptors for the sake of performing FindClass. 1147 static constexpr size_t kFindArrayCacheSize = 16; 1148 GcRoot<mirror::Class> find_array_class_cache_[kFindArrayCacheSize]; 1149 size_t find_array_class_cache_next_victim_; 1150 1151 bool init_done_; 1152 bool log_new_class_table_roots_ GUARDED_BY(Locks::classlinker_classes_lock_); 1153 1154 InternTable* intern_table_; 1155 1156 // Trampolines within the image the bounce to runtime entrypoints. Done so that there is a single 1157 // patch point within the image. TODO: make these proper relocations. 1158 const void* quick_resolution_trampoline_; 1159 const void* quick_imt_conflict_trampoline_; 1160 const void* quick_generic_jni_trampoline_; 1161 const void* quick_to_interpreter_bridge_trampoline_; 1162 1163 // Image pointer size. 1164 PointerSize image_pointer_size_; 1165 1166 class FindVirtualMethodHolderVisitor; 1167 friend struct CompilationHelper; // For Compile in ImageTest. 1168 friend class ImageDumper; // for DexLock 1169 friend class ImageWriter; // for GetClassRoots 1170 friend class VMClassLoader; // for LookupClass and FindClassInBaseDexClassLoader. 1171 friend class JniCompilerTest; // for GetRuntimeQuickGenericJniStub 1172 friend class JniInternalTest; // for GetRuntimeQuickGenericJniStub 1173 ART_FRIEND_TEST(ClassLinkerTest, RegisterDexFileName); // for DexLock, and RegisterDexFileLocked 1174 ART_FRIEND_TEST(mirror::DexCacheMethodHandlesTest, Open); // for AllocDexCache 1175 ART_FRIEND_TEST(mirror::DexCacheTest, Open); // for AllocDexCache 1176 DISALLOW_COPY_AND_ASSIGN(ClassLinker); 1177}; 1178 1179} // namespace art 1180 1181#endif // ART_RUNTIME_CLASS_LINKER_H_ 1182