2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ART_RUNTIME_MIRROR_CLASS_H_
18 #define ART_RUNTIME_MIRROR_CLASS_H_
20 #include "base/enums.h"
21 #include "base/iteration_range.h"
23 #include "dex_file_types.h"
24 #include "class_flags.h"
26 #include "gc/allocator_type.h"
28 #include "invoke_type.h"
29 #include "modifiers.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"
44 template<class T> class Handle;
45 template<typename T> class LengthPrefixedArray;
46 template<typename T> class ArraySlice;
49 template<size_t kNumReferences> class PACKED(4) StackHandleScope;
59 template <typename T> struct PACKED(8) DexCachePair;
61 using StringDexCachePair = DexCachePair<String>;
62 using StringDexCacheType = std::atomic<StringDexCachePair>;
64 // C++ mirror of java.lang.Class
65 class MANAGED Class FINAL : public Object {
67 // A magic value for reference_instance_offsets_. Ignore the bits and walk the super chain when
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;
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;
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
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.
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.
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.
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.
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.
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.
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
127 // TODO: Explain the other states
129 kStatusRetired = -3, // Retired, should not be used. Use the newly cloned one instead.
130 kStatusErrorResolved = -2,
131 kStatusErrorUnresolved = -1,
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.
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_)));
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_);
157 static MemberOffset StatusOffset() {
158 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
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;
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;
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;
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;
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>());
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;
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;
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;
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;
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;
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;
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;
233 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
234 ALWAYS_INLINE uint32_t GetAccessFlags() REQUIRES_SHARED(Locks::mutator_lock_) {
236 GetAccessFlagsDCheck<kVerifyFlags>();
238 return GetField32<kVerifyFlags>(AccessFlagsOffset());
241 static MemberOffset AccessFlagsOffset() {
242 return OFFSET_OF_OBJECT_MEMBER(Class, access_flags_);
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_));
249 void SetClassFlags(uint32_t new_flags) REQUIRES_SHARED(Locks::mutator_lock_);
251 void SetAccessFlags(uint32_t new_access_flags) REQUIRES_SHARED(Locks::mutator_lock_);
253 // Returns true if the class is an interface.
254 ALWAYS_INLINE bool IsInterface() REQUIRES_SHARED(Locks::mutator_lock_) {
255 return (GetAccessFlags() & kAccInterface) != 0;
258 // Returns true if the class is declared public.
259 ALWAYS_INLINE bool IsPublic() REQUIRES_SHARED(Locks::mutator_lock_) {
260 return (GetAccessFlags() & kAccPublic) != 0;
263 // Returns true if the class is declared final.
264 ALWAYS_INLINE bool IsFinal() REQUIRES_SHARED(Locks::mutator_lock_) {
265 return (GetAccessFlags() & kAccFinal) != 0;
268 ALWAYS_INLINE bool IsFinalizable() REQUIRES_SHARED(Locks::mutator_lock_) {
269 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
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);
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);
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);
289 ALWAYS_INLINE bool IsStringClass() REQUIRES_SHARED(Locks::mutator_lock_) {
290 return (GetClassFlags() & kClassFlagString) != 0;
293 ALWAYS_INLINE void SetStringClass() REQUIRES_SHARED(Locks::mutator_lock_) {
294 SetClassFlags(kClassFlagString | kClassFlagNoReferenceFields);
297 ALWAYS_INLINE bool IsClassLoaderClass() REQUIRES_SHARED(Locks::mutator_lock_) {
298 return GetClassFlags() == kClassFlagClassLoader;
301 ALWAYS_INLINE void SetClassLoaderClass() REQUIRES_SHARED(Locks::mutator_lock_) {
302 SetClassFlags(kClassFlagClassLoader);
305 ALWAYS_INLINE bool IsDexCacheClass() REQUIRES_SHARED(Locks::mutator_lock_) {
306 return (GetClassFlags() & kClassFlagDexCache) != 0;
309 ALWAYS_INLINE void SetDexCacheClass() REQUIRES_SHARED(Locks::mutator_lock_) {
310 SetClassFlags(GetClassFlags() | kClassFlagDexCache);
313 // Returns true if the class is abstract.
314 ALWAYS_INLINE bool IsAbstract() REQUIRES_SHARED(Locks::mutator_lock_) {
315 return (GetAccessFlags() & kAccAbstract) != 0;
318 // Returns true if the class is an annotation.
319 ALWAYS_INLINE bool IsAnnotation() REQUIRES_SHARED(Locks::mutator_lock_) {
320 return (GetAccessFlags() & kAccAnnotation) != 0;
323 // Returns true if the class is synthetic.
324 ALWAYS_INLINE bool IsSynthetic() REQUIRES_SHARED(Locks::mutator_lock_) {
325 return (GetAccessFlags() & kAccSynthetic) != 0;
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;
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);
344 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
345 bool IsTypeOfReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
346 return (GetClassFlags<kVerifyFlags>() & kClassFlagReference) != 0;
349 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
350 bool IsWeakReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
351 return GetClassFlags<kVerifyFlags>() == kClassFlagWeakReference;
354 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
355 bool IsSoftReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
356 return GetClassFlags<kVerifyFlags>() == kClassFlagSoftReference;
359 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
360 bool IsFinalizerReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
361 return GetClassFlags<kVerifyFlags>() == kClassFlagFinalizerReference;
364 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
365 bool IsPhantomReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
366 return GetClassFlags<kVerifyFlags>() == kClassFlagPhantomReference;
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_);
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();
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_);
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
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;
398 static MemberOffset PrimitiveTypeOffset() {
399 return OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_);
402 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
403 Primitive::Type GetPrimitiveType() ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_);
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);
414 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
415 size_t GetPrimitiveTypeSizeShift() ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_);
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;
423 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
424 bool IsPrimitiveBoolean() REQUIRES_SHARED(Locks::mutator_lock_) {
425 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
428 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
429 bool IsPrimitiveByte() REQUIRES_SHARED(Locks::mutator_lock_) {
430 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
433 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
434 bool IsPrimitiveChar() REQUIRES_SHARED(Locks::mutator_lock_) {
435 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
438 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
439 bool IsPrimitiveShort() REQUIRES_SHARED(Locks::mutator_lock_) {
440 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
443 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
444 bool IsPrimitiveInt() REQUIRES_SHARED(Locks::mutator_lock_) {
445 return GetPrimitiveType() == Primitive::kPrimInt;
448 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
449 bool IsPrimitiveLong() REQUIRES_SHARED(Locks::mutator_lock_) {
450 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
453 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
454 bool IsPrimitiveFloat() REQUIRES_SHARED(Locks::mutator_lock_) {
455 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
458 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
459 bool IsPrimitiveDouble() REQUIRES_SHARED(Locks::mutator_lock_) {
460 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
463 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
464 bool IsPrimitiveVoid() REQUIRES_SHARED(Locks::mutator_lock_) {
465 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
468 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
469 bool IsPrimitiveArray() REQUIRES_SHARED(Locks::mutator_lock_) {
470 return IsArrayClass<kVerifyFlags>() &&
471 GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
475 // Depth of class from java.lang.Object
476 uint32_t Depth() REQUIRES_SHARED(Locks::mutator_lock_);
478 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
479 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
480 bool IsArrayClass() REQUIRES_SHARED(Locks::mutator_lock_);
482 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
483 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
484 bool IsClassClass() REQUIRES_SHARED(Locks::mutator_lock_);
486 bool IsThrowableClass() REQUIRES_SHARED(Locks::mutator_lock_);
488 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
489 bool IsReferenceClass() const REQUIRES_SHARED(Locks::mutator_lock_);
491 static MemberOffset ComponentTypeOffset() {
492 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
495 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
496 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
497 Class* GetComponentType() REQUIRES_SHARED(Locks::mutator_lock_);
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);
506 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
507 size_t GetComponentSize() REQUIRES_SHARED(Locks::mutator_lock_) {
508 return 1U << GetComponentSizeShift<kReadBarrierOption>();
511 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
512 size_t GetComponentSizeShift() REQUIRES_SHARED(Locks::mutator_lock_) {
513 return GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveTypeSizeShift();
516 bool IsObjectClass() REQUIRES_SHARED(Locks::mutator_lock_) {
517 return !IsPrimitive() && GetSuperClass() == nullptr;
520 bool IsInstantiableNonArray() REQUIRES_SHARED(Locks::mutator_lock_) {
521 return !IsPrimitive() && !IsInterface() && !IsAbstract() && !IsArrayClass();
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>());
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();
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>();
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>();
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_);
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_);
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();
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_));
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_));
582 void SetClassSize(uint32_t new_class_size)
583 REQUIRES_SHARED(Locks::mutator_lock_);
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);
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);
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);
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_);
613 static MemberOffset ObjectSizeAllocFastPathOffset() {
614 return OFFSET_OF_OBJECT_MEMBER(Class, object_size_alloc_fast_path_);
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);
623 void SetObjectSizeAllocFastPath(uint32_t new_object_size) REQUIRES_SHARED(Locks::mutator_lock_);
625 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
626 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
627 uint32_t GetObjectSizeAllocFastPath() REQUIRES_SHARED(Locks::mutator_lock_);
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);
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_);
639 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
641 // Returns true if this class can access that class.
642 bool CanAccess(ObjPtr<Class> that) REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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,
655 ObjPtr<DexCache> dex_cache,
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_);
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,
668 REQUIRES_SHARED(Locks::mutator_lock_);
669 template <InvokeType throw_invoke_type>
670 bool CheckResolvedMethodAccess(ObjPtr<Class> access_to,
671 ArtMethod* resolved_method,
673 REQUIRES_SHARED(Locks::mutator_lock_);
675 bool IsSubClass(ObjPtr<Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
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_);
684 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
685 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
686 ALWAYS_INLINE Class* GetSuperClass() REQUIRES_SHARED(Locks::mutator_lock_);
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_);
692 void SetSuperClass(ObjPtr<Class> new_super_class) REQUIRES_SHARED(Locks::mutator_lock_);
694 bool HasSuperClass() REQUIRES_SHARED(Locks::mutator_lock_) {
695 return GetSuperClass() != nullptr;
698 static MemberOffset SuperClassOffset() {
699 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
702 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
703 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
704 ClassLoader* GetClassLoader() ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_);
706 void SetClassLoader(ObjPtr<ClassLoader> new_cl) REQUIRES_SHARED(Locks::mutator_lock_);
708 static MemberOffset DexCacheOffset() {
709 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
712 static MemberOffset IfTableOffset() {
713 return MemberOffset(OFFSETOF_MEMBER(Class, iftable_));
717 kDumpClassFullDetail = 1,
718 kDumpClassClassLoader = (1 << 1),
719 kDumpClassInitialized = (1 << 2),
722 void DumpClass(std::ostream& os, int flags) REQUIRES_SHARED(Locks::mutator_lock_);
724 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
725 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
726 DexCache* GetDexCache() REQUIRES_SHARED(Locks::mutator_lock_);
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_);
731 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDirectMethods(PointerSize pointer_size)
732 REQUIRES_SHARED(Locks::mutator_lock_);
734 ALWAYS_INLINE LengthPrefixedArray<ArtMethod>* GetMethodsPtr()
735 REQUIRES_SHARED(Locks::mutator_lock_);
737 static MemberOffset MethodsOffset() {
738 return MemberOffset(OFFSETOF_MEMBER(Class, methods_));
741 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetMethods(PointerSize pointer_size)
742 REQUIRES_SHARED(Locks::mutator_lock_);
744 void SetMethodsPtr(LengthPrefixedArray<ArtMethod>* new_methods,
746 uint32_t num_virtual)
747 REQUIRES_SHARED(Locks::mutator_lock_);
748 // Used by image writer.
749 void SetMethodsPtrUnchecked(LengthPrefixedArray<ArtMethod>* new_methods,
751 uint32_t num_virtual)
752 REQUIRES_SHARED(Locks::mutator_lock_);
754 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
755 ALWAYS_INLINE ArraySlice<ArtMethod> GetDirectMethodsSlice(PointerSize pointer_size)
756 REQUIRES_SHARED(Locks::mutator_lock_);
758 ALWAYS_INLINE ArtMethod* GetDirectMethod(size_t i, PointerSize pointer_size)
759 REQUIRES_SHARED(Locks::mutator_lock_);
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_);
767 // Returns the number of static, private, and constructor methods.
768 ALWAYS_INLINE uint32_t NumDirectMethods() REQUIRES_SHARED(Locks::mutator_lock_);
770 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
771 ALWAYS_INLINE ArraySlice<ArtMethod> GetMethodsSlice(PointerSize pointer_size)
772 REQUIRES_SHARED(Locks::mutator_lock_);
774 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
775 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredMethodsSlice(PointerSize pointer_size)
776 REQUIRES_SHARED(Locks::mutator_lock_);
778 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDeclaredMethods(
779 PointerSize pointer_size)
780 REQUIRES_SHARED(Locks::mutator_lock_);
782 template <PointerSize kPointerSize, bool kTransactionActive>
783 static ObjPtr<Method> GetDeclaredMethodInternal(Thread* self,
786 ObjPtr<ObjectArray<Class>> args)
787 REQUIRES_SHARED(Locks::mutator_lock_);
789 template <PointerSize kPointerSize, bool kTransactionActive>
790 static ObjPtr<Constructor> GetDeclaredConstructorInternal(Thread* self,
792 ObjPtr<ObjectArray<Class>> args)
793 REQUIRES_SHARED(Locks::mutator_lock_);
795 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
796 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredVirtualMethodsSlice(PointerSize pointer_size)
797 REQUIRES_SHARED(Locks::mutator_lock_);
799 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDeclaredVirtualMethods(
800 PointerSize pointer_size)
801 REQUIRES_SHARED(Locks::mutator_lock_);
803 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
804 ALWAYS_INLINE ArraySlice<ArtMethod> GetCopiedMethodsSlice(PointerSize pointer_size)
805 REQUIRES_SHARED(Locks::mutator_lock_);
807 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetCopiedMethods(PointerSize pointer_size)
808 REQUIRES_SHARED(Locks::mutator_lock_);
810 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
811 ALWAYS_INLINE ArraySlice<ArtMethod> GetVirtualMethodsSlice(PointerSize pointer_size)
812 REQUIRES_SHARED(Locks::mutator_lock_);
814 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetVirtualMethods(
815 PointerSize pointer_size)
816 REQUIRES_SHARED(Locks::mutator_lock_);
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_);
821 // Returns the number of copied virtual methods.
822 ALWAYS_INLINE uint32_t NumCopiedVirtualMethods() REQUIRES_SHARED(Locks::mutator_lock_);
824 // Returns the number of declared virtual methods.
825 ALWAYS_INLINE uint32_t NumDeclaredVirtualMethods() REQUIRES_SHARED(Locks::mutator_lock_);
827 ALWAYS_INLINE uint32_t NumMethods() REQUIRES_SHARED(Locks::mutator_lock_);
829 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
830 ArtMethod* GetVirtualMethod(size_t i, PointerSize pointer_size)
831 REQUIRES_SHARED(Locks::mutator_lock_);
833 ArtMethod* GetVirtualMethodDuringLinking(size_t i, PointerSize pointer_size)
834 REQUIRES_SHARED(Locks::mutator_lock_);
836 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
837 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
838 ALWAYS_INLINE PointerArray* GetVTable() REQUIRES_SHARED(Locks::mutator_lock_);
840 ALWAYS_INLINE PointerArray* GetVTableDuringLinking() REQUIRES_SHARED(Locks::mutator_lock_);
842 void SetVTable(PointerArray* new_vtable) REQUIRES_SHARED(Locks::mutator_lock_);
844 static MemberOffset VTableOffset() {
845 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
848 static MemberOffset EmbeddedVTableLengthOffset() {
849 return MemberOffset(sizeof(Class));
852 static MemberOffset ImtPtrOffset(PointerSize pointer_size) {
854 RoundUp(EmbeddedVTableLengthOffset().Uint32Value() + sizeof(uint32_t),
855 static_cast<size_t>(pointer_size)));
858 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
859 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
860 bool ShouldHaveImt() REQUIRES_SHARED(Locks::mutator_lock_) {
861 return ShouldHaveEmbeddedVTable<kVerifyFlags, kReadBarrierOption>();
864 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
865 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
866 bool ShouldHaveEmbeddedVTable() REQUIRES_SHARED(Locks::mutator_lock_) {
867 return IsInstantiable<kVerifyFlags, kReadBarrierOption>();
870 bool HasVTable() REQUIRES_SHARED(Locks::mutator_lock_);
872 static MemberOffset EmbeddedVTableEntryOffset(uint32_t i, PointerSize pointer_size);
874 int32_t GetVTableLength() REQUIRES_SHARED(Locks::mutator_lock_);
876 ArtMethod* GetVTableEntry(uint32_t i, PointerSize pointer_size)
877 REQUIRES_SHARED(Locks::mutator_lock_);
879 int32_t GetEmbeddedVTableLength() REQUIRES_SHARED(Locks::mutator_lock_);
881 void SetEmbeddedVTableLength(int32_t len) REQUIRES_SHARED(Locks::mutator_lock_);
883 ImTable* GetImt(PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_);
885 void SetImt(ImTable* imt, PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_);
887 ArtMethod* GetEmbeddedVTableEntry(uint32_t i, PointerSize pointer_size)
888 REQUIRES_SHARED(Locks::mutator_lock_);
890 void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method, PointerSize pointer_size)
891 REQUIRES_SHARED(Locks::mutator_lock_);
893 inline void SetEmbeddedVTableEntryUnchecked(uint32_t i,
895 PointerSize pointer_size)
896 REQUIRES_SHARED(Locks::mutator_lock_);
898 void PopulateEmbeddedVTable(PointerSize pointer_size)
899 REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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_);
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_);
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;
922 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method, PointerSize pointer_size)
923 REQUIRES_SHARED(Locks::mutator_lock_);
925 ArtMethod* FindInterfaceMethod(const StringPiece& name,
926 const StringPiece& signature,
927 PointerSize pointer_size)
928 REQUIRES_SHARED(Locks::mutator_lock_);
930 ArtMethod* FindInterfaceMethod(const StringPiece& name,
931 const Signature& signature,
932 PointerSize pointer_size)
933 REQUIRES_SHARED(Locks::mutator_lock_);
935 ArtMethod* FindInterfaceMethod(ObjPtr<DexCache> dex_cache,
936 uint32_t dex_method_idx,
937 PointerSize pointer_size)
938 REQUIRES_SHARED(Locks::mutator_lock_);
940 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name,
941 const StringPiece& signature,
942 PointerSize pointer_size)
943 REQUIRES_SHARED(Locks::mutator_lock_);
945 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name,
946 const Signature& signature,
947 PointerSize pointer_size)
948 REQUIRES_SHARED(Locks::mutator_lock_);
950 ArtMethod* FindDeclaredDirectMethod(ObjPtr<DexCache> dex_cache,
951 uint32_t dex_method_idx,
952 PointerSize pointer_size)
953 REQUIRES_SHARED(Locks::mutator_lock_);
955 ArtMethod* FindDirectMethod(const StringPiece& name,
956 const StringPiece& signature,
957 PointerSize pointer_size)
958 REQUIRES_SHARED(Locks::mutator_lock_);
960 ArtMethod* FindDirectMethod(const StringPiece& name,
961 const Signature& signature,
962 PointerSize pointer_size)
963 REQUIRES_SHARED(Locks::mutator_lock_);
965 ArtMethod* FindDirectMethod(ObjPtr<DexCache> dex_cache,
966 uint32_t dex_method_idx,
967 PointerSize pointer_size)
968 REQUIRES_SHARED(Locks::mutator_lock_);
970 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name,
971 const StringPiece& signature,
972 PointerSize pointer_size)
973 REQUIRES_SHARED(Locks::mutator_lock_);
975 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name,
976 const Signature& signature,
977 PointerSize pointer_size)
978 REQUIRES_SHARED(Locks::mutator_lock_);
980 ArtMethod* FindDeclaredVirtualMethod(ObjPtr<DexCache> dex_cache,
981 uint32_t dex_method_idx,
982 PointerSize pointer_size)
983 REQUIRES_SHARED(Locks::mutator_lock_);
985 ArtMethod* FindDeclaredVirtualMethodByName(const StringPiece& name,
986 PointerSize pointer_size)
987 REQUIRES_SHARED(Locks::mutator_lock_);
989 ArtMethod* FindDeclaredDirectMethodByName(const StringPiece& name,
990 PointerSize pointer_size)
991 REQUIRES_SHARED(Locks::mutator_lock_);
993 ArtMethod* FindVirtualMethod(const StringPiece& name,
994 const StringPiece& signature,
995 PointerSize pointer_size)
996 REQUIRES_SHARED(Locks::mutator_lock_);
998 ArtMethod* FindVirtualMethod(const StringPiece& name,
999 const Signature& signature,
1000 PointerSize pointer_size)
1001 REQUIRES_SHARED(Locks::mutator_lock_);
1003 ArtMethod* FindVirtualMethod(ObjPtr<DexCache> dex_cache,
1004 uint32_t dex_method_idx,
1005 PointerSize pointer_size)
1006 REQUIRES_SHARED(Locks::mutator_lock_);
1008 ArtMethod* FindClassInitializer(PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_);
1010 bool HasDefaultMethods() REQUIRES_SHARED(Locks::mutator_lock_) {
1011 return (GetAccessFlags() & kAccHasDefaultMethod) != 0;
1014 bool HasBeenRecursivelyInitialized() REQUIRES_SHARED(Locks::mutator_lock_) {
1015 return (GetAccessFlags() & kAccRecursivelyInitialized) != 0;
1018 ALWAYS_INLINE int32_t GetIfTableCount() REQUIRES_SHARED(Locks::mutator_lock_);
1020 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1021 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
1022 ALWAYS_INLINE IfTable* GetIfTable() REQUIRES_SHARED(Locks::mutator_lock_);
1024 ALWAYS_INLINE void SetIfTable(ObjPtr<IfTable> new_iftable)
1025 REQUIRES_SHARED(Locks::mutator_lock_);
1027 // Get instance fields of the class (See also GetSFields).
1028 LengthPrefixedArray<ArtField>* GetIFieldsPtr() REQUIRES_SHARED(Locks::mutator_lock_);
1030 ALWAYS_INLINE IterationRange<StrideIterator<ArtField>> GetIFields()
1031 REQUIRES_SHARED(Locks::mutator_lock_);
1033 void SetIFieldsPtr(LengthPrefixedArray<ArtField>* new_ifields)
1034 REQUIRES_SHARED(Locks::mutator_lock_);
1036 // Unchecked edition has no verification flags.
1037 void SetIFieldsPtrUnchecked(LengthPrefixedArray<ArtField>* new_sfields)
1038 REQUIRES_SHARED(Locks::mutator_lock_);
1040 uint32_t NumInstanceFields() REQUIRES_SHARED(Locks::mutator_lock_);
1041 ArtField* GetInstanceField(uint32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
1043 // Returns the number of instance fields containing reference types. Does not count fields in any
1045 uint32_t NumReferenceInstanceFields() REQUIRES_SHARED(Locks::mutator_lock_) {
1046 DCHECK(IsResolved());
1047 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
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_));
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);
1060 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
1061 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_);
1063 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
1064 REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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_));
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_));
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);
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_);
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_);
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_);
1103 void SetSFieldsPtr(LengthPrefixedArray<ArtField>* new_sfields)
1104 REQUIRES_SHARED(Locks::mutator_lock_);
1106 // Unchecked edition has no verification flags.
1107 void SetSFieldsPtrUnchecked(LengthPrefixedArray<ArtField>* new_sfields)
1108 REQUIRES_SHARED(Locks::mutator_lock_);
1110 uint32_t NumStaticFields() REQUIRES_SHARED(Locks::mutator_lock_);
1113 ArtField* GetStaticField(uint32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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_);
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_);
1131 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
1132 REQUIRES_SHARED(Locks::mutator_lock_);
1134 ArtField* FindDeclaredInstanceField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx)
1135 REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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_);
1152 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
1153 REQUIRES_SHARED(Locks::mutator_lock_);
1155 ArtField* FindDeclaredStaticField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx)
1156 REQUIRES_SHARED(Locks::mutator_lock_);
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_));
1163 void SetClinitThreadId(pid_t new_clinit_thread_id) REQUIRES_SHARED(Locks::mutator_lock_);
1165 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1166 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
1167 ClassExt* GetExtData() REQUIRES_SHARED(Locks::mutator_lock_);
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_);
1175 uint16_t GetDexClassDefIndex() REQUIRES_SHARED(Locks::mutator_lock_) {
1176 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
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);
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_))));
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_);
1194 dex::TypeIndex FindTypeIndexInOtherDexFile(const DexFile& dex_file)
1195 REQUIRES_SHARED(Locks::mutator_lock_);
1197 static Class* GetJavaLangClass() REQUIRES_SHARED(Locks::mutator_lock_) {
1198 DCHECK(HasJavaLangClass());
1199 return java_lang_Class_.Read();
1202 static bool HasJavaLangClass() REQUIRES_SHARED(Locks::mutator_lock_) {
1203 return !java_lang_Class_.IsNull();
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_);
1212 // Visit native roots visits roots which are keyed off the native pointers such as ArtFields and
1214 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, class Visitor>
1215 void VisitNativeRoots(Visitor& visitor, PointerSize pointer_size)
1216 REQUIRES_SHARED(Locks::mutator_lock_);
1218 // When class is verified, set the kAccSkipAccessChecks flag on each method.
1219 void SetSkipAccessChecksFlagOnAllMethods(PointerSize pointer_size)
1220 REQUIRES_SHARED(Locks::mutator_lock_);
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_);
1227 const char* GetArrayDescriptor(std::string* storage) REQUIRES_SHARED(Locks::mutator_lock_);
1229 bool DescriptorEquals(const char* match) REQUIRES_SHARED(Locks::mutator_lock_);
1231 const DexFile::ClassDef* GetClassDef() REQUIRES_SHARED(Locks::mutator_lock_);
1233 ALWAYS_INLINE uint32_t NumDirectInterfaces() REQUIRES_SHARED(Locks::mutator_lock_);
1235 dex::TypeIndex GetDirectInterfaceTypeIdx(uint32_t idx) REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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_);
1248 const char* GetSourceFile() REQUIRES_SHARED(Locks::mutator_lock_);
1250 std::string GetLocation() REQUIRES_SHARED(Locks::mutator_lock_);
1252 const DexFile& GetDexFile() REQUIRES_SHARED(Locks::mutator_lock_);
1254 const DexFile::TypeList* GetInterfaceTypeList() REQUIRES_SHARED(Locks::mutator_lock_);
1256 // Asserts we are initialized or initializing in the given thread.
1257 void AssertInitializedOrInitializingInThread(Thread* self)
1258 REQUIRES_SHARED(Locks::mutator_lock_);
1260 Class* CopyOf(Thread* self,
1263 PointerSize pointer_size)
1264 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
1266 // For proxy class only.
1267 ObjectArray<Class>* GetProxyInterfaces() REQUIRES_SHARED(Locks::mutator_lock_);
1269 // For proxy class only.
1270 ObjectArray<ObjectArray<Class>>* GetProxyThrows() REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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_);
1284 static int32_t GetInnerClassFlags(Handle<Class> h_this, int32_t default_value)
1285 REQUIRES_SHARED(Locks::mutator_lock_);
1287 // Used to initialize a class in the allocation code path to ensure it is guarded by a StoreStore
1289 class InitializeClassVisitor {
1291 explicit InitializeClassVisitor(uint32_t class_size) : class_size_(class_size) {
1294 void operator()(ObjPtr<Object> obj, size_t usable_size) const
1295 REQUIRES_SHARED(Locks::mutator_lock_);
1298 const uint32_t class_size_;
1300 DISALLOW_COPY_AND_ASSIGN(InitializeClassVisitor);
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;
1308 static size_t ImTableEntrySize(PointerSize pointer_size) {
1309 return static_cast<size_t>(pointer_size);
1312 static size_t VTableEntrySize(PointerSize pointer_size) {
1313 return static_cast<size_t>(pointer_size);
1316 ALWAYS_INLINE ArraySlice<ArtMethod> GetDirectMethodsSliceUnchecked(PointerSize pointer_size)
1317 REQUIRES_SHARED(Locks::mutator_lock_);
1319 ALWAYS_INLINE ArraySlice<ArtMethod> GetVirtualMethodsSliceUnchecked(PointerSize pointer_size)
1320 REQUIRES_SHARED(Locks::mutator_lock_);
1322 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredMethodsSliceUnchecked(PointerSize pointer_size)
1323 REQUIRES_SHARED(Locks::mutator_lock_);
1325 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredVirtualMethodsSliceUnchecked(
1326 PointerSize pointer_size)
1327 REQUIRES_SHARED(Locks::mutator_lock_);
1329 ALWAYS_INLINE ArraySlice<ArtMethod> GetCopiedMethodsSliceUnchecked(PointerSize pointer_size)
1330 REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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
1352 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1353 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
1355 void FixupNativePointers(Class* dest, PointerSize pointer_size, const Visitor& visitor)
1356 REQUIRES_SHARED(Locks::mutator_lock_);
1359 ALWAYS_INLINE void SetMethodsPtrInternal(LengthPrefixedArray<ArtMethod>* new_methods)
1360 REQUIRES_SHARED(Locks::mutator_lock_);
1362 template <bool throw_on_failure, bool use_referrers_cache>
1363 bool ResolvedFieldAccessTest(ObjPtr<Class> access_to,
1366 ObjPtr<DexCache> dex_cache)
1367 REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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_);
1380 void CheckObjectAlloc() REQUIRES_SHARED(Locks::mutator_lock_);
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_);
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_);
1393 // The index in the methods_ array where the first direct method is.
1394 ALWAYS_INLINE uint32_t GetDirectMethodsStartOffset() REQUIRES_SHARED(Locks::mutator_lock_);
1396 // The index in the methods_ array where the first copied method is.
1397 ALWAYS_INLINE uint32_t GetCopiedMethodsStartOffset() REQUIRES_SHARED(Locks::mutator_lock_);
1399 bool ProxyDescriptorEquals(const char* match) REQUIRES_SHARED(Locks::mutator_lock_);
1401 template<VerifyObjectFlags kVerifyFlags>
1402 void GetAccessFlagsDCheck() REQUIRES_SHARED(Locks::mutator_lock_);
1404 // Check that the pointer size matches the one in the class linker.
1405 ALWAYS_INLINE static void CheckPointerSize(PointerSize pointer_size);
1407 static MemberOffset EmbeddedVTableOffset(PointerSize pointer_size);
1408 template <bool kVisitNativeRoots,
1409 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1410 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
1412 void VisitReferences(ObjPtr<Class> klass, const Visitor& visitor)
1413 REQUIRES_SHARED(Locks::mutator_lock_);
1415 // 'Class' Object Fields
1416 // Order governed by java field ordering. See art::ClassLinker::LinkFields.
1418 // Defining class loader, or null for the "bootstrap" system loader.
1419 HeapReference<ClassLoader> class_loader_;
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_;
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_;
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_;
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.
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
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_;
1448 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
1449 HeapReference<String> name_;
1451 // The superclass, or null if this is java.lang.Object or a primitive type.
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_;
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_;
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.
1472 // ArtFields are allocated as a length prefixed ArtField array, and not an array of pointers to
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.
1480 // The slice methods_ [0, virtual_methods_offset_) are the direct (static, private, init) methods
1481 // declared by this class.
1483 // The slice methods_ [virtual_methods_offset_, copied_methods_offset_) are the virtual methods
1484 // declared by this class.
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.
1490 // Note that this field is used by the native debugger as the unique identifier for the type.
1493 // Static fields length-prefixed array.
1496 // Access flags; low 16 bits are defined by VM spec.
1497 uint32_t access_flags_;
1499 // Class flags to help speed up visiting object references.
1500 uint32_t class_flags_;
1502 // Total size of the Class instance; used when allocating storage on gc heap.
1503 // See also object_size_.
1504 uint32_t class_size_;
1506 // Tid used to check for recursive <clinit> invocation.
1507 pid_t clinit_thread_id_;
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_;
1513 // Type index in dex file.
1514 // TODO: really 16bits
1515 int32_t dex_type_idx_;
1517 // Number of instance fields that are object refs.
1518 uint32_t num_reference_instance_fields_;
1520 // Number of static fields that are object refs,
1521 uint32_t num_reference_static_fields_;
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_;
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_;
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_;
1536 // Bitmap of offsets of ifields.
1537 uint32_t reference_instance_offsets_;
1539 // State of class initialization.
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_;
1547 // The offset of the first declared virtual methods in the methods_ array.
1548 uint16_t virtual_methods_offset_;
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_;
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];
1565 static GcRoot<Class> java_lang_Class_;
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);
1573 std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1575 } // namespace mirror
1578 #endif // ART_RUNTIME_MIRROR_CLASS_H_