blob: a692381f92c2a1877a9f18d1be8af1a36775592d [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 Chartiercbb2d202013-11-14 17:45:16 -080020#include "gc/heap.h"
Vladimir Marko23a28212014-01-09 19:24:37 +000021#include "invoke_type.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "modifiers.h"
23#include "object.h"
24#include "primitive.h"
25
26/*
27 * A magic value for refOffsets. Ignore the bits and walk the super
28 * chain when this is the value.
29 * [This is an unlikely "natural" value, since it would be 30 non-ref instance
30 * fields followed by 2 ref instance fields.]
31 */
Brian Carlstromfb6996f2013-07-18 18:21:14 -070032#define CLASS_WALK_SUPER 3U
33#define CLASS_BITS_PER_WORD (sizeof(uint32_t) * 8)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034#define CLASS_OFFSET_ALIGNMENT 4
Brian Carlstromfb6996f2013-07-18 18:21:14 -070035#define CLASS_HIGH_BIT (1U << (CLASS_BITS_PER_WORD - 1))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036/*
37 * Given an offset, return the bit number which would encode that offset.
38 * Local use only.
39 */
40#define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \
41 ((unsigned int)(byteOffset) / \
42 CLASS_OFFSET_ALIGNMENT)
43/*
44 * Is the given offset too large to be encoded?
45 */
46#define CLASS_CAN_ENCODE_OFFSET(byteOffset) \
47 (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD)
48/*
49 * Return a single bit, encoding the offset.
50 * Undefined if the offset is too large, as defined above.
51 */
52#define CLASS_BIT_FROM_OFFSET(byteOffset) \
53 (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset))
54/*
55 * Return an offset, given a bit number as returned from CLZ.
56 */
57#define CLASS_OFFSET_FROM_CLZ(rshift) \
58 MemberOffset((static_cast<int>(rshift) * CLASS_OFFSET_ALIGNMENT))
59
60namespace art {
61
62struct ClassClassOffsets;
63struct ClassOffsets;
Ian Rogersd91d6d62013-09-25 20:26:14 -070064class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080065class StringPiece;
66
67namespace mirror {
68
Brian Carlstromea46f952013-07-30 01:26:50 -070069class ArtField;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070class ClassLoader;
71class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072class IfTable;
73
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074// C++ mirror of java.lang.Class
Ian Rogers5ddb4102014-01-07 08:58:46 -080075class MANAGED Class : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 public:
77 // Class Status
78 //
79 // kStatusNotReady: If a Class cannot be found in the class table by
80 // FindClass, it allocates an new one with AllocClass in the
81 // kStatusNotReady and calls LoadClass. Note if it does find a
82 // class, it may not be kStatusResolved and it will try to push it
83 // forward toward kStatusResolved.
84 //
85 // kStatusIdx: LoadClass populates with Class with information from
86 // the DexFile, moving the status to kStatusIdx, indicating that the
87 // Class value in super_class_ has not been populated. The new Class
88 // can then be inserted into the classes table.
89 //
90 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
91 // attempt to move a kStatusIdx class forward to kStatusLoaded by
92 // using ResolveClass to initialize the super_class_ and ensuring the
93 // interfaces are resolved.
94 //
95 // kStatusResolved: Still holding the lock on Class, the ClassLinker
96 // shows linking is complete and fields of the Class populated by making
97 // it kStatusResolved. Java allows circularities of the form where a super
98 // class has a field that is of the type of the sub class. We need to be able
99 // to fully resolve super classes while resolving types for fields.
100 //
101 // kStatusRetryVerificationAtRuntime: The verifier sets a class to
102 // this state if it encounters a soft failure at compile time. This
103 // often happens when there are unresolved classes in other dex
104 // files, and this status marks a class as needing to be verified
105 // again at runtime.
106 //
107 // TODO: Explain the other states
108 enum Status {
109 kStatusError = -1,
110 kStatusNotReady = 0,
111 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
112 kStatusLoaded = 2, // DEX idx values resolved.
113 kStatusResolved = 3, // Part of linking.
114 kStatusVerifying = 4, // In the process of being verified.
115 kStatusRetryVerificationAtRuntime = 5, // Compile time verification failed, retry at runtime.
116 kStatusVerifyingAtRuntime = 6, // Retrying verification at runtime.
117 kStatusVerified = 7, // Logically part of linking; done pre-init.
118 kStatusInitializing = 8, // Class init in progress.
119 kStatusInitialized = 9, // Ready to go.
Brian Carlstromba150c32013-08-27 17:31:03 -0700120 kStatusMax = 10,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800121 };
122
123 Status GetStatus() const {
124 DCHECK_EQ(sizeof(Status), sizeof(uint32_t));
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700125 return static_cast<Status>(GetField32(OFFSET_OF_OBJECT_MEMBER(Class, status_), true));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800126 }
127
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700128 void SetStatus(Status new_status, Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129
Ian Rogers5ddb4102014-01-07 08:58:46 -0800130 static MemberOffset StatusOffset() {
131 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
132 }
133
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800134 // Returns true if the class has failed to link.
135 bool IsErroneous() const {
136 return GetStatus() == kStatusError;
137 }
138
139 // Returns true if the class has been loaded.
140 bool IsIdxLoaded() const {
141 return GetStatus() >= kStatusIdx;
142 }
143
144 // Returns true if the class has been loaded.
145 bool IsLoaded() const {
146 return GetStatus() >= kStatusLoaded;
147 }
148
149 // Returns true if the class has been linked.
150 bool IsResolved() const {
151 return GetStatus() >= kStatusResolved;
152 }
153
154 // Returns true if the class was compile-time verified.
155 bool IsCompileTimeVerified() const {
156 return GetStatus() >= kStatusRetryVerificationAtRuntime;
157 }
158
159 // Returns true if the class has been verified.
160 bool IsVerified() const {
161 return GetStatus() >= kStatusVerified;
162 }
163
164 // Returns true if the class is initializing.
165 bool IsInitializing() const {
166 return GetStatus() >= kStatusInitializing;
167 }
168
169 // Returns true if the class is initialized.
170 bool IsInitialized() const {
171 return GetStatus() == kStatusInitialized;
172 }
173
174 uint32_t GetAccessFlags() const;
175
176 void SetAccessFlags(uint32_t new_access_flags) {
177 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), new_access_flags, false);
178 }
179
180 // Returns true if the class is an interface.
181 bool IsInterface() const {
182 return (GetAccessFlags() & kAccInterface) != 0;
183 }
184
185 // Returns true if the class is declared public.
186 bool IsPublic() const {
187 return (GetAccessFlags() & kAccPublic) != 0;
188 }
189
190 // Returns true if the class is declared final.
191 bool IsFinal() const {
192 return (GetAccessFlags() & kAccFinal) != 0;
193 }
194
195 bool IsFinalizable() const {
196 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
197 }
198
199 void SetFinalizable() {
200 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), false);
201 SetAccessFlags(flags | kAccClassIsFinalizable);
202 }
203
204 // Returns true if the class is abstract.
205 bool IsAbstract() const {
206 return (GetAccessFlags() & kAccAbstract) != 0;
207 }
208
209 // Returns true if the class is an annotation.
210 bool IsAnnotation() const {
211 return (GetAccessFlags() & kAccAnnotation) != 0;
212 }
213
214 // Returns true if the class is synthetic.
215 bool IsSynthetic() const {
216 return (GetAccessFlags() & kAccSynthetic) != 0;
217 }
218
219 bool IsReferenceClass() const {
220 return (GetAccessFlags() & kAccClassIsReference) != 0;
221 }
222
223 bool IsWeakReferenceClass() const {
224 return (GetAccessFlags() & kAccClassIsWeakReference) != 0;
225 }
226
227 bool IsSoftReferenceClass() const {
228 return (GetAccessFlags() & kAccReferenceFlagsMask) == kAccClassIsReference;
229 }
230
231 bool IsFinalizerReferenceClass() const {
232 return (GetAccessFlags() & kAccClassIsFinalizerReference) != 0;
233 }
234
235 bool IsPhantomReferenceClass() const {
236 return (GetAccessFlags() & kAccClassIsPhantomReference) != 0;
237 }
238
Ian Rogers04f94f42013-06-10 15:09:26 -0700239 // Can references of this type be assigned to by things of another type? For non-array types
240 // this is a matter of whether sub-classes may exist - which they can't if the type is final.
241 // For array classes, where all the classes are final due to there being no sub-classes, an
242 // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
243 // types as the component is final.
244 bool CannotBeAssignedFromOtherTypes() const {
245 if (!IsArrayClass()) {
246 return IsFinal();
247 } else {
248 Class* component = GetComponentType();
249 if (component->IsPrimitive()) {
Ian Rogersa9a82542013-10-04 11:17:26 -0700250 return true;
Ian Rogers04f94f42013-06-10 15:09:26 -0700251 } else {
252 return component->CannotBeAssignedFromOtherTypes();
253 }
254 }
255 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800256
257 String* GetName() const; // Returns the cached name.
258 void SetName(String* name) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Sets the cached name.
259 // Computes the name, then sets the cached value.
260 String* ComputeName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
261
262 bool IsProxyClass() const {
263 // Read access flags without using getter as whether something is a proxy can be check in
264 // any loaded state
265 // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
266 uint32_t access_flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), false);
267 return (access_flags & kAccClassIsProxy) != 0;
268 }
269
270 Primitive::Type GetPrimitiveType() const {
271 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
272 return static_cast<Primitive::Type>(
273 GetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), false));
274 }
275
276 void SetPrimitiveType(Primitive::Type new_type) {
277 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
278 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), new_type, false);
279 }
280
281 // Returns true if the class is a primitive type.
282 bool IsPrimitive() const {
283 return GetPrimitiveType() != Primitive::kPrimNot;
284 }
285
286 bool IsPrimitiveBoolean() const {
287 return GetPrimitiveType() == Primitive::kPrimBoolean;
288 }
289
290 bool IsPrimitiveByte() const {
291 return GetPrimitiveType() == Primitive::kPrimByte;
292 }
293
294 bool IsPrimitiveChar() const {
295 return GetPrimitiveType() == Primitive::kPrimChar;
296 }
297
298 bool IsPrimitiveShort() const {
299 return GetPrimitiveType() == Primitive::kPrimShort;
300 }
301
302 bool IsPrimitiveInt() const {
303 return GetPrimitiveType() == Primitive::kPrimInt;
304 }
305
306 bool IsPrimitiveLong() const {
307 return GetPrimitiveType() == Primitive::kPrimLong;
308 }
309
310 bool IsPrimitiveFloat() const {
311 return GetPrimitiveType() == Primitive::kPrimFloat;
312 }
313
314 bool IsPrimitiveDouble() const {
315 return GetPrimitiveType() == Primitive::kPrimDouble;
316 }
317
318 bool IsPrimitiveVoid() const {
319 return GetPrimitiveType() == Primitive::kPrimVoid;
320 }
321
322 bool IsPrimitiveArray() const {
323 return IsArrayClass() && GetComponentType()->IsPrimitive();
324 }
325
326 // Depth of class from java.lang.Object
327 size_t Depth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
328 size_t depth = 0;
329 for (Class* klass = this; klass->GetSuperClass() != NULL; klass = klass->GetSuperClass()) {
330 depth++;
331 }
332 return depth;
333 }
334
335 bool IsArrayClass() const {
336 return GetComponentType() != NULL;
337 }
338
339 bool IsClassClass() const;
340
341 bool IsStringClass() const;
342
343 bool IsThrowableClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
344
Brian Carlstromea46f952013-07-30 01:26:50 -0700345 bool IsArtFieldClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800346
Brian Carlstromea46f952013-07-30 01:26:50 -0700347 bool IsArtMethodClass() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800348
Ian Rogersa9a82542013-10-04 11:17:26 -0700349 static MemberOffset ComponentTypeOffset() {
350 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
351 }
352
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800353 Class* GetComponentType() const {
Ian Rogersa9a82542013-10-04 11:17:26 -0700354 return GetFieldObject<Class*>(ComponentTypeOffset(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800355 }
356
357 void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
358 DCHECK(GetComponentType() == NULL);
359 DCHECK(new_component_type != NULL);
Ian Rogersa9a82542013-10-04 11:17:26 -0700360 SetFieldObject(ComponentTypeOffset(), new_component_type, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800361 }
362
363 size_t GetComponentSize() const {
364 return Primitive::ComponentSize(GetComponentType()->GetPrimitiveType());
365 }
366
367 bool IsObjectClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
368 return !IsPrimitive() && GetSuperClass() == NULL;
369 }
370 bool IsInstantiable() const {
Sameer Abu Asal02c42232013-04-30 12:09:45 -0700371 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) || ((IsAbstract()) && IsArrayClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372 }
373
374 bool IsObjectArrayClass() const {
375 return GetComponentType() != NULL && !GetComponentType()->IsPrimitive();
376 }
377
378 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800379 template <bool kIsInstrumented>
380 ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
381 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700382
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800383 Object* AllocObject(Thread* self)
384 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
385 Object* AllocNonMovableObject(Thread* self)
386 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800387
388 bool IsVariableSize() const {
389 // Classes and arrays vary in size, and so the object_size_ field cannot
390 // be used to get their instance size
391 return IsClassClass() || IsArrayClass();
392 }
393
394 size_t SizeOf() const {
395 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
396 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false);
397 }
398
399 size_t GetClassSize() const {
400 DCHECK_EQ(sizeof(size_t), sizeof(uint32_t));
401 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false);
402 }
403
404 void SetClassSize(size_t new_class_size)
405 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
406
407 size_t GetObjectSize() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
408
409 void SetObjectSize(size_t new_object_size) {
410 DCHECK(!IsVariableSize());
411 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
412 return SetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size, false);
413 }
414
415 // Returns true if this class is in the same packages as that class.
416 bool IsInSamePackage(const Class* that) const
417 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
418
419 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
420
421 // Returns true if this class can access that class.
422 bool CanAccess(Class* that) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
423 return that->IsPublic() || this->IsInSamePackage(that);
424 }
425
426 // Can this class access a member in the provided class with the provided member access flags?
427 // Note that access to the class isn't checked in case the declaring class is protected and the
428 // method has been exposed by a public sub-class
429 bool CanAccessMember(Class* access_to, uint32_t member_flags) const
430 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
431 // Classes can access all of their own members
432 if (this == access_to) {
433 return true;
434 }
435 // Public members are trivially accessible
436 if (member_flags & kAccPublic) {
437 return true;
438 }
439 // Private members are trivially not accessible
440 if (member_flags & kAccPrivate) {
441 return false;
442 }
443 // Check for protected access from a sub-class, which may or may not be in the same package.
444 if (member_flags & kAccProtected) {
445 if (this->IsSubClass(access_to)) {
446 return true;
447 }
448 }
449 // Allow protected access from other classes in the same package.
450 return this->IsInSamePackage(access_to);
451 }
452
Vladimir Marko23a28212014-01-09 19:24:37 +0000453 // Can this class access a resolved field?
454 // Note that access to field's class is checked and this may require looking up the class
455 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000456 bool CanAccessResolvedField(Class* access_to, ArtField* field,
Vladimir Marko64cffee2014-02-04 17:59:35 +0000457 const DexCache& dex_cache, uint32_t field_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000458 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
459 bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
460 uint32_t field_idx)
461 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000462
463 // Can this class access a resolved method?
464 // Note that access to methods's class is checked and this may require looking up the class
465 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000466 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
Vladimir Marko64cffee2014-02-04 17:59:35 +0000467 const DexCache& dex_cache, uint32_t method_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000468 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
469 template <InvokeType throw_invoke_type>
470 bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
471 uint32_t method_idx)
472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000473
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800474 bool IsSubClass(const Class* klass) const
475 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
476
477 // Can src be assigned to this class? For example, String can be assigned to Object (by an
478 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
479 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
480 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
481 // to themselves. Classes for primitive types may not assign to each other.
Ian Rogersfa46d3e2013-05-15 00:16:04 -0700482 inline bool IsAssignableFrom(const Class* src) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800483 DCHECK(src != NULL);
484 if (this == src) {
485 // Can always assign to things of the same type.
486 return true;
487 } else if (IsObjectClass()) {
488 // Can assign any reference to java.lang.Object.
489 return !src->IsPrimitive();
490 } else if (IsInterface()) {
491 return src->Implements(this);
492 } else if (src->IsArrayClass()) {
493 return IsAssignableFromArray(src);
494 } else {
495 return !src->IsInterface() && src->IsSubClass(this);
496 }
497 }
498
499 Class* GetSuperClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
500
501 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
502 // super class is assigned once, except during class linker initialization
503 Class* old_super_class = GetFieldObject<Class*>(
504 OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false);
505 DCHECK(old_super_class == NULL || old_super_class == new_super_class);
506 DCHECK(new_super_class != NULL);
507 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class, false);
508 }
509
510 bool HasSuperClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
511 return GetSuperClass() != NULL;
512 }
513
514 static MemberOffset SuperClassOffset() {
515 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
516 }
517
518 ClassLoader* GetClassLoader() const;
519
520 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
521
522 static MemberOffset DexCacheOffset() {
523 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
524 }
525
526 enum {
527 kDumpClassFullDetail = 1,
528 kDumpClassClassLoader = (1 << 1),
529 kDumpClassInitialized = (1 << 2),
530 };
531
532 void DumpClass(std::ostream& os, int flags) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
533
534 DexCache* GetDexCache() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
535
536 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
537
Brian Carlstromea46f952013-07-30 01:26:50 -0700538 ObjectArray<ArtMethod>* GetDirectMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800539
Brian Carlstromea46f952013-07-30 01:26:50 -0700540 void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800541 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
542
Brian Carlstromea46f952013-07-30 01:26:50 -0700543 ArtMethod* GetDirectMethod(int32_t i) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800544
Brian Carlstromea46f952013-07-30 01:26:50 -0700545 void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800546 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
547
548 // Returns the number of static, private, and constructor methods.
549 size_t NumDirectMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
550
Brian Carlstromea46f952013-07-30 01:26:50 -0700551 ObjectArray<ArtMethod>* GetVirtualMethods() const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800552 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
553
Brian Carlstromea46f952013-07-30 01:26:50 -0700554 void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800555 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
556
557 // Returns the number of non-inherited virtual methods.
558 size_t NumVirtualMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
559
Brian Carlstromea46f952013-07-30 01:26:50 -0700560 ArtMethod* GetVirtualMethod(uint32_t i) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800561 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
562
Brian Carlstromea46f952013-07-30 01:26:50 -0700563 ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800564 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
565
Brian Carlstromea46f952013-07-30 01:26:50 -0700566 void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800567 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
568
Brian Carlstromea46f952013-07-30 01:26:50 -0700569 ObjectArray<ArtMethod>* GetVTable() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800570
Brian Carlstromea46f952013-07-30 01:26:50 -0700571 ObjectArray<ArtMethod>* GetVTableDuringLinking() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800572
Brian Carlstromea46f952013-07-30 01:26:50 -0700573 void SetVTable(ObjectArray<ArtMethod>* new_vtable)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800574 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
575
576 static MemberOffset VTableOffset() {
577 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
578 }
579
Jeff Hao88474b42013-10-23 16:24:40 -0700580 ObjectArray<ArtMethod>* GetImTable() const;
581
582 void SetImTable(ObjectArray<ArtMethod>* new_imtable)
583 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
584
585 static MemberOffset ImTableOffset() {
586 return OFFSET_OF_OBJECT_MEMBER(Class, imtable_);
587 }
588
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800589 // Given a method implemented by this class but potentially from a super class, return the
590 // specific implementation method for this class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700591 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800592 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
593
594 // Given a method implemented by this class' super class, return the specific implementation
595 // method for this class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700596 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800597 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
598
599 // Given a method implemented by this class, but potentially from a
600 // super class or interface, return the specific implementation
601 // method for this class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700602 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method) const
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800603 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800604
Ian Rogersd91d6d62013-09-25 20:26:14 -0700605 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method) const
606 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
607
608 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800609 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
610
Brian Carlstromea46f952013-07-30 01:26:50 -0700611 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800612 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
613
Brian Carlstromea46f952013-07-30 01:26:50 -0700614 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800615 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
616
Ian Rogersd91d6d62013-09-25 20:26:14 -0700617 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature) const
618 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
619
Brian Carlstromea46f952013-07-30 01:26:50 -0700620 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800621 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
622
Brian Carlstromea46f952013-07-30 01:26:50 -0700623 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800624 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
625
Ian Rogersd91d6d62013-09-25 20:26:14 -0700626 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature) const
627 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
628
Brian Carlstromea46f952013-07-30 01:26:50 -0700629 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800630 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
631
Ian Rogersd91d6d62013-09-25 20:26:14 -0700632 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature) const
633 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
634
635 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature) const
636 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
637
638 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
639 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
640
641 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature) const
642 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
643
644 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature) const
645 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
646
647 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
648 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
649
650 ArtMethod* FindClassInitializer() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
651
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800652 int32_t GetIfTableCount() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
653
654 IfTable* GetIfTable() const;
655
656 void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
657
658 // Get instance fields of the class (See also GetSFields).
Brian Carlstromea46f952013-07-30 01:26:50 -0700659 ObjectArray<ArtField>* GetIFields() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800660
Brian Carlstromea46f952013-07-30 01:26:50 -0700661 void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800662
663 size_t NumInstanceFields() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
664
Brian Carlstromea46f952013-07-30 01:26:50 -0700665 ArtField* GetInstanceField(uint32_t i) const // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800666 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
667
Brian Carlstromea46f952013-07-30 01:26:50 -0700668 void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800669 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
670
671 // Returns the number of instance fields containing reference types.
672 size_t NumReferenceInstanceFields() const {
673 DCHECK(IsResolved() || IsErroneous());
674 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
675 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false);
676 }
677
678 size_t NumReferenceInstanceFieldsDuringLinking() const {
679 DCHECK(IsLoaded() || IsErroneous());
680 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
681 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false);
682 }
683
684 void SetNumReferenceInstanceFields(size_t new_num) {
685 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
686 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num, false);
687 }
688
689 uint32_t GetReferenceInstanceOffsets() const {
690 DCHECK(IsResolved() || IsErroneous());
691 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), false);
692 }
693
694 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
695 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
696
697 // Beginning of static field data
698 static MemberOffset FieldsOffset() {
699 return OFFSET_OF_OBJECT_MEMBER(Class, fields_);
700 }
701
702 // Returns the number of static fields containing reference types.
703 size_t NumReferenceStaticFields() const {
704 DCHECK(IsResolved() || IsErroneous());
705 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
706 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false);
707 }
708
709 size_t NumReferenceStaticFieldsDuringLinking() const {
710 DCHECK(IsLoaded() || IsErroneous());
711 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
712 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false);
713 }
714
715 void SetNumReferenceStaticFields(size_t new_num) {
716 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
717 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num, false);
718 }
719
720 // Gets the static fields of the class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700721 ObjectArray<ArtField>* GetSFields() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800722
Brian Carlstromea46f952013-07-30 01:26:50 -0700723 void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800724
725 size_t NumStaticFields() const;
726
Brian Carlstromea46f952013-07-30 01:26:50 -0700727 ArtField* GetStaticField(uint32_t i) const; // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800728
Brian Carlstromea46f952013-07-30 01:26:50 -0700729 void SetStaticField(uint32_t i, ArtField* f); // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800730
731 uint32_t GetReferenceStaticOffsets() const {
732 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), false);
733 }
734
735 void SetReferenceStaticOffsets(uint32_t new_reference_offsets);
736
737 // Find a static or instance field using the JLS resolution order
Brian Carlstromea46f952013-07-30 01:26:50 -0700738 ArtField* FindField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800739 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
740
741 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700742 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800743 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
744
745 // Finds the given instance field in this class or a superclass, only searches classes that
746 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700747 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800748 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
749
Brian Carlstromea46f952013-07-30 01:26:50 -0700750 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800751 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
752
Brian Carlstromea46f952013-07-30 01:26:50 -0700753 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800754 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
755
756 // Finds the given static field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700757 ArtField* FindStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800758 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
759
760 // Finds the given static field in this class or superclass, only searches classes that
761 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700762 ArtField* FindStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800763 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
764
Brian Carlstromea46f952013-07-30 01:26:50 -0700765 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800766 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
767
Brian Carlstromea46f952013-07-30 01:26:50 -0700768 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800769 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
770
771 pid_t GetClinitThreadId() const {
772 DCHECK(IsIdxLoaded() || IsErroneous());
773 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), false);
774 }
775
776 void SetClinitThreadId(pid_t new_clinit_thread_id) {
777 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), new_clinit_thread_id, false);
778 }
779
780 Class* GetVerifyErrorClass() const {
781 // DCHECK(IsErroneous());
782 return GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), false);
783 }
784
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700785 uint16_t GetDexClassDefIndex() const {
786 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), false);
787 }
788
789 void SetDexClassDefIndex(uint16_t class_def_idx) {
790 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx, false);
791 }
792
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800793 uint16_t GetDexTypeIndex() const {
794 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), false);
795 }
796
797 void SetDexTypeIndex(uint16_t type_idx) {
798 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx, false);
799 }
800
801 static Class* GetJavaLangClass() {
802 DCHECK(java_lang_Class_ != NULL);
803 return java_lang_Class_;
804 }
805
806 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
807 static void SetClassClass(Class* java_lang_Class);
808 static void ResetClass();
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800809 static void VisitRoots(RootVisitor* visitor, void* arg)
810 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800811
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200812 // When class is verified, set the kAccPreverified flag on each method.
813 void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
814
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800815 private:
816 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
817
Vladimir Marko89786432014-01-31 15:03:55 +0000818 template <bool throw_on_failure, bool use_referrers_cache>
819 bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Vladimir Marko64cffee2014-02-04 17:59:35 +0000820 uint32_t field_idx, const DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +0000821 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
822 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
823 bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
Vladimir Marko64cffee2014-02-04 17:59:35 +0000824 uint32_t method_idx, const DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +0000825 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
826
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800827 bool Implements(const Class* klass) const
828 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
829 bool IsArrayAssignableFromArray(const Class* klass) const
830 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
831 bool IsAssignableFromArray(const Class* klass) const
832 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
833
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700834 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
835
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800836 // defining class loader, or NULL for the "bootstrap" system loader
837 ClassLoader* class_loader_;
838
839 // For array classes, the component class object for instanceof/checkcast
840 // (for String[][][], this will be String[][]). NULL for non-array classes.
841 Class* component_type_;
842
843 // DexCache of resolved constant pool entries (will be NULL for classes generated by the
844 // runtime such as arrays and primitive classes).
845 DexCache* dex_cache_;
846
847 // static, private, and <init> methods
Brian Carlstromea46f952013-07-30 01:26:50 -0700848 ObjectArray<ArtMethod>* direct_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800849
850 // instance fields
851 //
852 // These describe the layout of the contents of an Object.
853 // Note that only the fields directly declared by this class are
854 // listed in ifields; fields declared by a superclass are listed in
855 // the superclass's Class.ifields.
856 //
857 // All instance fields that refer to objects are guaranteed to be at
858 // the beginning of the field list. num_reference_instance_fields_
859 // specifies the number of reference fields.
Brian Carlstromea46f952013-07-30 01:26:50 -0700860 ObjectArray<ArtField>* ifields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800861
862 // The interface table (iftable_) contains pairs of a interface class and an array of the
863 // interface methods. There is one pair per interface supported by this class. That means one
864 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
865 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
866 //
867 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
868 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
869 // single vtable.
870 //
871 // For every interface a concrete class implements, we create an array of the concrete vtable_
872 // methods for the methods in the interface.
873 IfTable* iftable_;
874
Jeff Hao88474b42013-10-23 16:24:40 -0700875 // Interface method table (imt), for quick "invoke-interface".
876 ObjectArray<ArtMethod>* imtable_;
877
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800878 // descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
879 String* name_;
880
881 // Static fields
Brian Carlstromea46f952013-07-30 01:26:50 -0700882 ObjectArray<ArtField>* sfields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800883
884 // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
885 Class* super_class_;
886
887 // If class verify fails, we must return same error on subsequent tries.
888 Class* verify_error_class_;
889
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700890 // Virtual methods defined in this class; invoked through vtable.
Brian Carlstromea46f952013-07-30 01:26:50 -0700891 ObjectArray<ArtMethod>* virtual_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800892
893 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
894 // copied in, and virtual methods from our class either replace those from the super or are
895 // appended. For abstract classes, methods may be created in the vtable that aren't in
896 // virtual_ methods_ for miranda methods.
Brian Carlstromea46f952013-07-30 01:26:50 -0700897 ObjectArray<ArtMethod>* vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800898
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700899 // Access flags; low 16 bits are defined by VM spec.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800900 uint32_t access_flags_;
901
902 // Total size of the Class instance; used when allocating storage on gc heap.
903 // See also object_size_.
904 size_t class_size_;
905
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700906 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800907 pid_t clinit_thread_id_;
908
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700909 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800910 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700911 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800912
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700913 // Type index in dex file.
914 // TODO: really 16bits
915 int32_t dex_type_idx_;
916
917 // Number of instance fields that are object refs.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800918 size_t num_reference_instance_fields_;
919
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700920 // Number of static fields that are object refs,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800921 size_t num_reference_static_fields_;
922
923 // Total object size; used when allocating storage on gc heap.
924 // (For interfaces and abstract classes this will be zero.)
925 // See also class_size_.
926 size_t object_size_;
927
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700928 // Primitive type value, or Primitive::kPrimNot (0); set for generated primitive classes.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800929 Primitive::Type primitive_type_;
930
931 // Bitmap of offsets of ifields.
932 uint32_t reference_instance_offsets_;
933
934 // Bitmap of offsets of sfields.
935 uint32_t reference_static_offsets_;
936
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700937 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800938 Status status_;
939
940 // TODO: ?
941 // initiating class loader list
942 // NOTE: for classes with low serialNumber, these are unused, and the
943 // values are kept in a table in gDvm.
944 // InitiatingLoaderList initiating_loader_list_;
945
946 // Location of first static field.
947 uint32_t fields_[0];
948
949 // java.lang.Class
950 static Class* java_lang_Class_;
951
952 friend struct art::ClassOffsets; // for verifying offset information
953 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
954};
955
956std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
957
958class MANAGED ClassClass : public Class {
959 private:
Jeff Hao88474b42013-10-23 16:24:40 -0700960 int32_t pad_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800961 int64_t serialVersionUID_;
962 friend struct art::ClassClassOffsets; // for verifying offset information
963 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass);
964};
965
966} // namespace mirror
967} // namespace art
968
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700969#endif // ART_RUNTIME_MIRROR_CLASS_H_