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