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