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