blob: 1fed1902564f2d2baf29adc547fcd9db76876f3a [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 Gampe542451c2016-07-26 09:02:02 -070020#include "base/enums.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070021#include "base/iteration_range.h"
Mathieu Chartierf8322842014-05-16 10:59:25 -070022#include "dex_file.h"
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -070023#include "class_flags.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070024#include "gc_root.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070025#include "gc/allocator_type.h"
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000026#include "imtable.h"
Vladimir Marko23a28212014-01-09 19:24:37 +000027#include "invoke_type.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028#include "modifiers.h"
29#include "object.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070030#include "object_array.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070031#include "object_callbacks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032#include "primitive.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070033#include "read_barrier_option.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070034#include "stride_iterator.h"
Alex Lighteb7c1442015-08-31 13:17:42 -070035#include "thread.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070036#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038namespace art {
39
Mathieu Chartierc7853442015-03-27 14:35:38 -070040class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070041class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042struct ClassOffsets;
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070043template<class T> class Handle;
Mathieu Chartier54d220e2015-07-30 16:20:06 -070044template<typename T> class LengthPrefixedArray;
Alex Lighte64300b2015-12-15 15:02:47 -080045template<typename T> class ArraySlice;
Ian Rogersd91d6d62013-09-25 20:26:14 -070046class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080047class StringPiece;
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070048template<size_t kNumReferences> class PACKED(4) StackHandleScope;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049
50namespace mirror {
51
52class ClassLoader;
Mathieu Chartierfc58af42015-04-16 18:00:39 -070053class Constructor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080054class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080055class IfTable;
Andreas Gampebc4d2182016-02-22 10:03:12 -080056class Method;
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -070057struct StringDexCachePair;
58
59using StringDexCacheType = std::atomic<mirror::StringDexCachePair>;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080061// C++ mirror of java.lang.Class
Mingyao Yang98d1cc82014-05-15 17:02:16 -070062class MANAGED Class FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063 public:
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070064 // A magic value for reference_instance_offsets_. Ignore the bits and walk the super chain when
65 // this is the value.
66 // [This is an unlikely "natural" value, since it would be 30 non-ref instance fields followed by
67 // 2 ref instance fields.]
68 static constexpr uint32_t kClassWalkSuper = 0xC0000000;
69
Mathieu Chartier8261d022016-08-08 09:41:04 -070070 // Shift primitive type by kPrimitiveTypeSizeShiftShift to get the component type size shift
71 // Used for computing array size as follows:
72 // array_bytes = header_size + (elements << (primitive_type >> kPrimitiveTypeSizeShiftShift))
73 static constexpr uint32_t kPrimitiveTypeSizeShiftShift = 16;
74 static constexpr uint32_t kPrimitiveTypeMask = (1u << kPrimitiveTypeSizeShiftShift) - 1;
75
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 // Class Status
77 //
Mingyao Yang46f0e972014-09-10 15:16:19 -070078 // kStatusRetired: Class that's temporarily used till class linking time
79 // has its (vtable) size figured out and has been cloned to one with the
80 // right size which will be the one used later. The old one is retired and
81 // will be gc'ed once all refs to the class point to the newly
82 // cloned version.
83 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080084 // kStatusNotReady: If a Class cannot be found in the class table by
85 // FindClass, it allocates an new one with AllocClass in the
86 // kStatusNotReady and calls LoadClass. Note if it does find a
87 // class, it may not be kStatusResolved and it will try to push it
88 // forward toward kStatusResolved.
89 //
90 // kStatusIdx: LoadClass populates with Class with information from
91 // the DexFile, moving the status to kStatusIdx, indicating that the
92 // Class value in super_class_ has not been populated. The new Class
93 // can then be inserted into the classes table.
94 //
95 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
96 // attempt to move a kStatusIdx class forward to kStatusLoaded by
97 // using ResolveClass to initialize the super_class_ and ensuring the
98 // interfaces are resolved.
99 //
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700100 // kStatusResolving: Class is just cloned with the right size from
101 // temporary class that's acting as a placeholder for linking. The old
102 // class will be retired. New class is set to this status first before
103 // moving on to being resolved.
104 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105 // kStatusResolved: Still holding the lock on Class, the ClassLinker
106 // shows linking is complete and fields of the Class populated by making
107 // it kStatusResolved. Java allows circularities of the form where a super
108 // class has a field that is of the type of the sub class. We need to be able
109 // to fully resolve super classes while resolving types for fields.
110 //
111 // kStatusRetryVerificationAtRuntime: The verifier sets a class to
112 // this state if it encounters a soft failure at compile time. This
113 // often happens when there are unresolved classes in other dex
114 // files, and this status marks a class as needing to be verified
115 // again at runtime.
116 //
117 // TODO: Explain the other states
118 enum Status {
Brian Carlstromf3978662014-09-11 12:21:04 -0700119 kStatusRetired = -2, // Retired, should not be used. Use the newly cloned one instead.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800120 kStatusError = -1,
121 kStatusNotReady = 0,
122 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
123 kStatusLoaded = 2, // DEX idx values resolved.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700124 kStatusResolving = 3, // Just cloned from temporary class object.
125 kStatusResolved = 4, // Part of linking.
126 kStatusVerifying = 5, // In the process of being verified.
127 kStatusRetryVerificationAtRuntime = 6, // Compile time verification failed, retry at runtime.
128 kStatusVerifyingAtRuntime = 7, // Retrying verification at runtime.
129 kStatusVerified = 8, // Logically part of linking; done pre-init.
130 kStatusInitializing = 9, // Class init in progress.
131 kStatusInitialized = 10, // Ready to go.
132 kStatusMax = 11,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800133 };
134
Mathieu Chartier4e305412014-02-19 10:54:44 -0800135 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700136 Status GetStatus() SHARED_REQUIRES(Locks::mutator_lock_) {
Andreas Gampe575e78c2014-11-03 23:41:03 -0800137 static_assert(sizeof(Status) == sizeof(uint32_t), "Size of status not equal to uint32");
Ian Rogers03dbc042014-06-02 14:24:56 -0700138 return static_cast<Status>(
139 GetField32Volatile<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800140 }
141
Hiroshi Yamauchi5b783e62015-03-18 17:20:11 -0700142 // This is static because 'this' may be moved by GC.
143 static void SetStatus(Handle<Class> h_this, Status new_status, Thread* self)
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700144 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800145
Ian Rogers5ddb4102014-01-07 08:58:46 -0800146 static MemberOffset StatusOffset() {
147 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
148 }
149
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700150 // Returns true if the class has been retired.
151 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700152 bool IsRetired() SHARED_REQUIRES(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700153 return GetStatus<kVerifyFlags>() == kStatusRetired;
154 }
155
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156 // Returns true if the class has failed to link.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800157 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700158 bool IsErroneous() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800159 return GetStatus<kVerifyFlags>() == kStatusError;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800160 }
161
162 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800163 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700164 bool IsIdxLoaded() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800165 return GetStatus<kVerifyFlags>() >= kStatusIdx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166 }
167
168 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800169 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700170 bool IsLoaded() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800171 return GetStatus<kVerifyFlags>() >= kStatusLoaded;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172 }
173
174 // Returns true if the class has been linked.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800175 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700176 bool IsResolved() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800177 return GetStatus<kVerifyFlags>() >= kStatusResolved;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178 }
179
180 // Returns true if the class was compile-time verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800181 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700182 bool IsCompileTimeVerified() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800183 return GetStatus<kVerifyFlags>() >= kStatusRetryVerificationAtRuntime;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 }
185
186 // Returns true if the class has been verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800187 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700188 bool IsVerified() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800189 return GetStatus<kVerifyFlags>() >= kStatusVerified;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190 }
191
192 // Returns true if the class is initializing.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800193 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700194 bool IsInitializing() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800195 return GetStatus<kVerifyFlags>() >= kStatusInitializing;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 }
197
198 // Returns true if the class is initialized.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800199 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700200 bool IsInitialized() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800201 return GetStatus<kVerifyFlags>() == kStatusInitialized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800202 }
203
Mathieu Chartier4e305412014-02-19 10:54:44 -0800204 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700205 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700206 static MemberOffset AccessFlagsOffset() {
207 return OFFSET_OF_OBJECT_MEMBER(Class, access_flags_);
208 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700210 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
211 ALWAYS_INLINE uint32_t GetClassFlags() SHARED_REQUIRES(Locks::mutator_lock_) {
212 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_flags_));
213 }
214 void SetClassFlags(uint32_t new_flags) SHARED_REQUIRES(Locks::mutator_lock_);
215
Mathieu Chartier90443472015-07-16 20:32:27 -0700216 void SetAccessFlags(uint32_t new_access_flags) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800217
218 // Returns true if the class is an interface.
Mathieu Chartier90443472015-07-16 20:32:27 -0700219 ALWAYS_INLINE bool IsInterface() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800220 return (GetAccessFlags() & kAccInterface) != 0;
221 }
222
223 // Returns true if the class is declared public.
Mathieu Chartier90443472015-07-16 20:32:27 -0700224 ALWAYS_INLINE bool IsPublic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800225 return (GetAccessFlags() & kAccPublic) != 0;
226 }
227
228 // Returns true if the class is declared final.
Mathieu Chartier90443472015-07-16 20:32:27 -0700229 ALWAYS_INLINE bool IsFinal() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230 return (GetAccessFlags() & kAccFinal) != 0;
231 }
232
Mathieu Chartier90443472015-07-16 20:32:27 -0700233 ALWAYS_INLINE bool IsFinalizable() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800234 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
235 }
236
Alex Lighteb7c1442015-08-31 13:17:42 -0700237 ALWAYS_INLINE void SetRecursivelyInitialized() SHARED_REQUIRES(Locks::mutator_lock_) {
238 DCHECK_EQ(GetLockOwnerThreadId(), Thread::Current()->GetThreadId());
239 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
240 SetAccessFlags(flags | kAccRecursivelyInitialized);
241 }
242
243 ALWAYS_INLINE void SetHasDefaultMethods() SHARED_REQUIRES(Locks::mutator_lock_) {
244 DCHECK_EQ(GetLockOwnerThreadId(), Thread::Current()->GetThreadId());
245 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
246 SetAccessFlags(flags | kAccHasDefaultMethod);
247 }
248
Mathieu Chartier90443472015-07-16 20:32:27 -0700249 ALWAYS_INLINE void SetFinalizable() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700250 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800251 SetAccessFlags(flags | kAccClassIsFinalizable);
252 }
253
Mathieu Chartier90443472015-07-16 20:32:27 -0700254 ALWAYS_INLINE bool IsStringClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700255 return (GetClassFlags() & kClassFlagString) != 0;
Jeff Hao848f70a2014-01-15 13:49:50 -0800256 }
257
Mathieu Chartier90443472015-07-16 20:32:27 -0700258 ALWAYS_INLINE void SetStringClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700259 SetClassFlags(kClassFlagString | kClassFlagNoReferenceFields);
Jeff Hao848f70a2014-01-15 13:49:50 -0800260 }
261
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700262 ALWAYS_INLINE bool IsClassLoaderClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700263 return GetClassFlags() == kClassFlagClassLoader;
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700264 }
265
266 ALWAYS_INLINE void SetClassLoaderClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700267 SetClassFlags(kClassFlagClassLoader);
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700268 }
269
Vladimir Marko05792b92015-08-03 11:56:49 +0100270 ALWAYS_INLINE bool IsDexCacheClass() SHARED_REQUIRES(Locks::mutator_lock_) {
271 return (GetClassFlags() & kClassFlagDexCache) != 0;
272 }
273
274 ALWAYS_INLINE void SetDexCacheClass() SHARED_REQUIRES(Locks::mutator_lock_) {
275 SetClassFlags(GetClassFlags() | kClassFlagDexCache);
276 }
277
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800278 // Returns true if the class is abstract.
Mathieu Chartier90443472015-07-16 20:32:27 -0700279 ALWAYS_INLINE bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800280 return (GetAccessFlags() & kAccAbstract) != 0;
281 }
282
283 // Returns true if the class is an annotation.
Mathieu Chartier90443472015-07-16 20:32:27 -0700284 ALWAYS_INLINE bool IsAnnotation() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800285 return (GetAccessFlags() & kAccAnnotation) != 0;
286 }
287
288 // Returns true if the class is synthetic.
Mathieu Chartier90443472015-07-16 20:32:27 -0700289 ALWAYS_INLINE bool IsSynthetic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800290 return (GetAccessFlags() & kAccSynthetic) != 0;
291 }
292
Igor Murashkin8d1da852016-02-04 11:01:21 -0800293 // Return whether the class had run the verifier at least once.
Igor Murashkindf707e42016-02-02 16:56:50 -0800294 // This does not necessarily mean that access checks are avoidable,
295 // since the class methods might still need to be run with access checks.
Igor Murashkindf707e42016-02-02 16:56:50 -0800296 bool WasVerificationAttempted() SHARED_REQUIRES(Locks::mutator_lock_) {
297 return (GetAccessFlags() & kAccSkipAccessChecks) != 0;
Ian Rogers7b078e82014-09-10 14:44:24 -0700298 }
299
Igor Murashkindf707e42016-02-02 16:56:50 -0800300 // Mark the class as having gone through a verification attempt.
301 // Mutually exclusive from whether or not each method is allowed to skip access checks.
302 void SetVerificationAttempted() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers7b078e82014-09-10 14:44:24 -0700303 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Mathieu Chartier085a0722016-04-01 17:33:31 -0700304 if ((flags & kAccVerificationAttempted) == 0) {
305 SetAccessFlags(flags | kAccVerificationAttempted);
306 }
Ian Rogers7b078e82014-09-10 14:44:24 -0700307 }
308
Mathieu Chartier4e305412014-02-19 10:54:44 -0800309 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700310 bool IsTypeOfReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700311 return (GetClassFlags<kVerifyFlags>() & kClassFlagReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800312 }
313
Mathieu Chartier4e305412014-02-19 10:54:44 -0800314 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700315 bool IsWeakReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700316 return GetClassFlags<kVerifyFlags>() == kClassFlagWeakReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800317 }
318
Mathieu Chartier4e305412014-02-19 10:54:44 -0800319 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700320 bool IsSoftReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700321 return GetClassFlags<kVerifyFlags>() == kClassFlagSoftReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800322 }
323
Mathieu Chartier4e305412014-02-19 10:54:44 -0800324 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700325 bool IsFinalizerReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700326 return GetClassFlags<kVerifyFlags>() == kClassFlagFinalizerReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800327 }
328
Mathieu Chartier4e305412014-02-19 10:54:44 -0800329 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700330 bool IsPhantomReferenceClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -0700331 return GetClassFlags<kVerifyFlags>() == kClassFlagPhantomReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800332 }
333
Ian Rogers04f94f42013-06-10 15:09:26 -0700334 // Can references of this type be assigned to by things of another type? For non-array types
335 // this is a matter of whether sub-classes may exist - which they can't if the type is final.
336 // For array classes, where all the classes are final due to there being no sub-classes, an
337 // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
338 // types as the component is final.
Mathieu Chartier90443472015-07-16 20:32:27 -0700339 bool CannotBeAssignedFromOtherTypes() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers04f94f42013-06-10 15:09:26 -0700340 if (!IsArrayClass()) {
341 return IsFinal();
342 } else {
343 Class* component = GetComponentType();
344 if (component->IsPrimitive()) {
Ian Rogersa9a82542013-10-04 11:17:26 -0700345 return true;
Ian Rogers04f94f42013-06-10 15:09:26 -0700346 } else {
347 return component->CannotBeAssignedFromOtherTypes();
348 }
349 }
350 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800351
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700352 // Returns true if this class is the placeholder and should retire and
353 // be replaced with a class with the right size for embedded imt/vtable.
Mathieu Chartier90443472015-07-16 20:32:27 -0700354 bool IsTemp() SHARED_REQUIRES(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700355 Status s = GetStatus();
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000356 return s < Status::kStatusResolving && ShouldHaveEmbeddedVTable();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700357 }
358
Mathieu Chartier90443472015-07-16 20:32:27 -0700359 String* GetName() SHARED_REQUIRES(Locks::mutator_lock_); // Returns the cached name.
360 void SetName(String* name) SHARED_REQUIRES(Locks::mutator_lock_); // Sets the cached name.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800361 // Computes the name, then sets the cached value.
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700362 static String* ComputeName(Handle<Class> h_this) SHARED_REQUIRES(Locks::mutator_lock_)
363 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800364
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800365 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Nicolas Geoffraya7a47592015-11-24 09:17:30 +0000366 bool IsProxyClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367 // Read access flags without using getter as whether something is a proxy can be check in
368 // any loaded state
369 // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700370 uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800371 return (access_flags & kAccClassIsProxy) != 0;
372 }
373
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000374 static MemberOffset PrimitiveTypeOffset() {
375 return OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_);
376 }
377
Mathieu Chartier4e305412014-02-19 10:54:44 -0800378 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700379 Primitive::Type GetPrimitiveType() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380
Mathieu Chartier90443472015-07-16 20:32:27 -0700381 void SetPrimitiveType(Primitive::Type new_type) SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800382 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
Mathieu Chartier8261d022016-08-08 09:41:04 -0700383 uint32_t v32 = static_cast<uint32_t>(new_type);
384 DCHECK_EQ(v32 & kPrimitiveTypeMask, v32) << "upper 16 bits aren't zero";
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700385 // Store the component size shift in the upper 16 bits.
Mathieu Chartier8261d022016-08-08 09:41:04 -0700386 v32 |= Primitive::ComponentSizeShift(new_type) << kPrimitiveTypeSizeShiftShift;
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700387 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), v32);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388 }
389
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700390 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700391 size_t GetPrimitiveTypeSizeShift() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700392
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800393 // Returns true if the class is a primitive type.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800394 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700395 bool IsPrimitive() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800396 return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397 }
398
Mathieu Chartier4e305412014-02-19 10:54:44 -0800399 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700400 bool IsPrimitiveBoolean() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800401 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800402 }
403
Mathieu Chartier4e305412014-02-19 10:54:44 -0800404 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700405 bool IsPrimitiveByte() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800406 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800407 }
408
Mathieu Chartier4e305412014-02-19 10:54:44 -0800409 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700410 bool IsPrimitiveChar() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800411 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800412 }
413
Mathieu Chartier4e305412014-02-19 10:54:44 -0800414 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700415 bool IsPrimitiveShort() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800416 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800417 }
418
Mathieu Chartier4e305412014-02-19 10:54:44 -0800419 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700420 bool IsPrimitiveInt() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800421 return GetPrimitiveType() == Primitive::kPrimInt;
422 }
423
Mathieu Chartier4e305412014-02-19 10:54:44 -0800424 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700425 bool IsPrimitiveLong() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800426 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427 }
428
Mathieu Chartier4e305412014-02-19 10:54:44 -0800429 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700430 bool IsPrimitiveFloat() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800431 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800432 }
433
Mathieu Chartier4e305412014-02-19 10:54:44 -0800434 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700435 bool IsPrimitiveDouble() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800436 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800437 }
438
Mathieu Chartier4e305412014-02-19 10:54:44 -0800439 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700440 bool IsPrimitiveVoid() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800441 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800442 }
443
Mathieu Chartier4e305412014-02-19 10:54:44 -0800444 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700445 bool IsPrimitiveArray() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800446 return IsArrayClass<kVerifyFlags>() &&
447 GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
448 IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449 }
450
451 // Depth of class from java.lang.Object
Mathieu Chartier90443472015-07-16 20:32:27 -0700452 uint32_t Depth() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800453
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700454 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
455 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Calin Juravle2e768302015-07-28 14:41:11 +0000456 bool IsArrayClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800457
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700458 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
459 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700460 bool IsClassClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800461
Mathieu Chartier90443472015-07-16 20:32:27 -0700462 bool IsThrowableClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800463
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700464 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700465 bool IsReferenceClass() const SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih4ee7a662014-07-11 09:59:27 -0700466
Ian Rogersa9a82542013-10-04 11:17:26 -0700467 static MemberOffset ComponentTypeOffset() {
468 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
469 }
470
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700471 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
472 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Calin Juravle2e768302015-07-28 14:41:11 +0000473 Class* GetComponentType() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800474
Mathieu Chartier90443472015-07-16 20:32:27 -0700475 void SetComponentType(Class* new_component_type) SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700476 DCHECK(GetComponentType() == nullptr);
477 DCHECK(new_component_type != nullptr);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100478 // Component type is invariant: use non-transactional mode without check.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700479 SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800480 }
481
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700482 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700483 size_t GetComponentSize() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier5ffa0782016-07-27 10:45:47 -0700484 return 1U << GetComponentSizeShift<kReadBarrierOption>();
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700485 }
486
487 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700488 size_t GetComponentSizeShift() SHARED_REQUIRES(Locks::mutator_lock_) {
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700489 return GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveTypeSizeShift();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490 }
491
Mathieu Chartier90443472015-07-16 20:32:27 -0700492 bool IsObjectClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700493 return !IsPrimitive() && GetSuperClass() == nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800494 }
Ian Rogers68d8b422014-07-17 11:09:10 -0700495
Mathieu Chartier90443472015-07-16 20:32:27 -0700496 bool IsInstantiableNonArray() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700497 return !IsPrimitive() && !IsInterface() && !IsAbstract() && !IsArrayClass();
498 }
499
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800500 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
501 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700502 bool IsInstantiable() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700503 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) ||
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800504 (IsAbstract() && IsArrayClass<kVerifyFlags, kReadBarrierOption>());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800505 }
506
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800507 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
508 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700509 bool IsObjectArrayClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800510 mirror::Class* const component_type = GetComponentType<kVerifyFlags, kReadBarrierOption>();
511 return component_type != nullptr && !component_type->IsPrimitive();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700512 }
513
514 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700515 bool IsIntArrayClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700516 constexpr auto kNewFlags = static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis);
517 auto* component_type = GetComponentType<kVerifyFlags>();
518 return component_type != nullptr && component_type->template IsPrimitiveInt<kNewFlags>();
519 }
520
521 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700522 bool IsLongArrayClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700523 constexpr auto kNewFlags = static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis);
524 auto* component_type = GetComponentType<kVerifyFlags>();
525 return component_type != nullptr && component_type->template IsPrimitiveLong<kNewFlags>();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800526 }
527
528 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700529 template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800530 ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700531 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700532
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800533 Object* AllocObject(Thread* self)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700534 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800535 Object* AllocNonMovableObject(Thread* self)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700536 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800537
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700538 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
539 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700540 bool IsVariableSize() SHARED_REQUIRES(Locks::mutator_lock_) {
Jeff Hao848f70a2014-01-15 13:49:50 -0800541 // Classes, arrays, and strings vary in size, and so the object_size_ field cannot
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700542 // be used to Get their instance size
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700543 return IsClassClass<kVerifyFlags, kReadBarrierOption>() ||
Jeff Hao848f70a2014-01-15 13:49:50 -0800544 IsArrayClass<kVerifyFlags, kReadBarrierOption>() || IsStringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800545 }
546
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700547 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
548 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700549 uint32_t SizeOf() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700550 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800551 }
552
Mathieu Chartier4e305412014-02-19 10:54:44 -0800553 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700554 uint32_t GetClassSize() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700555 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800556 }
557
Ian Rogersef7d42f2014-01-06 12:55:46 -0800558 void SetClassSize(uint32_t new_class_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700559 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800560
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700561 // Compute how many bytes would be used a class with the given elements.
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000562 static uint32_t ComputeClassSize(bool has_embedded_vtable,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700563 uint32_t num_vtable_entries,
Fred Shih37f05ef2014-07-16 18:38:08 -0700564 uint32_t num_8bit_static_fields,
565 uint32_t num_16bit_static_fields,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700566 uint32_t num_32bit_static_fields,
567 uint32_t num_64bit_static_fields,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700568 uint32_t num_ref_static_fields,
Andreas Gampe542451c2016-07-26 09:02:02 -0700569 PointerSize pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700570
571 // The size of java.lang.Class.class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700572 static uint32_t ClassClassSize(PointerSize pointer_size) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700573 // The number of vtable entries in java.lang.Class.
Neil Fuller6e03d192016-08-23 14:32:21 +0100574 uint32_t vtable_entries = Object::kVTableLength + 72;
Yi Kongff633e22015-11-06 13:33:22 +0000575 return ComputeClassSize(true, vtable_entries, 0, 0, 4, 1, 0, pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700576 }
577
578 // The size of a java.lang.Class representing a primitive such as int.class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700579 static uint32_t PrimitiveClassSize(PointerSize pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700580 return ComputeClassSize(false, 0, 0, 0, 0, 0, 0, pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700581 }
582
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700583 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
584 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700585 uint32_t GetObjectSize() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700586 static MemberOffset ObjectSizeOffset() {
587 return OFFSET_OF_OBJECT_MEMBER(Class, object_size_);
588 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800589
Mathieu Chartier90443472015-07-16 20:32:27 -0700590 void SetObjectSize(uint32_t new_object_size) SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800591 DCHECK(!IsVariableSize());
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100592 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700593 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800594 }
595
Mathieu Chartier2d721012014-11-10 11:08:06 -0800596 void SetObjectSizeWithoutChecks(uint32_t new_object_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700597 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800598 // Not called within a transaction.
599 return SetField32<false, false, kVerifyNone>(
600 OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
601 }
602
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800603 // Returns true if this class is in the same packages as that class.
Mathieu Chartier90443472015-07-16 20:32:27 -0700604 bool IsInSamePackage(Class* that) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800605
606 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
607
608 // Returns true if this class can access that class.
Mathieu Chartier90443472015-07-16 20:32:27 -0700609 bool CanAccess(Class* that) SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800610 return that->IsPublic() || this->IsInSamePackage(that);
611 }
612
613 // Can this class access a member in the provided class with the provided member access flags?
614 // Note that access to the class isn't checked in case the declaring class is protected and the
615 // method has been exposed by a public sub-class
Ian Rogersef7d42f2014-01-06 12:55:46 -0800616 bool CanAccessMember(Class* access_to, uint32_t member_flags)
Mathieu Chartier90443472015-07-16 20:32:27 -0700617 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800618 // Classes can access all of their own members
619 if (this == access_to) {
620 return true;
621 }
622 // Public members are trivially accessible
623 if (member_flags & kAccPublic) {
624 return true;
625 }
626 // Private members are trivially not accessible
627 if (member_flags & kAccPrivate) {
628 return false;
629 }
630 // Check for protected access from a sub-class, which may or may not be in the same package.
631 if (member_flags & kAccProtected) {
Andreas Gampe13f8a162014-08-08 19:55:37 -0700632 if (!this->IsInterface() && this->IsSubClass(access_to)) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800633 return true;
634 }
635 }
636 // Allow protected access from other classes in the same package.
637 return this->IsInSamePackage(access_to);
638 }
639
Vladimir Marko23a28212014-01-09 19:24:37 +0000640 // Can this class access a resolved field?
641 // Note that access to field's class is checked and this may require looking up the class
642 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000643 bool CanAccessResolvedField(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800644 DexCache* dex_cache, uint32_t field_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700645 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko89786432014-01-31 15:03:55 +0000646 bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
647 uint32_t field_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700648 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000649
650 // Can this class access a resolved method?
651 // Note that access to methods's class is checked and this may require looking up the class
652 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000653 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800654 DexCache* dex_cache, uint32_t method_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700655 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko89786432014-01-31 15:03:55 +0000656 template <InvokeType throw_invoke_type>
657 bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
658 uint32_t method_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700659 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000660
Mathieu Chartier90443472015-07-16 20:32:27 -0700661 bool IsSubClass(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800662
663 // Can src be assigned to this class? For example, String can be assigned to Object (by an
664 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
665 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
666 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
667 // to themselves. Classes for primitive types may not assign to each other.
Calin Juravle2e768302015-07-28 14:41:11 +0000668 ALWAYS_INLINE bool IsAssignableFrom(Class* src) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800669
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800670 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
671 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700672 ALWAYS_INLINE Class* GetSuperClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800673
Calin Juravle52503d82015-11-11 16:58:31 +0000674 // Get first common super class. It will never return null.
675 // `This` and `klass` must be classes.
676 Class* GetCommonSuperClass(Handle<Class> klass) SHARED_REQUIRES(Locks::mutator_lock_);
677
Roland Levillainab880f42016-05-12 16:24:36 +0100678 void SetSuperClass(Class* new_super_class) SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800679 // Super class is assigned once, except during class linker initialization.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700680 Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800681 DCHECK(old_super_class == nullptr || old_super_class == new_super_class);
682 DCHECK(new_super_class != nullptr);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700683 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800684 }
685
Mathieu Chartier90443472015-07-16 20:32:27 -0700686 bool HasSuperClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700687 return GetSuperClass() != nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800688 }
689
690 static MemberOffset SuperClassOffset() {
691 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
692 }
693
Mathieu Chartier90443472015-07-16 20:32:27 -0700694 ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800695
Mathieu Chartier90443472015-07-16 20:32:27 -0700696 void SetClassLoader(ClassLoader* new_cl) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800697
698 static MemberOffset DexCacheOffset() {
699 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
700 }
701
702 enum {
703 kDumpClassFullDetail = 1,
704 kDumpClassClassLoader = (1 << 1),
705 kDumpClassInitialized = (1 << 2),
706 };
707
Mathieu Chartier90443472015-07-16 20:32:27 -0700708 void DumpClass(std::ostream& os, int flags) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800709
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800710 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700711 DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800712
Mathieu Chartier91a6dc42014-12-01 10:31:15 -0800713 // Also updates the dex_cache_strings_ variable from new_dex_cache.
Mathieu Chartier90443472015-07-16 20:32:27 -0700714 void SetDexCache(DexCache* new_dex_cache) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800715
Andreas Gampe542451c2016-07-26 09:02:02 -0700716 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDirectMethods(PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700717 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800718
Alex Lighte64300b2015-12-15 15:02:47 -0800719 ALWAYS_INLINE LengthPrefixedArray<ArtMethod>* GetMethodsPtr()
720 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700721
David Srbecky9b3607d2016-01-14 18:15:54 +0000722 static MemberOffset MethodsOffset() {
723 return MemberOffset(OFFSETOF_MEMBER(Class, methods_));
724 }
725
Andreas Gampe542451c2016-07-26 09:02:02 -0700726 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetMethods(PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -0800727 SHARED_REQUIRES(Locks::mutator_lock_);
728
729 void SetMethodsPtr(LengthPrefixedArray<ArtMethod>* new_methods,
730 uint32_t num_direct,
731 uint32_t num_virtual)
Mathieu Chartier90443472015-07-16 20:32:27 -0700732 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700733 // Used by image writer.
Alex Lighte64300b2015-12-15 15:02:47 -0800734 void SetMethodsPtrUnchecked(LengthPrefixedArray<ArtMethod>* new_methods,
735 uint32_t num_direct,
736 uint32_t num_virtual)
737 SHARED_REQUIRES(Locks::mutator_lock_);
738
739 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700740 ALWAYS_INLINE ArraySlice<ArtMethod> GetDirectMethodsSlice(PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700741 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700742
Andreas Gampe542451c2016-07-26 09:02:02 -0700743 ALWAYS_INLINE ArtMethod* GetDirectMethod(size_t i, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700744 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700745
746 // Use only when we are allocating populating the method arrays.
Andreas Gampe542451c2016-07-26 09:02:02 -0700747 ALWAYS_INLINE ArtMethod* GetDirectMethodUnchecked(size_t i, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700748 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe542451c2016-07-26 09:02:02 -0700749 ALWAYS_INLINE ArtMethod* GetVirtualMethodUnchecked(size_t i, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700750 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700751
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800752 // Returns the number of static, private, and constructor methods.
Mathieu Chartier54d220e2015-07-30 16:20:06 -0700753 ALWAYS_INLINE uint32_t NumDirectMethods() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800754
Mathieu Chartier4e305412014-02-19 10:54:44 -0800755 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700756 ALWAYS_INLINE ArraySlice<ArtMethod> GetMethodsSlice(PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -0800757 SHARED_REQUIRES(Locks::mutator_lock_);
758
759 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700760 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredMethodsSlice(PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -0800761 SHARED_REQUIRES(Locks::mutator_lock_);
762
763 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDeclaredMethods(
Andreas Gampe542451c2016-07-26 09:02:02 -0700764 PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -0800765 SHARED_REQUIRES(Locks::mutator_lock_);
766
Andreas Gampe542451c2016-07-26 09:02:02 -0700767 template <PointerSize kPointerSize, bool kTransactionActive>
Andreas Gampebc4d2182016-02-22 10:03:12 -0800768 static Method* GetDeclaredMethodInternal(Thread* self,
769 mirror::Class* klass,
770 mirror::String* name,
771 mirror::ObjectArray<mirror::Class>* args)
772 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe542451c2016-07-26 09:02:02 -0700773 template <PointerSize kPointerSize, bool kTransactionActive>
Andreas Gampe6039e562016-04-05 18:18:43 -0700774 static Constructor* GetDeclaredConstructorInternal(Thread* self,
775 mirror::Class* klass,
776 mirror::ObjectArray<mirror::Class>* args)
777 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampebc4d2182016-02-22 10:03:12 -0800778
Alex Lighte64300b2015-12-15 15:02:47 -0800779 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700780 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredVirtualMethodsSlice(PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -0800781 SHARED_REQUIRES(Locks::mutator_lock_);
782
783 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDeclaredVirtualMethods(
Andreas Gampe542451c2016-07-26 09:02:02 -0700784 PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -0800785 SHARED_REQUIRES(Locks::mutator_lock_);
786
787 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700788 ALWAYS_INLINE ArraySlice<ArtMethod> GetCopiedMethodsSlice(PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -0800789 SHARED_REQUIRES(Locks::mutator_lock_);
790
Andreas Gampe542451c2016-07-26 09:02:02 -0700791 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetCopiedMethods(PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -0800792 SHARED_REQUIRES(Locks::mutator_lock_);
793
794 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700795 ALWAYS_INLINE ArraySlice<ArtMethod> GetVirtualMethodsSlice(PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700796 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700797
Andreas Gampe542451c2016-07-26 09:02:02 -0700798 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetVirtualMethods(
799 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700800 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700801
Alex Lighte64300b2015-12-15 15:02:47 -0800802 // Returns the number of non-inherited virtual methods (sum of declared and copied methods).
Mathieu Chartier54d220e2015-07-30 16:20:06 -0700803 ALWAYS_INLINE uint32_t NumVirtualMethods() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800804
Alex Lighte64300b2015-12-15 15:02:47 -0800805 // Returns the number of copied virtual methods.
806 ALWAYS_INLINE uint32_t NumCopiedVirtualMethods() SHARED_REQUIRES(Locks::mutator_lock_);
807
808 // Returns the number of declared virtual methods.
809 ALWAYS_INLINE uint32_t NumDeclaredVirtualMethods() SHARED_REQUIRES(Locks::mutator_lock_);
810
811 ALWAYS_INLINE uint32_t NumMethods() SHARED_REQUIRES(Locks::mutator_lock_);
812
Mathieu Chartier4e305412014-02-19 10:54:44 -0800813 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampe542451c2016-07-26 09:02:02 -0700814 ArtMethod* GetVirtualMethod(size_t i, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700815 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800816
Andreas Gampe542451c2016-07-26 09:02:02 -0700817 ArtMethod* GetVirtualMethodDuringLinking(size_t i, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700818 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800819
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800820 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
821 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700822 ALWAYS_INLINE PointerArray* GetVTable() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700823
Mathieu Chartier90443472015-07-16 20:32:27 -0700824 ALWAYS_INLINE PointerArray* GetVTableDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700825
Mathieu Chartier90443472015-07-16 20:32:27 -0700826 void SetVTable(PointerArray* new_vtable) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800827
828 static MemberOffset VTableOffset() {
829 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
830 }
831
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700832 static MemberOffset EmbeddedVTableLengthOffset() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700833 return MemberOffset(sizeof(Class));
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700834 }
835
Andreas Gampe542451c2016-07-26 09:02:02 -0700836 static MemberOffset ImtPtrOffset(PointerSize pointer_size) {
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000837 return MemberOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -0700838 RoundUp(EmbeddedVTableLengthOffset().Uint32Value() + sizeof(uint32_t),
839 static_cast<size_t>(pointer_size)));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000840 }
841
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800842 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
843 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000844 bool ShouldHaveImt() SHARED_REQUIRES(Locks::mutator_lock_) {
845 return ShouldHaveEmbeddedVTable<kVerifyFlags, kReadBarrierOption>();
846 }
847
848 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
849 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
850 bool ShouldHaveEmbeddedVTable() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800851 return IsInstantiable<kVerifyFlags, kReadBarrierOption>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700852 }
853
Mathieu Chartier90443472015-07-16 20:32:27 -0700854 bool HasVTable() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700855
Andreas Gampe542451c2016-07-26 09:02:02 -0700856 static MemberOffset EmbeddedVTableEntryOffset(uint32_t i, PointerSize pointer_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700857
Mathieu Chartier90443472015-07-16 20:32:27 -0700858 int32_t GetVTableLength() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700859
Andreas Gampe542451c2016-07-26 09:02:02 -0700860 ArtMethod* GetVTableEntry(uint32_t i, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700861 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700862
Mathieu Chartier90443472015-07-16 20:32:27 -0700863 int32_t GetEmbeddedVTableLength() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700864
Mathieu Chartier90443472015-07-16 20:32:27 -0700865 void SetEmbeddedVTableLength(int32_t len) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700866
Andreas Gampe542451c2016-07-26 09:02:02 -0700867 ImTable* GetImt(PointerSize pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000868
Andreas Gampe542451c2016-07-26 09:02:02 -0700869 void SetImt(ImTable* imt, PointerSize pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000870
Andreas Gampe542451c2016-07-26 09:02:02 -0700871 ArtMethod* GetEmbeddedVTableEntry(uint32_t i, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700872 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700873
Andreas Gampe542451c2016-07-26 09:02:02 -0700874 void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700875 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700876
Andreas Gampe542451c2016-07-26 09:02:02 -0700877 inline void SetEmbeddedVTableEntryUnchecked(uint32_t i,
878 ArtMethod* method,
879 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700880 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700881
Andreas Gampe542451c2016-07-26 09:02:02 -0700882 void PopulateEmbeddedVTable(PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700883 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700884
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800885 // Given a method implemented by this class but potentially from a super class, return the
886 // specific implementation method for this class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700887 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700888 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800889
890 // Given a method implemented by this class' super class, return the specific implementation
891 // method for this class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700892 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700893 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800894
Alex Light705ad492015-09-21 11:36:30 -0700895 // Given a method from some implementor of this interface, return the specific implementation
896 // method for this class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700897 ArtMethod* FindVirtualMethodForInterfaceSuper(ArtMethod* method, PointerSize pointer_size)
Alex Light705ad492015-09-21 11:36:30 -0700898 SHARED_REQUIRES(Locks::mutator_lock_);
899
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800900 // Given a method implemented by this class, but potentially from a
901 // super class or interface, return the specific implementation
902 // method for this class.
Andreas Gampe542451c2016-07-26 09:02:02 -0700903 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700904 SHARED_REQUIRES(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800905
Andreas Gampe542451c2016-07-26 09:02:02 -0700906 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700907 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700908
Mathieu Chartiere401d142015-04-22 13:56:20 -0700909 ArtMethod* FindInterfaceMethod(const StringPiece& name, const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700910 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700911 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom004644f2014-06-18 08:34:01 -0700912
Mathieu Chartiere401d142015-04-22 13:56:20 -0700913 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700914 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700915 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800916
Mathieu Chartiere401d142015-04-22 13:56:20 -0700917 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700918 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700919 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800920
Mathieu Chartiere401d142015-04-22 13:56:20 -0700921 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700922 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700923 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800924
Mathieu Chartiere401d142015-04-22 13:56:20 -0700925 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700926 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700927 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700928
Mathieu Chartiere401d142015-04-22 13:56:20 -0700929 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700930 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700931 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800932
Mathieu Chartiere401d142015-04-22 13:56:20 -0700933 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700934 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700935 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800936
Mathieu Chartiere401d142015-04-22 13:56:20 -0700937 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700938 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700939 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700940
Mathieu Chartiere401d142015-04-22 13:56:20 -0700941 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700942 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700943 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800944
Mathieu Chartiere401d142015-04-22 13:56:20 -0700945 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700946 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700947 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700948
Mathieu Chartiere401d142015-04-22 13:56:20 -0700949 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700950 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700951 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700952
Mathieu Chartiere401d142015-04-22 13:56:20 -0700953 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700954 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700955 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700956
Andreas Gampe542451c2016-07-26 09:02:02 -0700957 ArtMethod* FindDeclaredVirtualMethodByName(const StringPiece& name, PointerSize pointer_size)
Jeff Hao13e748b2015-08-25 20:44:19 +0000958 SHARED_REQUIRES(Locks::mutator_lock_);
959
Andreas Gampe542451c2016-07-26 09:02:02 -0700960 ArtMethod* FindDeclaredDirectMethodByName(const StringPiece& name, PointerSize pointer_size)
Nicolas Geoffraya42363f2015-12-17 14:57:09 +0000961 SHARED_REQUIRES(Locks::mutator_lock_);
962
Mathieu Chartiere401d142015-04-22 13:56:20 -0700963 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700964 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700965 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700966
Mathieu Chartiere401d142015-04-22 13:56:20 -0700967 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature,
Andreas Gampe542451c2016-07-26 09:02:02 -0700968 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700969 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700970
Mathieu Chartiere401d142015-04-22 13:56:20 -0700971 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
Andreas Gampe542451c2016-07-26 09:02:02 -0700972 PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700973 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700974
Andreas Gampe542451c2016-07-26 09:02:02 -0700975 ArtMethod* FindClassInitializer(PointerSize pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700976
Alex Lighteb7c1442015-08-31 13:17:42 -0700977 bool HasDefaultMethods() SHARED_REQUIRES(Locks::mutator_lock_) {
978 return (GetAccessFlags() & kAccHasDefaultMethod) != 0;
979 }
980
981 bool HasBeenRecursivelyInitialized() SHARED_REQUIRES(Locks::mutator_lock_) {
982 return (GetAccessFlags() & kAccRecursivelyInitialized) != 0;
983 }
984
Mathieu Chartier90443472015-07-16 20:32:27 -0700985 ALWAYS_INLINE int32_t GetIfTableCount() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800986
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800987 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
988 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700989 ALWAYS_INLINE IfTable* GetIfTable() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800990
Mathieu Chartier90443472015-07-16 20:32:27 -0700991 ALWAYS_INLINE void SetIfTable(IfTable* new_iftable) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800992
993 // Get instance fields of the class (See also GetSFields).
Mathieu Chartier54d220e2015-07-30 16:20:06 -0700994 LengthPrefixedArray<ArtField>* GetIFieldsPtr() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800995
Mathieu Chartier54d220e2015-07-30 16:20:06 -0700996 ALWAYS_INLINE IterationRange<StrideIterator<ArtField>> GetIFields()
997 SHARED_REQUIRES(Locks::mutator_lock_);
998
999 void SetIFieldsPtr(LengthPrefixedArray<ArtField>* new_ifields)
1000 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001001
Mathieu Chartierc7853442015-03-27 14:35:38 -07001002 // Unchecked edition has no verification flags.
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001003 void SetIFieldsPtrUnchecked(LengthPrefixedArray<ArtField>* new_sfields)
1004 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001005
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001006 uint32_t NumInstanceFields() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -07001007 ArtField* GetInstanceField(uint32_t i) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001008
Mathieu Chartier66c2d2d2015-08-25 14:32:32 -07001009 // Returns the number of instance fields containing reference types. Does not count fields in any
1010 // super classes.
Mathieu Chartier90443472015-07-16 20:32:27 -07001011 uint32_t NumReferenceInstanceFields() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001012 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001013 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001014 }
1015
Mathieu Chartier90443472015-07-16 20:32:27 -07001016 uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001017 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001018 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001019 }
1020
Mathieu Chartier90443472015-07-16 20:32:27 -07001021 void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001022 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001023 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001024 }
1025
Mathieu Chartier4e305412014-02-19 10:54:44 -08001026 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -07001027 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001028
1029 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
Mathieu Chartier90443472015-07-16 20:32:27 -07001030 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001031
Vladimir Marko76649e82014-11-10 18:32:59 +00001032 // Get the offset of the first reference instance field. Other reference instance fields follow.
Hiroshi Yamauchi5496f692016-02-17 13:29:59 -08001033 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1034 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartiere401d142015-04-22 13:56:20 -07001035 MemberOffset GetFirstReferenceInstanceFieldOffset()
Mathieu Chartier90443472015-07-16 20:32:27 -07001036 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko76649e82014-11-10 18:32:59 +00001037
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001038 // Returns the number of static fields containing reference types.
Mathieu Chartier90443472015-07-16 20:32:27 -07001039 uint32_t NumReferenceStaticFields() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001040 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001041 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001042 }
1043
Mathieu Chartier90443472015-07-16 20:32:27 -07001044 uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001045 DCHECK(IsLoaded() || IsErroneous() || IsRetired());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001046 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001047 }
1048
Mathieu Chartier90443472015-07-16 20:32:27 -07001049 void SetNumReferenceStaticFields(uint32_t new_num) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001050 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001051 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001052 }
1053
Vladimir Marko76649e82014-11-10 18:32:59 +00001054 // Get the offset of the first reference static field. Other reference static fields follow.
Mathieu Chartierdfe02f62016-02-01 20:15:11 -08001055 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1056 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampe542451c2016-07-26 09:02:02 -07001057 MemberOffset GetFirstReferenceStaticFieldOffset(PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -07001058 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko76649e82014-11-10 18:32:59 +00001059
1060 // Get the offset of the first reference static field. Other reference static fields follow.
Andreas Gampe542451c2016-07-26 09:02:02 -07001061 MemberOffset GetFirstReferenceStaticFieldOffsetDuringLinking(PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -07001062 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko76649e82014-11-10 18:32:59 +00001063
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001064 // Gets the static fields of the class.
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001065 LengthPrefixedArray<ArtField>* GetSFieldsPtr() SHARED_REQUIRES(Locks::mutator_lock_);
1066 ALWAYS_INLINE IterationRange<StrideIterator<ArtField>> GetSFields()
1067 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001068
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001069 void SetSFieldsPtr(LengthPrefixedArray<ArtField>* new_sfields)
1070 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001071
Mathieu Chartierc7853442015-03-27 14:35:38 -07001072 // Unchecked edition has no verification flags.
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001073 void SetSFieldsPtrUnchecked(LengthPrefixedArray<ArtField>* new_sfields)
1074 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -07001075
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001076 uint32_t NumStaticFields() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001077
Ian Rogersef7d42f2014-01-06 12:55:46 -08001078 // TODO: uint16_t
Mathieu Chartier90443472015-07-16 20:32:27 -07001079 ArtField* GetStaticField(uint32_t i) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001080
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001081 // Find a static or instance field using the JLS resolution order
Mathieu Chartierf8322842014-05-16 10:59:25 -07001082 static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
1083 const StringPiece& type)
Mathieu Chartier90443472015-07-16 20:32:27 -07001084 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001085
1086 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -07001087 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Mathieu Chartier90443472015-07-16 20:32:27 -07001088 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001089
1090 // Finds the given instance field in this class or a superclass, only searches classes that
1091 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -07001092 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -07001093 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001094
Brian Carlstromea46f952013-07-30 01:26:50 -07001095 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Mathieu Chartier90443472015-07-16 20:32:27 -07001096 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001097
Brian Carlstromea46f952013-07-30 01:26:50 -07001098 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -07001099 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001100
1101 // Finds the given static field in this class or a superclass.
Mathieu Chartierf8322842014-05-16 10:59:25 -07001102 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
1103 const StringPiece& type)
Mathieu Chartier90443472015-07-16 20:32:27 -07001104 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001105
1106 // Finds the given static field in this class or superclass, only searches classes that
1107 // have the same dex cache.
Vladimir Markobb268b12016-06-30 15:52:56 +01001108 static ArtField* FindStaticField(Thread* self,
1109 Class* klass,
1110 const DexCache* dex_cache,
Mathieu Chartierf8322842014-05-16 10:59:25 -07001111 uint32_t dex_field_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -07001112 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001113
Brian Carlstromea46f952013-07-30 01:26:50 -07001114 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Mathieu Chartier90443472015-07-16 20:32:27 -07001115 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001116
Brian Carlstromea46f952013-07-30 01:26:50 -07001117 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -07001118 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001119
Mathieu Chartier90443472015-07-16 20:32:27 -07001120 pid_t GetClinitThreadId() SHARED_REQUIRES(Locks::mutator_lock_) {
Alex Light705ad492015-09-21 11:36:30 -07001121 DCHECK(IsIdxLoaded() || IsErroneous()) << PrettyClass(this);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001122 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001123 }
1124
Mathieu Chartier90443472015-07-16 20:32:27 -07001125 void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001126
Andreas Gampe99babb62015-11-02 16:20:00 -08001127 Object* GetVerifyError() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001128 // DCHECK(IsErroneous());
Andreas Gampe99babb62015-11-02 16:20:00 -08001129 return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001130 }
1131
Mathieu Chartier90443472015-07-16 20:32:27 -07001132 uint16_t GetDexClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001133 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001134 }
1135
Mathieu Chartier90443472015-07-16 20:32:27 -07001136 void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001137 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001138 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001139 }
1140
Mathieu Chartier90443472015-07-16 20:32:27 -07001141 uint16_t GetDexTypeIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001142 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001143 }
1144
Mathieu Chartier90443472015-07-16 20:32:27 -07001145 void SetDexTypeIndex(uint16_t type_idx) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001146 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001147 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001148 }
1149
Nicolas Geoffraye4084a52016-02-18 14:43:42 +00001150 uint32_t FindTypeIndexInOtherDexFile(const DexFile& dex_file)
1151 SHARED_REQUIRES(Locks::mutator_lock_);
1152
Mathieu Chartier90443472015-07-16 20:32:27 -07001153 static Class* GetJavaLangClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier31000802015-06-14 14:14:37 -07001154 DCHECK(HasJavaLangClass());
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001155 return java_lang_Class_.Read();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001156 }
1157
Mathieu Chartier90443472015-07-16 20:32:27 -07001158 static bool HasJavaLangClass() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier31000802015-06-14 14:14:37 -07001159 return !java_lang_Class_.IsNull();
1160 }
1161
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001162 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
Mathieu Chartier90443472015-07-16 20:32:27 -07001163 static void SetClassClass(Class* java_lang_Class) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001164 static void ResetClass();
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -07001165 static void VisitRoots(RootVisitor* visitor)
Mathieu Chartier90443472015-07-16 20:32:27 -07001166 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001167
Mathieu Chartiere401d142015-04-22 13:56:20 -07001168 // Visit native roots visits roots which are keyed off the native pointers such as ArtFields and
1169 // ArtMethods.
Hiroshi Yamauchi7a62e672016-06-10 17:22:48 -07001170 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, class Visitor>
Andreas Gampe542451c2016-07-26 09:02:02 -07001171 void VisitNativeRoots(Visitor& visitor, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -07001172 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -07001173
Igor Murashkindf707e42016-02-02 16:56:50 -08001174 // When class is verified, set the kAccSkipAccessChecks flag on each method.
Andreas Gampe542451c2016-07-26 09:02:02 -07001175 void SetSkipAccessChecksFlagOnAllMethods(PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -07001176 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz233ea8e2013-06-06 11:57:09 +02001177
Ian Rogers1ff3c982014-08-12 02:30:58 -07001178 // Get the descriptor of the class. In a few cases a std::string is required, rather than
1179 // always create one the storage argument is populated and its internal c_str() returned. We do
1180 // this to avoid memory allocation in the common case.
Mathieu Chartier90443472015-07-16 20:32:27 -07001181 const char* GetDescriptor(std::string* storage) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers1ff3c982014-08-12 02:30:58 -07001182
Mathieu Chartier90443472015-07-16 20:32:27 -07001183 const char* GetArrayDescriptor(std::string* storage) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001184
Mathieu Chartier90443472015-07-16 20:32:27 -07001185 bool DescriptorEquals(const char* match) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001186
Mathieu Chartier90443472015-07-16 20:32:27 -07001187 const DexFile::ClassDef* GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001188
Mathieu Chartier90443472015-07-16 20:32:27 -07001189 ALWAYS_INLINE uint32_t NumDirectInterfaces() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001190
Mathieu Chartier90443472015-07-16 20:32:27 -07001191 uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001192
Andreas Gampe5a4b8a22014-09-11 08:30:08 -07001193 static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass,
Mathieu Chartierbf99f772014-08-23 16:37:27 -07001194 uint32_t idx)
Mathieu Chartier90443472015-07-16 20:32:27 -07001195 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001196
Mathieu Chartier90443472015-07-16 20:32:27 -07001197 const char* GetSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001198
Mathieu Chartier90443472015-07-16 20:32:27 -07001199 std::string GetLocation() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001200
Mathieu Chartier90443472015-07-16 20:32:27 -07001201 const DexFile& GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001202
Mathieu Chartier90443472015-07-16 20:32:27 -07001203 const DexFile::TypeList* GetInterfaceTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierf8322842014-05-16 10:59:25 -07001204
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +02001205 // Asserts we are initialized or initializing in the given thread.
1206 void AssertInitializedOrInitializingInThread(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -07001207 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +02001208
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001209 Class* CopyOf(Thread* self, int32_t new_length, ImTable* imt,
Andreas Gampe542451c2016-07-26 09:02:02 -07001210 PointerSize pointer_size)
Mathieu Chartiered8990a2015-07-23 14:11:16 -07001211 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001212
Nicolas Geoffraya7a47592015-11-24 09:17:30 +00001213 // For proxy class only.
1214 ObjectArray<Class>* GetInterfaces() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001215
Nicolas Geoffraya7a47592015-11-24 09:17:30 +00001216 // For proxy class only.
1217 ObjectArray<ObjectArray<Class>>* GetThrows() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001218
Fred Shih4ee7a662014-07-11 09:59:27 -07001219 // For reference class only.
Mathieu Chartier90443472015-07-16 20:32:27 -07001220 MemberOffset GetDisableIntrinsicFlagOffset() SHARED_REQUIRES(Locks::mutator_lock_);
1221 MemberOffset GetSlowPathFlagOffset() SHARED_REQUIRES(Locks::mutator_lock_);
1222 bool GetSlowPathEnabled() SHARED_REQUIRES(Locks::mutator_lock_);
1223 void SetSlowPath(bool enabled) SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih4ee7a662014-07-11 09:59:27 -07001224
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07001225 StringDexCacheType* GetDexCacheStrings() SHARED_REQUIRES(Locks::mutator_lock_);
1226 void SetDexCacheStrings(StringDexCacheType* new_dex_cache_strings)
Mathieu Chartier90443472015-07-16 20:32:27 -07001227 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiereace4582014-11-24 18:29:54 -08001228 static MemberOffset DexCacheStringsOffset() {
1229 return OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_strings_);
1230 }
1231
Mathieu Chartierfc58af42015-04-16 18:00:39 -07001232 // May cause thread suspension due to EqualParameters.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001233 ArtMethod* GetDeclaredConstructor(
Andreas Gampe542451c2016-07-26 09:02:02 -07001234 Thread* self, Handle<mirror::ObjectArray<mirror::Class>> args, PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -07001235 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -07001236
Andreas Gampe715fdc22016-04-18 17:07:30 -07001237 static int32_t GetInnerClassFlags(Handle<Class> h_this, int32_t default_value)
1238 SHARED_REQUIRES(Locks::mutator_lock_);
1239
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001240 // Used to initialize a class in the allocation code path to ensure it is guarded by a StoreStore
1241 // fence.
1242 class InitializeClassVisitor {
1243 public:
1244 explicit InitializeClassVisitor(uint32_t class_size) : class_size_(class_size) {
1245 }
1246
1247 void operator()(mirror::Object* obj, size_t usable_size) const
Mathieu Chartier90443472015-07-16 20:32:27 -07001248 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001249
1250 private:
1251 const uint32_t class_size_;
1252
1253 DISALLOW_COPY_AND_ASSIGN(InitializeClassVisitor);
1254 };
1255
Sebastien Hertz6963e442014-11-26 22:11:27 +01001256 // Returns true if the class loader is null, ie the class loader is the boot strap class loader.
Mathieu Chartier90443472015-07-16 20:32:27 -07001257 bool IsBootStrapClassLoaded() SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz6963e442014-11-26 22:11:27 +01001258 return GetClassLoader() == nullptr;
1259 }
1260
Andreas Gampe542451c2016-07-26 09:02:02 -07001261 static size_t ImTableEntrySize(PointerSize pointer_size) {
1262 return static_cast<size_t>(pointer_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001263 }
1264
Andreas Gampe542451c2016-07-26 09:02:02 -07001265 static size_t VTableEntrySize(PointerSize pointer_size) {
1266 return static_cast<size_t>(pointer_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001267 }
1268
Andreas Gampe542451c2016-07-26 09:02:02 -07001269 ALWAYS_INLINE ArraySlice<ArtMethod> GetDirectMethodsSliceUnchecked(PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -07001270 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001271
Andreas Gampe542451c2016-07-26 09:02:02 -07001272 ALWAYS_INLINE ArraySlice<ArtMethod> GetVirtualMethodsSliceUnchecked(PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -08001273 SHARED_REQUIRES(Locks::mutator_lock_);
1274
Andreas Gampe542451c2016-07-26 09:02:02 -07001275 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredMethodsSliceUnchecked(PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -08001276 SHARED_REQUIRES(Locks::mutator_lock_);
1277
Andreas Gampe542451c2016-07-26 09:02:02 -07001278 ALWAYS_INLINE ArraySlice<ArtMethod> GetDeclaredVirtualMethodsSliceUnchecked(
1279 PointerSize pointer_size)
Alex Lighte64300b2015-12-15 15:02:47 -08001280 SHARED_REQUIRES(Locks::mutator_lock_);
1281
Andreas Gampe542451c2016-07-26 09:02:02 -07001282 ALWAYS_INLINE ArraySlice<ArtMethod> GetCopiedMethodsSliceUnchecked(PointerSize pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -07001283 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001284
Mathieu Chartier4b00d342015-11-13 10:42:08 -08001285 // Fix up all of the native pointers in the class by running them through the visitor. Only sets
1286 // the corresponding entry in dest if visitor(obj) != obj to prevent dirty memory. Dest should be
Mathieu Chartierfbc31082016-01-24 11:59:56 -08001287 // initialized to a copy of *this to prevent issues. Does not visit the ArtMethod and ArtField
1288 // roots.
Mathieu Chartierdfe02f62016-02-01 20:15:11 -08001289 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1290 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
1291 typename Visitor>
Andreas Gampe542451c2016-07-26 09:02:02 -07001292 void FixupNativePointers(mirror::Class* dest, PointerSize pointer_size, const Visitor& visitor)
Mathieu Chartier4b00d342015-11-13 10:42:08 -08001293 SHARED_REQUIRES(Locks::mutator_lock_);
1294
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001295 private:
Alex Lighte64300b2015-12-15 15:02:47 -08001296 ALWAYS_INLINE void SetMethodsPtrInternal(LengthPrefixedArray<ArtMethod>* new_methods)
1297 SHARED_REQUIRES(Locks::mutator_lock_);
1298
Andreas Gampe99babb62015-11-02 16:20:00 -08001299 void SetVerifyError(Object* klass) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001300
Vladimir Marko89786432014-01-31 15:03:55 +00001301 template <bool throw_on_failure, bool use_referrers_cache>
1302 bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001303 uint32_t field_idx, DexCache* dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -07001304 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko89786432014-01-31 15:03:55 +00001305 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
1306 bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001307 uint32_t method_idx, DexCache* dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -07001308 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko89786432014-01-31 15:03:55 +00001309
Mathieu Chartier90443472015-07-16 20:32:27 -07001310 bool Implements(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
1311 bool IsArrayAssignableFromArray(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
1312 bool IsAssignableFromArray(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001313
Mathieu Chartier90443472015-07-16 20:32:27 -07001314 void CheckObjectAlloc() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001315
Mathieu Chartierc7853442015-03-27 14:35:38 -07001316 // Unchecked editions is for root visiting.
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001317 LengthPrefixedArray<ArtField>* GetSFieldsPtrUnchecked() SHARED_REQUIRES(Locks::mutator_lock_);
1318 IterationRange<StrideIterator<ArtField>> GetSFieldsUnchecked()
1319 SHARED_REQUIRES(Locks::mutator_lock_);
1320 LengthPrefixedArray<ArtField>* GetIFieldsPtrUnchecked() SHARED_REQUIRES(Locks::mutator_lock_);
1321 IterationRange<StrideIterator<ArtField>> GetIFieldsUnchecked()
1322 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -07001323
Alex Lighte64300b2015-12-15 15:02:47 -08001324 // The index in the methods_ array where the first declared virtual method is.
1325 ALWAYS_INLINE uint32_t GetVirtualMethodsStartOffset() SHARED_REQUIRES(Locks::mutator_lock_);
1326
1327 // The index in the methods_ array where the first direct method is.
1328 ALWAYS_INLINE uint32_t GetDirectMethodsStartOffset() SHARED_REQUIRES(Locks::mutator_lock_);
1329
1330 // The index in the methods_ array where the first copied method is.
1331 ALWAYS_INLINE uint32_t GetCopiedMethodsStartOffset() SHARED_REQUIRES(Locks::mutator_lock_);
1332
Nicolas Geoffraya7a47592015-11-24 09:17:30 +00001333 bool ProxyDescriptorEquals(const char* match) SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko3481ba22015-04-13 12:22:36 +01001334
Roland Levillain0d5a2812015-11-13 10:07:31 +00001335 // Check that the pointer size matches the one in the class linker.
Andreas Gampe542451c2016-07-26 09:02:02 -07001336 ALWAYS_INLINE static void CheckPointerSize(PointerSize pointer_size);
1337
1338 static MemberOffset EmbeddedVTableOffset(PointerSize pointer_size);
Mathieu Chartierfbc31082016-01-24 11:59:56 -08001339 template <bool kVisitNativeRoots,
1340 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
1341 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
1342 typename Visitor>
Mathieu Chartier059ef3d2015-08-18 13:54:21 -07001343 void VisitReferences(mirror::Class* klass, const Visitor& visitor)
1344 SHARED_REQUIRES(Locks::mutator_lock_);
1345
Alex Lighte64300b2015-12-15 15:02:47 -08001346 // 'Class' Object Fields
1347 // Order governed by java field ordering. See art::ClassLinker::LinkFields.
1348
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001349 // Defining class loader, or null for the "bootstrap" system loader.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001350 HeapReference<ClassLoader> class_loader_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001351
1352 // For array classes, the component class object for instanceof/checkcast
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001353 // (for String[][][], this will be String[][]). null for non-array classes.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001354 HeapReference<Class> component_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001355
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001356 // DexCache of resolved constant pool entries (will be null for classes generated by the
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001357 // runtime such as arrays and primitive classes).
Ian Rogersef7d42f2014-01-06 12:55:46 -08001358 HeapReference<DexCache> dex_cache_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001359
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001360 // The interface table (iftable_) contains pairs of a interface class and an array of the
1361 // interface methods. There is one pair per interface supported by this class. That means one
1362 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
1363 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
1364 //
1365 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
1366 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
1367 // single vtable.
1368 //
1369 // For every interface a concrete class implements, we create an array of the concrete vtable_
1370 // methods for the methods in the interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001371 HeapReference<IfTable> iftable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001372
Ian Rogersef7d42f2014-01-06 12:55:46 -08001373 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
1374 HeapReference<String> name_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001375
Brian Carlstrom08ac9222015-05-22 13:43:00 -07001376 // The superclass, or null if this is java.lang.Object or a primitive type.
1377 //
1378 // Note that interfaces have java.lang.Object as their
1379 // superclass. This doesn't match the expectations in JNI
1380 // GetSuperClass or java.lang.Class.getSuperClass() which need to
1381 // check for interfaces and return null.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001382 HeapReference<Class> super_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001383
Andreas Gampe99babb62015-11-02 16:20:00 -08001384 // If class verify fails, we must return same error on subsequent tries. We may store either
1385 // the class of the error, or an actual instance of Throwable here.
1386 HeapReference<Object> verify_error_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001387
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001388 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
1389 // copied in, and virtual methods from our class either replace those from the super or are
1390 // appended. For abstract classes, methods may be created in the vtable that aren't in
1391 // virtual_ methods_ for miranda methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001392 HeapReference<PointerArray> vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001393
Vladimir Marko05792b92015-08-03 11:56:49 +01001394 // Short cuts to dex_cache_ member for fast compiled code access.
1395 uint64_t dex_cache_strings_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001396
Mathieu Chartierc7853442015-03-27 14:35:38 -07001397 // instance fields
1398 //
1399 // These describe the layout of the contents of an Object.
1400 // Note that only the fields directly declared by this class are
1401 // listed in ifields; fields declared by a superclass are listed in
1402 // the superclass's Class.ifields.
1403 //
Mathieu Chartierc0fe56a2015-08-11 13:01:23 -07001404 // ArtFields are allocated as a length prefixed ArtField array, and not an array of pointers to
1405 // ArtFields.
Mathieu Chartierc7853442015-03-27 14:35:38 -07001406 uint64_t ifields_;
1407
Alex Lighte64300b2015-12-15 15:02:47 -08001408 // Pointer to an ArtMethod length-prefixed array. All the methods where this class is the place
1409 // where they are logically defined. This includes all private, static, final and virtual methods
1410 // as well as inherited default methods and miranda methods.
1411 //
1412 // The slice methods_ [0, virtual_methods_offset_) are the direct (static, private, init) methods
1413 // declared by this class.
1414 //
1415 // The slice methods_ [virtual_methods_offset_, copied_methods_offset_) are the virtual methods
1416 // declared by this class.
1417 //
1418 // The slice methods_ [copied_methods_offset_, |methods_|) are the methods that are copied from
1419 // interfaces such as miranda or default methods. These are copied for resolution purposes as this
1420 // class is where they are (logically) declared as far as the virtual dispatch is concerned.
David Srbecky9b3607d2016-01-14 18:15:54 +00001421 //
1422 // Note that this field is used by the native debugger as the unique identifier for the type.
Alex Lighte64300b2015-12-15 15:02:47 -08001423 uint64_t methods_;
1424
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001425 // Static fields length-prefixed array.
Mathieu Chartierc7853442015-03-27 14:35:38 -07001426 uint64_t sfields_;
1427
Neil Fuller3d0aa882016-08-16 19:53:07 +01001428 // Access flags; low 16 bits are defined by VM spec.
1429 uint32_t access_flags_;
1430
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -07001431 // Class flags to help speed up visiting object references.
1432 uint32_t class_flags_;
1433
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001434 // Total size of the Class instance; used when allocating storage on gc heap.
1435 // See also object_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001436 uint32_t class_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001437
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001438 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001439 pid_t clinit_thread_id_;
1440
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001441 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001442 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001443 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001444
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001445 // Type index in dex file.
1446 // TODO: really 16bits
1447 int32_t dex_type_idx_;
1448
1449 // Number of instance fields that are object refs.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001450 uint32_t num_reference_instance_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001451
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001452 // Number of static fields that are object refs,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001453 uint32_t num_reference_static_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001454
1455 // Total object size; used when allocating storage on gc heap.
1456 // (For interfaces and abstract classes this will be zero.)
1457 // See also class_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001458 uint32_t object_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001459
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -07001460 // The lower 16 bits contains a Primitive::Type value. The upper 16
1461 // bits contains the size shift of the primitive type.
1462 uint32_t primitive_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001463
1464 // Bitmap of offsets of ifields.
1465 uint32_t reference_instance_offsets_;
1466
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001467 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001468 Status status_;
1469
Alex Lighte64300b2015-12-15 15:02:47 -08001470 // The offset of the first virtual method that is copied from an interface. This includes miranda,
1471 // default, and default-conflict methods. Having a hard limit of ((2 << 16) - 1) for methods
1472 // defined on a single class is well established in Java so we will use only uint16_t's here.
1473 uint16_t copied_methods_offset_;
1474
1475 // The offset of the first declared virtual methods in the methods_ array.
1476 uint16_t virtual_methods_offset_;
1477
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001478 // TODO: ?
1479 // initiating class loader list
1480 // NOTE: for classes with low serialNumber, these are unused, and the
1481 // values are kept in a table in gDvm.
1482 // InitiatingLoaderList initiating_loader_list_;
1483
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001484 // The following data exist in real class objects.
1485 // Embedded Imtable, for class object that's not an interface, fixed size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001486 // ImTableEntry embedded_imtable_[0];
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001487 // Embedded Vtable, for class object that's not an interface, variable size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001488 // VTableEntry embedded_vtable_[0];
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001489 // Static fields, variable size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001490 // uint32_t fields_[0];
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001491
1492 // java.lang.Class
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001493 static GcRoot<Class> java_lang_Class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001494
1495 friend struct art::ClassOffsets; // for verifying offset information
Mathieu Chartier059ef3d2015-08-18 13:54:21 -07001496 friend class Object; // For VisitReferences
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001497 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
1498};
1499
1500std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1501
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001502} // namespace mirror
1503} // namespace art
1504
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001505#endif // ART_RUNTIME_MIRROR_CLASS_H_