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