blob: 40c9975cdd6a314c7cccac2ee97f4a6d0915c592 [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
Mathieu Chartierf8322842014-05-16 10:59:25 -070020#include "dex_file.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070021#include "gc/allocator_type.h"
Vladimir Marko23a28212014-01-09 19:24:37 +000022#include "invoke_type.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "modifiers.h"
24#include "object.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070025#include "object_callbacks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "primitive.h"
27
28/*
29 * A magic value for refOffsets. Ignore the bits and walk the super
30 * chain when this is the value.
31 * [This is an unlikely "natural" value, since it would be 30 non-ref instance
32 * fields followed by 2 ref instance fields.]
33 */
Brian Carlstromfb6996f2013-07-18 18:21:14 -070034#define CLASS_WALK_SUPER 3U
35#define CLASS_BITS_PER_WORD (sizeof(uint32_t) * 8)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036#define CLASS_OFFSET_ALIGNMENT 4
Brian Carlstromfb6996f2013-07-18 18:21:14 -070037#define CLASS_HIGH_BIT (1U << (CLASS_BITS_PER_WORD - 1))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038/*
39 * Given an offset, return the bit number which would encode that offset.
40 * Local use only.
41 */
42#define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \
43 ((unsigned int)(byteOffset) / \
44 CLASS_OFFSET_ALIGNMENT)
45/*
46 * Is the given offset too large to be encoded?
47 */
48#define CLASS_CAN_ENCODE_OFFSET(byteOffset) \
49 (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD)
50/*
51 * Return a single bit, encoding the offset.
52 * Undefined if the offset is too large, as defined above.
53 */
54#define CLASS_BIT_FROM_OFFSET(byteOffset) \
55 (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset))
56/*
57 * Return an offset, given a bit number as returned from CLZ.
58 */
59#define CLASS_OFFSET_FROM_CLZ(rshift) \
60 MemberOffset((static_cast<int>(rshift) * CLASS_OFFSET_ALIGNMENT))
61
62namespace art {
63
64struct ClassClassOffsets;
65struct ClassOffsets;
Ian Rogersd91d6d62013-09-25 20:26:14 -070066class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067class StringPiece;
68
69namespace mirror {
70
Brian Carlstromea46f952013-07-30 01:26:50 -070071class ArtField;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072class ClassLoader;
73class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074class IfTable;
75
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076// C++ mirror of java.lang.Class
Ian Rogers5ddb4102014-01-07 08:58:46 -080077class MANAGED Class : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078 public:
79 // Class Status
80 //
81 // kStatusNotReady: If a Class cannot be found in the class table by
82 // FindClass, it allocates an new one with AllocClass in the
83 // kStatusNotReady and calls LoadClass. Note if it does find a
84 // class, it may not be kStatusResolved and it will try to push it
85 // forward toward kStatusResolved.
86 //
87 // kStatusIdx: LoadClass populates with Class with information from
88 // the DexFile, moving the status to kStatusIdx, indicating that the
89 // Class value in super_class_ has not been populated. The new Class
90 // can then be inserted into the classes table.
91 //
92 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
93 // attempt to move a kStatusIdx class forward to kStatusLoaded by
94 // using ResolveClass to initialize the super_class_ and ensuring the
95 // interfaces are resolved.
96 //
97 // kStatusResolved: Still holding the lock on Class, the ClassLinker
98 // shows linking is complete and fields of the Class populated by making
99 // it kStatusResolved. Java allows circularities of the form where a super
100 // class has a field that is of the type of the sub class. We need to be able
101 // to fully resolve super classes while resolving types for fields.
102 //
103 // kStatusRetryVerificationAtRuntime: The verifier sets a class to
104 // this state if it encounters a soft failure at compile time. This
105 // often happens when there are unresolved classes in other dex
106 // files, and this status marks a class as needing to be verified
107 // again at runtime.
108 //
109 // TODO: Explain the other states
110 enum Status {
111 kStatusError = -1,
112 kStatusNotReady = 0,
113 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
114 kStatusLoaded = 2, // DEX idx values resolved.
115 kStatusResolved = 3, // Part of linking.
116 kStatusVerifying = 4, // In the process of being verified.
117 kStatusRetryVerificationAtRuntime = 5, // Compile time verification failed, retry at runtime.
118 kStatusVerifyingAtRuntime = 6, // Retrying verification at runtime.
119 kStatusVerified = 7, // Logically part of linking; done pre-init.
120 kStatusInitializing = 8, // Class init in progress.
121 kStatusInitialized = 9, // Ready to go.
Brian Carlstromba150c32013-08-27 17:31:03 -0700122 kStatusMax = 10,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800123 };
124
Mathieu Chartier4e305412014-02-19 10:54:44 -0800125 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800126 Status GetStatus() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800127 COMPILE_ASSERT(sizeof(Status) == sizeof(uint32_t), size_of_status_not_uint32);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700128 return static_cast<Status>(GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129 }
130
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700131 void SetStatus(Status new_status, Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132
Ian Rogers5ddb4102014-01-07 08:58:46 -0800133 static MemberOffset StatusOffset() {
134 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
135 }
136
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137 // Returns true if the class has failed to link.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800138 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800139 bool IsErroneous() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800140 return GetStatus<kVerifyFlags>() == kStatusError;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800141 }
142
143 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800144 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145 bool IsIdxLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800146 return GetStatus<kVerifyFlags>() >= kStatusIdx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800147 }
148
149 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800150 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800151 bool IsLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800152 return GetStatus<kVerifyFlags>() >= kStatusLoaded;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 }
154
155 // Returns true if the class has been linked.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800156 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800157 bool IsResolved() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800158 return GetStatus<kVerifyFlags>() >= kStatusResolved;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159 }
160
161 // Returns true if the class was compile-time verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800162 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800163 bool IsCompileTimeVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800164 return GetStatus<kVerifyFlags>() >= kStatusRetryVerificationAtRuntime;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800165 }
166
167 // Returns true if the class has been verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800168 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800169 bool IsVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800170 return GetStatus<kVerifyFlags>() >= kStatusVerified;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800171 }
172
173 // Returns true if the class is initializing.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800174 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800175 bool IsInitializing() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800176 return GetStatus<kVerifyFlags>() >= kStatusInitializing;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177 }
178
179 // Returns true if the class is initialized.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800180 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800181 bool IsInitialized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800182 return GetStatus<kVerifyFlags>() == kStatusInitialized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800183 }
184
Mathieu Chartier4e305412014-02-19 10:54:44 -0800185 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800186 uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187
Ian Rogersef7d42f2014-01-06 12:55:46 -0800188 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100189 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700190 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), new_access_flags);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800191 }
192
193 // Returns true if the class is an interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800194 bool IsInterface() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195 return (GetAccessFlags() & kAccInterface) != 0;
196 }
197
198 // Returns true if the class is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800199 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 return (GetAccessFlags() & kAccPublic) != 0;
201 }
202
203 // Returns true if the class is declared final.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800204 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205 return (GetAccessFlags() & kAccFinal) != 0;
206 }
207
Ian Rogersef7d42f2014-01-06 12:55:46 -0800208 bool IsFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
210 }
211
Ian Rogersef7d42f2014-01-06 12:55:46 -0800212 void SetFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700213 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 SetAccessFlags(flags | kAccClassIsFinalizable);
215 }
216
217 // Returns true if the class is abstract.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800218 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219 return (GetAccessFlags() & kAccAbstract) != 0;
220 }
221
222 // Returns true if the class is an annotation.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800223 bool IsAnnotation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800224 return (GetAccessFlags() & kAccAnnotation) != 0;
225 }
226
227 // Returns true if the class is synthetic.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800228 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800229 return (GetAccessFlags() & kAccSynthetic) != 0;
230 }
231
Mathieu Chartier4e305412014-02-19 10:54:44 -0800232 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800233 bool IsReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800234 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800235 }
236
Mathieu Chartier4e305412014-02-19 10:54:44 -0800237 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800238 bool IsWeakReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800239 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsWeakReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800240 }
241
Mathieu Chartier4e305412014-02-19 10:54:44 -0800242 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800243 bool IsSoftReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800244 return (GetAccessFlags<kVerifyFlags>() & kAccReferenceFlagsMask) == kAccClassIsReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800245 }
246
Mathieu Chartier4e305412014-02-19 10:54:44 -0800247 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800248 bool IsFinalizerReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800249 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsFinalizerReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800250 }
251
Mathieu Chartier4e305412014-02-19 10:54:44 -0800252 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800253 bool IsPhantomReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800254 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsPhantomReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800255 }
256
Ian Rogers04f94f42013-06-10 15:09:26 -0700257 // Can references of this type be assigned to by things of another type? For non-array types
258 // this is a matter of whether sub-classes may exist - which they can't if the type is final.
259 // For array classes, where all the classes are final due to there being no sub-classes, an
260 // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
261 // types as the component is final.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800262 bool CannotBeAssignedFromOtherTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers04f94f42013-06-10 15:09:26 -0700263 if (!IsArrayClass()) {
264 return IsFinal();
265 } else {
266 Class* component = GetComponentType();
267 if (component->IsPrimitive()) {
Ian Rogersa9a82542013-10-04 11:17:26 -0700268 return true;
Ian Rogers04f94f42013-06-10 15:09:26 -0700269 } else {
270 return component->CannotBeAssignedFromOtherTypes();
271 }
272 }
273 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800274
Ian Rogersef7d42f2014-01-06 12:55:46 -0800275 String* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Returns the cached name.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800276 void SetName(String* name) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Sets the cached name.
277 // Computes the name, then sets the cached value.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700278 static String* ComputeName(Handle<Class> h_this) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800279
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800280 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier4e305412014-02-19 10:54:44 -0800281 bool IsProxyClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800282 // Read access flags without using getter as whether something is a proxy can be check in
283 // any loaded state
284 // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700285 uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800286 return (access_flags & kAccClassIsProxy) != 0;
287 }
288
Mathieu Chartier4e305412014-02-19 10:54:44 -0800289 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700290 Primitive::Type GetPrimitiveType() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800291
Ian Rogersef7d42f2014-01-06 12:55:46 -0800292 void SetPrimitiveType(Primitive::Type new_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800293 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700294 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), new_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800295 }
296
297 // Returns true if the class is a primitive type.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800298 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800299 bool IsPrimitive() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800300 return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800301 }
302
Mathieu Chartier4e305412014-02-19 10:54:44 -0800303 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800304 bool IsPrimitiveBoolean() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800305 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306 }
307
Mathieu Chartier4e305412014-02-19 10:54:44 -0800308 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800309 bool IsPrimitiveByte() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800310 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800311 }
312
Mathieu Chartier4e305412014-02-19 10:54:44 -0800313 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800314 bool IsPrimitiveChar() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800315 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800316 }
317
Mathieu Chartier4e305412014-02-19 10:54:44 -0800318 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800319 bool IsPrimitiveShort() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800320 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321 }
322
Mathieu Chartier4e305412014-02-19 10:54:44 -0800323 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800324 bool IsPrimitiveInt() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800325 return GetPrimitiveType() == Primitive::kPrimInt;
326 }
327
Mathieu Chartier4e305412014-02-19 10:54:44 -0800328 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800329 bool IsPrimitiveLong() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800330 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800331 }
332
Mathieu Chartier4e305412014-02-19 10:54:44 -0800333 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800334 bool IsPrimitiveFloat() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800335 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800336 }
337
Mathieu Chartier4e305412014-02-19 10:54:44 -0800338 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800339 bool IsPrimitiveDouble() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800340 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800341 }
342
Mathieu Chartier4e305412014-02-19 10:54:44 -0800343 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800344 bool IsPrimitiveVoid() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800345 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800346 }
347
Mathieu Chartier4e305412014-02-19 10:54:44 -0800348 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800349 bool IsPrimitiveArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800350 return IsArrayClass<kVerifyFlags>() &&
351 GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
352 IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800353 }
354
355 // Depth of class from java.lang.Object
Ian Rogersef7d42f2014-01-06 12:55:46 -0800356 uint32_t Depth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
357 uint32_t depth = 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358 for (Class* klass = this; klass->GetSuperClass() != NULL; klass = klass->GetSuperClass()) {
359 depth++;
360 }
361 return depth;
362 }
363
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700364 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
365 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800366 bool IsArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700367 return GetComponentType<kVerifyFlags, kReadBarrierOption>() != NULL;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800368 }
369
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700370 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
371 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800372 bool IsClassClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800373
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700374 bool IsStringClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800375
Ian Rogersef7d42f2014-01-06 12:55:46 -0800376 bool IsThrowableClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800377
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700378 bool IsArtFieldClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800379
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700380 bool IsArtMethodClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800381
Ian Rogersa9a82542013-10-04 11:17:26 -0700382 static MemberOffset ComponentTypeOffset() {
383 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
384 }
385
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700386 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
387 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800388 Class* GetComponentType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700389 return GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(ComponentTypeOffset());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800390 }
391
392 void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
393 DCHECK(GetComponentType() == NULL);
394 DCHECK(new_component_type != NULL);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100395 // Component type is invariant: use non-transactional mode without check.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700396 SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397 }
398
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700399 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800400 size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700401 return Primitive::ComponentSize(
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700402 GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveType());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800403 }
404
Ian Rogersef7d42f2014-01-06 12:55:46 -0800405 bool IsObjectClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406 return !IsPrimitive() && GetSuperClass() == NULL;
407 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800408 bool IsInstantiable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sameer Abu Asal02c42232013-04-30 12:09:45 -0700409 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) || ((IsAbstract()) && IsArrayClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800410 }
411
Mathieu Chartier4e305412014-02-19 10:54:44 -0800412 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800413 bool IsObjectArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800414 return GetComponentType<kVerifyFlags>() != nullptr && !GetComponentType<kVerifyFlags>()->IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415 }
416
417 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700418 template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800419 ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
420 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700421
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800422 Object* AllocObject(Thread* self)
423 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
424 Object* AllocNonMovableObject(Thread* self)
425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800426
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700427 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
428 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800429 bool IsVariableSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800430 // Classes and arrays vary in size, and so the object_size_ field cannot
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700431 // be used to Get their instance size
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700432 return IsClassClass<kVerifyFlags, kReadBarrierOption>() ||
433 IsArrayClass<kVerifyFlags, kReadBarrierOption>();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434 }
435
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700436 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
437 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800438 uint32_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700439 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440 }
441
Mathieu Chartier4e305412014-02-19 10:54:44 -0800442 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800443 uint32_t GetClassSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700444 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800445 }
446
Ian Rogersef7d42f2014-01-06 12:55:46 -0800447 void SetClassSize(uint32_t new_class_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800448 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
449
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700450 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
451 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800452 uint32_t GetObjectSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800453
Ian Rogersef7d42f2014-01-06 12:55:46 -0800454 void SetObjectSize(uint32_t new_object_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800455 DCHECK(!IsVariableSize());
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100456 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700457 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800458 }
459
460 // Returns true if this class is in the same packages as that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800461 bool IsInSamePackage(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800462
463 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
464
465 // Returns true if this class can access that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800466 bool CanAccess(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800467 return that->IsPublic() || this->IsInSamePackage(that);
468 }
469
470 // Can this class access a member in the provided class with the provided member access flags?
471 // Note that access to the class isn't checked in case the declaring class is protected and the
472 // method has been exposed by a public sub-class
Ian Rogersef7d42f2014-01-06 12:55:46 -0800473 bool CanAccessMember(Class* access_to, uint32_t member_flags)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800474 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
475 // Classes can access all of their own members
476 if (this == access_to) {
477 return true;
478 }
479 // Public members are trivially accessible
480 if (member_flags & kAccPublic) {
481 return true;
482 }
483 // Private members are trivially not accessible
484 if (member_flags & kAccPrivate) {
485 return false;
486 }
487 // Check for protected access from a sub-class, which may or may not be in the same package.
488 if (member_flags & kAccProtected) {
489 if (this->IsSubClass(access_to)) {
490 return true;
491 }
492 }
493 // Allow protected access from other classes in the same package.
494 return this->IsInSamePackage(access_to);
495 }
496
Vladimir Marko23a28212014-01-09 19:24:37 +0000497 // Can this class access a resolved field?
498 // Note that access to field's class is checked and this may require looking up the class
499 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000500 bool CanAccessResolvedField(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800501 DexCache* dex_cache, uint32_t field_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000502 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
503 bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
504 uint32_t field_idx)
505 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000506
507 // Can this class access a resolved method?
508 // Note that access to methods's class is checked and this may require looking up the class
509 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000510 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800511 DexCache* dex_cache, uint32_t method_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000512 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
513 template <InvokeType throw_invoke_type>
514 bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
515 uint32_t method_idx)
516 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000517
Ian Rogersef7d42f2014-01-06 12:55:46 -0800518 bool IsSubClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800519
520 // Can src be assigned to this class? For example, String can be assigned to Object (by an
521 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
522 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
523 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
524 // to themselves. Classes for primitive types may not assign to each other.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800525 inline bool IsAssignableFrom(Class* src) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800526 DCHECK(src != NULL);
527 if (this == src) {
528 // Can always assign to things of the same type.
529 return true;
530 } else if (IsObjectClass()) {
531 // Can assign any reference to java.lang.Object.
532 return !src->IsPrimitive();
533 } else if (IsInterface()) {
534 return src->Implements(this);
535 } else if (src->IsArrayClass()) {
536 return IsAssignableFromArray(src);
537 } else {
538 return !src->IsInterface() && src->IsSubClass(this);
539 }
540 }
541
Ian Rogersef7d42f2014-01-06 12:55:46 -0800542 Class* GetSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800543
544 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800545 // Super class is assigned once, except during class linker initialization.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700546 Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800547 DCHECK(old_super_class == nullptr || old_super_class == new_super_class);
548 DCHECK(new_super_class != nullptr);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700549 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800550 }
551
Ian Rogersef7d42f2014-01-06 12:55:46 -0800552 bool HasSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800553 return GetSuperClass() != NULL;
554 }
555
556 static MemberOffset SuperClassOffset() {
557 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
558 }
559
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700560 ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800561
562 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
563
564 static MemberOffset DexCacheOffset() {
565 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
566 }
567
568 enum {
569 kDumpClassFullDetail = 1,
570 kDumpClassClassLoader = (1 << 1),
571 kDumpClassInitialized = (1 << 2),
572 };
573
Ian Rogersef7d42f2014-01-06 12:55:46 -0800574 void DumpClass(std::ostream& os, int flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800575
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800576 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800577 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800578
579 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
580
Ian Rogersef7d42f2014-01-06 12:55:46 -0800581 ObjectArray<ArtMethod>* GetDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800582
Brian Carlstromea46f952013-07-30 01:26:50 -0700583 void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800584 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
585
Ian Rogersef7d42f2014-01-06 12:55:46 -0800586 ArtMethod* GetDirectMethod(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800587
Brian Carlstromea46f952013-07-30 01:26:50 -0700588 void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800589 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
590
591 // Returns the number of static, private, and constructor methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800592 uint32_t NumDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800593
Mathieu Chartier4e305412014-02-19 10:54:44 -0800594 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800595 ObjectArray<ArtMethod>* GetVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800596
Brian Carlstromea46f952013-07-30 01:26:50 -0700597 void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800598 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
599
600 // Returns the number of non-inherited virtual methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800601 uint32_t NumVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800602
Mathieu Chartier4e305412014-02-19 10:54:44 -0800603 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800604 ArtMethod* GetVirtualMethod(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800605
Ian Rogersef7d42f2014-01-06 12:55:46 -0800606 ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800607
Brian Carlstromea46f952013-07-30 01:26:50 -0700608 void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800609 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
610
Ian Rogersef7d42f2014-01-06 12:55:46 -0800611 ObjectArray<ArtMethod>* GetVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800612
Ian Rogersef7d42f2014-01-06 12:55:46 -0800613 ObjectArray<ArtMethod>* GetVTableDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800614
Brian Carlstromea46f952013-07-30 01:26:50 -0700615 void SetVTable(ObjectArray<ArtMethod>* new_vtable)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800616 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
617
618 static MemberOffset VTableOffset() {
619 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
620 }
621
Ian Rogersef7d42f2014-01-06 12:55:46 -0800622 ObjectArray<ArtMethod>* GetImTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700623
624 void SetImTable(ObjectArray<ArtMethod>* new_imtable)
625 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
626
627 static MemberOffset ImTableOffset() {
628 return OFFSET_OF_OBJECT_MEMBER(Class, imtable_);
629 }
630
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800631 // Given a method implemented by this class but potentially from a super class, return the
632 // specific implementation method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800633 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800634 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
635
636 // Given a method implemented by this class' super class, return the specific implementation
637 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800638 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800639 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
640
641 // Given a method implemented by this class, but potentially from a
642 // super class or interface, return the specific implementation
643 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800644 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method)
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800645 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800646
Ian Rogersef7d42f2014-01-06 12:55:46 -0800647 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700648 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
649
Ian Rogersef7d42f2014-01-06 12:55:46 -0800650 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800651 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
652
Ian Rogersef7d42f2014-01-06 12:55:46 -0800653 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800654 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
655
Ian Rogersef7d42f2014-01-06 12:55:46 -0800656 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800657 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
658
Ian Rogersef7d42f2014-01-06 12:55:46 -0800659 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700660 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
661
Ian Rogersef7d42f2014-01-06 12:55:46 -0800662 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800663 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
664
Ian Rogersef7d42f2014-01-06 12:55:46 -0800665 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800666 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
667
Ian Rogersef7d42f2014-01-06 12:55:46 -0800668 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700669 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
670
Ian Rogersef7d42f2014-01-06 12:55:46 -0800671 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800672 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
673
Ian Rogersef7d42f2014-01-06 12:55:46 -0800674 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700675 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
676
Ian Rogersef7d42f2014-01-06 12:55:46 -0800677 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700678 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
679
Ian Rogersef7d42f2014-01-06 12:55:46 -0800680 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700681 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
682
Ian Rogersef7d42f2014-01-06 12:55:46 -0800683 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700684 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
685
Ian Rogersef7d42f2014-01-06 12:55:46 -0800686 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700687 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
688
Ian Rogersef7d42f2014-01-06 12:55:46 -0800689 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700690 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
691
Ian Rogersef7d42f2014-01-06 12:55:46 -0800692 ArtMethod* FindClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700693
Ian Rogersef7d42f2014-01-06 12:55:46 -0800694 int32_t GetIfTableCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800695
Ian Rogersef7d42f2014-01-06 12:55:46 -0800696 IfTable* GetIfTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800697
698 void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
699
700 // Get instance fields of the class (See also GetSFields).
Ian Rogersef7d42f2014-01-06 12:55:46 -0800701 ObjectArray<ArtField>* GetIFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800702
Brian Carlstromea46f952013-07-30 01:26:50 -0700703 void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800704
Ian Rogersef7d42f2014-01-06 12:55:46 -0800705 uint32_t NumInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800706
Ian Rogersef7d42f2014-01-06 12:55:46 -0800707 ArtField* GetInstanceField(uint32_t i) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800708 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
709
Brian Carlstromea46f952013-07-30 01:26:50 -0700710 void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800711 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
712
713 // Returns the number of instance fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800714 uint32_t NumReferenceInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800715 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700716 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800717 }
718
Ian Rogersef7d42f2014-01-06 12:55:46 -0800719 uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800720 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700721 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800722 }
723
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700724 void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100725 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700726 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800727 }
728
Mathieu Chartier4e305412014-02-19 10:54:44 -0800729 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700730 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800731
732 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
733 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
734
735 // Beginning of static field data
736 static MemberOffset FieldsOffset() {
737 return OFFSET_OF_OBJECT_MEMBER(Class, fields_);
738 }
739
740 // Returns the number of static fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800741 uint32_t NumReferenceStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800742 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700743 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800744 }
745
Ian Rogersef7d42f2014-01-06 12:55:46 -0800746 uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800747 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700748 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800749 }
750
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700751 void SetNumReferenceStaticFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100752 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700753 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800754 }
755
756 // Gets the static fields of the class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800757 ObjectArray<ArtField>* GetSFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800758
Brian Carlstromea46f952013-07-30 01:26:50 -0700759 void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800760
Ian Rogersef7d42f2014-01-06 12:55:46 -0800761 uint32_t NumStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800762
Ian Rogersef7d42f2014-01-06 12:55:46 -0800763 // TODO: uint16_t
764 ArtField* GetStaticField(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800765
Ian Rogersef7d42f2014-01-06 12:55:46 -0800766 // TODO: uint16_t
767 void SetStaticField(uint32_t i, ArtField* f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800768
Mathieu Chartier4e305412014-02-19 10:54:44 -0800769 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800770 uint32_t GetReferenceStaticOffsets() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700771 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800772 }
773
Ian Rogersef7d42f2014-01-06 12:55:46 -0800774 void SetReferenceStaticOffsets(uint32_t new_reference_offsets)
775 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800776
777 // Find a static or instance field using the JLS resolution order
Mathieu Chartierf8322842014-05-16 10:59:25 -0700778 static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
779 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800780 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
781
782 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700783 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800784 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
785
786 // Finds the given instance field in this class or a superclass, only searches classes that
787 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700788 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800789 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
790
Brian Carlstromea46f952013-07-30 01:26:50 -0700791 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800792 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
793
Brian Carlstromea46f952013-07-30 01:26:50 -0700794 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800795 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
796
797 // Finds the given static field in this class or a superclass.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700798 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
799 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800800 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
801
802 // Finds the given static field in this class or superclass, only searches classes that
803 // have the same dex cache.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700804 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
805 uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800806 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
807
Brian Carlstromea46f952013-07-30 01:26:50 -0700808 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800809 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
810
Brian Carlstromea46f952013-07-30 01:26:50 -0700811 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800812 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
813
Ian Rogersef7d42f2014-01-06 12:55:46 -0800814 pid_t GetClinitThreadId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800815 DCHECK(IsIdxLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700816 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800817 }
818
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700819 void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800820
Ian Rogersef7d42f2014-01-06 12:55:46 -0800821 Class* GetVerifyErrorClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800822 // DCHECK(IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700823 return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800824 }
825
Ian Rogersef7d42f2014-01-06 12:55:46 -0800826 uint16_t GetDexClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700827 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700828 }
829
Ian Rogersef7d42f2014-01-06 12:55:46 -0800830 void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100831 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700832 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700833 }
834
Ian Rogersef7d42f2014-01-06 12:55:46 -0800835 uint16_t GetDexTypeIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700836 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800837 }
838
Ian Rogersef7d42f2014-01-06 12:55:46 -0800839 void SetDexTypeIndex(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100840 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700841 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800842 }
843
844 static Class* GetJavaLangClass() {
845 DCHECK(java_lang_Class_ != NULL);
846 return java_lang_Class_;
847 }
848
849 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
850 static void SetClassClass(Class* java_lang_Class);
851 static void ResetClass();
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800852 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800853 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800854
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200855 // When class is verified, set the kAccPreverified flag on each method.
856 void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
857
Mathieu Chartier407f7022014-02-18 14:37:05 -0800858 template <bool kVisitClass, typename Visitor>
859 void VisitReferences(mirror::Class* klass, const Visitor& visitor)
860 NO_THREAD_SAFETY_ANALYSIS;
861
Mathieu Chartierf8322842014-05-16 10:59:25 -0700862 std::string GetDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
863 bool DescriptorEquals(const char* match) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
864 std::string GetArrayDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
865 const DexFile::ClassDef* GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
866 uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
867 uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
868 static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass, uint32_t idx)
869 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
870 const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
871 std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
872 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
873 const DexFile::TypeList* GetInterfaceTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
874
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800875 private:
876 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
877
Vladimir Marko89786432014-01-31 15:03:55 +0000878 template <bool throw_on_failure, bool use_referrers_cache>
879 bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800880 uint32_t field_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +0000881 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
882 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
883 bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800884 uint32_t method_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +0000885 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
886
Ian Rogersef7d42f2014-01-06 12:55:46 -0800887 bool Implements(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
888 bool IsArrayAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
889 bool IsAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800890
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700891 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
892
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800893 // defining class loader, or NULL for the "bootstrap" system loader
Ian Rogersef7d42f2014-01-06 12:55:46 -0800894 HeapReference<ClassLoader> class_loader_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800895
896 // For array classes, the component class object for instanceof/checkcast
897 // (for String[][][], this will be String[][]). NULL for non-array classes.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800898 HeapReference<Class> component_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800899
900 // DexCache of resolved constant pool entries (will be NULL for classes generated by the
901 // runtime such as arrays and primitive classes).
Ian Rogersef7d42f2014-01-06 12:55:46 -0800902 HeapReference<DexCache> dex_cache_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800903
904 // static, private, and <init> methods
Ian Rogers700a4022014-05-19 16:49:03 -0700905 HeapReference<ObjectArray<ArtMethod>> direct_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800906
907 // instance fields
908 //
909 // These describe the layout of the contents of an Object.
910 // Note that only the fields directly declared by this class are
911 // listed in ifields; fields declared by a superclass are listed in
912 // the superclass's Class.ifields.
913 //
914 // All instance fields that refer to objects are guaranteed to be at
915 // the beginning of the field list. num_reference_instance_fields_
916 // specifies the number of reference fields.
Ian Rogers700a4022014-05-19 16:49:03 -0700917 HeapReference<ObjectArray<ArtField>> ifields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800918
919 // The interface table (iftable_) contains pairs of a interface class and an array of the
920 // interface methods. There is one pair per interface supported by this class. That means one
921 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
922 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
923 //
924 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
925 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
926 // single vtable.
927 //
928 // For every interface a concrete class implements, we create an array of the concrete vtable_
929 // methods for the methods in the interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800930 HeapReference<IfTable> iftable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800931
Jeff Hao88474b42013-10-23 16:24:40 -0700932 // Interface method table (imt), for quick "invoke-interface".
Ian Rogers700a4022014-05-19 16:49:03 -0700933 HeapReference<ObjectArray<ArtMethod>> imtable_;
Jeff Hao88474b42013-10-23 16:24:40 -0700934
Ian Rogersef7d42f2014-01-06 12:55:46 -0800935 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
936 HeapReference<String> name_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800937
938 // Static fields
Ian Rogersef7d42f2014-01-06 12:55:46 -0800939 HeapReference<ObjectArray<ArtField>> sfields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800940
941 // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800942 HeapReference<Class> super_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800943
944 // If class verify fails, we must return same error on subsequent tries.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800945 HeapReference<Class> verify_error_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800946
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700947 // Virtual methods defined in this class; invoked through vtable.
Ian Rogers700a4022014-05-19 16:49:03 -0700948 HeapReference<ObjectArray<ArtMethod>> virtual_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800949
950 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
951 // copied in, and virtual methods from our class either replace those from the super or are
952 // appended. For abstract classes, methods may be created in the vtable that aren't in
953 // virtual_ methods_ for miranda methods.
Ian Rogers700a4022014-05-19 16:49:03 -0700954 HeapReference<ObjectArray<ArtMethod>> vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800955
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700956 // Access flags; low 16 bits are defined by VM spec.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800957 uint32_t access_flags_;
958
959 // Total size of the Class instance; used when allocating storage on gc heap.
960 // See also object_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800961 uint32_t class_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800962
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700963 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800964 pid_t clinit_thread_id_;
965
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700966 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800967 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700968 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800969
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700970 // Type index in dex file.
971 // TODO: really 16bits
972 int32_t dex_type_idx_;
973
974 // Number of instance fields that are object refs.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800975 uint32_t num_reference_instance_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800976
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700977 // Number of static fields that are object refs,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800978 uint32_t num_reference_static_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800979
980 // Total object size; used when allocating storage on gc heap.
981 // (For interfaces and abstract classes this will be zero.)
982 // See also class_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800983 uint32_t object_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800984
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700985 // Primitive type value, or Primitive::kPrimNot (0); set for generated primitive classes.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800986 Primitive::Type primitive_type_;
987
988 // Bitmap of offsets of ifields.
989 uint32_t reference_instance_offsets_;
990
991 // Bitmap of offsets of sfields.
992 uint32_t reference_static_offsets_;
993
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700994 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800995 Status status_;
996
997 // TODO: ?
998 // initiating class loader list
999 // NOTE: for classes with low serialNumber, these are unused, and the
1000 // values are kept in a table in gDvm.
1001 // InitiatingLoaderList initiating_loader_list_;
1002
1003 // Location of first static field.
1004 uint32_t fields_[0];
1005
1006 // java.lang.Class
1007 static Class* java_lang_Class_;
1008
1009 friend struct art::ClassOffsets; // for verifying offset information
1010 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
1011};
1012
1013std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1014
1015class MANAGED ClassClass : public Class {
1016 private:
Jeff Hao88474b42013-10-23 16:24:40 -07001017 int32_t pad_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001018 int64_t serialVersionUID_;
1019 friend struct art::ClassClassOffsets; // for verifying offset information
1020 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass);
1021};
1022
1023} // namespace mirror
1024} // namespace art
1025
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001026#endif // ART_RUNTIME_MIRROR_CLASS_H_