blob: 913ab796a16b1359fc1c06b88e52e2e1d83dc300 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_MIRROR_CLASS_H_
18#define ART_RUNTIME_MIRROR_CLASS_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Andreas Gampe3b7dc352017-06-06 20:02:03 -070020#include "base/bit_utils.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070021#include "base/enums.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070022#include "base/iteration_range.h"
Mathieu Chartierf8322842014-05-16 10:59:25 -070023#include "dex_file.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080024#include "dex_file_types.h"
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -070025#include "class_flags.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070026#include "gc_root.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070027#include "gc/allocator_type.h"
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000028#include "imtable.h"
Vladimir Marko23a28212014-01-09 19:24:37 +000029#include "invoke_type.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030#include "modifiers.h"
31#include "object.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070032#include "object_array.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033#include "primitive.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070034#include "read_barrier_option.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070035#include "stride_iterator.h"
Alex Lighteb7c1442015-08-31 13:17:42 -070036#include "thread.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070037#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039namespace art {
40
Mathieu Chartierc7853442015-03-27 14:35:38 -070041class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070042class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043struct ClassOffsets;
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070044template<class T> class Handle;
Mathieu Chartier54d220e2015-07-30 16:20:06 -070045template<typename T> class LengthPrefixedArray;
Alex Lighte64300b2015-12-15 15:02:47 -080046template<typename T> class ArraySlice;
Ian Rogersd91d6d62013-09-25 20:26:14 -070047class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048class StringPiece;
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070049template<size_t kNumReferences> class PACKED(4) StackHandleScope;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050
51namespace mirror {
52
Alex Lightd6251582016-10-31 11:12:30 -070053class ClassExt;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080054class ClassLoader;
Mathieu Chartierfc58af42015-04-16 18:00:39 -070055class Constructor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080056class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057class IfTable;
Andreas Gampebc4d2182016-02-22 10:03:12 -080058class Method;
Narayan Kamathc38a6f82016-09-29 17:07:20 +010059template <typename T> struct PACKED(8) DexCachePair;
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -070060
Mathieu Chartier28bd2e42016-10-04 13:54:57 -070061using StringDexCachePair = DexCachePair<String>;
Narayan Kamathc38a6f82016-09-29 17:07:20 +010062using StringDexCacheType = std::atomic<StringDexCachePair>;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064// C++ mirror of java.lang.Class
Mingyao Yang98d1cc82014-05-15 17:02:16 -070065class MANAGED Class FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080066 public:
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070067 // 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
Mathieu Chartier8261d022016-08-08 09:41:04 -070073 // 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
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079 // Class Status
80 //
Mingyao Yang46f0e972014-09-10 15:16:19 -070081 // 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 //
Vladimir Marko72ab6842017-01-20 19:32:50 +000087 // 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 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080094 // 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 //
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700110 // 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 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800115 // 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 {
Vladimir Marko72ab6842017-01-20 19:32:50 +0000129 kStatusRetired = -3, // Retired, should not be used. Use the newly cloned one instead.
130 kStatusErrorResolved = -2,
131 kStatusErrorUnresolved = -1,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132 kStatusNotReady = 0,
133 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
134 kStatusLoaded = 2, // DEX idx values resolved.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700135 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,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800144 };
145
Mathieu Chartier4e305412014-02-19 10:54:44 -0800146 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700147 Status GetStatus() REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe575e78c2014-11-03 23:41:03 -0800148 static_assert(sizeof(Status) == sizeof(uint32_t), "Size of status not equal to uint32");
Ian Rogers03dbc042014-06-02 14:24:56 -0700149 return static_cast<Status>(
150 GetField32Volatile<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800151 }
152
Hiroshi Yamauchi5b783e62015-03-18 17:20:11 -0700153 // This is static because 'this' may be moved by GC.
154 static void SetStatus(Handle<Class> h_this, Status new_status, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700155 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156
Ian Rogers5ddb4102014-01-07 08:58:46 -0800157 static MemberOffset StatusOffset() {
158 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
159 }
160
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700161 // Returns true if the class has been retired.
162 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700163 bool IsRetired() REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700164 return GetStatus<kVerifyFlags>() == kStatusRetired;
165 }
166
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800167 // Returns true if the class has failed to link.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800168 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Vladimir Marko72ab6842017-01-20 19:32:50 +0000169 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>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700186 bool IsErroneous() REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko72ab6842017-01-20 19:32:50 +0000187 return IsErroneous(GetStatus<kVerifyFlags>());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188 }
189
190 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800191 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700192 bool IsIdxLoaded() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800193 return GetStatus<kVerifyFlags>() >= kStatusIdx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800194 }
195
196 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800197 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700198 bool IsLoaded() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800199 return GetStatus<kVerifyFlags>() >= kStatusLoaded;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 }
201
202 // Returns true if the class has been linked.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800203 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700204 bool IsResolved() REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko72ab6842017-01-20 19:32:50 +0000205 Status status = GetStatus<kVerifyFlags>();
206 return status >= kStatusResolved || status == kStatusErrorResolved;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207 }
208
Nicolas Geoffray7cc3ae52017-03-07 14:33:37 +0000209 // Returns true if the class should be verified at runtime.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800210 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Nicolas Geoffray7cc3ae52017-03-07 14:33:37 +0000211 bool ShouldVerifyAtRuntime() REQUIRES_SHARED(Locks::mutator_lock_) {
212 return GetStatus<kVerifyFlags>() == kStatusRetryVerificationAtRuntime;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800213 }
214
215 // Returns true if the class has been verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800216 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700217 bool IsVerified() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800218 return GetStatus<kVerifyFlags>() >= kStatusVerified;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219 }
220
221 // Returns true if the class is initializing.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800222 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700223 bool IsInitializing() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800224 return GetStatus<kVerifyFlags>() >= kStatusInitializing;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800225 }
226
227 // Returns true if the class is initialized.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800228 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700229 bool IsInitialized() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800230 return GetStatus<kVerifyFlags>() == kStatusInitialized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800231 }
232
Mathieu Chartier4e305412014-02-19 10:54:44 -0800233 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe90b936d2017-01-31 08:58:55 -0800234 ALWAYS_INLINE uint32_t GetAccessFlags() REQUIRES_SHARED(Locks::mutator_lock_) {
235 if (kIsDebugBuild) {
236 GetAccessFlagsDCheck<kVerifyFlags>();
237 }
238 return GetField32<kVerifyFlags>(AccessFlagsOffset());
239 }
240
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700241 static MemberOffset AccessFlagsOffset() {
242 return OFFSET_OF_OBJECT_MEMBER(Class, access_flags_);
243 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800244
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700245 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700246 ALWAYS_INLINE uint32_t GetClassFlags() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700247 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_flags_));
248 }
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700249 void SetClassFlags(uint32_t new_flags) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700250
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700251 void SetAccessFlags(uint32_t new_access_flags) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800252
253 // Returns true if the class is an interface.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700254 ALWAYS_INLINE bool IsInterface() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800255 return (GetAccessFlags() & kAccInterface) != 0;
256 }
257
258 // Returns true if the class is declared public.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700259 ALWAYS_INLINE bool IsPublic() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260 return (GetAccessFlags() & kAccPublic) != 0;
261 }
262
263 // Returns true if the class is declared final.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700264 ALWAYS_INLINE bool IsFinal() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800265 return (GetAccessFlags() & kAccFinal) != 0;
266 }
267
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700268 ALWAYS_INLINE bool IsFinalizable() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800269 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
270 }
271
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700272 ALWAYS_INLINE void SetRecursivelyInitialized() REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Lighteb7c1442015-08-31 13:17:42 -0700273 DCHECK_EQ(GetLockOwnerThreadId(), Thread::Current()->GetThreadId());
274 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
275 SetAccessFlags(flags | kAccRecursivelyInitialized);
276 }
277
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700278 ALWAYS_INLINE void SetHasDefaultMethods() REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Lighteb7c1442015-08-31 13:17:42 -0700279 DCHECK_EQ(GetLockOwnerThreadId(), Thread::Current()->GetThreadId());
280 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
281 SetAccessFlags(flags | kAccHasDefaultMethod);
282 }
283
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700284 ALWAYS_INLINE void SetFinalizable() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700285 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800286 SetAccessFlags(flags | kAccClassIsFinalizable);
287 }
288
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700289 ALWAYS_INLINE bool IsStringClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700290 return (GetClassFlags() & kClassFlagString) != 0;
Jeff Hao848f70a2014-01-15 13:49:50 -0800291 }
292
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700293 ALWAYS_INLINE void SetStringClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700294 SetClassFlags(kClassFlagString | kClassFlagNoReferenceFields);
Jeff Hao848f70a2014-01-15 13:49:50 -0800295 }
296
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700297 ALWAYS_INLINE bool IsClassLoaderClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700298 return GetClassFlags() == kClassFlagClassLoader;
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700299 }
300
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700301 ALWAYS_INLINE void SetClassLoaderClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700302 SetClassFlags(kClassFlagClassLoader);
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700303 }
304
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700305 ALWAYS_INLINE bool IsDexCacheClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100306 return (GetClassFlags() & kClassFlagDexCache) != 0;
307 }
308
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700309 ALWAYS_INLINE void SetDexCacheClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100310 SetClassFlags(GetClassFlags() | kClassFlagDexCache);
311 }
312
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313 // Returns true if the class is abstract.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700314 ALWAYS_INLINE bool IsAbstract() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800315 return (GetAccessFlags() & kAccAbstract) != 0;
316 }
317
318 // Returns true if the class is an annotation.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700319 ALWAYS_INLINE bool IsAnnotation() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800320 return (GetAccessFlags() & kAccAnnotation) != 0;
321 }
322
323 // Returns true if the class is synthetic.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700324 ALWAYS_INLINE bool IsSynthetic() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800325 return (GetAccessFlags() & kAccSynthetic) != 0;
326 }
327
Igor Murashkin8d1da852016-02-04 11:01:21 -0800328 // Return whether the class had run the verifier at least once.
Igor Murashkindf707e42016-02-02 16:56:50 -0800329 // This does not necessarily mean that access checks are avoidable,
330 // since the class methods might still need to be run with access checks.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700331 bool WasVerificationAttempted() REQUIRES_SHARED(Locks::mutator_lock_) {
Igor Murashkindf707e42016-02-02 16:56:50 -0800332 return (GetAccessFlags() & kAccSkipAccessChecks) != 0;
Ian Rogers7b078e82014-09-10 14:44:24 -0700333 }
334
Igor Murashkindf707e42016-02-02 16:56:50 -0800335 // 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.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700337 void SetVerificationAttempted() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers7b078e82014-09-10 14:44:24 -0700338 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Mathieu Chartier085a0722016-04-01 17:33:31 -0700339 if ((flags & kAccVerificationAttempted) == 0) {
340 SetAccessFlags(flags | kAccVerificationAttempted);
341 }
Ian Rogers7b078e82014-09-10 14:44:24 -0700342 }
343
Mathieu Chartier4e305412014-02-19 10:54:44 -0800344 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700345 bool IsTypeOfReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700346 return (GetClassFlags<kVerifyFlags>() & kClassFlagReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800347 }
348
Mathieu Chartier4e305412014-02-19 10:54:44 -0800349 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700350 bool IsWeakReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700351 return GetClassFlags<kVerifyFlags>() == kClassFlagWeakReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352 }
353
Mathieu Chartier4e305412014-02-19 10:54:44 -0800354 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700355 bool IsSoftReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700356 return GetClassFlags<kVerifyFlags>() == kClassFlagSoftReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800357 }
358
Mathieu Chartier4e305412014-02-19 10:54:44 -0800359 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700360 bool IsFinalizerReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700361 return GetClassFlags<kVerifyFlags>() == kClassFlagFinalizerReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800362 }
363
Mathieu Chartier4e305412014-02-19 10:54:44 -0800364 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700365 bool IsPhantomReferenceClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700366 return GetClassFlags<kVerifyFlags>() == kClassFlagPhantomReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367 }
368
Ian Rogers04f94f42013-06-10 15:09:26 -0700369 // 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.
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700374 bool CannotBeAssignedFromOtherTypes() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800375
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700376 // 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.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700378 bool IsTemp() REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700379 Status s = GetStatus();
Vladimir Marko72ab6842017-01-20 19:32:50 +0000380 return s < Status::kStatusResolving && s != kStatusErrorResolved && ShouldHaveEmbeddedVTable();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700381 }
382
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700383 String* GetName() REQUIRES_SHARED(Locks::mutator_lock_); // Returns the cached name.
Mathieu Chartier1a5337f2016-10-13 13:48:23 -0700384 void SetName(ObjPtr<String> name) REQUIRES_SHARED(Locks::mutator_lock_); // Sets the cached name.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800385 // Computes the name, then sets the cached value.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700386 static String* ComputeName(Handle<Class> h_this) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700387 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800389 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700390 bool IsProxyClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800391 // 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?
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700394 uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800395 return (access_flags & kAccClassIsProxy) != 0;
396 }
397
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000398 static MemberOffset PrimitiveTypeOffset() {
399 return OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_);
400 }
401
Mathieu Chartier4e305412014-02-19 10:54:44 -0800402 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700403 Primitive::Type GetPrimitiveType() ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800404
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700405 void SetPrimitiveType(Primitive::Type new_type) REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
Mathieu Chartier8261d022016-08-08 09:41:04 -0700407 uint32_t v32 = static_cast<uint32_t>(new_type);
408 DCHECK_EQ(v32 & kPrimitiveTypeMask, v32) << "upper 16 bits aren't zero";
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700409 // Store the component size shift in the upper 16 bits.
Mathieu Chartier8261d022016-08-08 09:41:04 -0700410 v32 |= Primitive::ComponentSizeShift(new_type) << kPrimitiveTypeSizeShiftShift;
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700411 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), v32);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800412 }
413
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700414 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700415 size_t GetPrimitiveTypeSizeShift() ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700416
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800417 // Returns true if the class is a primitive type.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800418 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700419 bool IsPrimitive() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800420 return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800421 }
422
Mathieu Chartier4e305412014-02-19 10:54:44 -0800423 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700424 bool IsPrimitiveBoolean() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800425 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800426 }
427
Mathieu Chartier4e305412014-02-19 10:54:44 -0800428 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700429 bool IsPrimitiveByte() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800430 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800431 }
432
Mathieu Chartier4e305412014-02-19 10:54:44 -0800433 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700434 bool IsPrimitiveChar() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800435 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800436 }
437
Mathieu Chartier4e305412014-02-19 10:54:44 -0800438 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700439 bool IsPrimitiveShort() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800440 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800441 }
442
Mathieu Chartier4e305412014-02-19 10:54:44 -0800443 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700444 bool IsPrimitiveInt() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800445 return GetPrimitiveType() == Primitive::kPrimInt;
446 }
447
Mathieu Chartier4e305412014-02-19 10:54:44 -0800448 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700449 bool IsPrimitiveLong() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800450 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800451 }
452
Mathieu Chartier4e305412014-02-19 10:54:44 -0800453 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700454 bool IsPrimitiveFloat() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800455 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800456 }
457
Mathieu Chartier4e305412014-02-19 10:54:44 -0800458 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700459 bool IsPrimitiveDouble() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800460 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800461 }
462
Mathieu Chartier4e305412014-02-19 10:54:44 -0800463 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700464 bool IsPrimitiveVoid() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800465 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800466 }
467
Mathieu Chartier4e305412014-02-19 10:54:44 -0800468 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700469 bool IsPrimitiveArray() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800470 return IsArrayClass<kVerifyFlags>() &&
471 GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
472 IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800473 }
474
475 // Depth of class from java.lang.Object
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700476 uint32_t Depth() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800477
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700478 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
479 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700480 bool IsArrayClass() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800481
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700482 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
483 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700484 bool IsClassClass() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800485
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700486 bool IsThrowableClass() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800487
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700488 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700489 bool IsReferenceClass() const REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih4ee7a662014-07-11 09:59:27 -0700490
Ian Rogersa9a82542013-10-04 11:17:26 -0700491 static MemberOffset ComponentTypeOffset() {
492 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
493 }
494
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700495 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
496 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700497 Class* GetComponentType() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800498
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700499 void SetComponentType(ObjPtr<Class> new_component_type) REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700500 DCHECK(GetComponentType() == nullptr);
501 DCHECK(new_component_type != nullptr);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100502 // Component type is invariant: use non-transactional mode without check.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700503 SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800504 }
505
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700506 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700507 size_t GetComponentSize() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier5ffa0782016-07-27 10:45:47 -0700508 return 1U << GetComponentSizeShift<kReadBarrierOption>();
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700509 }
510
511 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700512 size_t GetComponentSizeShift() REQUIRES_SHARED(Locks::mutator_lock_) {
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700513 return GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveTypeSizeShift();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800514 }
515
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700516 bool IsObjectClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700517 return !IsPrimitive() && GetSuperClass() == nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800518 }
Ian Rogers68d8b422014-07-17 11:09:10 -0700519
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700520 bool IsInstantiableNonArray() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700521 return !IsPrimitive() && !IsInterface() && !IsAbstract() && !IsArrayClass();
522 }
523
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800524 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
525 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700526 bool IsInstantiable() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700527 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) ||
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800528 (IsAbstract() && IsArrayClass<kVerifyFlags, kReadBarrierOption>());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800529 }
530
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800531 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
532 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampec6ea7d02017-02-01 16:46:28 -0800533 ALWAYS_INLINE bool IsObjectArrayClass() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700534
535 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700536 bool IsIntArrayClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700537 constexpr auto kNewFlags = static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis);
538 auto* component_type = GetComponentType<kVerifyFlags>();
539 return component_type != nullptr && component_type->template IsPrimitiveInt<kNewFlags>();
540 }
541
542 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700543 bool IsLongArrayClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700544 constexpr auto kNewFlags = static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis);
545 auto* component_type = GetComponentType<kVerifyFlags>();
546 return component_type != nullptr && component_type->template IsPrimitiveLong<kNewFlags>();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800547 }
548
549 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700550 template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700551 ALWAYS_INLINE ObjPtr<Object> Alloc(Thread* self, gc::AllocatorType allocator_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700552 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700553
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700554 ObjPtr<Object> AllocObject(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700555 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700556 ObjPtr<Object> AllocNonMovableObject(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700557 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800558
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700559 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
560 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampec6ea7d02017-02-01 16:46:28 -0800561 ALWAYS_INLINE bool IsVariableSize() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800562
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700563 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
564 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700565 uint32_t SizeOf() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700566 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800567 }
568
Mathieu Chartier4e305412014-02-19 10:54:44 -0800569 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700570 uint32_t GetClassSize() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700571 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800572 }
573
Ian Rogersef7d42f2014-01-06 12:55:46 -0800574 void SetClassSize(uint32_t new_class_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700575 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800576
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700577 // Compute how many bytes would be used a class with the given elements.
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000578 static uint32_t ComputeClassSize(bool has_embedded_vtable,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700579 uint32_t num_vtable_entries,
Fred Shih37f05ef2014-07-16 18:38:08 -0700580 uint32_t num_8bit_static_fields,
581 uint32_t num_16bit_static_fields,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700582 uint32_t num_32bit_static_fields,
583 uint32_t num_64bit_static_fields,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700584 uint32_t num_ref_static_fields,
Andreas Gampe542451c2016-07-26 09:02:02 -0700585 PointerSize pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700586
587 // The size of java.lang.Class.class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700588 static uint32_t ClassClassSize(PointerSize pointer_size) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700589 // The number of vtable entries in java.lang.Class.
Narayan Kamath6b2dc312017-03-14 13:26:12 +0000590 uint32_t vtable_entries = Object::kVTableLength + 67;
Yi Kongff633e22015-11-06 13:33:22 +0000591 return ComputeClassSize(true, vtable_entries, 0, 0, 4, 1, 0, pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700592 }
593
594 // The size of a java.lang.Class representing a primitive such as int.class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700595 static uint32_t PrimitiveClassSize(PointerSize pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700596 return ComputeClassSize(false, 0, 0, 0, 0, 0, 0, pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700597 }
598
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700599 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
600 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700601 uint32_t GetObjectSize() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700602 static MemberOffset ObjectSizeOffset() {
603 return OFFSET_OF_OBJECT_MEMBER(Class, object_size_);
604 }
Mathieu Chartier93bbee02016-08-31 09:38:40 -0700605 static MemberOffset ObjectSizeAllocFastPathOffset() {
606 return OFFSET_OF_OBJECT_MEMBER(Class, object_size_alloc_fast_path_);
607 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800608
Andreas Gampec6ea7d02017-02-01 16:46:28 -0800609 ALWAYS_INLINE void SetObjectSize(uint32_t new_object_size) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800610
Mathieu Chartier93bbee02016-08-31 09:38:40 -0700611 void SetObjectSizeAllocFastPath(uint32_t new_object_size) REQUIRES_SHARED(Locks::mutator_lock_);
612
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700613 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
614 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
615 uint32_t GetObjectSizeAllocFastPath() REQUIRES_SHARED(Locks::mutator_lock_);
616
Mathieu Chartier2d721012014-11-10 11:08:06 -0800617 void SetObjectSizeWithoutChecks(uint32_t new_object_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700618 REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800619 // Not called within a transaction.
620 return SetField32<false, false, kVerifyNone>(
621 OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
622 }
623
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800624 // Returns true if this class is in the same packages as that class.
Mathieu Chartier3398c782016-09-30 10:27:43 -0700625 bool IsInSamePackage(ObjPtr<Class> that) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800626
627 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
628
629 // Returns true if this class can access that class.
Mathieu Chartier3398c782016-09-30 10:27:43 -0700630 bool CanAccess(ObjPtr<Class> that) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800631
632 // Can this class access a member in the provided class with the provided member access flags?
633 // Note that access to the class isn't checked in case the declaring class is protected and the
634 // method has been exposed by a public sub-class
Mathieu Chartier3398c782016-09-30 10:27:43 -0700635 bool CanAccessMember(ObjPtr<Class> access_to, uint32_t member_flags)
636 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800637
Vladimir Marko23a28212014-01-09 19:24:37 +0000638 // Can this class access a resolved field?
639 // Note that access to field's class is checked and this may require looking up the class
640 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Mathieu Chartier3398c782016-09-30 10:27:43 -0700641 bool CanAccessResolvedField(ObjPtr<Class> access_to,
642 ArtField* field,
643 ObjPtr<DexCache> dex_cache,
644 uint32_t field_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700645 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3398c782016-09-30 10:27:43 -0700646 bool CheckResolvedFieldAccess(ObjPtr<Class> access_to, ArtField* field, uint32_t field_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700647 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000648
649 // Can this class access a resolved method?
650 // Note that access to methods's class is checked and this may require looking up the class
651 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700652 bool CanAccessResolvedMethod(ObjPtr<Class> access_to,
653 ArtMethod* resolved_method,
654 ObjPtr<DexCache> dex_cache,
655 uint32_t method_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700656 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko89786432014-01-31 15:03:55 +0000657 template <InvokeType throw_invoke_type>
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700658 bool CheckResolvedMethodAccess(ObjPtr<Class> access_to,
659 ArtMethod* resolved_method,
Vladimir Marko89786432014-01-31 15:03:55 +0000660 uint32_t method_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700661 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000662
Mathieu Chartier3398c782016-09-30 10:27:43 -0700663 bool IsSubClass(ObjPtr<Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800664
665 // Can src be assigned to this class? For example, String can be assigned to Object (by an
666 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
667 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
668 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
669 // to themselves. Classes for primitive types may not assign to each other.
Mathieu Chartier3398c782016-09-30 10:27:43 -0700670 ALWAYS_INLINE bool IsAssignableFrom(ObjPtr<Class> src) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800671
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800672 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
673 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700674 ALWAYS_INLINE Class* GetSuperClass() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800675
Calin Juravle52503d82015-11-11 16:58:31 +0000676 // Get first common super class. It will never return null.
677 // `This` and `klass` must be classes.
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700678 ObjPtr<Class> GetCommonSuperClass(Handle<Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
Calin Juravle52503d82015-11-11 16:58:31 +0000679
Roland Levillain8ca4e4e2017-02-03 15:12:38 +0000680 void SetSuperClass(ObjPtr<Class> new_super_class) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800681
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700682 bool HasSuperClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700683 return GetSuperClass() != nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800684 }
685
686 static MemberOffset SuperClassOffset() {
687 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
688 }
689
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000690 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
691 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700692 ClassLoader* GetClassLoader() ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800693
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700694 void SetClassLoader(ObjPtr<ClassLoader> new_cl) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800695
696 static MemberOffset DexCacheOffset() {
697 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
698 }
699
Mathieu Chartier2ecfd272016-11-01 10:10:05 -0700700 static MemberOffset IfTableOffset() {
701 return MemberOffset(OFFSETOF_MEMBER(Class, iftable_));
702 }
703
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800704 enum {
705 kDumpClassFullDetail = 1,
706 kDumpClassClassLoader = (1 << 1),
707 kDumpClassInitialized = (1 << 2),
708 };
709
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700710 void DumpClass(std::ostream& os, int flags) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800711
Mathieu Chartier137cdfa2017-01-26 14:03:11 -0800712 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
713 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700714 DexCache* GetDexCache() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800715
Mathieu Chartier91a6dc42014-12-01 10:31:15 -0800716 // Also updates the dex_cache_strings_ variable from new_dex_cache.
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700717 void SetDexCache(ObjPtr<DexCache> new_dex_cache) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800718
Andreas Gampe542451c2016-07-26 09:02:02 -0700719 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDirectMethods(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700720 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800721
Alex Lighte64300b2015-12-15 15:02:47 -0800722 ALWAYS_INLINE LengthPrefixedArray<ArtMethod>* GetMethodsPtr()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700723 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700724
David Srbecky9b3607d2016-01-14 18:15:54 +0000725 static MemberOffset MethodsOffset() {
726 return MemberOffset(OFFSETOF_MEMBER(Class, methods_));
727 }
728
Andreas Gampe542451c2016-07-26 09:02:02 -0700729 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetMethods(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700730 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800731
732 void SetMethodsPtr(LengthPrefixedArray<ArtMethod>* new_methods,
733 uint32_t num_direct,
734 uint32_t num_virtual)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700735 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700736 // Used by image writer.
Alex Lighte64300b2015-12-15 15:02:47 -0800737 void SetMethodsPtrUnchecked(LengthPrefixedArray<ArtMethod>* new_methods,
738 uint32_t num_direct,
739 uint32_t num_virtual)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700740 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800741
742 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700743 ALWAYS_INLINE ArraySlice<ArtMethod> GetDirectMethodsSlice(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700744 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700745
Andreas Gampe542451c2016-07-26 09:02:02 -0700746 ALWAYS_INLINE ArtMethod* GetDirectMethod(size_t i, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700747 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700748
749 // Use only when we are allocating populating the method arrays.
Andreas Gampe542451c2016-07-26 09:02:02 -0700750 ALWAYS_INLINE ArtMethod* GetDirectMethodUnchecked(size_t i, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700751 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe542451c2016-07-26 09:02:02 -0700752 ALWAYS_INLINE ArtMethod* GetVirtualMethodUnchecked(size_t i, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700753 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700754
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800755 // Returns the number of static, private, and constructor methods.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700756 ALWAYS_INLINE uint32_t NumDirectMethods() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800757
Mathieu Chartier4e305412014-02-19 10:54:44 -0800758 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700759 ALWAYS_INLINE ArraySlice<ArtMethod> GetMethodsSlice(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700760 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800761
762 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700763 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredMethodsSlice(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700764 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800765
766 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDeclaredMethods(
Andreas Gampe542451c2016-07-26 09:02:02 -0700767 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700768 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800769
Andreas Gampe542451c2016-07-26 09:02:02 -0700770 template <PointerSize kPointerSize, bool kTransactionActive>
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700771 static ObjPtr<Method> GetDeclaredMethodInternal(Thread* self,
772 ObjPtr<Class> klass,
773 ObjPtr<String> name,
774 ObjPtr<ObjectArray<Class>> args)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700775 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700776
Andreas Gampe542451c2016-07-26 09:02:02 -0700777 template <PointerSize kPointerSize, bool kTransactionActive>
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700778 static ObjPtr<Constructor> GetDeclaredConstructorInternal(Thread* self,
779 ObjPtr<Class> klass,
780 ObjPtr<ObjectArray<Class>> args)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700781 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampebc4d2182016-02-22 10:03:12 -0800782
Alex Lighte64300b2015-12-15 15:02:47 -0800783 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700784 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredVirtualMethodsSlice(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700785 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800786
787 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDeclaredVirtualMethods(
Andreas Gampe542451c2016-07-26 09:02:02 -0700788 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700789 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800790
791 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700792 ALWAYS_INLINE ArraySlice<ArtMethod> GetCopiedMethodsSlice(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700793 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800794
Andreas Gampe542451c2016-07-26 09:02:02 -0700795 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetCopiedMethods(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700796 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800797
798 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700799 ALWAYS_INLINE ArraySlice<ArtMethod> GetVirtualMethodsSlice(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700800 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700801
Andreas Gampe542451c2016-07-26 09:02:02 -0700802 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetVirtualMethods(
803 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700804 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700805
Alex Lighte64300b2015-12-15 15:02:47 -0800806 // Returns the number of non-inherited virtual methods (sum of declared and copied methods).
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700807 ALWAYS_INLINE uint32_t NumVirtualMethods() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800808
Alex Lighte64300b2015-12-15 15:02:47 -0800809 // Returns the number of copied virtual methods.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700810 ALWAYS_INLINE uint32_t NumCopiedVirtualMethods() REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800811
812 // Returns the number of declared virtual methods.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700813 ALWAYS_INLINE uint32_t NumDeclaredVirtualMethods() REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800814
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700815 ALWAYS_INLINE uint32_t NumMethods() REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -0800816
Mathieu Chartier4e305412014-02-19 10:54:44 -0800817 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700818 ArtMethod* GetVirtualMethod(size_t i, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700819 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800820
Andreas Gampe542451c2016-07-26 09:02:02 -0700821 ArtMethod* GetVirtualMethodDuringLinking(size_t i, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700822 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800823
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800824 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
825 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700826 ALWAYS_INLINE PointerArray* GetVTable() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700827
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700828 ALWAYS_INLINE PointerArray* GetVTableDuringLinking() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700829
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700830 void SetVTable(PointerArray* new_vtable) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800831
832 static MemberOffset VTableOffset() {
833 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
834 }
835
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700836 static MemberOffset EmbeddedVTableLengthOffset() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700837 return MemberOffset(sizeof(Class));
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700838 }
839
Andreas Gampe542451c2016-07-26 09:02:02 -0700840 static MemberOffset ImtPtrOffset(PointerSize pointer_size) {
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000841 return MemberOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -0700842 RoundUp(EmbeddedVTableLengthOffset().Uint32Value() + sizeof(uint32_t),
843 static_cast<size_t>(pointer_size)));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000844 }
845
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800846 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
847 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700848 bool ShouldHaveImt() REQUIRES_SHARED(Locks::mutator_lock_) {
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000849 return ShouldHaveEmbeddedVTable<kVerifyFlags, kReadBarrierOption>();
850 }
851
852 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
853 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700854 bool ShouldHaveEmbeddedVTable() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800855 return IsInstantiable<kVerifyFlags, kReadBarrierOption>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700856 }
857
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700858 bool HasVTable() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700859
Andreas Gampe542451c2016-07-26 09:02:02 -0700860 static MemberOffset EmbeddedVTableEntryOffset(uint32_t i, PointerSize pointer_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700861
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700862 int32_t GetVTableLength() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700863
Andreas Gampe542451c2016-07-26 09:02:02 -0700864 ArtMethod* GetVTableEntry(uint32_t i, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700865 REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700866
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700867 int32_t GetEmbeddedVTableLength() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700868
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700869 void SetEmbeddedVTableLength(int32_t len) REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700870
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700871 ImTable* GetImt(PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000872
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700873 void SetImt(ImTable* imt, PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000874
Andreas Gampe542451c2016-07-26 09:02:02 -0700875 ArtMethod* GetEmbeddedVTableEntry(uint32_t i, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700876 REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700877
Andreas Gampe542451c2016-07-26 09:02:02 -0700878 void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700879 REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700880
Andreas Gampe542451c2016-07-26 09:02:02 -0700881 inline void SetEmbeddedVTableEntryUnchecked(uint32_t i,
882 ArtMethod* method,
883 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700884 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700885
Andreas Gampe542451c2016-07-26 09:02:02 -0700886 void PopulateEmbeddedVTable(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700887 REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700888
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800889 // Given a method implemented by this class but potentially from a super class, return the
890 // specific implementation method for this class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700891 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700892 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800893
894 // Given a method implemented by this class' super class, return the specific implementation
895 // method for this class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700896 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700897 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800898
Alex Light705ad492015-09-21 11:36:30 -0700899 // Given a method from some implementor of this interface, return the specific implementation
900 // method for this class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700901 ArtMethod* FindVirtualMethodForInterfaceSuper(ArtMethod* method, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700902 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light705ad492015-09-21 11:36:30 -0700903
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800904 // Given a method implemented by this class, but potentially from a
905 // super class or interface, return the specific implementation
906 // method for this class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700907 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700908 REQUIRES_SHARED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800909
Andreas Gampe542451c2016-07-26 09:02:02 -0700910 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700911 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700912
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700913 ArtMethod* FindInterfaceMethod(const StringPiece& name,
914 const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700915 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700916 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstrom004644f2014-06-18 08:34:01 -0700917
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700918 ArtMethod* FindInterfaceMethod(const StringPiece& name,
919 const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700920 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700921 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800922
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700923 ArtMethod* FindInterfaceMethod(ObjPtr<DexCache> dex_cache,
924 uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700925 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700926 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800927
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700928 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name,
929 const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700930 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700931 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800932
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700933 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name,
934 const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700935 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700936 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700937
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700938 ArtMethod* FindDeclaredDirectMethod(ObjPtr<DexCache> dex_cache,
939 uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700940 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700941 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800942
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700943 ArtMethod* FindDirectMethod(const StringPiece& name,
944 const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700945 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700946 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800947
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700948 ArtMethod* FindDirectMethod(const StringPiece& name,
949 const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700950 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700951 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700952
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700953 ArtMethod* FindDirectMethod(ObjPtr<DexCache> dex_cache,
954 uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700955 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700956 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800957
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700958 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name,
959 const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700960 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700961 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700962
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700963 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name,
964 const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700965 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700966 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700967
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700968 ArtMethod* FindDeclaredVirtualMethod(ObjPtr<DexCache> dex_cache,
969 uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700970 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700971 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700972
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700973 ArtMethod* FindDeclaredVirtualMethodByName(const StringPiece& name,
974 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700975 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao13e748b2015-08-25 20:44:19 +0000976
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700977 ArtMethod* FindDeclaredDirectMethodByName(const StringPiece& name,
978 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700979 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +0000980
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700981 ArtMethod* FindVirtualMethod(const StringPiece& name,
982 const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700983 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700984 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700985
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700986 ArtMethod* FindVirtualMethod(const StringPiece& name,
987 const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700988 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700989 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700990
Mathieu Chartier28bd2e42016-10-04 13:54:57 -0700991 ArtMethod* FindVirtualMethod(ObjPtr<DexCache> dex_cache,
992 uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700993 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700994 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700995
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700996 ArtMethod* FindClassInitializer(PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700997
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700998 bool HasDefaultMethods() REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Lighteb7c1442015-08-31 13:17:42 -0700999 return (GetAccessFlags() & kAccHasDefaultMethod) != 0;
1000 }
1001
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001002 bool HasBeenRecursivelyInitialized() REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Lighteb7c1442015-08-31 13:17:42 -07001003 return (GetAccessFlags() & kAccRecursivelyInitialized) != 0;
1004 }
1005
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001006 ALWAYS_INLINE int32_t GetIfTableCount() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001007
Mathieu Chartierfbc31082016-01-24 11:59:56 -08001008 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1009 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001010 ALWAYS_INLINE IfTable* GetIfTable() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001011
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001012 ALWAYS_INLINE void SetIfTable(ObjPtr<IfTable> new_iftable)
1013 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001014
1015 // Get instance fields of the class (See also GetSFields).
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001016 LengthPrefixedArray<ArtField>* GetIFieldsPtr() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001017
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001018 ALWAYS_INLINE IterationRange<StrideIterator<ArtField>> GetIFields()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001019 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001020
1021 void SetIFieldsPtr(LengthPrefixedArray<ArtField>* new_ifields)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001022 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001023
Mathieu Chartierc7853442015-03-27 14:35:38 -07001024 // Unchecked edition has no verification flags.
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001025 void SetIFieldsPtrUnchecked(LengthPrefixedArray<ArtField>* new_sfields)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001026 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001027
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001028 uint32_t NumInstanceFields() REQUIRES_SHARED(Locks::mutator_lock_);
1029 ArtField* GetInstanceField(uint32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001030
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -07001031 // Returns the number of instance fields containing reference types. Does not count fields in any
1032 // super classes.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001033 uint32_t NumReferenceInstanceFields() REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko72ab6842017-01-20 19:32:50 +00001034 DCHECK(IsResolved());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001035 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001036 }
1037
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001038 uint32_t NumReferenceInstanceFieldsDuringLinking() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001039 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001040 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001041 }
1042
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001043 void SetNumReferenceInstanceFields(uint32_t new_num) REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001044 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001045 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001046 }
1047
Mathieu Chartier4e305412014-02-19 10:54:44 -08001048 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001049 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001050
1051 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001052 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001053
Vladimir Marko76649e82014-11-10 18:32:59 +00001054 // Get the offset of the first reference instance field. Other reference instance fields follow.
Hiroshi Yamauchi5496f692016-02-17 13:29:59 -08001055 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1056 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartiere401d142015-04-22 13:56:20 -07001057 MemberOffset GetFirstReferenceInstanceFieldOffset()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001058 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko76649e82014-11-10 18:32:59 +00001059
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001060 // Returns the number of static fields containing reference types.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001061 uint32_t NumReferenceStaticFields() REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko72ab6842017-01-20 19:32:50 +00001062 DCHECK(IsResolved());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001063 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001064 }
1065
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001066 uint32_t NumReferenceStaticFieldsDuringLinking() REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001067 DCHECK(IsLoaded() || IsErroneous() || IsRetired());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001068 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001069 }
1070
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001071 void SetNumReferenceStaticFields(uint32_t new_num) REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001072 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001073 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001074 }
1075
Vladimir Marko76649e82014-11-10 18:32:59 +00001076 // Get the offset of the first reference static field. Other reference static fields follow.
Mathieu Chartierdfe02f62016-02-01 20:15:11 -08001077 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1078 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampe542451c2016-07-26 09:02:02 -07001079 MemberOffset GetFirstReferenceStaticFieldOffset(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001080 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko76649e82014-11-10 18:32:59 +00001081
1082 // Get the offset of the first reference static field. Other reference static fields follow.
Andreas Gampe542451c2016-07-26 09:02:02 -07001083 MemberOffset GetFirstReferenceStaticFieldOffsetDuringLinking(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001084 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko76649e82014-11-10 18:32:59 +00001085
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001086 // Gets the static fields of the class.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001087 LengthPrefixedArray<ArtField>* GetSFieldsPtr() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001088 ALWAYS_INLINE IterationRange<StrideIterator<ArtField>> GetSFields()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001089 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001090
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001091 void SetSFieldsPtr(LengthPrefixedArray<ArtField>* new_sfields)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001092 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001093
Mathieu Chartierc7853442015-03-27 14:35:38 -07001094 // Unchecked edition has no verification flags.
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001095 void SetSFieldsPtrUnchecked(LengthPrefixedArray<ArtField>* new_sfields)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001096 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -07001097
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001098 uint32_t NumStaticFields() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001099
Ian Rogersef7d42f2014-01-06 12:55:46 -08001100 // TODO: uint16_t
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001101 ArtField* GetStaticField(uint32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001102
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001103 // Find a static or instance field using the JLS resolution order
Vladimir Marko19a4d372016-12-08 14:41:46 +00001104 static ArtField* FindField(Thread* self,
1105 ObjPtr<Class> klass,
1106 const StringPiece& name,
Mathieu Chartierf8322842014-05-16 10:59:25 -07001107 const StringPiece& type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001108 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001109
1110 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -07001111 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001112 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001113
1114 // Finds the given instance field in this class or a superclass, only searches classes that
1115 // have the same dex cache.
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001116 ArtField* FindInstanceField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001117 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001118
Brian Carlstromea46f952013-07-30 01:26:50 -07001119 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001120 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001121
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001122 ArtField* FindDeclaredInstanceField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001123 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001124
1125 // Finds the given static field in this class or a superclass.
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001126 static ArtField* FindStaticField(Thread* self,
Vladimir Marko19a4d372016-12-08 14:41:46 +00001127 ObjPtr<Class> klass,
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001128 const StringPiece& name,
Mathieu Chartierf8322842014-05-16 10:59:25 -07001129 const StringPiece& type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001130 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001131
1132 // Finds the given static field in this class or superclass, only searches classes that
1133 // have the same dex cache.
Vladimir Markobb268b12016-06-30 15:52:56 +01001134 static ArtField* FindStaticField(Thread* self,
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001135 ObjPtr<Class> klass,
1136 ObjPtr<DexCache> dex_cache,
Mathieu Chartierf8322842014-05-16 10:59:25 -07001137 uint32_t dex_field_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001138 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001139
Brian Carlstromea46f952013-07-30 01:26:50 -07001140 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001141 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001142
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001143 ArtField* FindDeclaredStaticField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001144 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001145
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001146 pid_t GetClinitThreadId() REQUIRES_SHARED(Locks::mutator_lock_) {
David Sehr709b0702016-10-13 09:12:37 -07001147 DCHECK(IsIdxLoaded() || IsErroneous()) << PrettyClass();
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001148 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001149 }
1150
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001151 void SetClinitThreadId(pid_t new_clinit_thread_id) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001152
Alex Light4f2e9572017-03-16 13:13:31 -07001153 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1154 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Alex Lightd6251582016-10-31 11:12:30 -07001155 ClassExt* GetExtData() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001156
Alex Light0273ad12016-11-02 11:19:31 -07001157 // Returns the ExtData for this class, allocating one if necessary. This should be the only way
1158 // to force ext_data_ to be set. No functions are available for changing an already set ext_data_
1159 // since doing so is not allowed.
1160 ClassExt* EnsureExtDataPresent(Thread* self)
1161 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
1162
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001163 uint16_t GetDexClassDefIndex() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001164 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001165 }
1166
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001167 void SetDexClassDefIndex(uint16_t class_def_idx) REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001168 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001169 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001170 }
1171
Andreas Gampea5b09a62016-11-17 15:21:22 -08001172 dex::TypeIndex GetDexTypeIndex() REQUIRES_SHARED(Locks::mutator_lock_) {
1173 return dex::TypeIndex(
1174 static_cast<uint16_t>(GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_))));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001175 }
1176
Andreas Gampea5b09a62016-11-17 15:21:22 -08001177 void SetDexTypeIndex(dex::TypeIndex type_idx) REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001178 // Not called within a transaction.
Andreas Gampea5b09a62016-11-17 15:21:22 -08001179 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx.index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001180 }
1181
Andreas Gampea5b09a62016-11-17 15:21:22 -08001182 dex::TypeIndex FindTypeIndexInOtherDexFile(const DexFile& dex_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001183 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffraye4084a52016-02-18 14:43:42 +00001184
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001185 static Class* GetJavaLangClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier31000802015-06-14 14:14:37 -07001186 DCHECK(HasJavaLangClass());
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001187 return java_lang_Class_.Read();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001188 }
1189
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001190 static bool HasJavaLangClass() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier31000802015-06-14 14:14:37 -07001191 return !java_lang_Class_.IsNull();
1192 }
1193
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001194 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001195 static void SetClassClass(ObjPtr<Class> java_lang_Class) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001196 static void ResetClass();
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -07001197 static void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001198 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001199
Mathieu Chartiere401d142015-04-22 13:56:20 -07001200 // Visit native roots visits roots which are keyed off the native pointers such as ArtFields and
1201 // ArtMethods.
Hiroshi Yamauchi7a62e672016-06-10 17:22:48 -07001202 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, class Visitor>
Andreas Gampe542451c2016-07-26 09:02:02 -07001203 void VisitNativeRoots(Visitor& visitor, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001204 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -07001205
Igor Murashkindf707e42016-02-02 16:56:50 -08001206 // When class is verified, set the kAccSkipAccessChecks flag on each method.
Andreas Gampe542451c2016-07-26 09:02:02 -07001207 void SetSkipAccessChecksFlagOnAllMethods(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001208 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz233ea8e2013-06-06 11:57:09 +02001209
Ian Rogers1ff3c982014-08-12 02:30:58 -07001210 // Get the descriptor of the class. In a few cases a std::string is required, rather than
1211 // always create one the storage argument is populated and its internal c_str() returned. We do
1212 // this to avoid memory allocation in the common case.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001213 const char* GetDescriptor(std::string* storage) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers1ff3c982014-08-12 02:30:58 -07001214
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001215 const char* GetArrayDescriptor(std::string* storage) REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001216
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001217 bool DescriptorEquals(const char* match) REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001218
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001219 const DexFile::ClassDef* GetClassDef() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001220
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001221 ALWAYS_INLINE uint32_t NumDirectInterfaces() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001222
Andreas Gampea5b09a62016-11-17 15:21:22 -08001223 dex::TypeIndex GetDirectInterfaceTypeIdx(uint32_t idx) REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001224
Vladimir Marko19a4d372016-12-08 14:41:46 +00001225 // Get the direct interface of the `klass` at index `idx` if resolved, otherwise return null.
1226 // If the caller expects the interface to be resolved, for example for a resolved `klass`,
1227 // that assumption should be checked by `DCHECK(result != nullptr)`.
1228 static ObjPtr<Class> GetDirectInterface(Thread* self, ObjPtr<Class> klass, uint32_t idx)
1229 REQUIRES_SHARED(Locks::mutator_lock_);
1230
1231 // Resolve and get the direct interface of the `klass` at index `idx`.
1232 // Returns null with a pending exception if the resolution fails.
1233 static ObjPtr<Class> ResolveDirectInterface(Thread* self, Handle<Class> klass, uint32_t idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001234 REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001235
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001236 const char* GetSourceFile() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001237
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001238 std::string GetLocation() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001239
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001240 const DexFile& GetDexFile() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001241
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001242 const DexFile::TypeList* GetInterfaceTypeList() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierf8322842014-05-16 10:59:25 -07001243
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +02001244 // Asserts we are initialized or initializing in the given thread.
1245 void AssertInitializedOrInitializingInThread(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001246 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +02001247
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001248 Class* CopyOf(Thread* self,
1249 int32_t new_length,
1250 ImTable* imt,
Andreas Gampe542451c2016-07-26 09:02:02 -07001251 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001252 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001253
Nicolas Geoffraya7a47592015-11-24 09:17:30 +00001254 // For proxy class only.
Narayan Kamath6b2dc312017-03-14 13:26:12 +00001255 ObjectArray<Class>* GetProxyInterfaces() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001256
Nicolas Geoffraya7a47592015-11-24 09:17:30 +00001257 // For proxy class only.
Narayan Kamath6b2dc312017-03-14 13:26:12 +00001258 ObjectArray<ObjectArray<Class>>* GetProxyThrows() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001259
Fred Shih4ee7a662014-07-11 09:59:27 -07001260 // For reference class only.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001261 MemberOffset GetDisableIntrinsicFlagOffset() REQUIRES_SHARED(Locks::mutator_lock_);
1262 MemberOffset GetSlowPathFlagOffset() REQUIRES_SHARED(Locks::mutator_lock_);
1263 bool GetSlowPathEnabled() REQUIRES_SHARED(Locks::mutator_lock_);
1264 void SetSlowPath(bool enabled) REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih4ee7a662014-07-11 09:59:27 -07001265
Mathieu Chartierfc58af42015-04-16 18:00:39 -07001266 // May cause thread suspension due to EqualParameters.
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001267 ArtMethod* GetDeclaredConstructor(Thread* self,
1268 Handle<ObjectArray<Class>> args,
1269 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001270 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -07001271
Andreas Gampe715fdc22016-04-18 17:07:30 -07001272 static int32_t GetInnerClassFlags(Handle<Class> h_this, int32_t default_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001273 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe715fdc22016-04-18 17:07:30 -07001274
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001275 // Used to initialize a class in the allocation code path to ensure it is guarded by a StoreStore
1276 // fence.
1277 class InitializeClassVisitor {
1278 public:
1279 explicit InitializeClassVisitor(uint32_t class_size) : class_size_(class_size) {
1280 }
1281
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001282 void operator()(ObjPtr<Object> obj, size_t usable_size) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001283 REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001284
1285 private:
1286 const uint32_t class_size_;
1287
1288 DISALLOW_COPY_AND_ASSIGN(InitializeClassVisitor);
1289 };
1290
Sebastien Hertz6963e442014-11-26 22:11:27 +01001291 // Returns true if the class loader is null, ie the class loader is the boot strap class loader.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001292 bool IsBootStrapClassLoaded() REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz6963e442014-11-26 22:11:27 +01001293 return GetClassLoader() == nullptr;
1294 }
1295
Andreas Gampe542451c2016-07-26 09:02:02 -07001296 static size_t ImTableEntrySize(PointerSize pointer_size) {
1297 return static_cast<size_t>(pointer_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001298 }
1299
Andreas Gampe542451c2016-07-26 09:02:02 -07001300 static size_t VTableEntrySize(PointerSize pointer_size) {
1301 return static_cast<size_t>(pointer_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001302 }
1303
Andreas Gampe542451c2016-07-26 09:02:02 -07001304 ALWAYS_INLINE ArraySlice<ArtMethod> GetDirectMethodsSliceUnchecked(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001305 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001306
Andreas Gampe542451c2016-07-26 09:02:02 -07001307 ALWAYS_INLINE ArraySlice<ArtMethod> GetVirtualMethodsSliceUnchecked(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001308 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -08001309
Andreas Gampe542451c2016-07-26 09:02:02 -07001310 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredMethodsSliceUnchecked(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001311 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -08001312
Andreas Gampe542451c2016-07-26 09:02:02 -07001313 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredVirtualMethodsSliceUnchecked(
1314 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001315 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -08001316
Andreas Gampe542451c2016-07-26 09:02:02 -07001317 ALWAYS_INLINE ArraySlice<ArtMethod> GetCopiedMethodsSliceUnchecked(PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001318 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001319
David Sehr709b0702016-10-13 09:12:37 -07001320 static std::string PrettyDescriptor(ObjPtr<mirror::Class> klass)
1321 REQUIRES_SHARED(Locks::mutator_lock_);
1322 std::string PrettyDescriptor()
1323 REQUIRES_SHARED(Locks::mutator_lock_);
1324 // Returns a human-readable form of the name of the given class.
1325 // Given String.class, the output would be "java.lang.Class<java.lang.String>".
1326 static std::string PrettyClass(ObjPtr<mirror::Class> c)
1327 REQUIRES_SHARED(Locks::mutator_lock_);
1328 std::string PrettyClass()
1329 REQUIRES_SHARED(Locks::mutator_lock_);
1330 // Returns a human-readable form of the name of the given class with its class loader.
1331 static std::string PrettyClassAndClassLoader(ObjPtr<mirror::Class> c)
1332 REQUIRES_SHARED(Locks::mutator_lock_);
1333 std::string PrettyClassAndClassLoader()
1334 REQUIRES_SHARED(Locks::mutator_lock_);
1335
Mathieu Chartier4b00d342015-11-13 10:42:08 -08001336 // Fix up all of the native pointers in the class by running them through the visitor. Only sets
1337 // the corresponding entry in dest if visitor(obj) != obj to prevent dirty memory. Dest should be
Mathieu Chartierfbc31082016-01-24 11:59:56 -08001338 // initialized to a copy of *this to prevent issues. Does not visit the ArtMethod and ArtField
1339 // roots.
Mathieu Chartierdfe02f62016-02-01 20:15:11 -08001340 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1341 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
1342 typename Visitor>
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001343 void FixupNativePointers(Class* dest, PointerSize pointer_size, const Visitor& visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001344 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4b00d342015-11-13 10:42:08 -08001345
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001346 private:
Alex Lighte64300b2015-12-15 15:02:47 -08001347 ALWAYS_INLINE void SetMethodsPtrInternal(LengthPrefixedArray<ArtMethod>* new_methods)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001348 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -08001349
Vladimir Marko89786432014-01-31 15:03:55 +00001350 template <bool throw_on_failure, bool use_referrers_cache>
Mathieu Chartierb8901302016-09-30 10:27:43 -07001351 bool ResolvedFieldAccessTest(ObjPtr<Class> access_to,
Mathieu Chartier3398c782016-09-30 10:27:43 -07001352 ArtField* field,
1353 uint32_t field_idx,
Mathieu Chartierb8901302016-09-30 10:27:43 -07001354 ObjPtr<DexCache> dex_cache)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001355 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierb8901302016-09-30 10:27:43 -07001356
Vladimir Marko89786432014-01-31 15:03:55 +00001357 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
Mathieu Chartierb8901302016-09-30 10:27:43 -07001358 bool ResolvedMethodAccessTest(ObjPtr<Class> access_to,
1359 ArtMethod* resolved_method,
1360 uint32_t method_idx,
1361 ObjPtr<DexCache> dex_cache)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001362 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko89786432014-01-31 15:03:55 +00001363
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001364 bool Implements(ObjPtr<Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3398c782016-09-30 10:27:43 -07001365 bool IsArrayAssignableFromArray(ObjPtr<Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
1366 bool IsAssignableFromArray(ObjPtr<Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001367
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001368 void CheckObjectAlloc() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001369
Mathieu Chartierc7853442015-03-27 14:35:38 -07001370 // Unchecked editions is for root visiting.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001371 LengthPrefixedArray<ArtField>* GetSFieldsPtrUnchecked() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001372 IterationRange<StrideIterator<ArtField>> GetSFieldsUnchecked()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001373 REQUIRES_SHARED(Locks::mutator_lock_);
1374 LengthPrefixedArray<ArtField>* GetIFieldsPtrUnchecked() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001375 IterationRange<StrideIterator<ArtField>> GetIFieldsUnchecked()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001376 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -07001377
Alex Lighte64300b2015-12-15 15:02:47 -08001378 // The index in the methods_ array where the first declared virtual method is.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001379 ALWAYS_INLINE uint32_t GetVirtualMethodsStartOffset() REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -08001380
1381 // The index in the methods_ array where the first direct method is.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001382 ALWAYS_INLINE uint32_t GetDirectMethodsStartOffset() REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -08001383
1384 // The index in the methods_ array where the first copied method is.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001385 ALWAYS_INLINE uint32_t GetCopiedMethodsStartOffset() REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighte64300b2015-12-15 15:02:47 -08001386
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001387 bool ProxyDescriptorEquals(const char* match) REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko3481ba22015-04-13 12:22:36 +01001388
Andreas Gampe90b936d2017-01-31 08:58:55 -08001389 template<VerifyObjectFlags kVerifyFlags>
1390 void GetAccessFlagsDCheck() REQUIRES_SHARED(Locks::mutator_lock_);
1391
Roland Levillain0d5a2812015-11-13 10:07:31 +00001392 // Check that the pointer size matches the one in the class linker.
Andreas Gampe542451c2016-07-26 09:02:02 -07001393 ALWAYS_INLINE static void CheckPointerSize(PointerSize pointer_size);
1394
1395 static MemberOffset EmbeddedVTableOffset(PointerSize pointer_size);
Mathieu Chartierfbc31082016-01-24 11:59:56 -08001396 template <bool kVisitNativeRoots,
1397 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1398 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
1399 typename Visitor>
Mathieu Chartier28bd2e42016-10-04 13:54:57 -07001400 void VisitReferences(ObjPtr<Class> klass, const Visitor& visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001401 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier059ef3d2015-08-18 13:54:21 -07001402
Alex Lighte64300b2015-12-15 15:02:47 -08001403 // 'Class' Object Fields
1404 // Order governed by java field ordering. See art::ClassLinker::LinkFields.
1405
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001406 // Defining class loader, or null for the "bootstrap" system loader.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001407 HeapReference<ClassLoader> class_loader_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001408
1409 // For array classes, the component class object for instanceof/checkcast
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001410 // (for String[][][], this will be String[][]). null for non-array classes.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001411 HeapReference<Class> component_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001412
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001413 // DexCache of resolved constant pool entries (will be null for classes generated by the
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001414 // runtime such as arrays and primitive classes).
Ian Rogersef7d42f2014-01-06 12:55:46 -08001415 HeapReference<DexCache> dex_cache_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001416
Alex Lightd6251582016-10-31 11:12:30 -07001417 // Extraneous class data that is not always needed. This field is allocated lazily and may
1418 // only be set with 'this' locked. This is synchronized on 'this'.
1419 // TODO(allight) We should probably synchronize it on something external or handle allocation in
1420 // some other (safe) way to prevent possible deadlocks.
1421 HeapReference<ClassExt> ext_data_;
1422
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001423 // The interface table (iftable_) contains pairs of a interface class and an array of the
1424 // interface methods. There is one pair per interface supported by this class. That means one
1425 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
1426 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
1427 //
1428 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
1429 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
1430 // single vtable.
1431 //
1432 // For every interface a concrete class implements, we create an array of the concrete vtable_
1433 // methods for the methods in the interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001434 HeapReference<IfTable> iftable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001435
Ian Rogersef7d42f2014-01-06 12:55:46 -08001436 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
1437 HeapReference<String> name_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001438
Brian Carlstrom08ac9222015-05-22 13:43:00 -07001439 // The superclass, or null if this is java.lang.Object or a primitive type.
1440 //
1441 // Note that interfaces have java.lang.Object as their
1442 // superclass. This doesn't match the expectations in JNI
1443 // GetSuperClass or java.lang.Class.getSuperClass() which need to
1444 // check for interfaces and return null.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001445 HeapReference<Class> super_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001446
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001447 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
1448 // copied in, and virtual methods from our class either replace those from the super or are
1449 // appended. For abstract classes, methods may be created in the vtable that aren't in
1450 // virtual_ methods_ for miranda methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001451 HeapReference<PointerArray> vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001452
Mathieu Chartierc7853442015-03-27 14:35:38 -07001453 // instance fields
1454 //
1455 // These describe the layout of the contents of an Object.
1456 // Note that only the fields directly declared by this class are
1457 // listed in ifields; fields declared by a superclass are listed in
1458 // the superclass's Class.ifields.
1459 //
Mathieu Chartierc0fe56a2015-08-11 13:01:23 -07001460 // ArtFields are allocated as a length prefixed ArtField array, and not an array of pointers to
1461 // ArtFields.
Mathieu Chartierc7853442015-03-27 14:35:38 -07001462 uint64_t ifields_;
1463
Alex Lighte64300b2015-12-15 15:02:47 -08001464 // Pointer to an ArtMethod length-prefixed array. All the methods where this class is the place
1465 // where they are logically defined. This includes all private, static, final and virtual methods
1466 // as well as inherited default methods and miranda methods.
1467 //
1468 // The slice methods_ [0, virtual_methods_offset_) are the direct (static, private, init) methods
1469 // declared by this class.
1470 //
1471 // The slice methods_ [virtual_methods_offset_, copied_methods_offset_) are the virtual methods
1472 // declared by this class.
1473 //
1474 // The slice methods_ [copied_methods_offset_, |methods_|) are the methods that are copied from
1475 // interfaces such as miranda or default methods. These are copied for resolution purposes as this
1476 // class is where they are (logically) declared as far as the virtual dispatch is concerned.
David Srbecky9b3607d2016-01-14 18:15:54 +00001477 //
1478 // Note that this field is used by the native debugger as the unique identifier for the type.
Alex Lighte64300b2015-12-15 15:02:47 -08001479 uint64_t methods_;
1480
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001481 // Static fields length-prefixed array.
Mathieu Chartierc7853442015-03-27 14:35:38 -07001482 uint64_t sfields_;
1483
Neil Fuller3d0aa882016-08-16 19:53:07 +01001484 // Access flags; low 16 bits are defined by VM spec.
1485 uint32_t access_flags_;
1486
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -07001487 // Class flags to help speed up visiting object references.
1488 uint32_t class_flags_;
1489
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001490 // Total size of the Class instance; used when allocating storage on gc heap.
1491 // See also object_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001492 uint32_t class_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001493
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001494 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001495 pid_t clinit_thread_id_;
1496
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001497 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001498 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001499 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001500
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001501 // Type index in dex file.
1502 // TODO: really 16bits
1503 int32_t dex_type_idx_;
1504
1505 // Number of instance fields that are object refs.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001506 uint32_t num_reference_instance_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001507
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001508 // Number of static fields that are object refs,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001509 uint32_t num_reference_static_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001510
1511 // Total object size; used when allocating storage on gc heap.
1512 // (For interfaces and abstract classes this will be zero.)
1513 // See also class_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001514 uint32_t object_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001515
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001516 // Aligned object size for allocation fast path. The value is max uint32_t if the object is
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001517 // uninitialized or finalizable. Not currently used for variable sized objects.
1518 uint32_t object_size_alloc_fast_path_;
1519
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -07001520 // The lower 16 bits contains a Primitive::Type value. The upper 16
1521 // bits contains the size shift of the primitive type.
1522 uint32_t primitive_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001523
1524 // Bitmap of offsets of ifields.
1525 uint32_t reference_instance_offsets_;
1526
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001527 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001528 Status status_;
1529
Alex Lighte64300b2015-12-15 15:02:47 -08001530 // The offset of the first virtual method that is copied from an interface. This includes miranda,
1531 // default, and default-conflict methods. Having a hard limit of ((2 << 16) - 1) for methods
1532 // defined on a single class is well established in Java so we will use only uint16_t's here.
1533 uint16_t copied_methods_offset_;
1534
1535 // The offset of the first declared virtual methods in the methods_ array.
1536 uint16_t virtual_methods_offset_;
1537
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001538 // TODO: ?
1539 // initiating class loader list
1540 // NOTE: for classes with low serialNumber, these are unused, and the
1541 // values are kept in a table in gDvm.
1542 // InitiatingLoaderList initiating_loader_list_;
1543
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001544 // The following data exist in real class objects.
1545 // Embedded Imtable, for class object that's not an interface, fixed size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001546 // ImTableEntry embedded_imtable_[0];
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001547 // Embedded Vtable, for class object that's not an interface, variable size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001548 // VTableEntry embedded_vtable_[0];
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001549 // Static fields, variable size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001550 // uint32_t fields_[0];
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001551
1552 // java.lang.Class
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001553 static GcRoot<Class> java_lang_Class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001554
Mathieu Chartier279ac5c2016-09-08 17:34:25 -07001555 ART_FRIEND_TEST(DexCacheTest, TestResolvedFieldAccess); // For ResolvedFieldAccessTest
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001556 friend struct art::ClassOffsets; // for verifying offset information
Mathieu Chartier059ef3d2015-08-18 13:54:21 -07001557 friend class Object; // For VisitReferences
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001558 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
1559};
1560
1561std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1562
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001563} // namespace mirror
1564} // namespace art
1565
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001566#endif // ART_RUNTIME_MIRROR_CLASS_H_