blob: d751363e3f2bfc1334ea47b00e9443365aa16d9f [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.
456 template <bool throw_on_failure>
457 bool CanAccessResolvedField(Class* access_to, ArtField* field,
458 uint32_t field_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
459
460 // Can this class access a resolved method?
461 // Note that access to methods's class is checked and this may require looking up the class
462 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
463 template <bool throw_on_failure, InvokeType throw_invoke_type = kStatic>
464 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
465 uint32_t method_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
466
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800467 bool IsSubClass(const Class* klass) const
468 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
469
470 // Can src be assigned to this class? For example, String can be assigned to Object (by an
471 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
472 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
473 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
474 // to themselves. Classes for primitive types may not assign to each other.
Ian Rogersfa46d3e2013-05-15 00:16:04 -0700475 inline bool IsAssignableFrom(const Class* src) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800476 DCHECK(src != NULL);
477 if (this == src) {
478 // Can always assign to things of the same type.
479 return true;
480 } else if (IsObjectClass()) {
481 // Can assign any reference to java.lang.Object.
482 return !src->IsPrimitive();
483 } else if (IsInterface()) {
484 return src->Implements(this);
485 } else if (src->IsArrayClass()) {
486 return IsAssignableFromArray(src);
487 } else {
488 return !src->IsInterface() && src->IsSubClass(this);
489 }
490 }
491
492 Class* GetSuperClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
493
494 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
495 // super class is assigned once, except during class linker initialization
496 Class* old_super_class = GetFieldObject<Class*>(
497 OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false);
498 DCHECK(old_super_class == NULL || old_super_class == new_super_class);
499 DCHECK(new_super_class != NULL);
500 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class, false);
501 }
502
503 bool HasSuperClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
504 return GetSuperClass() != NULL;
505 }
506
507 static MemberOffset SuperClassOffset() {
508 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
509 }
510
511 ClassLoader* GetClassLoader() const;
512
513 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
514
515 static MemberOffset DexCacheOffset() {
516 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
517 }
518
519 enum {
520 kDumpClassFullDetail = 1,
521 kDumpClassClassLoader = (1 << 1),
522 kDumpClassInitialized = (1 << 2),
523 };
524
525 void DumpClass(std::ostream& os, int flags) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
526
527 DexCache* GetDexCache() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
528
529 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
530
Brian Carlstromea46f952013-07-30 01:26:50 -0700531 ObjectArray<ArtMethod>* GetDirectMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800532
Brian Carlstromea46f952013-07-30 01:26:50 -0700533 void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800534 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
535
Brian Carlstromea46f952013-07-30 01:26:50 -0700536 ArtMethod* GetDirectMethod(int32_t i) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800537
Brian Carlstromea46f952013-07-30 01:26:50 -0700538 void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800539 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
540
541 // Returns the number of static, private, and constructor methods.
542 size_t NumDirectMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
543
Brian Carlstromea46f952013-07-30 01:26:50 -0700544 ObjectArray<ArtMethod>* GetVirtualMethods() const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
546
Brian Carlstromea46f952013-07-30 01:26:50 -0700547 void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800548 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
549
550 // Returns the number of non-inherited virtual methods.
551 size_t NumVirtualMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
552
Brian Carlstromea46f952013-07-30 01:26:50 -0700553 ArtMethod* GetVirtualMethod(uint32_t i) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800554 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
555
Brian Carlstromea46f952013-07-30 01:26:50 -0700556 ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800557 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
558
Brian Carlstromea46f952013-07-30 01:26:50 -0700559 void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800560 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
561
Brian Carlstromea46f952013-07-30 01:26:50 -0700562 ObjectArray<ArtMethod>* GetVTable() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800563
Brian Carlstromea46f952013-07-30 01:26:50 -0700564 ObjectArray<ArtMethod>* GetVTableDuringLinking() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800565
Brian Carlstromea46f952013-07-30 01:26:50 -0700566 void SetVTable(ObjectArray<ArtMethod>* new_vtable)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800567 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
568
569 static MemberOffset VTableOffset() {
570 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
571 }
572
Jeff Hao88474b42013-10-23 16:24:40 -0700573 ObjectArray<ArtMethod>* GetImTable() const;
574
575 void SetImTable(ObjectArray<ArtMethod>* new_imtable)
576 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
577
578 static MemberOffset ImTableOffset() {
579 return OFFSET_OF_OBJECT_MEMBER(Class, imtable_);
580 }
581
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800582 // Given a method implemented by this class but potentially from a super class, return the
583 // specific implementation method for this class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700584 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800585 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
586
587 // Given a method implemented by this class' super class, return the specific implementation
588 // method for this class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700589 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800590 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
591
592 // Given a method implemented by this class, but potentially from a
593 // super class or interface, return the specific implementation
594 // method for this class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700595 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method) const
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800596 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800597
Ian Rogersd91d6d62013-09-25 20:26:14 -0700598 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method) const
599 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
600
601 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800602 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
603
Brian Carlstromea46f952013-07-30 01:26:50 -0700604 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800605 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
606
Brian Carlstromea46f952013-07-30 01:26:50 -0700607 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800608 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
609
Ian Rogersd91d6d62013-09-25 20:26:14 -0700610 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature) const
611 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
612
Brian Carlstromea46f952013-07-30 01:26:50 -0700613 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800614 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
615
Brian Carlstromea46f952013-07-30 01:26:50 -0700616 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800617 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
618
Ian Rogersd91d6d62013-09-25 20:26:14 -0700619 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature) const
620 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
621
Brian Carlstromea46f952013-07-30 01:26:50 -0700622 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800623 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
624
Ian Rogersd91d6d62013-09-25 20:26:14 -0700625 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature) const
626 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
627
628 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature) const
629 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
630
631 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
632 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
633
634 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature) const
635 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
636
637 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature) const
638 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
639
640 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
641 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
642
643 ArtMethod* FindClassInitializer() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
644
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800645 int32_t GetIfTableCount() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
646
647 IfTable* GetIfTable() const;
648
649 void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
650
651 // Get instance fields of the class (See also GetSFields).
Brian Carlstromea46f952013-07-30 01:26:50 -0700652 ObjectArray<ArtField>* GetIFields() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800653
Brian Carlstromea46f952013-07-30 01:26:50 -0700654 void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800655
656 size_t NumInstanceFields() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
657
Brian Carlstromea46f952013-07-30 01:26:50 -0700658 ArtField* GetInstanceField(uint32_t i) const // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800659 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
660
Brian Carlstromea46f952013-07-30 01:26:50 -0700661 void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800662 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
663
664 // Returns the number of instance fields containing reference types.
665 size_t NumReferenceInstanceFields() const {
666 DCHECK(IsResolved() || IsErroneous());
667 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
668 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false);
669 }
670
671 size_t NumReferenceInstanceFieldsDuringLinking() const {
672 DCHECK(IsLoaded() || IsErroneous());
673 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
674 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false);
675 }
676
677 void SetNumReferenceInstanceFields(size_t new_num) {
678 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
679 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num, false);
680 }
681
682 uint32_t GetReferenceInstanceOffsets() const {
683 DCHECK(IsResolved() || IsErroneous());
684 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), false);
685 }
686
687 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
688 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
689
690 // Beginning of static field data
691 static MemberOffset FieldsOffset() {
692 return OFFSET_OF_OBJECT_MEMBER(Class, fields_);
693 }
694
695 // Returns the number of static fields containing reference types.
696 size_t NumReferenceStaticFields() const {
697 DCHECK(IsResolved() || IsErroneous());
698 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
699 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false);
700 }
701
702 size_t NumReferenceStaticFieldsDuringLinking() const {
703 DCHECK(IsLoaded() || IsErroneous());
704 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
705 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false);
706 }
707
708 void SetNumReferenceStaticFields(size_t new_num) {
709 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
710 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num, false);
711 }
712
713 // Gets the static fields of the class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700714 ObjectArray<ArtField>* GetSFields() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800715
Brian Carlstromea46f952013-07-30 01:26:50 -0700716 void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800717
718 size_t NumStaticFields() const;
719
Brian Carlstromea46f952013-07-30 01:26:50 -0700720 ArtField* GetStaticField(uint32_t i) const; // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800721
Brian Carlstromea46f952013-07-30 01:26:50 -0700722 void SetStaticField(uint32_t i, ArtField* f); // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800723
724 uint32_t GetReferenceStaticOffsets() const {
725 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), false);
726 }
727
728 void SetReferenceStaticOffsets(uint32_t new_reference_offsets);
729
730 // Find a static or instance field using the JLS resolution order
Brian Carlstromea46f952013-07-30 01:26:50 -0700731 ArtField* FindField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800732 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
733
734 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700735 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800736 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
737
738 // Finds the given instance field in this class or a superclass, only searches classes that
739 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700740 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800741 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
742
Brian Carlstromea46f952013-07-30 01:26:50 -0700743 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800744 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
745
Brian Carlstromea46f952013-07-30 01:26:50 -0700746 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800747 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
748
749 // Finds the given static field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700750 ArtField* FindStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800751 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
752
753 // Finds the given static field in this class or superclass, only searches classes that
754 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700755 ArtField* FindStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800756 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
757
Brian Carlstromea46f952013-07-30 01:26:50 -0700758 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800759 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
760
Brian Carlstromea46f952013-07-30 01:26:50 -0700761 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800762 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
763
764 pid_t GetClinitThreadId() const {
765 DCHECK(IsIdxLoaded() || IsErroneous());
766 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), false);
767 }
768
769 void SetClinitThreadId(pid_t new_clinit_thread_id) {
770 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), new_clinit_thread_id, false);
771 }
772
773 Class* GetVerifyErrorClass() const {
774 // DCHECK(IsErroneous());
775 return GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), false);
776 }
777
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700778 uint16_t GetDexClassDefIndex() const {
779 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), false);
780 }
781
782 void SetDexClassDefIndex(uint16_t class_def_idx) {
783 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx, false);
784 }
785
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800786 uint16_t GetDexTypeIndex() const {
787 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), false);
788 }
789
790 void SetDexTypeIndex(uint16_t type_idx) {
791 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx, false);
792 }
793
794 static Class* GetJavaLangClass() {
795 DCHECK(java_lang_Class_ != NULL);
796 return java_lang_Class_;
797 }
798
799 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
800 static void SetClassClass(Class* java_lang_Class);
801 static void ResetClass();
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800802 static void VisitRoots(RootVisitor* visitor, void* arg)
803 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800804
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200805 // When class is verified, set the kAccPreverified flag on each method.
806 void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
807
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800808 private:
809 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
810
811 bool Implements(const Class* klass) const
812 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
813 bool IsArrayAssignableFromArray(const Class* klass) const
814 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
815 bool IsAssignableFromArray(const Class* klass) const
816 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
817
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700818 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
819
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800820 // defining class loader, or NULL for the "bootstrap" system loader
821 ClassLoader* class_loader_;
822
823 // For array classes, the component class object for instanceof/checkcast
824 // (for String[][][], this will be String[][]). NULL for non-array classes.
825 Class* component_type_;
826
827 // DexCache of resolved constant pool entries (will be NULL for classes generated by the
828 // runtime such as arrays and primitive classes).
829 DexCache* dex_cache_;
830
831 // static, private, and <init> methods
Brian Carlstromea46f952013-07-30 01:26:50 -0700832 ObjectArray<ArtMethod>* direct_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800833
834 // instance fields
835 //
836 // These describe the layout of the contents of an Object.
837 // Note that only the fields directly declared by this class are
838 // listed in ifields; fields declared by a superclass are listed in
839 // the superclass's Class.ifields.
840 //
841 // All instance fields that refer to objects are guaranteed to be at
842 // the beginning of the field list. num_reference_instance_fields_
843 // specifies the number of reference fields.
Brian Carlstromea46f952013-07-30 01:26:50 -0700844 ObjectArray<ArtField>* ifields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800845
846 // The interface table (iftable_) contains pairs of a interface class and an array of the
847 // interface methods. There is one pair per interface supported by this class. That means one
848 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
849 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
850 //
851 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
852 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
853 // single vtable.
854 //
855 // For every interface a concrete class implements, we create an array of the concrete vtable_
856 // methods for the methods in the interface.
857 IfTable* iftable_;
858
Jeff Hao88474b42013-10-23 16:24:40 -0700859 // Interface method table (imt), for quick "invoke-interface".
860 ObjectArray<ArtMethod>* imtable_;
861
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800862 // descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
863 String* name_;
864
865 // Static fields
Brian Carlstromea46f952013-07-30 01:26:50 -0700866 ObjectArray<ArtField>* sfields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800867
868 // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
869 Class* super_class_;
870
871 // If class verify fails, we must return same error on subsequent tries.
872 Class* verify_error_class_;
873
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700874 // Virtual methods defined in this class; invoked through vtable.
Brian Carlstromea46f952013-07-30 01:26:50 -0700875 ObjectArray<ArtMethod>* virtual_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800876
877 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
878 // copied in, and virtual methods from our class either replace those from the super or are
879 // appended. For abstract classes, methods may be created in the vtable that aren't in
880 // virtual_ methods_ for miranda methods.
Brian Carlstromea46f952013-07-30 01:26:50 -0700881 ObjectArray<ArtMethod>* vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800882
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700883 // Access flags; low 16 bits are defined by VM spec.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800884 uint32_t access_flags_;
885
886 // Total size of the Class instance; used when allocating storage on gc heap.
887 // See also object_size_.
888 size_t class_size_;
889
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700890 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800891 pid_t clinit_thread_id_;
892
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700893 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800894 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700895 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800896
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700897 // Type index in dex file.
898 // TODO: really 16bits
899 int32_t dex_type_idx_;
900
901 // Number of instance fields that are object refs.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800902 size_t num_reference_instance_fields_;
903
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700904 // Number of static fields that are object refs,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800905 size_t num_reference_static_fields_;
906
907 // Total object size; used when allocating storage on gc heap.
908 // (For interfaces and abstract classes this will be zero.)
909 // See also class_size_.
910 size_t object_size_;
911
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700912 // Primitive type value, or Primitive::kPrimNot (0); set for generated primitive classes.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800913 Primitive::Type primitive_type_;
914
915 // Bitmap of offsets of ifields.
916 uint32_t reference_instance_offsets_;
917
918 // Bitmap of offsets of sfields.
919 uint32_t reference_static_offsets_;
920
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700921 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800922 Status status_;
923
924 // TODO: ?
925 // initiating class loader list
926 // NOTE: for classes with low serialNumber, these are unused, and the
927 // values are kept in a table in gDvm.
928 // InitiatingLoaderList initiating_loader_list_;
929
930 // Location of first static field.
931 uint32_t fields_[0];
932
933 // java.lang.Class
934 static Class* java_lang_Class_;
935
936 friend struct art::ClassOffsets; // for verifying offset information
937 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
938};
939
940std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
941
942class MANAGED ClassClass : public Class {
943 private:
Jeff Hao88474b42013-10-23 16:24:40 -0700944 int32_t pad_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800945 int64_t serialVersionUID_;
946 friend struct art::ClassClassOffsets; // for verifying offset information
947 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass);
948};
949
950} // namespace mirror
951} // namespace art
952
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700953#endif // ART_RUNTIME_MIRROR_CLASS_H_