OSDN Git Service

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