blob: a283f601afc3180317760dd599eb657f1a8699e3 [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
374 bool IsStringClass() const;
375
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 Yamauchi6e83c172014-05-01 21:25:41 -0700378 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800379 bool IsArtFieldClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700381 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800382 bool IsArtMethodClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800383
Ian Rogersa9a82542013-10-04 11:17:26 -0700384 static MemberOffset ComponentTypeOffset() {
385 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
386 }
387
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700388 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
389 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800390 Class* GetComponentType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700391 return GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(ComponentTypeOffset());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800392 }
393
394 void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
395 DCHECK(GetComponentType() == NULL);
396 DCHECK(new_component_type != NULL);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100397 // Component type is invariant: use non-transactional mode without check.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700398 SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800399 }
400
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700401 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800402 size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700403 return Primitive::ComponentSize(
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700404 GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveType());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800405 }
406
Ian Rogersef7d42f2014-01-06 12:55:46 -0800407 bool IsObjectClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800408 return !IsPrimitive() && GetSuperClass() == NULL;
409 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800410 bool IsInstantiable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sameer Abu Asal02c42232013-04-30 12:09:45 -0700411 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) || ((IsAbstract()) && IsArrayClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800412 }
413
Mathieu Chartier4e305412014-02-19 10:54:44 -0800414 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800415 bool IsObjectArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800416 return GetComponentType<kVerifyFlags>() != nullptr && !GetComponentType<kVerifyFlags>()->IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800417 }
418
419 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700420 template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800421 ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
422 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700423
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800424 Object* AllocObject(Thread* self)
425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
426 Object* AllocNonMovableObject(Thread* self)
427 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800428
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700429 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
430 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800431 bool IsVariableSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800432 // Classes and arrays vary in size, and so the object_size_ field cannot
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700433 // be used to Get their instance size
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700434 return IsClassClass<kVerifyFlags, kReadBarrierOption>() ||
435 IsArrayClass<kVerifyFlags, kReadBarrierOption>();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800436 }
437
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700438 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
439 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800440 uint32_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700441 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800442 }
443
Mathieu Chartier4e305412014-02-19 10:54:44 -0800444 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800445 uint32_t GetClassSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700446 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800447 }
448
Ian Rogersef7d42f2014-01-06 12:55:46 -0800449 void SetClassSize(uint32_t new_class_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800450 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
451
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700452 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
453 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800454 uint32_t GetObjectSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800455
Ian Rogersef7d42f2014-01-06 12:55:46 -0800456 void SetObjectSize(uint32_t new_object_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800457 DCHECK(!IsVariableSize());
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100458 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700459 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800460 }
461
462 // Returns true if this class is in the same packages as that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800463 bool IsInSamePackage(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800464
465 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
466
467 // Returns true if this class can access that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800468 bool CanAccess(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800469 return that->IsPublic() || this->IsInSamePackage(that);
470 }
471
472 // Can this class access a member in the provided class with the provided member access flags?
473 // Note that access to the class isn't checked in case the declaring class is protected and the
474 // method has been exposed by a public sub-class
Ian Rogersef7d42f2014-01-06 12:55:46 -0800475 bool CanAccessMember(Class* access_to, uint32_t member_flags)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800476 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
477 // Classes can access all of their own members
478 if (this == access_to) {
479 return true;
480 }
481 // Public members are trivially accessible
482 if (member_flags & kAccPublic) {
483 return true;
484 }
485 // Private members are trivially not accessible
486 if (member_flags & kAccPrivate) {
487 return false;
488 }
489 // Check for protected access from a sub-class, which may or may not be in the same package.
490 if (member_flags & kAccProtected) {
491 if (this->IsSubClass(access_to)) {
492 return true;
493 }
494 }
495 // Allow protected access from other classes in the same package.
496 return this->IsInSamePackage(access_to);
497 }
498
Vladimir Marko23a28212014-01-09 19:24:37 +0000499 // Can this class access a resolved field?
500 // Note that access to field's class is checked and this may require looking up the class
501 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000502 bool CanAccessResolvedField(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800503 DexCache* dex_cache, uint32_t field_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000504 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
505 bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
506 uint32_t field_idx)
507 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000508
509 // Can this class access a resolved method?
510 // Note that access to methods's class is checked and this may require looking up the class
511 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000512 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800513 DexCache* dex_cache, uint32_t method_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000514 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
515 template <InvokeType throw_invoke_type>
516 bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
517 uint32_t method_idx)
518 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000519
Ian Rogersef7d42f2014-01-06 12:55:46 -0800520 bool IsSubClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800521
522 // Can src be assigned to this class? For example, String can be assigned to Object (by an
523 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
524 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
525 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
526 // to themselves. Classes for primitive types may not assign to each other.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800527 inline bool IsAssignableFrom(Class* src) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800528 DCHECK(src != NULL);
529 if (this == src) {
530 // Can always assign to things of the same type.
531 return true;
532 } else if (IsObjectClass()) {
533 // Can assign any reference to java.lang.Object.
534 return !src->IsPrimitive();
535 } else if (IsInterface()) {
536 return src->Implements(this);
537 } else if (src->IsArrayClass()) {
538 return IsAssignableFromArray(src);
539 } else {
540 return !src->IsInterface() && src->IsSubClass(this);
541 }
542 }
543
Ian Rogersef7d42f2014-01-06 12:55:46 -0800544 Class* GetSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800545
546 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800547 // Super class is assigned once, except during class linker initialization.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700548 Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800549 DCHECK(old_super_class == nullptr || old_super_class == new_super_class);
550 DCHECK(new_super_class != nullptr);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700551 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800552 }
553
Ian Rogersef7d42f2014-01-06 12:55:46 -0800554 bool HasSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800555 return GetSuperClass() != NULL;
556 }
557
558 static MemberOffset SuperClassOffset() {
559 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
560 }
561
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700562 ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800563
564 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
565
566 static MemberOffset DexCacheOffset() {
567 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
568 }
569
570 enum {
571 kDumpClassFullDetail = 1,
572 kDumpClassClassLoader = (1 << 1),
573 kDumpClassInitialized = (1 << 2),
574 };
575
Ian Rogersef7d42f2014-01-06 12:55:46 -0800576 void DumpClass(std::ostream& os, int flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800577
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800578 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800579 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800580
581 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
582
Ian Rogersef7d42f2014-01-06 12:55:46 -0800583 ObjectArray<ArtMethod>* GetDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800584
Brian Carlstromea46f952013-07-30 01:26:50 -0700585 void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800586 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
587
Ian Rogersef7d42f2014-01-06 12:55:46 -0800588 ArtMethod* GetDirectMethod(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800589
Brian Carlstromea46f952013-07-30 01:26:50 -0700590 void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800591 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
592
593 // Returns the number of static, private, and constructor methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800594 uint32_t NumDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800595
Mathieu Chartier4e305412014-02-19 10:54:44 -0800596 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800597 ObjectArray<ArtMethod>* GetVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800598
Brian Carlstromea46f952013-07-30 01:26:50 -0700599 void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800600 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
601
602 // Returns the number of non-inherited virtual methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800603 uint32_t NumVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800604
Mathieu Chartier4e305412014-02-19 10:54:44 -0800605 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800606 ArtMethod* GetVirtualMethod(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800607
Ian Rogersef7d42f2014-01-06 12:55:46 -0800608 ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800609
Brian Carlstromea46f952013-07-30 01:26:50 -0700610 void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800611 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
612
Ian Rogersef7d42f2014-01-06 12:55:46 -0800613 ObjectArray<ArtMethod>* GetVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800614
Ian Rogersef7d42f2014-01-06 12:55:46 -0800615 ObjectArray<ArtMethod>* GetVTableDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800616
Brian Carlstromea46f952013-07-30 01:26:50 -0700617 void SetVTable(ObjectArray<ArtMethod>* new_vtable)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800618 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
619
620 static MemberOffset VTableOffset() {
621 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
622 }
623
Ian Rogersef7d42f2014-01-06 12:55:46 -0800624 ObjectArray<ArtMethod>* GetImTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700625
626 void SetImTable(ObjectArray<ArtMethod>* new_imtable)
627 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
628
629 static MemberOffset ImTableOffset() {
630 return OFFSET_OF_OBJECT_MEMBER(Class, imtable_);
631 }
632
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800633 // Given a method implemented by this class but potentially from a super class, return the
634 // specific implementation method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800635 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800636 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
637
638 // Given a method implemented by this class' super class, return the specific implementation
639 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800640 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800641 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
642
643 // Given a method implemented by this class, but potentially from a
644 // super class or interface, return the specific implementation
645 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800646 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method)
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800647 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800648
Ian Rogersef7d42f2014-01-06 12:55:46 -0800649 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700650 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
651
Ian Rogersef7d42f2014-01-06 12:55:46 -0800652 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800653 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
654
Ian Rogersef7d42f2014-01-06 12:55:46 -0800655 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800656 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
657
Ian Rogersef7d42f2014-01-06 12:55:46 -0800658 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800659 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
660
Ian Rogersef7d42f2014-01-06 12:55:46 -0800661 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700662 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
663
Ian Rogersef7d42f2014-01-06 12:55:46 -0800664 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800665 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
666
Ian Rogersef7d42f2014-01-06 12:55:46 -0800667 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800668 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
669
Ian Rogersef7d42f2014-01-06 12:55:46 -0800670 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700671 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
672
Ian Rogersef7d42f2014-01-06 12:55:46 -0800673 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800674 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
675
Ian Rogersef7d42f2014-01-06 12:55:46 -0800676 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700677 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
678
Ian Rogersef7d42f2014-01-06 12:55:46 -0800679 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700680 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
681
Ian Rogersef7d42f2014-01-06 12:55:46 -0800682 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700683 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
684
Ian Rogersef7d42f2014-01-06 12:55:46 -0800685 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700686 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
687
Ian Rogersef7d42f2014-01-06 12:55:46 -0800688 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700689 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
690
Ian Rogersef7d42f2014-01-06 12:55:46 -0800691 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700692 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
693
Ian Rogersef7d42f2014-01-06 12:55:46 -0800694 ArtMethod* FindClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700695
Ian Rogersef7d42f2014-01-06 12:55:46 -0800696 int32_t GetIfTableCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800697
Ian Rogersef7d42f2014-01-06 12:55:46 -0800698 IfTable* GetIfTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800699
700 void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
701
702 // Get instance fields of the class (See also GetSFields).
Ian Rogersef7d42f2014-01-06 12:55:46 -0800703 ObjectArray<ArtField>* GetIFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800704
Brian Carlstromea46f952013-07-30 01:26:50 -0700705 void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800706
Ian Rogersef7d42f2014-01-06 12:55:46 -0800707 uint32_t NumInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800708
Ian Rogersef7d42f2014-01-06 12:55:46 -0800709 ArtField* GetInstanceField(uint32_t i) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800710 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
711
Brian Carlstromea46f952013-07-30 01:26:50 -0700712 void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800713 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
714
715 // Returns the number of instance fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800716 uint32_t NumReferenceInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800717 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700718 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800719 }
720
Ian Rogersef7d42f2014-01-06 12:55:46 -0800721 uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800722 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700723 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800724 }
725
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700726 void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100727 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700728 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800729 }
730
Mathieu Chartier4e305412014-02-19 10:54:44 -0800731 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700732 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800733
734 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
735 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
736
737 // Beginning of static field data
738 static MemberOffset FieldsOffset() {
739 return OFFSET_OF_OBJECT_MEMBER(Class, fields_);
740 }
741
742 // Returns the number of static fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800743 uint32_t NumReferenceStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800744 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700745 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800746 }
747
Ian Rogersef7d42f2014-01-06 12:55:46 -0800748 uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800749 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700750 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800751 }
752
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700753 void SetNumReferenceStaticFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100754 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700755 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800756 }
757
758 // Gets the static fields of the class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800759 ObjectArray<ArtField>* GetSFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800760
Brian Carlstromea46f952013-07-30 01:26:50 -0700761 void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800762
Ian Rogersef7d42f2014-01-06 12:55:46 -0800763 uint32_t NumStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800764
Ian Rogersef7d42f2014-01-06 12:55:46 -0800765 // TODO: uint16_t
766 ArtField* GetStaticField(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800767
Ian Rogersef7d42f2014-01-06 12:55:46 -0800768 // TODO: uint16_t
769 void SetStaticField(uint32_t i, ArtField* f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800770
Mathieu Chartier4e305412014-02-19 10:54:44 -0800771 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800772 uint32_t GetReferenceStaticOffsets() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700773 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800774 }
775
Ian Rogersef7d42f2014-01-06 12:55:46 -0800776 void SetReferenceStaticOffsets(uint32_t new_reference_offsets)
777 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800778
779 // Find a static or instance field using the JLS resolution order
Mathieu Chartierf8322842014-05-16 10:59:25 -0700780 static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
781 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800782 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
783
784 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700785 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800786 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
787
788 // Finds the given instance field in this class or a superclass, only searches classes that
789 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700790 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800791 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
792
Brian Carlstromea46f952013-07-30 01:26:50 -0700793 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800794 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
795
Brian Carlstromea46f952013-07-30 01:26:50 -0700796 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800797 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
798
799 // Finds the given static field in this class or a superclass.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700800 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
801 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800802 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
803
804 // Finds the given static field in this class or superclass, only searches classes that
805 // have the same dex cache.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700806 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
807 uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800808 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
809
Brian Carlstromea46f952013-07-30 01:26:50 -0700810 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800811 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
812
Brian Carlstromea46f952013-07-30 01:26:50 -0700813 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800814 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
815
Ian Rogersef7d42f2014-01-06 12:55:46 -0800816 pid_t GetClinitThreadId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800817 DCHECK(IsIdxLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700818 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800819 }
820
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700821 void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800822
Ian Rogersef7d42f2014-01-06 12:55:46 -0800823 Class* GetVerifyErrorClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800824 // DCHECK(IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700825 return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800826 }
827
Ian Rogersef7d42f2014-01-06 12:55:46 -0800828 uint16_t GetDexClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700829 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700830 }
831
Ian Rogersef7d42f2014-01-06 12:55:46 -0800832 void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100833 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700834 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700835 }
836
Ian Rogersef7d42f2014-01-06 12:55:46 -0800837 uint16_t GetDexTypeIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700838 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800839 }
840
Ian Rogersef7d42f2014-01-06 12:55:46 -0800841 void SetDexTypeIndex(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100842 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700843 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800844 }
845
846 static Class* GetJavaLangClass() {
847 DCHECK(java_lang_Class_ != NULL);
848 return java_lang_Class_;
849 }
850
851 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
852 static void SetClassClass(Class* java_lang_Class);
853 static void ResetClass();
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800854 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800855 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800856
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200857 // When class is verified, set the kAccPreverified flag on each method.
858 void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
859
Mathieu Chartier407f7022014-02-18 14:37:05 -0800860 template <bool kVisitClass, typename Visitor>
861 void VisitReferences(mirror::Class* klass, const Visitor& visitor)
862 NO_THREAD_SAFETY_ANALYSIS;
863
Mathieu Chartierf8322842014-05-16 10:59:25 -0700864 std::string GetDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
865 bool DescriptorEquals(const char* match) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
866 std::string GetArrayDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
867 const DexFile::ClassDef* GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
868 uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
869 uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
870 static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass, uint32_t idx)
871 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
872 const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
873 std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
874 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
875 const DexFile::TypeList* GetInterfaceTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
876
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800877 private:
878 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
879
Vladimir Marko89786432014-01-31 15:03:55 +0000880 template <bool throw_on_failure, bool use_referrers_cache>
881 bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800882 uint32_t field_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +0000883 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
884 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
885 bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800886 uint32_t method_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +0000887 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
888
Ian Rogersef7d42f2014-01-06 12:55:46 -0800889 bool Implements(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
890 bool IsArrayAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
891 bool IsAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800892
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700893 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
894
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800895 // defining class loader, or NULL for the "bootstrap" system loader
Ian Rogersef7d42f2014-01-06 12:55:46 -0800896 HeapReference<ClassLoader> class_loader_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800897
898 // For array classes, the component class object for instanceof/checkcast
899 // (for String[][][], this will be String[][]). NULL for non-array classes.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800900 HeapReference<Class> component_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800901
902 // DexCache of resolved constant pool entries (will be NULL for classes generated by the
903 // runtime such as arrays and primitive classes).
Ian Rogersef7d42f2014-01-06 12:55:46 -0800904 HeapReference<DexCache> dex_cache_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800905
906 // static, private, and <init> methods
Ian Rogersef7d42f2014-01-06 12:55:46 -0800907 HeapReference<ObjectArray<ArtMethod> > direct_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800908
909 // instance fields
910 //
911 // These describe the layout of the contents of an Object.
912 // Note that only the fields directly declared by this class are
913 // listed in ifields; fields declared by a superclass are listed in
914 // the superclass's Class.ifields.
915 //
916 // All instance fields that refer to objects are guaranteed to be at
917 // the beginning of the field list. num_reference_instance_fields_
918 // specifies the number of reference fields.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800919 HeapReference<ObjectArray<ArtField> > ifields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800920
921 // The interface table (iftable_) contains pairs of a interface class and an array of the
922 // interface methods. There is one pair per interface supported by this class. That means one
923 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
924 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
925 //
926 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
927 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
928 // single vtable.
929 //
930 // For every interface a concrete class implements, we create an array of the concrete vtable_
931 // methods for the methods in the interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800932 HeapReference<IfTable> iftable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800933
Jeff Hao88474b42013-10-23 16:24:40 -0700934 // Interface method table (imt), for quick "invoke-interface".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800935 HeapReference<ObjectArray<ArtMethod> > imtable_;
Jeff Hao88474b42013-10-23 16:24:40 -0700936
Ian Rogersef7d42f2014-01-06 12:55:46 -0800937 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
938 HeapReference<String> name_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800939
940 // Static fields
Ian Rogersef7d42f2014-01-06 12:55:46 -0800941 HeapReference<ObjectArray<ArtField>> sfields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800942
943 // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800944 HeapReference<Class> super_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800945
946 // If class verify fails, we must return same error on subsequent tries.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800947 HeapReference<Class> verify_error_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800948
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700949 // Virtual methods defined in this class; invoked through vtable.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800950 HeapReference<ObjectArray<ArtMethod> > virtual_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800951
952 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
953 // copied in, and virtual methods from our class either replace those from the super or are
954 // appended. For abstract classes, methods may be created in the vtable that aren't in
955 // virtual_ methods_ for miranda methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800956 HeapReference<ObjectArray<ArtMethod> > vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800957
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700958 // Access flags; low 16 bits are defined by VM spec.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800959 uint32_t access_flags_;
960
961 // Total size of the Class instance; used when allocating storage on gc heap.
962 // See also object_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800963 uint32_t class_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800964
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700965 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800966 pid_t clinit_thread_id_;
967
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700968 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800969 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700970 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800971
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700972 // Type index in dex file.
973 // TODO: really 16bits
974 int32_t dex_type_idx_;
975
976 // Number of instance fields that are object refs.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800977 uint32_t num_reference_instance_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800978
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700979 // Number of static fields that are object refs,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800980 uint32_t num_reference_static_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800981
982 // Total object size; used when allocating storage on gc heap.
983 // (For interfaces and abstract classes this will be zero.)
984 // See also class_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800985 uint32_t object_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800986
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700987 // Primitive type value, or Primitive::kPrimNot (0); set for generated primitive classes.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800988 Primitive::Type primitive_type_;
989
990 // Bitmap of offsets of ifields.
991 uint32_t reference_instance_offsets_;
992
993 // Bitmap of offsets of sfields.
994 uint32_t reference_static_offsets_;
995
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700996 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800997 Status status_;
998
999 // TODO: ?
1000 // initiating class loader list
1001 // NOTE: for classes with low serialNumber, these are unused, and the
1002 // values are kept in a table in gDvm.
1003 // InitiatingLoaderList initiating_loader_list_;
1004
1005 // Location of first static field.
1006 uint32_t fields_[0];
1007
1008 // java.lang.Class
1009 static Class* java_lang_Class_;
1010
1011 friend struct art::ClassOffsets; // for verifying offset information
1012 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
1013};
1014
1015std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1016
1017class MANAGED ClassClass : public Class {
1018 private:
Jeff Hao88474b42013-10-23 16:24:40 -07001019 int32_t pad_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001020 int64_t serialVersionUID_;
1021 friend struct art::ClassClassOffsets; // for verifying offset information
1022 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass);
1023};
1024
1025} // namespace mirror
1026} // namespace art
1027
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001028#endif // ART_RUNTIME_MIRROR_CLASS_H_