blob: 0525abf27ab64c39c943cd2033fc8b95167b0412 [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"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070025#include "object_array.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070026#include "object_callbacks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027#include "primitive.h"
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -070028#include "read_barrier.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029
30/*
31 * A magic value for refOffsets. Ignore the bits and walk the super
32 * chain when this is the value.
33 * [This is an unlikely "natural" value, since it would be 30 non-ref instance
34 * fields followed by 2 ref instance fields.]
35 */
Brian Carlstromfb6996f2013-07-18 18:21:14 -070036#define CLASS_WALK_SUPER 3U
37#define CLASS_BITS_PER_WORD (sizeof(uint32_t) * 8)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038#define CLASS_OFFSET_ALIGNMENT 4
Brian Carlstromfb6996f2013-07-18 18:21:14 -070039#define CLASS_HIGH_BIT (1U << (CLASS_BITS_PER_WORD - 1))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040/*
41 * Given an offset, return the bit number which would encode that offset.
42 * Local use only.
43 */
44#define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \
45 ((unsigned int)(byteOffset) / \
46 CLASS_OFFSET_ALIGNMENT)
47/*
48 * Is the given offset too large to be encoded?
49 */
50#define CLASS_CAN_ENCODE_OFFSET(byteOffset) \
51 (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD)
52/*
53 * Return a single bit, encoding the offset.
54 * Undefined if the offset is too large, as defined above.
55 */
56#define CLASS_BIT_FROM_OFFSET(byteOffset) \
57 (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset))
58/*
59 * Return an offset, given a bit number as returned from CLZ.
60 */
61#define CLASS_OFFSET_FROM_CLZ(rshift) \
62 MemberOffset((static_cast<int>(rshift) * CLASS_OFFSET_ALIGNMENT))
63
64namespace art {
65
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080066struct ClassOffsets;
Ian Rogersd91d6d62013-09-25 20:26:14 -070067class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068class StringPiece;
69
70namespace mirror {
71
Brian Carlstromea46f952013-07-30 01:26:50 -070072class ArtField;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070073class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074class ClassLoader;
75class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076class IfTable;
77
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078// C++ mirror of java.lang.Class
Mingyao Yang98d1cc82014-05-15 17:02:16 -070079class MANAGED Class FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070081 // Interface method table size. Increasing this value reduces the chance of two interface methods
82 // colliding in the interface method table but increases the size of classes that implement
83 // (non-marker) interfaces.
84 static constexpr size_t kImtSize = 64;
85
86 // imtable entry embedded in class object.
87 struct MANAGED ImTableEntry {
88 HeapReference<ArtMethod> method;
89 };
90
91 // vtable entry embedded in class object.
92 struct MANAGED VTableEntry {
93 HeapReference<ArtMethod> method;
94 };
95
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080096 // Class Status
97 //
98 // kStatusNotReady: If a Class cannot be found in the class table by
99 // FindClass, it allocates an new one with AllocClass in the
100 // kStatusNotReady and calls LoadClass. Note if it does find a
101 // class, it may not be kStatusResolved and it will try to push it
102 // forward toward kStatusResolved.
103 //
104 // kStatusIdx: LoadClass populates with Class with information from
105 // the DexFile, moving the status to kStatusIdx, indicating that the
106 // Class value in super_class_ has not been populated. The new Class
107 // can then be inserted into the classes table.
108 //
109 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
110 // attempt to move a kStatusIdx class forward to kStatusLoaded by
111 // using ResolveClass to initialize the super_class_ and ensuring the
112 // interfaces are resolved.
113 //
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700114 // kStatusResolving: Class is just cloned with the right size from
115 // temporary class that's acting as a placeholder for linking. The old
116 // class will be retired. New class is set to this status first before
117 // moving on to being resolved.
118 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800119 // kStatusResolved: Still holding the lock on Class, the ClassLinker
120 // shows linking is complete and fields of the Class populated by making
121 // it kStatusResolved. Java allows circularities of the form where a super
122 // class has a field that is of the type of the sub class. We need to be able
123 // to fully resolve super classes while resolving types for fields.
124 //
125 // kStatusRetryVerificationAtRuntime: The verifier sets a class to
126 // this state if it encounters a soft failure at compile time. This
127 // often happens when there are unresolved classes in other dex
128 // files, and this status marks a class as needing to be verified
129 // again at runtime.
130 //
131 // TODO: Explain the other states
132 enum Status {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700133 kStatusRetired = -2,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800134 kStatusError = -1,
135 kStatusNotReady = 0,
136 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
137 kStatusLoaded = 2, // DEX idx values resolved.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700138 kStatusResolving = 3, // Just cloned from temporary class object.
139 kStatusResolved = 4, // Part of linking.
140 kStatusVerifying = 5, // In the process of being verified.
141 kStatusRetryVerificationAtRuntime = 6, // Compile time verification failed, retry at runtime.
142 kStatusVerifyingAtRuntime = 7, // Retrying verification at runtime.
143 kStatusVerified = 8, // Logically part of linking; done pre-init.
144 kStatusInitializing = 9, // Class init in progress.
145 kStatusInitialized = 10, // Ready to go.
146 kStatusMax = 11,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800147 };
148
Mathieu Chartier4e305412014-02-19 10:54:44 -0800149 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800150 Status GetStatus() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800151 COMPILE_ASSERT(sizeof(Status) == sizeof(uint32_t), size_of_status_not_uint32);
Ian Rogers03dbc042014-06-02 14:24:56 -0700152 return static_cast<Status>(
153 GetField32Volatile<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154 }
155
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700156 void SetStatus(Status new_status, Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157
Ian Rogers5ddb4102014-01-07 08:58:46 -0800158 static MemberOffset StatusOffset() {
159 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
160 }
161
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700162 // Returns true if the class has been retired.
163 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
164 bool IsRetired() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
165 return GetStatus<kVerifyFlags>() == kStatusRetired;
166 }
167
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800168 // Returns true if the class has failed to link.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800169 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800170 bool IsErroneous() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800171 return GetStatus<kVerifyFlags>() == kStatusError;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172 }
173
174 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800175 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800176 bool IsIdxLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800177 return GetStatus<kVerifyFlags>() >= kStatusIdx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178 }
179
180 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800181 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800182 bool IsLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800183 return GetStatus<kVerifyFlags>() >= kStatusLoaded;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 }
185
186 // Returns true if the class has been linked.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800187 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800188 bool IsResolved() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800189 return GetStatus<kVerifyFlags>() >= kStatusResolved;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190 }
191
192 // Returns true if the class was compile-time verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800193 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800194 bool IsCompileTimeVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800195 return GetStatus<kVerifyFlags>() >= kStatusRetryVerificationAtRuntime;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 }
197
198 // Returns true if the class has been verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800199 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800200 bool IsVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800201 return GetStatus<kVerifyFlags>() >= kStatusVerified;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800202 }
203
204 // Returns true if the class is initializing.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800205 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800206 bool IsInitializing() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800207 return GetStatus<kVerifyFlags>() >= kStatusInitializing;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800208 }
209
210 // Returns true if the class is initialized.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800211 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800212 bool IsInitialized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800213 return GetStatus<kVerifyFlags>() == kStatusInitialized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 }
215
Mathieu Chartier4e305412014-02-19 10:54:44 -0800216 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800217 uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800218
Ian Rogersef7d42f2014-01-06 12:55:46 -0800219 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100220 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700221 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), new_access_flags);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800222 }
223
224 // Returns true if the class is an interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800225 bool IsInterface() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800226 return (GetAccessFlags() & kAccInterface) != 0;
227 }
228
229 // Returns true if the class is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800230 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800231 return (GetAccessFlags() & kAccPublic) != 0;
232 }
233
234 // Returns true if the class is declared final.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800235 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800236 return (GetAccessFlags() & kAccFinal) != 0;
237 }
238
Ian Rogersef7d42f2014-01-06 12:55:46 -0800239 bool IsFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800240 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
241 }
242
Ian Rogersef7d42f2014-01-06 12:55:46 -0800243 void SetFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700244 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800245 SetAccessFlags(flags | kAccClassIsFinalizable);
246 }
247
248 // Returns true if the class is abstract.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800249 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800250 return (GetAccessFlags() & kAccAbstract) != 0;
251 }
252
253 // Returns true if the class is an annotation.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800254 bool IsAnnotation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800255 return (GetAccessFlags() & kAccAnnotation) != 0;
256 }
257
258 // Returns true if the class is synthetic.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800259 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260 return (GetAccessFlags() & kAccSynthetic) != 0;
261 }
262
Mathieu Chartier4e305412014-02-19 10:54:44 -0800263 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Fred Shih4ee7a662014-07-11 09:59:27 -0700264 bool IsTypeOfReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800265 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800266 }
267
Mathieu Chartier4e305412014-02-19 10:54:44 -0800268 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800269 bool IsWeakReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800270 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsWeakReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800271 }
272
Mathieu Chartier4e305412014-02-19 10:54:44 -0800273 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800274 bool IsSoftReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800275 return (GetAccessFlags<kVerifyFlags>() & kAccReferenceFlagsMask) == kAccClassIsReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800276 }
277
Mathieu Chartier4e305412014-02-19 10:54:44 -0800278 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800279 bool IsFinalizerReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800280 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsFinalizerReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800281 }
282
Mathieu Chartier4e305412014-02-19 10:54:44 -0800283 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800284 bool IsPhantomReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800285 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsPhantomReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800286 }
287
Ian Rogers04f94f42013-06-10 15:09:26 -0700288 // Can references of this type be assigned to by things of another type? For non-array types
289 // this is a matter of whether sub-classes may exist - which they can't if the type is final.
290 // For array classes, where all the classes are final due to there being no sub-classes, an
291 // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
292 // types as the component is final.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800293 bool CannotBeAssignedFromOtherTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers04f94f42013-06-10 15:09:26 -0700294 if (!IsArrayClass()) {
295 return IsFinal();
296 } else {
297 Class* component = GetComponentType();
298 if (component->IsPrimitive()) {
Ian Rogersa9a82542013-10-04 11:17:26 -0700299 return true;
Ian Rogers04f94f42013-06-10 15:09:26 -0700300 } else {
301 return component->CannotBeAssignedFromOtherTypes();
302 }
303 }
304 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800305
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700306 // Returns true if this class is the placeholder and should retire and
307 // be replaced with a class with the right size for embedded imt/vtable.
308 bool IsTemp() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
309 Status s = GetStatus();
310 return s < Status::kStatusResolving && ShouldHaveEmbeddedImtAndVTable();
311 }
312
Ian Rogersef7d42f2014-01-06 12:55:46 -0800313 String* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Returns the cached name.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800314 void SetName(String* name) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Sets the cached name.
315 // Computes the name, then sets the cached value.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700316 static String* ComputeName(Handle<Class> h_this) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800317
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800318 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier4e305412014-02-19 10:54:44 -0800319 bool IsProxyClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800320 // Read access flags without using getter as whether something is a proxy can be check in
321 // any loaded state
322 // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700323 uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800324 return (access_flags & kAccClassIsProxy) != 0;
325 }
326
Mathieu Chartier4e305412014-02-19 10:54:44 -0800327 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700328 Primitive::Type GetPrimitiveType() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800329
Ian Rogersef7d42f2014-01-06 12:55:46 -0800330 void SetPrimitiveType(Primitive::Type new_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800331 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700332 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), new_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800333 }
334
335 // Returns true if the class is a primitive type.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800336 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800337 bool IsPrimitive() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800338 return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800339 }
340
Mathieu Chartier4e305412014-02-19 10:54:44 -0800341 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800342 bool IsPrimitiveBoolean() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800343 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800344 }
345
Mathieu Chartier4e305412014-02-19 10:54:44 -0800346 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800347 bool IsPrimitiveByte() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800348 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800349 }
350
Mathieu Chartier4e305412014-02-19 10:54:44 -0800351 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800352 bool IsPrimitiveChar() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800353 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800354 }
355
Mathieu Chartier4e305412014-02-19 10:54:44 -0800356 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800357 bool IsPrimitiveShort() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800358 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800359 }
360
Mathieu Chartier4e305412014-02-19 10:54:44 -0800361 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800362 bool IsPrimitiveInt() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800363 return GetPrimitiveType() == Primitive::kPrimInt;
364 }
365
Mathieu Chartier4e305412014-02-19 10:54:44 -0800366 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800367 bool IsPrimitiveLong() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800368 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800369 }
370
Mathieu Chartier4e305412014-02-19 10:54:44 -0800371 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800372 bool IsPrimitiveFloat() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800373 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800374 }
375
Mathieu Chartier4e305412014-02-19 10:54:44 -0800376 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800377 bool IsPrimitiveDouble() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800378 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800379 }
380
Mathieu Chartier4e305412014-02-19 10:54:44 -0800381 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800382 bool IsPrimitiveVoid() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800383 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800384 }
385
Mathieu Chartier4e305412014-02-19 10:54:44 -0800386 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800387 bool IsPrimitiveArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800388 return IsArrayClass<kVerifyFlags>() &&
389 GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
390 IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800391 }
392
393 // Depth of class from java.lang.Object
Ian Rogersef7d42f2014-01-06 12:55:46 -0800394 uint32_t Depth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
395 uint32_t depth = 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800396 for (Class* klass = this; klass->GetSuperClass() != NULL; klass = klass->GetSuperClass()) {
397 depth++;
398 }
399 return depth;
400 }
401
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700402 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
403 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800404 bool IsArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700405 return GetComponentType<kVerifyFlags, kReadBarrierOption>() != NULL;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406 }
407
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700408 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
409 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800410 bool IsClassClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800411
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700412 bool IsStringClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800413
Ian Rogersef7d42f2014-01-06 12:55:46 -0800414 bool IsThrowableClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700416 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700417 bool IsArtFieldClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700419 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700420 bool IsArtMethodClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800421
Fred Shih4ee7a662014-07-11 09:59:27 -0700422 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
423 bool IsReferenceClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
424
Ian Rogersa9a82542013-10-04 11:17:26 -0700425 static MemberOffset ComponentTypeOffset() {
426 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
427 }
428
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700429 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
430 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800431 Class* GetComponentType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700432 return GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(ComponentTypeOffset());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800433 }
434
435 void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
436 DCHECK(GetComponentType() == NULL);
437 DCHECK(new_component_type != NULL);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100438 // Component type is invariant: use non-transactional mode without check.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700439 SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440 }
441
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700442 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800443 size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700444 return Primitive::ComponentSize(
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700445 GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveType());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800446 }
447
Ian Rogersef7d42f2014-01-06 12:55:46 -0800448 bool IsObjectClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449 return !IsPrimitive() && GetSuperClass() == NULL;
450 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800451 bool IsInstantiable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sameer Abu Asal02c42232013-04-30 12:09:45 -0700452 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) || ((IsAbstract()) && IsArrayClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800453 }
454
Mathieu Chartier4e305412014-02-19 10:54:44 -0800455 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800456 bool IsObjectArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800457 return GetComponentType<kVerifyFlags>() != nullptr && !GetComponentType<kVerifyFlags>()->IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800458 }
459
460 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700461 template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800462 ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
463 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700464
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800465 Object* AllocObject(Thread* self)
466 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
467 Object* AllocNonMovableObject(Thread* self)
468 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800469
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700470 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
471 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800472 bool IsVariableSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800473 // Classes and arrays vary in size, and so the object_size_ field cannot
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700474 // be used to Get their instance size
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700475 return IsClassClass<kVerifyFlags, kReadBarrierOption>() ||
476 IsArrayClass<kVerifyFlags, kReadBarrierOption>();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800477 }
478
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700479 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
480 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800481 uint32_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700482 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800483 }
484
Mathieu Chartier4e305412014-02-19 10:54:44 -0800485 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800486 uint32_t GetClassSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700487 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800488 }
489
Ian Rogersef7d42f2014-01-06 12:55:46 -0800490 void SetClassSize(uint32_t new_class_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800491 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
492
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700493 // Compute how many bytes would be used a class with the given elements.
494 static uint32_t ComputeClassSize(bool has_embedded_tables,
495 uint32_t num_vtable_entries,
496 uint32_t num_32bit_static_fields,
497 uint32_t num_64bit_static_fields,
498 uint32_t num_ref_static_fields);
499
500 // The size of java.lang.Class.class.
501 static uint32_t ClassClassSize() {
502 // The number of vtable entries in java.lang.Class.
503 uint32_t vtable_entries = Object::kVTableLength + 64;
504 return ComputeClassSize(true, vtable_entries, 0, 1, 0);
505 }
506
507 // The size of a java.lang.Class representing a primitive such as int.class.
508 static uint32_t PrimitiveClassSize() {
509 return ComputeClassSize(false, 0, 0, 0, 0);
510 }
511
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700512 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
513 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800514 uint32_t GetObjectSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800515
Ian Rogersef7d42f2014-01-06 12:55:46 -0800516 void SetObjectSize(uint32_t new_object_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800517 DCHECK(!IsVariableSize());
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100518 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700519 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800520 }
521
522 // Returns true if this class is in the same packages as that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800523 bool IsInSamePackage(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800524
525 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
526
527 // Returns true if this class can access that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800528 bool CanAccess(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800529 return that->IsPublic() || this->IsInSamePackage(that);
530 }
531
532 // Can this class access a member in the provided class with the provided member access flags?
533 // Note that access to the class isn't checked in case the declaring class is protected and the
534 // method has been exposed by a public sub-class
Ian Rogersef7d42f2014-01-06 12:55:46 -0800535 bool CanAccessMember(Class* access_to, uint32_t member_flags)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800536 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
537 // Classes can access all of their own members
538 if (this == access_to) {
539 return true;
540 }
541 // Public members are trivially accessible
542 if (member_flags & kAccPublic) {
543 return true;
544 }
545 // Private members are trivially not accessible
546 if (member_flags & kAccPrivate) {
547 return false;
548 }
549 // Check for protected access from a sub-class, which may or may not be in the same package.
550 if (member_flags & kAccProtected) {
551 if (this->IsSubClass(access_to)) {
552 return true;
553 }
554 }
555 // Allow protected access from other classes in the same package.
556 return this->IsInSamePackage(access_to);
557 }
558
Vladimir Marko23a28212014-01-09 19:24:37 +0000559 // Can this class access a resolved field?
560 // Note that access to field's class is checked and this may require looking up the class
561 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000562 bool CanAccessResolvedField(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800563 DexCache* dex_cache, uint32_t field_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000564 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
565 bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
566 uint32_t field_idx)
567 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000568
569 // Can this class access a resolved method?
570 // Note that access to methods's class is checked and this may require looking up the class
571 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000572 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800573 DexCache* dex_cache, uint32_t method_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000574 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
575 template <InvokeType throw_invoke_type>
576 bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
577 uint32_t method_idx)
578 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000579
Ian Rogersef7d42f2014-01-06 12:55:46 -0800580 bool IsSubClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800581
582 // Can src be assigned to this class? For example, String can be assigned to Object (by an
583 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
584 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
585 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
586 // to themselves. Classes for primitive types may not assign to each other.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800587 inline bool IsAssignableFrom(Class* src) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800588 DCHECK(src != NULL);
589 if (this == src) {
590 // Can always assign to things of the same type.
591 return true;
592 } else if (IsObjectClass()) {
593 // Can assign any reference to java.lang.Object.
594 return !src->IsPrimitive();
595 } else if (IsInterface()) {
596 return src->Implements(this);
597 } else if (src->IsArrayClass()) {
598 return IsAssignableFromArray(src);
599 } else {
600 return !src->IsInterface() && src->IsSubClass(this);
601 }
602 }
603
Ian Rogersef7d42f2014-01-06 12:55:46 -0800604 Class* GetSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800605
606 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800607 // Super class is assigned once, except during class linker initialization.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700608 Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800609 DCHECK(old_super_class == nullptr || old_super_class == new_super_class);
610 DCHECK(new_super_class != nullptr);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700611 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800612 }
613
Ian Rogersef7d42f2014-01-06 12:55:46 -0800614 bool HasSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800615 return GetSuperClass() != NULL;
616 }
617
618 static MemberOffset SuperClassOffset() {
619 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
620 }
621
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700622 ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800623
624 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
625
626 static MemberOffset DexCacheOffset() {
627 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
628 }
629
630 enum {
631 kDumpClassFullDetail = 1,
632 kDumpClassClassLoader = (1 << 1),
633 kDumpClassInitialized = (1 << 2),
634 };
635
Ian Rogersef7d42f2014-01-06 12:55:46 -0800636 void DumpClass(std::ostream& os, int flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800637
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800638 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800639 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800640
641 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
642
Ian Rogersef7d42f2014-01-06 12:55:46 -0800643 ObjectArray<ArtMethod>* GetDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800644
Brian Carlstromea46f952013-07-30 01:26:50 -0700645 void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800646 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
647
Ian Rogersef7d42f2014-01-06 12:55:46 -0800648 ArtMethod* GetDirectMethod(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800649
Brian Carlstromea46f952013-07-30 01:26:50 -0700650 void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800651 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
652
653 // Returns the number of static, private, and constructor methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800654 uint32_t NumDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800655
Mathieu Chartier4e305412014-02-19 10:54:44 -0800656 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800657 ObjectArray<ArtMethod>* GetVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800658
Brian Carlstromea46f952013-07-30 01:26:50 -0700659 void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800660 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
661
662 // Returns the number of non-inherited virtual methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800663 uint32_t NumVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800664
Mathieu Chartier4e305412014-02-19 10:54:44 -0800665 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800666 ArtMethod* GetVirtualMethod(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800667
Ian Rogersef7d42f2014-01-06 12:55:46 -0800668 ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800669
Brian Carlstromea46f952013-07-30 01:26:50 -0700670 void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800671 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
672
Ian Rogersef7d42f2014-01-06 12:55:46 -0800673 ObjectArray<ArtMethod>* GetVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800674
Ian Rogersef7d42f2014-01-06 12:55:46 -0800675 ObjectArray<ArtMethod>* GetVTableDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800676
Brian Carlstromea46f952013-07-30 01:26:50 -0700677 void SetVTable(ObjectArray<ArtMethod>* new_vtable)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800678 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
679
680 static MemberOffset VTableOffset() {
681 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
682 }
683
Jeff Hao88474b42013-10-23 16:24:40 -0700684 void SetImTable(ObjectArray<ArtMethod>* new_imtable)
685 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
686
687 static MemberOffset ImTableOffset() {
688 return OFFSET_OF_OBJECT_MEMBER(Class, imtable_);
689 }
690
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700691 static MemberOffset EmbeddedImTableOffset() {
692 return MemberOffset(sizeof(Class));
693 }
694
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700695 static MemberOffset EmbeddedVTableLengthOffset() {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700696 return MemberOffset(sizeof(Class) + kImtSize * sizeof(mirror::Class::ImTableEntry));
697 }
698
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700699 static MemberOffset EmbeddedVTableOffset() {
700 return MemberOffset(sizeof(Class) + kImtSize * sizeof(mirror::Class::ImTableEntry) + sizeof(int32_t));
701 }
702
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700703 bool ShouldHaveEmbeddedImtAndVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
704 return IsInstantiable();
705 }
706
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700707 bool HasVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
708
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700709 ArtMethod* GetEmbeddedImTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
710
711 void SetEmbeddedImTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
712
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700713 int32_t GetVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
714
715 ArtMethod* GetVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
716
717 int32_t GetEmbeddedVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
718
719 void SetEmbeddedVTableLength(int32_t len) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
720
721 ArtMethod* GetEmbeddedVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
722
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700723 void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
724
725 void PopulateEmbeddedImtAndVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
726
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800727 // Given a method implemented by this class but potentially from a super class, return the
728 // specific implementation method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800729 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800730 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
731
732 // Given a method implemented by this class' super class, return the specific implementation
733 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800734 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800735 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
736
737 // Given a method implemented by this class, but potentially from a
738 // super class or interface, return the specific implementation
739 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800740 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method)
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800741 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800742
Ian Rogersef7d42f2014-01-06 12:55:46 -0800743 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700744 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
745
Brian Carlstrom004644f2014-06-18 08:34:01 -0700746 ArtMethod* FindInterfaceMethod(const StringPiece& name, const StringPiece& signature)
747 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
748
Ian Rogersef7d42f2014-01-06 12:55:46 -0800749 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800750 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
751
Ian Rogersef7d42f2014-01-06 12:55:46 -0800752 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800753 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
754
Ian Rogersef7d42f2014-01-06 12:55:46 -0800755 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800756 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
757
Ian Rogersef7d42f2014-01-06 12:55:46 -0800758 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700759 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
760
Ian Rogersef7d42f2014-01-06 12:55:46 -0800761 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800762 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
763
Ian Rogersef7d42f2014-01-06 12:55:46 -0800764 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800765 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
766
Ian Rogersef7d42f2014-01-06 12:55:46 -0800767 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700768 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
769
Ian Rogersef7d42f2014-01-06 12:55:46 -0800770 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800771 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
772
Ian Rogersef7d42f2014-01-06 12:55:46 -0800773 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700774 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
775
Ian Rogersef7d42f2014-01-06 12:55:46 -0800776 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700777 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
778
Ian Rogersef7d42f2014-01-06 12:55:46 -0800779 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700780 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
781
Ian Rogersef7d42f2014-01-06 12:55:46 -0800782 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700783 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
784
Ian Rogersef7d42f2014-01-06 12:55:46 -0800785 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700786 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
787
Ian Rogersef7d42f2014-01-06 12:55:46 -0800788 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700789 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
790
Ian Rogersef7d42f2014-01-06 12:55:46 -0800791 ArtMethod* FindClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700792
Ian Rogersef7d42f2014-01-06 12:55:46 -0800793 int32_t GetIfTableCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800794
Ian Rogersef7d42f2014-01-06 12:55:46 -0800795 IfTable* GetIfTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800796
797 void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
798
799 // Get instance fields of the class (See also GetSFields).
Ian Rogersef7d42f2014-01-06 12:55:46 -0800800 ObjectArray<ArtField>* GetIFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800801
Brian Carlstromea46f952013-07-30 01:26:50 -0700802 void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800803
Ian Rogersef7d42f2014-01-06 12:55:46 -0800804 uint32_t NumInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800805
Ian Rogersef7d42f2014-01-06 12:55:46 -0800806 ArtField* GetInstanceField(uint32_t i) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800807 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
808
Brian Carlstromea46f952013-07-30 01:26:50 -0700809 void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800810 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
811
812 // Returns the number of instance fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800813 uint32_t NumReferenceInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800814 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700815 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800816 }
817
Ian Rogersef7d42f2014-01-06 12:55:46 -0800818 uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800819 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700820 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800821 }
822
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700823 void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100824 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700825 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800826 }
827
Mathieu Chartier4e305412014-02-19 10:54:44 -0800828 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700829 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800830
831 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
832 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
833
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800834 // Returns the number of static fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800835 uint32_t NumReferenceStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800836 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700837 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800838 }
839
Ian Rogersef7d42f2014-01-06 12:55:46 -0800840 uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700841 DCHECK(IsLoaded() || IsErroneous() || IsRetired());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700842 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800843 }
844
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700845 void SetNumReferenceStaticFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100846 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700847 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800848 }
849
850 // Gets the static fields of the class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800851 ObjectArray<ArtField>* GetSFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800852
Brian Carlstromea46f952013-07-30 01:26:50 -0700853 void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800854
Ian Rogersef7d42f2014-01-06 12:55:46 -0800855 uint32_t NumStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800856
Ian Rogersef7d42f2014-01-06 12:55:46 -0800857 // TODO: uint16_t
858 ArtField* GetStaticField(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800859
Ian Rogersef7d42f2014-01-06 12:55:46 -0800860 // TODO: uint16_t
861 void SetStaticField(uint32_t i, ArtField* f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800862
Mathieu Chartier4e305412014-02-19 10:54:44 -0800863 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800864 uint32_t GetReferenceStaticOffsets() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700865 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800866 }
867
Ian Rogersef7d42f2014-01-06 12:55:46 -0800868 void SetReferenceStaticOffsets(uint32_t new_reference_offsets)
869 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800870
871 // Find a static or instance field using the JLS resolution order
Mathieu Chartierf8322842014-05-16 10:59:25 -0700872 static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
873 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800874 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
875
876 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700877 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800878 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
879
880 // Finds the given instance field in this class or a superclass, only searches classes that
881 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700882 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800883 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
884
Brian Carlstromea46f952013-07-30 01:26:50 -0700885 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800886 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
887
Brian Carlstromea46f952013-07-30 01:26:50 -0700888 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800889 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
890
891 // Finds the given static field in this class or a superclass.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700892 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
893 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800894 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
895
896 // Finds the given static field in this class or superclass, only searches classes that
897 // have the same dex cache.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700898 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
899 uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800900 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
901
Brian Carlstromea46f952013-07-30 01:26:50 -0700902 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800903 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
904
Brian Carlstromea46f952013-07-30 01:26:50 -0700905 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800906 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
907
Ian Rogersef7d42f2014-01-06 12:55:46 -0800908 pid_t GetClinitThreadId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800909 DCHECK(IsIdxLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700910 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800911 }
912
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700913 void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800914
Ian Rogersef7d42f2014-01-06 12:55:46 -0800915 Class* GetVerifyErrorClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800916 // DCHECK(IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700917 return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800918 }
919
Ian Rogersef7d42f2014-01-06 12:55:46 -0800920 uint16_t GetDexClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700921 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700922 }
923
Ian Rogersef7d42f2014-01-06 12:55:46 -0800924 void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100925 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700926 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700927 }
928
Ian Rogersef7d42f2014-01-06 12:55:46 -0800929 uint16_t GetDexTypeIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700930 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800931 }
932
Ian Rogersef7d42f2014-01-06 12:55:46 -0800933 void SetDexTypeIndex(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100934 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700935 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800936 }
937
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700938 static Class* GetJavaLangClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800939 DCHECK(java_lang_Class_ != NULL);
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700940 return ReadBarrier::BarrierForRoot<mirror::Class, kWithReadBarrier>(
941 &java_lang_Class_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800942 }
943
944 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700945 static void SetClassClass(Class* java_lang_Class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800946 static void ResetClass();
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800947 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800948 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800949
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200950 // When class is verified, set the kAccPreverified flag on each method.
951 void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
952
Mathieu Chartier407f7022014-02-18 14:37:05 -0800953 template <bool kVisitClass, typename Visitor>
954 void VisitReferences(mirror::Class* klass, const Visitor& visitor)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700955 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
956
957 // Visit references within the embedded tables of the class.
958 // TODO: remove NO_THREAD_SAFETY_ANALYSIS when annotalysis handles visitors better.
959 template<typename Visitor>
960 void VisitEmbeddedImtAndVTable(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier407f7022014-02-18 14:37:05 -0800961
Mathieu Chartierf8322842014-05-16 10:59:25 -0700962 std::string GetDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700963
Mathieu Chartierf8322842014-05-16 10:59:25 -0700964 bool DescriptorEquals(const char* match) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700965
Mathieu Chartierf8322842014-05-16 10:59:25 -0700966 std::string GetArrayDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700967
Mathieu Chartierf8322842014-05-16 10:59:25 -0700968 const DexFile::ClassDef* GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700969
Mathieu Chartierf8322842014-05-16 10:59:25 -0700970 uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700971
Mathieu Chartierf8322842014-05-16 10:59:25 -0700972 uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700973
Mathieu Chartierf8322842014-05-16 10:59:25 -0700974 static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass, uint32_t idx)
975 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700976
Mathieu Chartierf8322842014-05-16 10:59:25 -0700977 const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700978
Mathieu Chartierf8322842014-05-16 10:59:25 -0700979 std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700980
Mathieu Chartierf8322842014-05-16 10:59:25 -0700981 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700982
Mathieu Chartierf8322842014-05-16 10:59:25 -0700983 const DexFile::TypeList* GetInterfaceTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
984
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +0200985 // Asserts we are initialized or initializing in the given thread.
986 void AssertInitializedOrInitializingInThread(Thread* self)
987 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
988
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700989 Class* CopyOf(Thread* self, int32_t new_length)
990 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
991
992 // For proxy class only.
993 ObjectArray<Class>* GetInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
994
995 // For proxy class only.
996 ObjectArray<ObjectArray<Class>>* GetThrows() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
997
Fred Shih4ee7a662014-07-11 09:59:27 -0700998 // For reference class only.
999 MemberOffset GetDisableIntrinsicFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1000 MemberOffset GetSlowPathFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1001 bool GetSlowPathEnabled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1002 void SetSlowPath(bool enabled) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1003
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001004 // Used to initialize a class in the allocation code path to ensure it is guarded by a StoreStore
1005 // fence.
1006 class InitializeClassVisitor {
1007 public:
1008 explicit InitializeClassVisitor(uint32_t class_size) : class_size_(class_size) {
1009 }
1010
1011 void operator()(mirror::Object* obj, size_t usable_size) const
1012 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1013
1014 private:
1015 const uint32_t class_size_;
1016
1017 DISALLOW_COPY_AND_ASSIGN(InitializeClassVisitor);
1018 };
1019
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001020 private:
1021 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1022
Vladimir Marko89786432014-01-31 15:03:55 +00001023 template <bool throw_on_failure, bool use_referrers_cache>
1024 bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001025 uint32_t field_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001026 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1027 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
1028 bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001029 uint32_t method_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001030 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1031
Ian Rogersef7d42f2014-01-06 12:55:46 -08001032 bool Implements(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1033 bool IsArrayAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1034 bool IsAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001035
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001036 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1037
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001038 ObjectArray<ArtMethod>* GetImTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1039
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001040 // defining class loader, or NULL for the "bootstrap" system loader
Ian Rogersef7d42f2014-01-06 12:55:46 -08001041 HeapReference<ClassLoader> class_loader_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001042
1043 // For array classes, the component class object for instanceof/checkcast
1044 // (for String[][][], this will be String[][]). NULL for non-array classes.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001045 HeapReference<Class> component_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001046
1047 // DexCache of resolved constant pool entries (will be NULL for classes generated by the
1048 // runtime such as arrays and primitive classes).
Ian Rogersef7d42f2014-01-06 12:55:46 -08001049 HeapReference<DexCache> dex_cache_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001050
1051 // static, private, and <init> methods
Ian Rogers700a4022014-05-19 16:49:03 -07001052 HeapReference<ObjectArray<ArtMethod>> direct_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001053
1054 // instance fields
1055 //
1056 // These describe the layout of the contents of an Object.
1057 // Note that only the fields directly declared by this class are
1058 // listed in ifields; fields declared by a superclass are listed in
1059 // the superclass's Class.ifields.
1060 //
1061 // All instance fields that refer to objects are guaranteed to be at
1062 // the beginning of the field list. num_reference_instance_fields_
1063 // specifies the number of reference fields.
Ian Rogers700a4022014-05-19 16:49:03 -07001064 HeapReference<ObjectArray<ArtField>> ifields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001065
1066 // The interface table (iftable_) contains pairs of a interface class and an array of the
1067 // interface methods. There is one pair per interface supported by this class. That means one
1068 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
1069 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
1070 //
1071 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
1072 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
1073 // single vtable.
1074 //
1075 // For every interface a concrete class implements, we create an array of the concrete vtable_
1076 // methods for the methods in the interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001077 HeapReference<IfTable> iftable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001078
Jeff Hao88474b42013-10-23 16:24:40 -07001079 // Interface method table (imt), for quick "invoke-interface".
Ian Rogers700a4022014-05-19 16:49:03 -07001080 HeapReference<ObjectArray<ArtMethod>> imtable_;
Jeff Hao88474b42013-10-23 16:24:40 -07001081
Ian Rogersef7d42f2014-01-06 12:55:46 -08001082 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
1083 HeapReference<String> name_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001084
1085 // Static fields
Ian Rogersef7d42f2014-01-06 12:55:46 -08001086 HeapReference<ObjectArray<ArtField>> sfields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001087
1088 // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001089 HeapReference<Class> super_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001090
1091 // If class verify fails, we must return same error on subsequent tries.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001092 HeapReference<Class> verify_error_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001093
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001094 // Virtual methods defined in this class; invoked through vtable.
Ian Rogers700a4022014-05-19 16:49:03 -07001095 HeapReference<ObjectArray<ArtMethod>> virtual_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001096
1097 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
1098 // copied in, and virtual methods from our class either replace those from the super or are
1099 // appended. For abstract classes, methods may be created in the vtable that aren't in
1100 // virtual_ methods_ for miranda methods.
Ian Rogers700a4022014-05-19 16:49:03 -07001101 HeapReference<ObjectArray<ArtMethod>> vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001102
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001103 // Access flags; low 16 bits are defined by VM spec.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001104 uint32_t access_flags_;
1105
1106 // Total size of the Class instance; used when allocating storage on gc heap.
1107 // See also object_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001108 uint32_t class_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001109
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001110 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001111 pid_t clinit_thread_id_;
1112
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001113 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001114 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001115 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001116
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001117 // Type index in dex file.
1118 // TODO: really 16bits
1119 int32_t dex_type_idx_;
1120
1121 // Number of instance fields that are object refs.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001122 uint32_t num_reference_instance_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001123
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001124 // Number of static fields that are object refs,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001125 uint32_t num_reference_static_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001126
1127 // Total object size; used when allocating storage on gc heap.
1128 // (For interfaces and abstract classes this will be zero.)
1129 // See also class_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001130 uint32_t object_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001131
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001132 // Primitive type value, or Primitive::kPrimNot (0); set for generated primitive classes.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001133 Primitive::Type primitive_type_;
1134
1135 // Bitmap of offsets of ifields.
1136 uint32_t reference_instance_offsets_;
1137
1138 // Bitmap of offsets of sfields.
1139 uint32_t reference_static_offsets_;
1140
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001141 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001142 Status status_;
1143
1144 // TODO: ?
1145 // initiating class loader list
1146 // NOTE: for classes with low serialNumber, these are unused, and the
1147 // values are kept in a table in gDvm.
1148 // InitiatingLoaderList initiating_loader_list_;
1149
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001150 // The following data exist in real class objects.
1151 // Embedded Imtable, for class object that's not an interface, fixed size.
1152 ImTableEntry embedded_imtable_[0];
1153 // Embedded Vtable, for class object that's not an interface, variable size.
1154 VTableEntry embedded_vtable_[0];
1155 // Static fields, variable size.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001156 uint32_t fields_[0];
1157
1158 // java.lang.Class
1159 static Class* java_lang_Class_;
1160
1161 friend struct art::ClassOffsets; // for verifying offset information
1162 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
1163};
1164
1165std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1166
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001167} // namespace mirror
1168} // namespace art
1169
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001170#endif // ART_RUNTIME_MIRROR_CLASS_H_