Home | History | Annotate | Download | only in mirror
      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_MIRROR_CLASS_H_
     18 #define ART_RUNTIME_MIRROR_CLASS_H_
     19 
     20 #include "base/iteration_range.h"
     21 #include "dex_file.h"
     22 #include "class_flags.h"
     23 #include "gc_root.h"
     24 #include "gc/allocator_type.h"
     25 #include "imtable.h"
     26 #include "invoke_type.h"
     27 #include "modifiers.h"
     28 #include "object.h"
     29 #include "object_array.h"
     30 #include "object_callbacks.h"
     31 #include "primitive.h"
     32 #include "read_barrier_option.h"
     33 #include "stride_iterator.h"
     34 #include "thread.h"
     35 #include "utils.h"
     36 
     37 namespace art {
     38 
     39 class ArtField;
     40 class ArtMethod;
     41 struct ClassOffsets;
     42 template<class T> class Handle;
     43 template<typename T> class LengthPrefixedArray;
     44 template<typename T> class ArraySlice;
     45 class Signature;
     46 class StringPiece;
     47 template<size_t kNumReferences> class PACKED(4) StackHandleScope;
     48 
     49 namespace mirror {
     50 
     51 class ClassLoader;
     52 class Constructor;
     53 class DexCache;
     54 class IfTable;
     55 class Method;
     56 
     57 // C++ mirror of java.lang.Class
     58 class MANAGED Class FINAL : public Object {
     59  public:
     60   // A magic value for reference_instance_offsets_. Ignore the bits and walk the super chain when
     61   // this is the value.
     62   // [This is an unlikely "natural" value, since it would be 30 non-ref instance fields followed by
     63   // 2 ref instance fields.]
     64   static constexpr uint32_t kClassWalkSuper = 0xC0000000;
     65 
     66   // Class Status
     67   //
     68   // kStatusRetired: Class that's temporarily used till class linking time
     69   // has its (vtable) size figured out and has been cloned to one with the
     70   // right size which will be the one used later. The old one is retired and
     71   // will be gc'ed once all refs to the class point to the newly
     72   // cloned version.
     73   //
     74   // kStatusNotReady: If a Class cannot be found in the class table by
     75   // FindClass, it allocates an new one with AllocClass in the
     76   // kStatusNotReady and calls LoadClass. Note if it does find a
     77   // class, it may not be kStatusResolved and it will try to push it
     78   // forward toward kStatusResolved.
     79   //
     80   // kStatusIdx: LoadClass populates with Class with information from
     81   // the DexFile, moving the status to kStatusIdx, indicating that the
     82   // Class value in super_class_ has not been populated. The new Class
     83   // can then be inserted into the classes table.
     84   //
     85   // kStatusLoaded: After taking a lock on Class, the ClassLinker will
     86   // attempt to move a kStatusIdx class forward to kStatusLoaded by
     87   // using ResolveClass to initialize the super_class_ and ensuring the
     88   // interfaces are resolved.
     89   //
     90   // kStatusResolving: Class is just cloned with the right size from
     91   // temporary class that's acting as a placeholder for linking. The old
     92   // class will be retired. New class is set to this status first before
     93   // moving on to being resolved.
     94   //
     95   // kStatusResolved: Still holding the lock on Class, the ClassLinker
     96   // shows linking is complete and fields of the Class populated by making
     97   // it kStatusResolved. Java allows circularities of the form where a super
     98   // class has a field that is of the type of the sub class. We need to be able
     99   // to fully resolve super classes while resolving types for fields.
    100   //
    101   // kStatusRetryVerificationAtRuntime: The verifier sets a class to
    102   // this state if it encounters a soft failure at compile time. This
    103   // often happens when there are unresolved classes in other dex
    104   // files, and this status marks a class as needing to be verified
    105   // again at runtime.
    106   //
    107   // TODO: Explain the other states
    108   enum Status {
    109     kStatusRetired = -2,  // Retired, should not be used. Use the newly cloned one instead.
    110     kStatusError = -1,
    111     kStatusNotReady = 0,
    112     kStatusIdx = 1,  // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
    113     kStatusLoaded = 2,  // DEX idx values resolved.
    114     kStatusResolving = 3,  // Just cloned from temporary class object.
    115     kStatusResolved = 4,  // Part of linking.
    116     kStatusVerifying = 5,  // In the process of being verified.
    117     kStatusRetryVerificationAtRuntime = 6,  // Compile time verification failed, retry at runtime.
    118     kStatusVerifyingAtRuntime = 7,  // Retrying verification at runtime.
    119     kStatusVerified = 8,  // Logically part of linking; done pre-init.
    120     kStatusInitializing = 9,  // Class init in progress.
    121     kStatusInitialized = 10,  // Ready to go.
    122     kStatusMax = 11,
    123   };
    124 
    125   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    126   Status GetStatus() SHARED_REQUIRES(Locks::mutator_lock_) {
    127     static_assert(sizeof(Status) == sizeof(uint32_t), "Size of status not equal to uint32");
    128     return static_cast<Status>(
    129         GetField32Volatile<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_)));
    130   }
    131 
    132   // This is static because 'this' may be moved by GC.
    133   static void SetStatus(Handle<Class> h_this, Status new_status, Thread* self)
    134       SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
    135 
    136   static MemberOffset StatusOffset() {
    137     return OFFSET_OF_OBJECT_MEMBER(Class, status_);
    138   }
    139 
    140   // Returns true if the class has been retired.
    141   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    142   bool IsRetired() SHARED_REQUIRES(Locks::mutator_lock_) {
    143     return GetStatus<kVerifyFlags>() == kStatusRetired;
    144   }
    145 
    146   // Returns true if the class has failed to link.
    147   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    148   bool IsErroneous() SHARED_REQUIRES(Locks::mutator_lock_) {
    149     return GetStatus<kVerifyFlags>() == kStatusError;
    150   }
    151 
    152   // Returns true if the class has been loaded.
    153   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    154   bool IsIdxLoaded() SHARED_REQUIRES(Locks::mutator_lock_) {
    155     return GetStatus<kVerifyFlags>() >= kStatusIdx;
    156   }
    157 
    158   // Returns true if the class has been loaded.
    159   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    160   bool IsLoaded() SHARED_REQUIRES(Locks::mutator_lock_) {
    161     return GetStatus<kVerifyFlags>() >= kStatusLoaded;
    162   }
    163 
    164   // Returns true if the class has been linked.
    165   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    166   bool IsResolved() SHARED_REQUIRES(Locks::mutator_lock_) {
    167     return GetStatus<kVerifyFlags>() >= kStatusResolved;
    168   }
    169 
    170   // Returns true if the class was compile-time verified.
    171   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    172   bool IsCompileTimeVerified() SHARED_REQUIRES(Locks::mutator_lock_) {
    173     return GetStatus<kVerifyFlags>() >= kStatusRetryVerificationAtRuntime;
    174   }
    175 
    176   // Returns true if the class has been verified.
    177   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    178   bool IsVerified() SHARED_REQUIRES(Locks::mutator_lock_) {
    179     return GetStatus<kVerifyFlags>() >= kStatusVerified;
    180   }
    181 
    182   // Returns true if the class is initializing.
    183   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    184   bool IsInitializing() SHARED_REQUIRES(Locks::mutator_lock_) {
    185     return GetStatus<kVerifyFlags>() >= kStatusInitializing;
    186   }
    187 
    188   // Returns true if the class is initialized.
    189   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    190   bool IsInitialized() SHARED_REQUIRES(Locks::mutator_lock_) {
    191     return GetStatus<kVerifyFlags>() == kStatusInitialized;
    192   }
    193 
    194   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    195   ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_REQUIRES(Locks::mutator_lock_);
    196   static MemberOffset AccessFlagsOffset() {
    197     return OFFSET_OF_OBJECT_MEMBER(Class, access_flags_);
    198   }
    199 
    200   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    201   ALWAYS_INLINE uint32_t GetClassFlags() SHARED_REQUIRES(Locks::mutator_lock_) {
    202     return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_flags_));
    203   }
    204   void SetClassFlags(uint32_t new_flags) SHARED_REQUIRES(Locks::mutator_lock_);
    205 
    206   void SetAccessFlags(uint32_t new_access_flags) SHARED_REQUIRES(Locks::mutator_lock_);
    207 
    208   // Returns true if the class is an interface.
    209   ALWAYS_INLINE bool IsInterface() SHARED_REQUIRES(Locks::mutator_lock_) {
    210     return (GetAccessFlags() & kAccInterface) != 0;
    211   }
    212 
    213   // Returns true if the class is declared public.
    214   ALWAYS_INLINE bool IsPublic() SHARED_REQUIRES(Locks::mutator_lock_) {
    215     return (GetAccessFlags() & kAccPublic) != 0;
    216   }
    217 
    218   // Returns true if the class is declared final.
    219   ALWAYS_INLINE bool IsFinal() SHARED_REQUIRES(Locks::mutator_lock_) {
    220     return (GetAccessFlags() & kAccFinal) != 0;
    221   }
    222 
    223   ALWAYS_INLINE bool IsFinalizable() SHARED_REQUIRES(Locks::mutator_lock_) {
    224     return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
    225   }
    226 
    227   ALWAYS_INLINE void SetRecursivelyInitialized() SHARED_REQUIRES(Locks::mutator_lock_) {
    228     DCHECK_EQ(GetLockOwnerThreadId(), Thread::Current()->GetThreadId());
    229     uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
    230     SetAccessFlags(flags | kAccRecursivelyInitialized);
    231   }
    232 
    233   ALWAYS_INLINE void SetHasDefaultMethods() SHARED_REQUIRES(Locks::mutator_lock_) {
    234     DCHECK_EQ(GetLockOwnerThreadId(), Thread::Current()->GetThreadId());
    235     uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
    236     SetAccessFlags(flags | kAccHasDefaultMethod);
    237   }
    238 
    239   ALWAYS_INLINE void SetFinalizable() SHARED_REQUIRES(Locks::mutator_lock_) {
    240     uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
    241     SetAccessFlags(flags | kAccClassIsFinalizable);
    242   }
    243 
    244   ALWAYS_INLINE bool IsStringClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    245     return (GetClassFlags() & kClassFlagString) != 0;
    246   }
    247 
    248   ALWAYS_INLINE void SetStringClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    249     SetClassFlags(kClassFlagString | kClassFlagNoReferenceFields);
    250   }
    251 
    252   ALWAYS_INLINE bool IsClassLoaderClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    253     return GetClassFlags() == kClassFlagClassLoader;
    254   }
    255 
    256   ALWAYS_INLINE void SetClassLoaderClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    257     SetClassFlags(kClassFlagClassLoader);
    258   }
    259 
    260   ALWAYS_INLINE bool IsDexCacheClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    261     return (GetClassFlags() & kClassFlagDexCache) != 0;
    262   }
    263 
    264   ALWAYS_INLINE void SetDexCacheClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    265     SetClassFlags(GetClassFlags() | kClassFlagDexCache);
    266   }
    267 
    268   // Returns true if the class is abstract.
    269   ALWAYS_INLINE bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) {
    270     return (GetAccessFlags() & kAccAbstract) != 0;
    271   }
    272 
    273   // Returns true if the class is an annotation.
    274   ALWAYS_INLINE bool IsAnnotation() SHARED_REQUIRES(Locks::mutator_lock_) {
    275     return (GetAccessFlags() & kAccAnnotation) != 0;
    276   }
    277 
    278   // Returns true if the class is synthetic.
    279   ALWAYS_INLINE bool IsSynthetic() SHARED_REQUIRES(Locks::mutator_lock_) {
    280     return (GetAccessFlags() & kAccSynthetic) != 0;
    281   }
    282 
    283   // Return whether the class had run the verifier at least once.
    284   // This does not necessarily mean that access checks are avoidable,
    285   // since the class methods might still need to be run with access checks.
    286   bool WasVerificationAttempted() SHARED_REQUIRES(Locks::mutator_lock_) {
    287     return (GetAccessFlags() & kAccSkipAccessChecks) != 0;
    288   }
    289 
    290   // Mark the class as having gone through a verification attempt.
    291   // Mutually exclusive from whether or not each method is allowed to skip access checks.
    292   void SetVerificationAttempted() SHARED_REQUIRES(Locks::mutator_lock_) {
    293     uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
    294     if ((flags & kAccVerificationAttempted) == 0) {
    295       SetAccessFlags(flags | kAccVerificationAttempted);
    296     }
    297   }
    298 
    299   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    300   bool IsTypeOfReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    301     return (GetClassFlags<kVerifyFlags>() & kClassFlagReference) != 0;
    302   }
    303 
    304   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    305   bool IsWeakReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    306     return GetClassFlags<kVerifyFlags>() == kClassFlagWeakReference;
    307   }
    308 
    309   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    310   bool IsSoftReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    311     return GetClassFlags<kVerifyFlags>() == kClassFlagSoftReference;
    312   }
    313 
    314   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    315   bool IsFinalizerReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    316     return GetClassFlags<kVerifyFlags>() == kClassFlagFinalizerReference;
    317   }
    318 
    319   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    320   bool IsPhantomReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    321     return GetClassFlags<kVerifyFlags>() == kClassFlagPhantomReference;
    322   }
    323 
    324   // Can references of this type be assigned to by things of another type? For non-array types
    325   // this is a matter of whether sub-classes may exist - which they can't if the type is final.
    326   // For array classes, where all the classes are final due to there being no sub-classes, an
    327   // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
    328   // types as the component is final.
    329   bool CannotBeAssignedFromOtherTypes() SHARED_REQUIRES(Locks::mutator_lock_) {
    330     if (!IsArrayClass()) {
    331       return IsFinal();
    332     } else {
    333       Class* component = GetComponentType();
    334       if (component->IsPrimitive()) {
    335         return true;
    336       } else {
    337         return component->CannotBeAssignedFromOtherTypes();
    338       }
    339     }
    340   }
    341 
    342   // Returns true if this class is the placeholder and should retire and
    343   // be replaced with a class with the right size for embedded imt/vtable.
    344   bool IsTemp() SHARED_REQUIRES(Locks::mutator_lock_) {
    345     Status s = GetStatus();
    346     return s < Status::kStatusResolving && ShouldHaveEmbeddedVTable();
    347   }
    348 
    349   String* GetName() SHARED_REQUIRES(Locks::mutator_lock_);  // Returns the cached name.
    350   void SetName(String* name) SHARED_REQUIRES(Locks::mutator_lock_);  // Sets the cached name.
    351   // Computes the name, then sets the cached value.
    352   static String* ComputeName(Handle<Class> h_this) SHARED_REQUIRES(Locks::mutator_lock_)
    353       REQUIRES(!Roles::uninterruptible_);
    354 
    355   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    356   bool IsProxyClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    357     // Read access flags without using getter as whether something is a proxy can be check in
    358     // any loaded state
    359     // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
    360     uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
    361     return (access_flags & kAccClassIsProxy) != 0;
    362   }
    363 
    364   static MemberOffset PrimitiveTypeOffset() {
    365     return OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_);
    366   }
    367 
    368   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    369   Primitive::Type GetPrimitiveType() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_);
    370 
    371   void SetPrimitiveType(Primitive::Type new_type) SHARED_REQUIRES(Locks::mutator_lock_) {
    372     DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
    373     int32_t v32 = static_cast<int32_t>(new_type);
    374     DCHECK_EQ(v32 & 0xFFFF, v32) << "upper 16 bits aren't zero";
    375     // Store the component size shift in the upper 16 bits.
    376     v32 |= Primitive::ComponentSizeShift(new_type) << 16;
    377     SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), v32);
    378   }
    379 
    380   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    381   size_t GetPrimitiveTypeSizeShift() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_);
    382 
    383   // Returns true if the class is a primitive type.
    384   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    385   bool IsPrimitive() SHARED_REQUIRES(Locks::mutator_lock_) {
    386     return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot;
    387   }
    388 
    389   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    390   bool IsPrimitiveBoolean() SHARED_REQUIRES(Locks::mutator_lock_) {
    391     return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
    392   }
    393 
    394   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    395   bool IsPrimitiveByte() SHARED_REQUIRES(Locks::mutator_lock_) {
    396     return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
    397   }
    398 
    399   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    400   bool IsPrimitiveChar() SHARED_REQUIRES(Locks::mutator_lock_) {
    401     return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
    402   }
    403 
    404   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    405   bool IsPrimitiveShort() SHARED_REQUIRES(Locks::mutator_lock_) {
    406     return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
    407   }
    408 
    409   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    410   bool IsPrimitiveInt() SHARED_REQUIRES(Locks::mutator_lock_) {
    411     return GetPrimitiveType() == Primitive::kPrimInt;
    412   }
    413 
    414   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    415   bool IsPrimitiveLong() SHARED_REQUIRES(Locks::mutator_lock_) {
    416     return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
    417   }
    418 
    419   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    420   bool IsPrimitiveFloat() SHARED_REQUIRES(Locks::mutator_lock_) {
    421     return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
    422   }
    423 
    424   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    425   bool IsPrimitiveDouble() SHARED_REQUIRES(Locks::mutator_lock_) {
    426     return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
    427   }
    428 
    429   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    430   bool IsPrimitiveVoid() SHARED_REQUIRES(Locks::mutator_lock_) {
    431     return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
    432   }
    433 
    434   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    435   bool IsPrimitiveArray() SHARED_REQUIRES(Locks::mutator_lock_) {
    436     return IsArrayClass<kVerifyFlags>() &&
    437         GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
    438         IsPrimitive();
    439   }
    440 
    441   // Depth of class from java.lang.Object
    442   uint32_t Depth() SHARED_REQUIRES(Locks::mutator_lock_);
    443 
    444   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    445            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    446   bool IsArrayClass() SHARED_REQUIRES(Locks::mutator_lock_);
    447 
    448   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    449            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    450   bool IsClassClass() SHARED_REQUIRES(Locks::mutator_lock_);
    451 
    452   bool IsThrowableClass() SHARED_REQUIRES(Locks::mutator_lock_);
    453 
    454   template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    455   bool IsReferenceClass() const SHARED_REQUIRES(Locks::mutator_lock_);
    456 
    457   static MemberOffset ComponentTypeOffset() {
    458     return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
    459   }
    460 
    461   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    462            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    463   Class* GetComponentType() SHARED_REQUIRES(Locks::mutator_lock_);
    464 
    465   void SetComponentType(Class* new_component_type) SHARED_REQUIRES(Locks::mutator_lock_) {
    466     DCHECK(GetComponentType() == nullptr);
    467     DCHECK(new_component_type != nullptr);
    468     // Component type is invariant: use non-transactional mode without check.
    469     SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
    470   }
    471 
    472   template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    473   size_t GetComponentSize() SHARED_REQUIRES(Locks::mutator_lock_) {
    474     return 1U << GetComponentSizeShift();
    475   }
    476 
    477   template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    478   size_t GetComponentSizeShift() SHARED_REQUIRES(Locks::mutator_lock_) {
    479     return GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveTypeSizeShift();
    480   }
    481 
    482   bool IsObjectClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    483     return !IsPrimitive() && GetSuperClass() == nullptr;
    484   }
    485 
    486   bool IsInstantiableNonArray() SHARED_REQUIRES(Locks::mutator_lock_) {
    487     return !IsPrimitive() && !IsInterface() && !IsAbstract() && !IsArrayClass();
    488   }
    489 
    490   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    491            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    492   bool IsInstantiable() SHARED_REQUIRES(Locks::mutator_lock_) {
    493     return (!IsPrimitive() && !IsInterface() && !IsAbstract()) ||
    494         (IsAbstract() && IsArrayClass<kVerifyFlags, kReadBarrierOption>());
    495   }
    496 
    497   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    498            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    499   bool IsObjectArrayClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    500     mirror::Class* const component_type = GetComponentType<kVerifyFlags, kReadBarrierOption>();
    501     return component_type != nullptr && !component_type->IsPrimitive();
    502   }
    503 
    504   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    505   bool IsIntArrayClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    506     constexpr auto kNewFlags = static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis);
    507     auto* component_type = GetComponentType<kVerifyFlags>();
    508     return component_type != nullptr && component_type->template IsPrimitiveInt<kNewFlags>();
    509   }
    510 
    511   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    512   bool IsLongArrayClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    513     constexpr auto kNewFlags = static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis);
    514     auto* component_type = GetComponentType<kVerifyFlags>();
    515     return component_type != nullptr && component_type->template IsPrimitiveLong<kNewFlags>();
    516   }
    517 
    518   // Creates a raw object instance but does not invoke the default constructor.
    519   template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
    520   ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
    521       SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
    522 
    523   Object* AllocObject(Thread* self)
    524       SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
    525   Object* AllocNonMovableObject(Thread* self)
    526       SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
    527 
    528   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    529            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    530   bool IsVariableSize() SHARED_REQUIRES(Locks::mutator_lock_) {
    531     // Classes, arrays, and strings vary in size, and so the object_size_ field cannot
    532     // be used to Get their instance size
    533     return IsClassClass<kVerifyFlags, kReadBarrierOption>() ||
    534         IsArrayClass<kVerifyFlags, kReadBarrierOption>() || IsStringClass();
    535   }
    536 
    537   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    538            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    539   uint32_t SizeOf() SHARED_REQUIRES(Locks::mutator_lock_) {
    540     return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
    541   }
    542 
    543   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    544   uint32_t GetClassSize() SHARED_REQUIRES(Locks::mutator_lock_) {
    545     return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
    546   }
    547 
    548   void SetClassSize(uint32_t new_class_size)
    549       SHARED_REQUIRES(Locks::mutator_lock_);
    550 
    551   // Compute how many bytes would be used a class with the given elements.
    552   static uint32_t ComputeClassSize(bool has_embedded_vtable,
    553                                    uint32_t num_vtable_entries,
    554                                    uint32_t num_8bit_static_fields,
    555                                    uint32_t num_16bit_static_fields,
    556                                    uint32_t num_32bit_static_fields,
    557                                    uint32_t num_64bit_static_fields,
    558                                    uint32_t num_ref_static_fields,
    559                                    size_t pointer_size);
    560 
    561   // The size of java.lang.Class.class.
    562   static uint32_t ClassClassSize(size_t pointer_size) {
    563     // The number of vtable entries in java.lang.Class.
    564     uint32_t vtable_entries = Object::kVTableLength + 72;
    565     return ComputeClassSize(true, vtable_entries, 0, 0, 4, 1, 0, pointer_size);
    566   }
    567 
    568   // The size of a java.lang.Class representing a primitive such as int.class.
    569   static uint32_t PrimitiveClassSize(size_t pointer_size) {
    570     return ComputeClassSize(false, 0, 0, 0, 0, 0, 0, pointer_size);
    571   }
    572 
    573   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    574            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    575   uint32_t GetObjectSize() SHARED_REQUIRES(Locks::mutator_lock_);
    576   static MemberOffset ObjectSizeOffset() {
    577     return OFFSET_OF_OBJECT_MEMBER(Class, object_size_);
    578   }
    579 
    580   void SetObjectSize(uint32_t new_object_size) SHARED_REQUIRES(Locks::mutator_lock_) {
    581     DCHECK(!IsVariableSize());
    582     // Not called within a transaction.
    583     return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
    584   }
    585 
    586   void SetObjectSizeWithoutChecks(uint32_t new_object_size)
    587       SHARED_REQUIRES(Locks::mutator_lock_) {
    588     // Not called within a transaction.
    589     return SetField32<false, false, kVerifyNone>(
    590         OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
    591   }
    592 
    593   // Returns true if this class is in the same packages as that class.
    594   bool IsInSamePackage(Class* that) SHARED_REQUIRES(Locks::mutator_lock_);
    595 
    596   static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
    597 
    598   // Returns true if this class can access that class.
    599   bool CanAccess(Class* that) SHARED_REQUIRES(Locks::mutator_lock_) {
    600     return that->IsPublic() || this->IsInSamePackage(that);
    601   }
    602 
    603   // Can this class access a member in the provided class with the provided member access flags?
    604   // Note that access to the class isn't checked in case the declaring class is protected and the
    605   // method has been exposed by a public sub-class
    606   bool CanAccessMember(Class* access_to, uint32_t member_flags)
    607       SHARED_REQUIRES(Locks::mutator_lock_) {
    608     // Classes can access all of their own members
    609     if (this == access_to) {
    610       return true;
    611     }
    612     // Public members are trivially accessible
    613     if (member_flags & kAccPublic) {
    614       return true;
    615     }
    616     // Private members are trivially not accessible
    617     if (member_flags & kAccPrivate) {
    618       return false;
    619     }
    620     // Check for protected access from a sub-class, which may or may not be in the same package.
    621     if (member_flags & kAccProtected) {
    622       if (!this->IsInterface() && this->IsSubClass(access_to)) {
    623         return true;
    624       }
    625     }
    626     // Allow protected access from other classes in the same package.
    627     return this->IsInSamePackage(access_to);
    628   }
    629 
    630   // Can this class access a resolved field?
    631   // Note that access to field's class is checked and this may require looking up the class
    632   // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
    633   bool CanAccessResolvedField(Class* access_to, ArtField* field,
    634                               DexCache* dex_cache, uint32_t field_idx)
    635       SHARED_REQUIRES(Locks::mutator_lock_);
    636   bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
    637                                 uint32_t field_idx)
    638       SHARED_REQUIRES(Locks::mutator_lock_);
    639 
    640   // Can this class access a resolved method?
    641   // Note that access to methods's class is checked and this may require looking up the class
    642   // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
    643   bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
    644                                DexCache* dex_cache, uint32_t method_idx)
    645       SHARED_REQUIRES(Locks::mutator_lock_);
    646   template <InvokeType throw_invoke_type>
    647   bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
    648                                  uint32_t method_idx)
    649       SHARED_REQUIRES(Locks::mutator_lock_);
    650 
    651   bool IsSubClass(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
    652 
    653   // Can src be assigned to this class? For example, String can be assigned to Object (by an
    654   // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
    655   // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
    656   // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
    657   // to themselves. Classes for primitive types may not assign to each other.
    658   ALWAYS_INLINE bool IsAssignableFrom(Class* src) SHARED_REQUIRES(Locks::mutator_lock_);
    659 
    660   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    661            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    662   ALWAYS_INLINE Class* GetSuperClass() SHARED_REQUIRES(Locks::mutator_lock_);
    663 
    664   // Get first common super class. It will never return null.
    665   // `This` and `klass` must be classes.
    666   Class* GetCommonSuperClass(Handle<Class> klass) SHARED_REQUIRES(Locks::mutator_lock_);
    667 
    668   void SetSuperClass(Class *new_super_class) SHARED_REQUIRES(Locks::mutator_lock_) {
    669     // Super class is assigned once, except during class linker initialization.
    670     Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
    671     DCHECK(old_super_class == nullptr || old_super_class == new_super_class);
    672     DCHECK(new_super_class != nullptr);
    673     SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class);
    674   }
    675 
    676   bool HasSuperClass() SHARED_REQUIRES(Locks::mutator_lock_) {
    677     return GetSuperClass() != nullptr;
    678   }
    679 
    680   static MemberOffset SuperClassOffset() {
    681     return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
    682   }
    683 
    684   ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_);
    685 
    686   void SetClassLoader(ClassLoader* new_cl) SHARED_REQUIRES(Locks::mutator_lock_);
    687 
    688   static MemberOffset DexCacheOffset() {
    689     return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
    690   }
    691 
    692   enum {
    693     kDumpClassFullDetail = 1,
    694     kDumpClassClassLoader = (1 << 1),
    695     kDumpClassInitialized = (1 << 2),
    696   };
    697 
    698   void DumpClass(std::ostream& os, int flags) SHARED_REQUIRES(Locks::mutator_lock_);
    699 
    700   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    701   DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
    702 
    703   // Also updates the dex_cache_strings_ variable from new_dex_cache.
    704   void SetDexCache(DexCache* new_dex_cache) SHARED_REQUIRES(Locks::mutator_lock_);
    705 
    706   ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDirectMethods(size_t pointer_size)
    707       SHARED_REQUIRES(Locks::mutator_lock_);
    708 
    709   ALWAYS_INLINE LengthPrefixedArray<ArtMethod>* GetMethodsPtr()
    710       SHARED_REQUIRES(Locks::mutator_lock_);
    711 
    712   static MemberOffset MethodsOffset() {
    713     return MemberOffset(OFFSETOF_MEMBER(Class, methods_));
    714   }
    715 
    716   ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetMethods(size_t pointer_size)
    717       SHARED_REQUIRES(Locks::mutator_lock_);
    718 
    719   void SetMethodsPtr(LengthPrefixedArray<ArtMethod>* new_methods,
    720                      uint32_t num_direct,
    721                      uint32_t num_virtual)
    722       SHARED_REQUIRES(Locks::mutator_lock_);
    723   // Used by image writer.
    724   void SetMethodsPtrUnchecked(LengthPrefixedArray<ArtMethod>* new_methods,
    725                               uint32_t num_direct,
    726                               uint32_t num_virtual)
    727       SHARED_REQUIRES(Locks::mutator_lock_);
    728 
    729   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    730   ALWAYS_INLINE ArraySlice<ArtMethod> GetDirectMethodsSlice(size_t pointer_size)
    731       SHARED_REQUIRES(Locks::mutator_lock_);
    732 
    733   ALWAYS_INLINE ArtMethod* GetDirectMethod(size_t i, size_t pointer_size)
    734       SHARED_REQUIRES(Locks::mutator_lock_);
    735 
    736   // Use only when we are allocating populating the method arrays.
    737   ALWAYS_INLINE ArtMethod* GetDirectMethodUnchecked(size_t i, size_t pointer_size)
    738         SHARED_REQUIRES(Locks::mutator_lock_);
    739   ALWAYS_INLINE ArtMethod* GetVirtualMethodUnchecked(size_t i, size_t pointer_size)
    740         SHARED_REQUIRES(Locks::mutator_lock_);
    741 
    742   // Returns the number of static, private, and constructor methods.
    743   ALWAYS_INLINE uint32_t NumDirectMethods() SHARED_REQUIRES(Locks::mutator_lock_);
    744 
    745   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    746   ALWAYS_INLINE ArraySlice<ArtMethod> GetMethodsSlice(size_t pointer_size)
    747       SHARED_REQUIRES(Locks::mutator_lock_);
    748 
    749   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    750   ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredMethodsSlice(size_t pointer_size)
    751       SHARED_REQUIRES(Locks::mutator_lock_);
    752 
    753   ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDeclaredMethods(
    754         size_t pointer_size)
    755       SHARED_REQUIRES(Locks::mutator_lock_);
    756 
    757   template <bool kTransactionActive = false>
    758   static Method* GetDeclaredMethodInternal(Thread* self,
    759                                            mirror::Class* klass,
    760                                            mirror::String* name,
    761                                            mirror::ObjectArray<mirror::Class>* args)
    762       SHARED_REQUIRES(Locks::mutator_lock_);
    763   template <bool kTransactionActive = false>
    764   static Constructor* GetDeclaredConstructorInternal(Thread* self,
    765                                                      mirror::Class* klass,
    766                                                      mirror::ObjectArray<mirror::Class>* args)
    767       SHARED_REQUIRES(Locks::mutator_lock_);
    768 
    769   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    770   ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredVirtualMethodsSlice(size_t pointer_size)
    771       SHARED_REQUIRES(Locks::mutator_lock_);
    772 
    773   ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDeclaredVirtualMethods(
    774         size_t pointer_size)
    775       SHARED_REQUIRES(Locks::mutator_lock_);
    776 
    777   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    778   ALWAYS_INLINE ArraySlice<ArtMethod> GetCopiedMethodsSlice(size_t pointer_size)
    779       SHARED_REQUIRES(Locks::mutator_lock_);
    780 
    781   ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetCopiedMethods(size_t pointer_size)
    782       SHARED_REQUIRES(Locks::mutator_lock_);
    783 
    784   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    785   ALWAYS_INLINE ArraySlice<ArtMethod> GetVirtualMethodsSlice(size_t pointer_size)
    786       SHARED_REQUIRES(Locks::mutator_lock_);
    787 
    788   ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetVirtualMethods(size_t pointer_size)
    789       SHARED_REQUIRES(Locks::mutator_lock_);
    790 
    791   // Returns the number of non-inherited virtual methods (sum of declared and copied methods).
    792   ALWAYS_INLINE uint32_t NumVirtualMethods() SHARED_REQUIRES(Locks::mutator_lock_);
    793 
    794   // Returns the number of copied virtual methods.
    795   ALWAYS_INLINE uint32_t NumCopiedVirtualMethods() SHARED_REQUIRES(Locks::mutator_lock_);
    796 
    797   // Returns the number of declared virtual methods.
    798   ALWAYS_INLINE uint32_t NumDeclaredVirtualMethods() SHARED_REQUIRES(Locks::mutator_lock_);
    799 
    800   ALWAYS_INLINE uint32_t NumMethods() SHARED_REQUIRES(Locks::mutator_lock_);
    801 
    802   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
    803   ArtMethod* GetVirtualMethod(size_t i, size_t pointer_size)
    804       SHARED_REQUIRES(Locks::mutator_lock_);
    805 
    806   ArtMethod* GetVirtualMethodDuringLinking(size_t i, size_t pointer_size)
    807       SHARED_REQUIRES(Locks::mutator_lock_);
    808 
    809   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    810            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    811   ALWAYS_INLINE PointerArray* GetVTable() SHARED_REQUIRES(Locks::mutator_lock_);
    812 
    813   ALWAYS_INLINE PointerArray* GetVTableDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
    814 
    815   void SetVTable(PointerArray* new_vtable) SHARED_REQUIRES(Locks::mutator_lock_);
    816 
    817   static MemberOffset VTableOffset() {
    818     return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
    819   }
    820 
    821   static MemberOffset EmbeddedVTableLengthOffset() {
    822     return MemberOffset(sizeof(Class));
    823   }
    824 
    825   static MemberOffset ImtPtrOffset(size_t pointer_size) {
    826     return MemberOffset(
    827         RoundUp(EmbeddedVTableLengthOffset().Uint32Value() + sizeof(uint32_t), pointer_size));
    828   }
    829 
    830   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    831            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    832   bool ShouldHaveImt() SHARED_REQUIRES(Locks::mutator_lock_) {
    833     return ShouldHaveEmbeddedVTable<kVerifyFlags, kReadBarrierOption>();
    834   }
    835 
    836   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    837            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    838   bool ShouldHaveEmbeddedVTable() SHARED_REQUIRES(Locks::mutator_lock_) {
    839     return IsInstantiable<kVerifyFlags, kReadBarrierOption>();
    840   }
    841 
    842   bool HasVTable() SHARED_REQUIRES(Locks::mutator_lock_);
    843 
    844   static MemberOffset EmbeddedVTableEntryOffset(uint32_t i, size_t pointer_size);
    845 
    846   int32_t GetVTableLength() SHARED_REQUIRES(Locks::mutator_lock_);
    847 
    848   ArtMethod* GetVTableEntry(uint32_t i, size_t pointer_size)
    849       SHARED_REQUIRES(Locks::mutator_lock_);
    850 
    851   int32_t GetEmbeddedVTableLength() SHARED_REQUIRES(Locks::mutator_lock_);
    852 
    853   void SetEmbeddedVTableLength(int32_t len) SHARED_REQUIRES(Locks::mutator_lock_);
    854 
    855   ImTable* GetImt(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
    856 
    857   void SetImt(ImTable* imt, size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
    858 
    859   ArtMethod* GetEmbeddedVTableEntry(uint32_t i, size_t pointer_size)
    860       SHARED_REQUIRES(Locks::mutator_lock_);
    861 
    862   void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method, size_t pointer_size)
    863       SHARED_REQUIRES(Locks::mutator_lock_);
    864 
    865   inline void SetEmbeddedVTableEntryUnchecked(uint32_t i, ArtMethod* method, size_t pointer_size)
    866       SHARED_REQUIRES(Locks::mutator_lock_);
    867 
    868   void PopulateEmbeddedVTable(size_t pointer_size)
    869       SHARED_REQUIRES(Locks::mutator_lock_);
    870 
    871   // Given a method implemented by this class but potentially from a super class, return the
    872   // specific implementation method for this class.
    873   ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method, size_t pointer_size)
    874       SHARED_REQUIRES(Locks::mutator_lock_);
    875 
    876   // Given a method implemented by this class' super class, return the specific implementation
    877   // method for this class.
    878   ArtMethod* FindVirtualMethodForSuper(ArtMethod* method, size_t pointer_size)
    879       SHARED_REQUIRES(Locks::mutator_lock_);
    880 
    881   // Given a method from some implementor of this interface, return the specific implementation
    882   // method for this class.
    883   ArtMethod* FindVirtualMethodForInterfaceSuper(ArtMethod* method, size_t pointer_size)
    884       SHARED_REQUIRES(Locks::mutator_lock_);
    885 
    886   // Given a method implemented by this class, but potentially from a
    887   // super class or interface, return the specific implementation
    888   // method for this class.
    889   ArtMethod* FindVirtualMethodForInterface(ArtMethod* method, size_t pointer_size)
    890       SHARED_REQUIRES(Locks::mutator_lock_) ALWAYS_INLINE;
    891 
    892   ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method, size_t pointer_size)
    893       SHARED_REQUIRES(Locks::mutator_lock_);
    894 
    895   ArtMethod* FindInterfaceMethod(const StringPiece& name, const StringPiece& signature,
    896                                  size_t pointer_size)
    897       SHARED_REQUIRES(Locks::mutator_lock_);
    898 
    899   ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature,
    900                                  size_t pointer_size)
    901       SHARED_REQUIRES(Locks::mutator_lock_);
    902 
    903   ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
    904                                  size_t pointer_size)
    905       SHARED_REQUIRES(Locks::mutator_lock_);
    906 
    907   ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature,
    908                                       size_t pointer_size)
    909       SHARED_REQUIRES(Locks::mutator_lock_);
    910 
    911   ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature,
    912                                       size_t pointer_size)
    913       SHARED_REQUIRES(Locks::mutator_lock_);
    914 
    915   ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
    916                                       size_t pointer_size)
    917       SHARED_REQUIRES(Locks::mutator_lock_);
    918 
    919   ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature,
    920                               size_t pointer_size)
    921       SHARED_REQUIRES(Locks::mutator_lock_);
    922 
    923   ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature,
    924                               size_t pointer_size)
    925       SHARED_REQUIRES(Locks::mutator_lock_);
    926 
    927   ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
    928                               size_t pointer_size)
    929       SHARED_REQUIRES(Locks::mutator_lock_);
    930 
    931   ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature,
    932                                        size_t pointer_size)
    933       SHARED_REQUIRES(Locks::mutator_lock_);
    934 
    935   ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature,
    936                                        size_t pointer_size)
    937       SHARED_REQUIRES(Locks::mutator_lock_);
    938 
    939   ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
    940                                        size_t pointer_size)
    941       SHARED_REQUIRES(Locks::mutator_lock_);
    942 
    943   ArtMethod* FindDeclaredVirtualMethodByName(const StringPiece& name, size_t pointer_size)
    944       SHARED_REQUIRES(Locks::mutator_lock_);
    945 
    946   ArtMethod* FindDeclaredDirectMethodByName(const StringPiece& name, size_t pointer_size)
    947       SHARED_REQUIRES(Locks::mutator_lock_);
    948 
    949   ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature,
    950                                size_t pointer_size)
    951       SHARED_REQUIRES(Locks::mutator_lock_);
    952 
    953   ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature,
    954                                size_t pointer_size)
    955       SHARED_REQUIRES(Locks::mutator_lock_);
    956 
    957   ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
    958                                size_t pointer_size)
    959       SHARED_REQUIRES(Locks::mutator_lock_);
    960 
    961   ArtMethod* FindClassInitializer(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
    962 
    963   bool HasDefaultMethods() SHARED_REQUIRES(Locks::mutator_lock_) {
    964     return (GetAccessFlags() & kAccHasDefaultMethod) != 0;
    965   }
    966 
    967   bool HasBeenRecursivelyInitialized() SHARED_REQUIRES(Locks::mutator_lock_) {
    968     return (GetAccessFlags() & kAccRecursivelyInitialized) != 0;
    969   }
    970 
    971   ALWAYS_INLINE int32_t GetIfTableCount() SHARED_REQUIRES(Locks::mutator_lock_);
    972 
    973   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
    974            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
    975   ALWAYS_INLINE IfTable* GetIfTable() SHARED_REQUIRES(Locks::mutator_lock_);
    976 
    977   ALWAYS_INLINE void SetIfTable(IfTable* new_iftable) SHARED_REQUIRES(Locks::mutator_lock_);
    978 
    979   // Get instance fields of the class (See also GetSFields).
    980   LengthPrefixedArray<ArtField>* GetIFieldsPtr() SHARED_REQUIRES(Locks::mutator_lock_);
    981 
    982   ALWAYS_INLINE IterationRange<StrideIterator<ArtField>> GetIFields()
    983       SHARED_REQUIRES(Locks::mutator_lock_);
    984 
    985   void SetIFieldsPtr(LengthPrefixedArray<ArtField>* new_ifields)
    986       SHARED_REQUIRES(Locks::mutator_lock_);
    987 
    988   // Unchecked edition has no verification flags.
    989   void SetIFieldsPtrUnchecked(LengthPrefixedArray<ArtField>* new_sfields)
    990       SHARED_REQUIRES(Locks::mutator_lock_);
    991 
    992   uint32_t NumInstanceFields() SHARED_REQUIRES(Locks::mutator_lock_);
    993   ArtField* GetInstanceField(uint32_t i) SHARED_REQUIRES(Locks::mutator_lock_);
    994 
    995   // Returns the number of instance fields containing reference types. Does not count fields in any
    996   // super classes.
    997   uint32_t NumReferenceInstanceFields() SHARED_REQUIRES(Locks::mutator_lock_) {
    998     DCHECK(IsResolved() || IsErroneous());
    999     return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
   1000   }
   1001 
   1002   uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_) {
   1003     DCHECK(IsLoaded() || IsErroneous());
   1004     return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
   1005   }
   1006 
   1007   void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_REQUIRES(Locks::mutator_lock_) {
   1008     // Not called within a transaction.
   1009     SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
   1010   }
   1011 
   1012   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
   1013   uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_);
   1014 
   1015   void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
   1016       SHARED_REQUIRES(Locks::mutator_lock_);
   1017 
   1018   // Get the offset of the first reference instance field. Other reference instance fields follow.
   1019   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
   1020            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
   1021   MemberOffset GetFirstReferenceInstanceFieldOffset()
   1022       SHARED_REQUIRES(Locks::mutator_lock_);
   1023 
   1024   // Returns the number of static fields containing reference types.
   1025   uint32_t NumReferenceStaticFields() SHARED_REQUIRES(Locks::mutator_lock_) {
   1026     DCHECK(IsResolved() || IsErroneous());
   1027     return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
   1028   }
   1029 
   1030   uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_) {
   1031     DCHECK(IsLoaded() || IsErroneous() || IsRetired());
   1032     return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
   1033   }
   1034 
   1035   void SetNumReferenceStaticFields(uint32_t new_num) SHARED_REQUIRES(Locks::mutator_lock_) {
   1036     // Not called within a transaction.
   1037     SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
   1038   }
   1039 
   1040   // Get the offset of the first reference static field. Other reference static fields follow.
   1041   template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
   1042             ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
   1043   MemberOffset GetFirstReferenceStaticFieldOffset(size_t pointer_size)
   1044       SHARED_REQUIRES(Locks::mutator_lock_);
   1045 
   1046   // Get the offset of the first reference static field. Other reference static fields follow.
   1047   MemberOffset GetFirstReferenceStaticFieldOffsetDuringLinking(size_t pointer_size)
   1048       SHARED_REQUIRES(Locks::mutator_lock_);
   1049 
   1050   // Gets the static fields of the class.
   1051   LengthPrefixedArray<ArtField>* GetSFieldsPtr() SHARED_REQUIRES(Locks::mutator_lock_);
   1052   ALWAYS_INLINE IterationRange<StrideIterator<ArtField>> GetSFields()
   1053       SHARED_REQUIRES(Locks::mutator_lock_);
   1054 
   1055   void SetSFieldsPtr(LengthPrefixedArray<ArtField>* new_sfields)
   1056       SHARED_REQUIRES(Locks::mutator_lock_);
   1057 
   1058   // Unchecked edition has no verification flags.
   1059   void SetSFieldsPtrUnchecked(LengthPrefixedArray<ArtField>* new_sfields)
   1060       SHARED_REQUIRES(Locks::mutator_lock_);
   1061 
   1062   uint32_t NumStaticFields() SHARED_REQUIRES(Locks::mutator_lock_);
   1063 
   1064   // TODO: uint16_t
   1065   ArtField* GetStaticField(uint32_t i) SHARED_REQUIRES(Locks::mutator_lock_);
   1066 
   1067   // Find a static or instance field using the JLS resolution order
   1068   static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
   1069                              const StringPiece& type)
   1070       SHARED_REQUIRES(Locks::mutator_lock_);
   1071 
   1072   // Finds the given instance field in this class or a superclass.
   1073   ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
   1074       SHARED_REQUIRES(Locks::mutator_lock_);
   1075 
   1076   // Finds the given instance field in this class or a superclass, only searches classes that
   1077   // have the same dex cache.
   1078   ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
   1079       SHARED_REQUIRES(Locks::mutator_lock_);
   1080 
   1081   ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
   1082       SHARED_REQUIRES(Locks::mutator_lock_);
   1083 
   1084   ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
   1085       SHARED_REQUIRES(Locks::mutator_lock_);
   1086 
   1087   // Finds the given static field in this class or a superclass.
   1088   static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
   1089                                    const StringPiece& type)
   1090       SHARED_REQUIRES(Locks::mutator_lock_);
   1091 
   1092   // Finds the given static field in this class or superclass, only searches classes that
   1093   // have the same dex cache.
   1094   static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
   1095                                    uint32_t dex_field_idx)
   1096       SHARED_REQUIRES(Locks::mutator_lock_);
   1097 
   1098   ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
   1099       SHARED_REQUIRES(Locks::mutator_lock_);
   1100 
   1101   ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
   1102       SHARED_REQUIRES(Locks::mutator_lock_);
   1103 
   1104   pid_t GetClinitThreadId() SHARED_REQUIRES(Locks::mutator_lock_) {
   1105     DCHECK(IsIdxLoaded() || IsErroneous()) << PrettyClass(this);
   1106     return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
   1107   }
   1108 
   1109   void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_REQUIRES(Locks::mutator_lock_);
   1110 
   1111   Object* GetVerifyError() SHARED_REQUIRES(Locks::mutator_lock_) {
   1112     // DCHECK(IsErroneous());
   1113     return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_));
   1114   }
   1115 
   1116   uint16_t GetDexClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
   1117     return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
   1118   }
   1119 
   1120   void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_REQUIRES(Locks::mutator_lock_) {
   1121     // Not called within a transaction.
   1122     SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
   1123   }
   1124 
   1125   uint16_t GetDexTypeIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
   1126     return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_));
   1127   }
   1128 
   1129   void SetDexTypeIndex(uint16_t type_idx) SHARED_REQUIRES(Locks::mutator_lock_) {
   1130     // Not called within a transaction.
   1131     SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx);
   1132   }
   1133 
   1134   uint32_t FindTypeIndexInOtherDexFile(const DexFile& dex_file)
   1135       SHARED_REQUIRES(Locks::mutator_lock_);
   1136 
   1137   static Class* GetJavaLangClass() SHARED_REQUIRES(Locks::mutator_lock_) {
   1138     DCHECK(HasJavaLangClass());
   1139     return java_lang_Class_.Read();
   1140   }
   1141 
   1142   static bool HasJavaLangClass() SHARED_REQUIRES(Locks::mutator_lock_) {
   1143     return !java_lang_Class_.IsNull();
   1144   }
   1145 
   1146   // Can't call this SetClass or else gets called instead of Object::SetClass in places.
   1147   static void SetClassClass(Class* java_lang_Class) SHARED_REQUIRES(Locks::mutator_lock_);
   1148   static void ResetClass();
   1149   static void VisitRoots(RootVisitor* visitor)
   1150       SHARED_REQUIRES(Locks::mutator_lock_);
   1151 
   1152   // Visit native roots visits roots which are keyed off the native pointers such as ArtFields and
   1153   // ArtMethods.
   1154   template<class Visitor>
   1155   void VisitNativeRoots(Visitor& visitor, size_t pointer_size)
   1156       SHARED_REQUIRES(Locks::mutator_lock_);
   1157 
   1158   // When class is verified, set the kAccSkipAccessChecks flag on each method.
   1159   void SetSkipAccessChecksFlagOnAllMethods(size_t pointer_size)
   1160       SHARED_REQUIRES(Locks::mutator_lock_);
   1161 
   1162   // Get the descriptor of the class. In a few cases a std::string is required, rather than
   1163   // always create one the storage argument is populated and its internal c_str() returned. We do
   1164   // this to avoid memory allocation in the common case.
   1165   const char* GetDescriptor(std::string* storage) SHARED_REQUIRES(Locks::mutator_lock_);
   1166 
   1167   const char* GetArrayDescriptor(std::string* storage) SHARED_REQUIRES(Locks::mutator_lock_);
   1168 
   1169   bool DescriptorEquals(const char* match) SHARED_REQUIRES(Locks::mutator_lock_);
   1170 
   1171   const DexFile::ClassDef* GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
   1172 
   1173   ALWAYS_INLINE uint32_t NumDirectInterfaces() SHARED_REQUIRES(Locks::mutator_lock_);
   1174 
   1175   uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_REQUIRES(Locks::mutator_lock_);
   1176 
   1177   static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass,
   1178                                            uint32_t idx)
   1179       SHARED_REQUIRES(Locks::mutator_lock_);
   1180 
   1181   const char* GetSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
   1182 
   1183   std::string GetLocation() SHARED_REQUIRES(Locks::mutator_lock_);
   1184 
   1185   const DexFile& GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
   1186 
   1187   const DexFile::TypeList* GetInterfaceTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
   1188 
   1189   // Asserts we are initialized or initializing in the given thread.
   1190   void AssertInitializedOrInitializingInThread(Thread* self)
   1191       SHARED_REQUIRES(Locks::mutator_lock_);
   1192 
   1193   Class* CopyOf(Thread* self, int32_t new_length, ImTable* imt,
   1194                 size_t pointer_size)
   1195       SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
   1196 
   1197   // For proxy class only.
   1198   ObjectArray<Class>* GetInterfaces() SHARED_REQUIRES(Locks::mutator_lock_);
   1199 
   1200   // For proxy class only.
   1201   ObjectArray<ObjectArray<Class>>* GetThrows() SHARED_REQUIRES(Locks::mutator_lock_);
   1202 
   1203   // For reference class only.
   1204   MemberOffset GetDisableIntrinsicFlagOffset() SHARED_REQUIRES(Locks::mutator_lock_);
   1205   MemberOffset GetSlowPathFlagOffset() SHARED_REQUIRES(Locks::mutator_lock_);
   1206   bool GetSlowPathEnabled() SHARED_REQUIRES(Locks::mutator_lock_);
   1207   void SetSlowPath(bool enabled) SHARED_REQUIRES(Locks::mutator_lock_);
   1208 
   1209   GcRoot<String>* GetDexCacheStrings() SHARED_REQUIRES(Locks::mutator_lock_);
   1210   void SetDexCacheStrings(GcRoot<String>* new_dex_cache_strings)
   1211       SHARED_REQUIRES(Locks::mutator_lock_);
   1212   static MemberOffset DexCacheStringsOffset() {
   1213     return OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_strings_);
   1214   }
   1215 
   1216   // May cause thread suspension due to EqualParameters.
   1217   ArtMethod* GetDeclaredConstructor(
   1218       Thread* self, Handle<mirror::ObjectArray<mirror::Class>> args, size_t pointer_size)
   1219       SHARED_REQUIRES(Locks::mutator_lock_);
   1220 
   1221   static int32_t GetInnerClassFlags(Handle<Class> h_this, int32_t default_value)
   1222       SHARED_REQUIRES(Locks::mutator_lock_);
   1223 
   1224   // Used to initialize a class in the allocation code path to ensure it is guarded by a StoreStore
   1225   // fence.
   1226   class InitializeClassVisitor {
   1227    public:
   1228     explicit InitializeClassVisitor(uint32_t class_size) : class_size_(class_size) {
   1229     }
   1230 
   1231     void operator()(mirror::Object* obj, size_t usable_size) const
   1232         SHARED_REQUIRES(Locks::mutator_lock_);
   1233 
   1234    private:
   1235     const uint32_t class_size_;
   1236 
   1237     DISALLOW_COPY_AND_ASSIGN(InitializeClassVisitor);
   1238   };
   1239 
   1240   // Returns true if the class loader is null, ie the class loader is the boot strap class loader.
   1241   bool IsBootStrapClassLoaded() SHARED_REQUIRES(Locks::mutator_lock_) {
   1242     return GetClassLoader() == nullptr;
   1243   }
   1244 
   1245   static size_t ImTableEntrySize(size_t pointer_size) {
   1246     return pointer_size;
   1247   }
   1248 
   1249   static size_t VTableEntrySize(size_t pointer_size) {
   1250     return pointer_size;
   1251   }
   1252 
   1253   ALWAYS_INLINE ArraySlice<ArtMethod> GetDirectMethodsSliceUnchecked(size_t pointer_size)
   1254       SHARED_REQUIRES(Locks::mutator_lock_);
   1255 
   1256   ALWAYS_INLINE ArraySlice<ArtMethod> GetVirtualMethodsSliceUnchecked(size_t pointer_size)
   1257       SHARED_REQUIRES(Locks::mutator_lock_);
   1258 
   1259   ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredMethodsSliceUnchecked(size_t pointer_size)
   1260       SHARED_REQUIRES(Locks::mutator_lock_);
   1261 
   1262   ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredVirtualMethodsSliceUnchecked(size_t pointer_size)
   1263       SHARED_REQUIRES(Locks::mutator_lock_);
   1264 
   1265   ALWAYS_INLINE ArraySlice<ArtMethod> GetCopiedMethodsSliceUnchecked(size_t pointer_size)
   1266       SHARED_REQUIRES(Locks::mutator_lock_);
   1267 
   1268   // Fix up all of the native pointers in the class by running them through the visitor. Only sets
   1269   // the corresponding entry in dest if visitor(obj) != obj to prevent dirty memory. Dest should be
   1270   // initialized to a copy of *this to prevent issues. Does not visit the ArtMethod and ArtField
   1271   // roots.
   1272   template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
   1273             ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
   1274             typename Visitor>
   1275   void FixupNativePointers(mirror::Class* dest, size_t pointer_size, const Visitor& visitor)
   1276       SHARED_REQUIRES(Locks::mutator_lock_);
   1277 
   1278  private:
   1279   ALWAYS_INLINE void SetMethodsPtrInternal(LengthPrefixedArray<ArtMethod>* new_methods)
   1280       SHARED_REQUIRES(Locks::mutator_lock_);
   1281 
   1282   void SetVerifyError(Object* klass) SHARED_REQUIRES(Locks::mutator_lock_);
   1283 
   1284   template <bool throw_on_failure, bool use_referrers_cache>
   1285   bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
   1286                                uint32_t field_idx, DexCache* dex_cache)
   1287       SHARED_REQUIRES(Locks::mutator_lock_);
   1288   template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
   1289   bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
   1290                                 uint32_t method_idx, DexCache* dex_cache)
   1291       SHARED_REQUIRES(Locks::mutator_lock_);
   1292 
   1293   bool Implements(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
   1294   bool IsArrayAssignableFromArray(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
   1295   bool IsAssignableFromArray(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
   1296 
   1297   void CheckObjectAlloc() SHARED_REQUIRES(Locks::mutator_lock_);
   1298 
   1299   // Unchecked editions is for root visiting.
   1300   LengthPrefixedArray<ArtField>* GetSFieldsPtrUnchecked() SHARED_REQUIRES(Locks::mutator_lock_);
   1301   IterationRange<StrideIterator<ArtField>> GetSFieldsUnchecked()
   1302       SHARED_REQUIRES(Locks::mutator_lock_);
   1303   LengthPrefixedArray<ArtField>* GetIFieldsPtrUnchecked() SHARED_REQUIRES(Locks::mutator_lock_);
   1304   IterationRange<StrideIterator<ArtField>> GetIFieldsUnchecked()
   1305       SHARED_REQUIRES(Locks::mutator_lock_);
   1306 
   1307   // The index in the methods_ array where the first declared virtual method is.
   1308   ALWAYS_INLINE uint32_t GetVirtualMethodsStartOffset() SHARED_REQUIRES(Locks::mutator_lock_);
   1309 
   1310   // The index in the methods_ array where the first direct method is.
   1311   ALWAYS_INLINE uint32_t GetDirectMethodsStartOffset() SHARED_REQUIRES(Locks::mutator_lock_);
   1312 
   1313   // The index in the methods_ array where the first copied method is.
   1314   ALWAYS_INLINE uint32_t GetCopiedMethodsStartOffset() SHARED_REQUIRES(Locks::mutator_lock_);
   1315 
   1316   bool ProxyDescriptorEquals(const char* match) SHARED_REQUIRES(Locks::mutator_lock_);
   1317 
   1318   // Check that the pointer size matches the one in the class linker.
   1319   ALWAYS_INLINE static void CheckPointerSize(size_t pointer_size);
   1320   static MemberOffset EmbeddedVTableOffset(size_t pointer_size);
   1321   template <bool kVisitNativeRoots,
   1322             VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
   1323             ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
   1324             typename Visitor>
   1325   void VisitReferences(mirror::Class* klass, const Visitor& visitor)
   1326       SHARED_REQUIRES(Locks::mutator_lock_);
   1327 
   1328   // 'Class' Object Fields
   1329   // Order governed by java field ordering. See art::ClassLinker::LinkFields.
   1330 
   1331   HeapReference<Object> annotation_type_;
   1332 
   1333   // Defining class loader, or null for the "bootstrap" system loader.
   1334   HeapReference<ClassLoader> class_loader_;
   1335 
   1336   // For array classes, the component class object for instanceof/checkcast
   1337   // (for String[][][], this will be String[][]). null for non-array classes.
   1338   HeapReference<Class> component_type_;
   1339 
   1340   // DexCache of resolved constant pool entries (will be null for classes generated by the
   1341   // runtime such as arrays and primitive classes).
   1342   HeapReference<DexCache> dex_cache_;
   1343 
   1344   // The interface table (iftable_) contains pairs of a interface class and an array of the
   1345   // interface methods. There is one pair per interface supported by this class.  That means one
   1346   // pair for each interface we support directly, indirectly via superclass, or indirectly via a
   1347   // superinterface.  This will be null if neither we nor our superclass implement any interfaces.
   1348   //
   1349   // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
   1350   // Invoke faceObj.blah(), where "blah" is part of the Face interface.  We can't easily use a
   1351   // single vtable.
   1352   //
   1353   // For every interface a concrete class implements, we create an array of the concrete vtable_
   1354   // methods for the methods in the interface.
   1355   HeapReference<IfTable> iftable_;
   1356 
   1357   // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
   1358   HeapReference<String> name_;
   1359 
   1360   // The superclass, or null if this is java.lang.Object or a primitive type.
   1361   //
   1362   // Note that interfaces have java.lang.Object as their
   1363   // superclass. This doesn't match the expectations in JNI
   1364   // GetSuperClass or java.lang.Class.getSuperClass() which need to
   1365   // check for interfaces and return null.
   1366   HeapReference<Class> super_class_;
   1367 
   1368   // If class verify fails, we must return same error on subsequent tries. We may store either
   1369   // the class of the error, or an actual instance of Throwable here.
   1370   HeapReference<Object> verify_error_;
   1371 
   1372   // Virtual method table (vtable), for use by "invoke-virtual".  The vtable from the superclass is
   1373   // copied in, and virtual methods from our class either replace those from the super or are
   1374   // appended. For abstract classes, methods may be created in the vtable that aren't in
   1375   // virtual_ methods_ for miranda methods.
   1376   HeapReference<PointerArray> vtable_;
   1377 
   1378   // Access flags; low 16 bits are defined by VM spec.
   1379   uint32_t access_flags_;
   1380 
   1381   // Short cuts to dex_cache_ member for fast compiled code access.
   1382   uint64_t dex_cache_strings_;
   1383 
   1384   // instance fields
   1385   //
   1386   // These describe the layout of the contents of an Object.
   1387   // Note that only the fields directly declared by this class are
   1388   // listed in ifields; fields declared by a superclass are listed in
   1389   // the superclass's Class.ifields.
   1390   //
   1391   // ArtFields are allocated as a length prefixed ArtField array, and not an array of pointers to
   1392   // ArtFields.
   1393   uint64_t ifields_;
   1394 
   1395   // Pointer to an ArtMethod length-prefixed array. All the methods where this class is the place
   1396   // where they are logically defined. This includes all private, static, final and virtual methods
   1397   // as well as inherited default methods and miranda methods.
   1398   //
   1399   // The slice methods_ [0, virtual_methods_offset_) are the direct (static, private, init) methods
   1400   // declared by this class.
   1401   //
   1402   // The slice methods_ [virtual_methods_offset_, copied_methods_offset_) are the virtual methods
   1403   // declared by this class.
   1404   //
   1405   // The slice methods_ [copied_methods_offset_, |methods_|) are the methods that are copied from
   1406   // interfaces such as miranda or default methods. These are copied for resolution purposes as this
   1407   // class is where they are (logically) declared as far as the virtual dispatch is concerned.
   1408   //
   1409   // Note that this field is used by the native debugger as the unique identifier for the type.
   1410   uint64_t methods_;
   1411 
   1412   // Static fields length-prefixed array.
   1413   uint64_t sfields_;
   1414 
   1415   // Class flags to help speed up visiting object references.
   1416   uint32_t class_flags_;
   1417 
   1418   // Total size of the Class instance; used when allocating storage on gc heap.
   1419   // See also object_size_.
   1420   uint32_t class_size_;
   1421 
   1422   // Tid used to check for recursive <clinit> invocation.
   1423   pid_t clinit_thread_id_;
   1424 
   1425   // ClassDef index in dex file, -1 if no class definition such as an array.
   1426   // TODO: really 16bits
   1427   int32_t dex_class_def_idx_;
   1428 
   1429   // Type index in dex file.
   1430   // TODO: really 16bits
   1431   int32_t dex_type_idx_;
   1432 
   1433   // Number of instance fields that are object refs.
   1434   uint32_t num_reference_instance_fields_;
   1435 
   1436   // Number of static fields that are object refs,
   1437   uint32_t num_reference_static_fields_;
   1438 
   1439   // Total object size; used when allocating storage on gc heap.
   1440   // (For interfaces and abstract classes this will be zero.)
   1441   // See also class_size_.
   1442   uint32_t object_size_;
   1443 
   1444   // The lower 16 bits contains a Primitive::Type value. The upper 16
   1445   // bits contains the size shift of the primitive type.
   1446   uint32_t primitive_type_;
   1447 
   1448   // Bitmap of offsets of ifields.
   1449   uint32_t reference_instance_offsets_;
   1450 
   1451   // State of class initialization.
   1452   Status status_;
   1453 
   1454   // The offset of the first virtual method that is copied from an interface. This includes miranda,
   1455   // default, and default-conflict methods. Having a hard limit of ((2 << 16) - 1) for methods
   1456   // defined on a single class is well established in Java so we will use only uint16_t's here.
   1457   uint16_t copied_methods_offset_;
   1458 
   1459   // The offset of the first declared virtual methods in the methods_ array.
   1460   uint16_t virtual_methods_offset_;
   1461 
   1462   // TODO: ?
   1463   // initiating class loader list
   1464   // NOTE: for classes with low serialNumber, these are unused, and the
   1465   // values are kept in a table in gDvm.
   1466   // InitiatingLoaderList initiating_loader_list_;
   1467 
   1468   // The following data exist in real class objects.
   1469   // Embedded Imtable, for class object that's not an interface, fixed size.
   1470   // ImTableEntry embedded_imtable_[0];
   1471   // Embedded Vtable, for class object that's not an interface, variable size.
   1472   // VTableEntry embedded_vtable_[0];
   1473   // Static fields, variable size.
   1474   // uint32_t fields_[0];
   1475 
   1476   // java.lang.Class
   1477   static GcRoot<Class> java_lang_Class_;
   1478 
   1479   ART_FRIEND_TEST(DexCacheTest, TestResolvedFieldAccess);  // For ResolvedFieldAccessTest
   1480   friend struct art::ClassOffsets;  // for verifying offset information
   1481   friend class Object;  // For VisitReferences
   1482   DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
   1483 };
   1484 
   1485 std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
   1486 
   1487 }  // namespace mirror
   1488 }  // namespace art
   1489 
   1490 #endif  // ART_RUNTIME_MIRROR_CLASS_H_
   1491