blob: ed1aad39d21fc0ca63d854e3a04672997b5af0af [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
20#include "modifiers.h"
21#include "object.h"
22#include "primitive.h"
23
24/*
25 * A magic value for refOffsets. Ignore the bits and walk the super
26 * chain when this is the value.
27 * [This is an unlikely "natural" value, since it would be 30 non-ref instance
28 * fields followed by 2 ref instance fields.]
29 */
Brian Carlstromfb6996f2013-07-18 18:21:14 -070030#define CLASS_WALK_SUPER 3U
31#define CLASS_BITS_PER_WORD (sizeof(uint32_t) * 8)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032#define CLASS_OFFSET_ALIGNMENT 4
Brian Carlstromfb6996f2013-07-18 18:21:14 -070033#define CLASS_HIGH_BIT (1U << (CLASS_BITS_PER_WORD - 1))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034/*
35 * Given an offset, return the bit number which would encode that offset.
36 * Local use only.
37 */
38#define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \
39 ((unsigned int)(byteOffset) / \
40 CLASS_OFFSET_ALIGNMENT)
41/*
42 * Is the given offset too large to be encoded?
43 */
44#define CLASS_CAN_ENCODE_OFFSET(byteOffset) \
45 (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD)
46/*
47 * Return a single bit, encoding the offset.
48 * Undefined if the offset is too large, as defined above.
49 */
50#define CLASS_BIT_FROM_OFFSET(byteOffset) \
51 (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset))
52/*
53 * Return an offset, given a bit number as returned from CLZ.
54 */
55#define CLASS_OFFSET_FROM_CLZ(rshift) \
56 MemberOffset((static_cast<int>(rshift) * CLASS_OFFSET_ALIGNMENT))
57
58namespace art {
59
60struct ClassClassOffsets;
61struct ClassOffsets;
Ian Rogersd91d6d62013-09-25 20:26:14 -070062class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063class StringPiece;
64
65namespace mirror {
66
Brian Carlstromea46f952013-07-30 01:26:50 -070067class ArtField;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068class ClassLoader;
69class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070class IfTable;
71
72// Type for the InitializedStaticStorage table. Currently the Class
73// provides the static storage. However, this might change to an Array
74// to improve image sharing, so we use this type to avoid assumptions
75// on the current storage.
76class MANAGED StaticStorageBase : public Object {
77};
78
79// C++ mirror of java.lang.Class
80class MANAGED Class : public StaticStorageBase {
81 public:
82 // Class Status
83 //
84 // kStatusNotReady: If a Class cannot be found in the class table by
85 // FindClass, it allocates an new one with AllocClass in the
86 // kStatusNotReady and calls LoadClass. Note if it does find a
87 // class, it may not be kStatusResolved and it will try to push it
88 // forward toward kStatusResolved.
89 //
90 // kStatusIdx: LoadClass populates with Class with information from
91 // the DexFile, moving the status to kStatusIdx, indicating that the
92 // Class value in super_class_ has not been populated. The new Class
93 // can then be inserted into the classes table.
94 //
95 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
96 // attempt to move a kStatusIdx class forward to kStatusLoaded by
97 // using ResolveClass to initialize the super_class_ and ensuring the
98 // interfaces are resolved.
99 //
100 // kStatusResolved: Still holding the lock on Class, the ClassLinker
101 // shows linking is complete and fields of the Class populated by making
102 // it kStatusResolved. Java allows circularities of the form where a super
103 // class has a field that is of the type of the sub class. We need to be able
104 // to fully resolve super classes while resolving types for fields.
105 //
106 // kStatusRetryVerificationAtRuntime: The verifier sets a class to
107 // this state if it encounters a soft failure at compile time. This
108 // often happens when there are unresolved classes in other dex
109 // files, and this status marks a class as needing to be verified
110 // again at runtime.
111 //
112 // TODO: Explain the other states
113 enum Status {
114 kStatusError = -1,
115 kStatusNotReady = 0,
116 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
117 kStatusLoaded = 2, // DEX idx values resolved.
118 kStatusResolved = 3, // Part of linking.
119 kStatusVerifying = 4, // In the process of being verified.
120 kStatusRetryVerificationAtRuntime = 5, // Compile time verification failed, retry at runtime.
121 kStatusVerifyingAtRuntime = 6, // Retrying verification at runtime.
122 kStatusVerified = 7, // Logically part of linking; done pre-init.
123 kStatusInitializing = 8, // Class init in progress.
124 kStatusInitialized = 9, // Ready to go.
Brian Carlstromba150c32013-08-27 17:31:03 -0700125 kStatusMax = 10,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800126 };
127
128 Status GetStatus() const {
129 DCHECK_EQ(sizeof(Status), sizeof(uint32_t));
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700130 return static_cast<Status>(GetField32(OFFSET_OF_OBJECT_MEMBER(Class, status_), true));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800131 }
132
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700133 void SetStatus(Status new_status, Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800134
135 // Returns true if the class has failed to link.
136 bool IsErroneous() const {
137 return GetStatus() == kStatusError;
138 }
139
140 // Returns true if the class has been loaded.
141 bool IsIdxLoaded() const {
142 return GetStatus() >= kStatusIdx;
143 }
144
145 // Returns true if the class has been loaded.
146 bool IsLoaded() const {
147 return GetStatus() >= kStatusLoaded;
148 }
149
150 // Returns true if the class has been linked.
151 bool IsResolved() const {
152 return GetStatus() >= kStatusResolved;
153 }
154
155 // Returns true if the class was compile-time verified.
156 bool IsCompileTimeVerified() const {
157 return GetStatus() >= kStatusRetryVerificationAtRuntime;
158 }
159
160 // Returns true if the class has been verified.
161 bool IsVerified() const {
162 return GetStatus() >= kStatusVerified;
163 }
164
165 // Returns true if the class is initializing.
166 bool IsInitializing() const {
167 return GetStatus() >= kStatusInitializing;
168 }
169
170 // Returns true if the class is initialized.
171 bool IsInitialized() const {
172 return GetStatus() == kStatusInitialized;
173 }
174
175 uint32_t GetAccessFlags() const;
176
177 void SetAccessFlags(uint32_t new_access_flags) {
178 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), new_access_flags, false);
179 }
180
181 // Returns true if the class is an interface.
182 bool IsInterface() const {
183 return (GetAccessFlags() & kAccInterface) != 0;
184 }
185
186 // Returns true if the class is declared public.
187 bool IsPublic() const {
188 return (GetAccessFlags() & kAccPublic) != 0;
189 }
190
191 // Returns true if the class is declared final.
192 bool IsFinal() const {
193 return (GetAccessFlags() & kAccFinal) != 0;
194 }
195
196 bool IsFinalizable() const {
197 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
198 }
199
200 void SetFinalizable() {
201 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), false);
202 SetAccessFlags(flags | kAccClassIsFinalizable);
203 }
204
205 // Returns true if the class is abstract.
206 bool IsAbstract() const {
207 return (GetAccessFlags() & kAccAbstract) != 0;
208 }
209
210 // Returns true if the class is an annotation.
211 bool IsAnnotation() const {
212 return (GetAccessFlags() & kAccAnnotation) != 0;
213 }
214
215 // Returns true if the class is synthetic.
216 bool IsSynthetic() const {
217 return (GetAccessFlags() & kAccSynthetic) != 0;
218 }
219
220 bool IsReferenceClass() const {
221 return (GetAccessFlags() & kAccClassIsReference) != 0;
222 }
223
224 bool IsWeakReferenceClass() const {
225 return (GetAccessFlags() & kAccClassIsWeakReference) != 0;
226 }
227
228 bool IsSoftReferenceClass() const {
229 return (GetAccessFlags() & kAccReferenceFlagsMask) == kAccClassIsReference;
230 }
231
232 bool IsFinalizerReferenceClass() const {
233 return (GetAccessFlags() & kAccClassIsFinalizerReference) != 0;
234 }
235
236 bool IsPhantomReferenceClass() const {
237 return (GetAccessFlags() & kAccClassIsPhantomReference) != 0;
238 }
239
Ian Rogers04f94f42013-06-10 15:09:26 -0700240 // Can references of this type be assigned to by things of another type? For non-array types
241 // this is a matter of whether sub-classes may exist - which they can't if the type is final.
242 // For array classes, where all the classes are final due to there being no sub-classes, an
243 // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
244 // types as the component is final.
245 bool CannotBeAssignedFromOtherTypes() const {
246 if (!IsArrayClass()) {
247 return IsFinal();
248 } else {
249 Class* component = GetComponentType();
250 if (component->IsPrimitive()) {
Ian Rogersa9a82542013-10-04 11:17:26 -0700251 return true;
Ian Rogers04f94f42013-06-10 15:09:26 -0700252 } else {
253 return component->CannotBeAssignedFromOtherTypes();
254 }
255 }
256 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800257
258 String* GetName() const; // Returns the cached name.
259 void SetName(String* name) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Sets the cached name.
260 // Computes the name, then sets the cached value.
261 String* ComputeName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
262
263 bool IsProxyClass() const {
264 // Read access flags without using getter as whether something is a proxy can be check in
265 // any loaded state
266 // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
267 uint32_t access_flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), false);
268 return (access_flags & kAccClassIsProxy) != 0;
269 }
270
271 Primitive::Type GetPrimitiveType() const {
272 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
273 return static_cast<Primitive::Type>(
274 GetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), false));
275 }
276
277 void SetPrimitiveType(Primitive::Type new_type) {
278 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
279 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), new_type, false);
280 }
281
282 // Returns true if the class is a primitive type.
283 bool IsPrimitive() const {
284 return GetPrimitiveType() != Primitive::kPrimNot;
285 }
286
287 bool IsPrimitiveBoolean() const {
288 return GetPrimitiveType() == Primitive::kPrimBoolean;
289 }
290
291 bool IsPrimitiveByte() const {
292 return GetPrimitiveType() == Primitive::kPrimByte;
293 }
294
295 bool IsPrimitiveChar() const {
296 return GetPrimitiveType() == Primitive::kPrimChar;
297 }
298
299 bool IsPrimitiveShort() const {
300 return GetPrimitiveType() == Primitive::kPrimShort;
301 }
302
303 bool IsPrimitiveInt() const {
304 return GetPrimitiveType() == Primitive::kPrimInt;
305 }
306
307 bool IsPrimitiveLong() const {
308 return GetPrimitiveType() == Primitive::kPrimLong;
309 }
310
311 bool IsPrimitiveFloat() const {
312 return GetPrimitiveType() == Primitive::kPrimFloat;
313 }
314
315 bool IsPrimitiveDouble() const {
316 return GetPrimitiveType() == Primitive::kPrimDouble;
317 }
318
319 bool IsPrimitiveVoid() const {
320 return GetPrimitiveType() == Primitive::kPrimVoid;
321 }
322
323 bool IsPrimitiveArray() const {
324 return IsArrayClass() && GetComponentType()->IsPrimitive();
325 }
326
327 // Depth of class from java.lang.Object
328 size_t Depth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
329 size_t depth = 0;
330 for (Class* klass = this; klass->GetSuperClass() != NULL; klass = klass->GetSuperClass()) {
331 depth++;
332 }
333 return depth;
334 }
335
336 bool IsArrayClass() const {
337 return GetComponentType() != NULL;
338 }
339
340 bool IsClassClass() const;
341
342 bool IsStringClass() const;
343
344 bool IsThrowableClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
345
Brian Carlstromea46f952013-07-30 01:26:50 -0700346 bool IsArtFieldClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800347
Brian Carlstromea46f952013-07-30 01:26:50 -0700348 bool IsArtMethodClass() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800349
Ian Rogersa9a82542013-10-04 11:17:26 -0700350 static MemberOffset ComponentTypeOffset() {
351 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
352 }
353
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800354 Class* GetComponentType() const {
Ian Rogersa9a82542013-10-04 11:17:26 -0700355 return GetFieldObject<Class*>(ComponentTypeOffset(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800356 }
357
358 void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
359 DCHECK(GetComponentType() == NULL);
360 DCHECK(new_component_type != NULL);
Ian Rogersa9a82542013-10-04 11:17:26 -0700361 SetFieldObject(ComponentTypeOffset(), new_component_type, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800362 }
363
364 size_t GetComponentSize() const {
365 return Primitive::ComponentSize(GetComponentType()->GetPrimitiveType());
366 }
367
368 bool IsObjectClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
369 return !IsPrimitive() && GetSuperClass() == NULL;
370 }
371 bool IsInstantiable() const {
Sameer Abu Asal02c42232013-04-30 12:09:45 -0700372 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) || ((IsAbstract()) && IsArrayClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800373 }
374
375 bool IsObjectArrayClass() const {
376 return GetComponentType() != NULL && !GetComponentType()->IsPrimitive();
377 }
378
379 // Creates a raw object instance but does not invoke the default constructor.
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700380 Object* AllocObject(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
381 return AllocObjectInstrumented(self);
382 }
383
384 Object* AllocObjectUninstrumented(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
385 Object* AllocObjectInstrumented(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386
387 bool IsVariableSize() const {
388 // Classes and arrays vary in size, and so the object_size_ field cannot
389 // be used to get their instance size
390 return IsClassClass() || IsArrayClass();
391 }
392
393 size_t SizeOf() const {
394 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
395 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false);
396 }
397
398 size_t GetClassSize() const {
399 DCHECK_EQ(sizeof(size_t), sizeof(uint32_t));
400 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false);
401 }
402
403 void SetClassSize(size_t new_class_size)
404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
405
406 size_t GetObjectSize() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
407
408 void SetObjectSize(size_t new_object_size) {
409 DCHECK(!IsVariableSize());
410 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
411 return SetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size, false);
412 }
413
414 // Returns true if this class is in the same packages as that class.
415 bool IsInSamePackage(const Class* that) const
416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
417
418 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
419
420 // Returns true if this class can access that class.
421 bool CanAccess(Class* that) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
422 return that->IsPublic() || this->IsInSamePackage(that);
423 }
424
425 // Can this class access a member in the provided class with the provided member access flags?
426 // Note that access to the class isn't checked in case the declaring class is protected and the
427 // method has been exposed by a public sub-class
428 bool CanAccessMember(Class* access_to, uint32_t member_flags) const
429 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
430 // Classes can access all of their own members
431 if (this == access_to) {
432 return true;
433 }
434 // Public members are trivially accessible
435 if (member_flags & kAccPublic) {
436 return true;
437 }
438 // Private members are trivially not accessible
439 if (member_flags & kAccPrivate) {
440 return false;
441 }
442 // Check for protected access from a sub-class, which may or may not be in the same package.
443 if (member_flags & kAccProtected) {
444 if (this->IsSubClass(access_to)) {
445 return true;
446 }
447 }
448 // Allow protected access from other classes in the same package.
449 return this->IsInSamePackage(access_to);
450 }
451
452 bool IsSubClass(const Class* klass) const
453 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
454
455 // Can src be assigned to this class? For example, String can be assigned to Object (by an
456 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
457 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
458 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
459 // to themselves. Classes for primitive types may not assign to each other.
Ian Rogersfa46d3e2013-05-15 00:16:04 -0700460 inline bool IsAssignableFrom(const Class* src) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800461 DCHECK(src != NULL);
462 if (this == src) {
463 // Can always assign to things of the same type.
464 return true;
465 } else if (IsObjectClass()) {
466 // Can assign any reference to java.lang.Object.
467 return !src->IsPrimitive();
468 } else if (IsInterface()) {
469 return src->Implements(this);
470 } else if (src->IsArrayClass()) {
471 return IsAssignableFromArray(src);
472 } else {
473 return !src->IsInterface() && src->IsSubClass(this);
474 }
475 }
476
477 Class* GetSuperClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
478
479 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
480 // super class is assigned once, except during class linker initialization
481 Class* old_super_class = GetFieldObject<Class*>(
482 OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false);
483 DCHECK(old_super_class == NULL || old_super_class == new_super_class);
484 DCHECK(new_super_class != NULL);
485 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class, false);
486 }
487
488 bool HasSuperClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
489 return GetSuperClass() != NULL;
490 }
491
492 static MemberOffset SuperClassOffset() {
493 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
494 }
495
496 ClassLoader* GetClassLoader() const;
497
498 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
499
500 static MemberOffset DexCacheOffset() {
501 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
502 }
503
504 enum {
505 kDumpClassFullDetail = 1,
506 kDumpClassClassLoader = (1 << 1),
507 kDumpClassInitialized = (1 << 2),
508 };
509
510 void DumpClass(std::ostream& os, int flags) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
511
512 DexCache* GetDexCache() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
513
514 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
515
Brian Carlstromea46f952013-07-30 01:26:50 -0700516 ObjectArray<ArtMethod>* GetDirectMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800517
Brian Carlstromea46f952013-07-30 01:26:50 -0700518 void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800519 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
520
Brian Carlstromea46f952013-07-30 01:26:50 -0700521 ArtMethod* GetDirectMethod(int32_t i) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800522
Brian Carlstromea46f952013-07-30 01:26:50 -0700523 void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
525
526 // Returns the number of static, private, and constructor methods.
527 size_t NumDirectMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
528
Brian Carlstromea46f952013-07-30 01:26:50 -0700529 ObjectArray<ArtMethod>* GetVirtualMethods() const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800530 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
531
Brian Carlstromea46f952013-07-30 01:26:50 -0700532 void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800533 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
534
535 // Returns the number of non-inherited virtual methods.
536 size_t NumVirtualMethods() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
537
Brian Carlstromea46f952013-07-30 01:26:50 -0700538 ArtMethod* GetVirtualMethod(uint32_t i) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800539 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
540
Brian Carlstromea46f952013-07-30 01:26:50 -0700541 ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800542 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
543
Brian Carlstromea46f952013-07-30 01:26:50 -0700544 void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
546
Brian Carlstromea46f952013-07-30 01:26:50 -0700547 ObjectArray<ArtMethod>* GetVTable() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800548
Brian Carlstromea46f952013-07-30 01:26:50 -0700549 ObjectArray<ArtMethod>* GetVTableDuringLinking() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800550
Brian Carlstromea46f952013-07-30 01:26:50 -0700551 void SetVTable(ObjectArray<ArtMethod>* new_vtable)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800552 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
553
554 static MemberOffset VTableOffset() {
555 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
556 }
557
Jeff Hao88474b42013-10-23 16:24:40 -0700558 ObjectArray<ArtMethod>* GetImTable() const;
559
560 void SetImTable(ObjectArray<ArtMethod>* new_imtable)
561 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
562
563 static MemberOffset ImTableOffset() {
564 return OFFSET_OF_OBJECT_MEMBER(Class, imtable_);
565 }
566
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800567 // Given a method implemented by this class but potentially from a super class, return the
568 // specific implementation method for this class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700569 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800570 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
571
572 // Given a method implemented by this class' super class, return the specific implementation
573 // method for this class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700574 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800575 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
576
577 // Given a method implemented by this class, but potentially from a
578 // super class or interface, return the specific implementation
579 // method for this class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700580 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method) const
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800581 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800582
Ian Rogersd91d6d62013-09-25 20:26:14 -0700583 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method) const
584 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
585
586 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800587 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
588
Brian Carlstromea46f952013-07-30 01:26:50 -0700589 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800590 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
591
Brian Carlstromea46f952013-07-30 01:26:50 -0700592 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800593 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
594
Ian Rogersd91d6d62013-09-25 20:26:14 -0700595 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature) const
596 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
597
Brian Carlstromea46f952013-07-30 01:26:50 -0700598 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800599 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
600
Brian Carlstromea46f952013-07-30 01:26:50 -0700601 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature) const
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800602 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
603
Ian Rogersd91d6d62013-09-25 20:26:14 -0700604 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature) const
605 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
606
Brian Carlstromea46f952013-07-30 01:26:50 -0700607 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) 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* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature) const
611 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
612
613 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature) const
614 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
615
616 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
617 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
618
619 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature) const
620 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
621
622 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature) const
623 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
624
625 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const
626 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
627
628 ArtMethod* FindClassInitializer() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
629
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800630 int32_t GetIfTableCount() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
631
632 IfTable* GetIfTable() const;
633
634 void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
635
636 // Get instance fields of the class (See also GetSFields).
Brian Carlstromea46f952013-07-30 01:26:50 -0700637 ObjectArray<ArtField>* GetIFields() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800638
Brian Carlstromea46f952013-07-30 01:26:50 -0700639 void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800640
641 size_t NumInstanceFields() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
642
Brian Carlstromea46f952013-07-30 01:26:50 -0700643 ArtField* GetInstanceField(uint32_t i) const // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800644 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
645
Brian Carlstromea46f952013-07-30 01:26:50 -0700646 void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800647 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
648
649 // Returns the number of instance fields containing reference types.
650 size_t NumReferenceInstanceFields() const {
651 DCHECK(IsResolved() || IsErroneous());
652 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
653 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false);
654 }
655
656 size_t NumReferenceInstanceFieldsDuringLinking() const {
657 DCHECK(IsLoaded() || IsErroneous());
658 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
659 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false);
660 }
661
662 void SetNumReferenceInstanceFields(size_t new_num) {
663 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
664 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num, false);
665 }
666
667 uint32_t GetReferenceInstanceOffsets() const {
668 DCHECK(IsResolved() || IsErroneous());
669 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), false);
670 }
671
672 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
673 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
674
675 // Beginning of static field data
676 static MemberOffset FieldsOffset() {
677 return OFFSET_OF_OBJECT_MEMBER(Class, fields_);
678 }
679
680 // Returns the number of static fields containing reference types.
681 size_t NumReferenceStaticFields() const {
682 DCHECK(IsResolved() || IsErroneous());
683 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
684 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false);
685 }
686
687 size_t NumReferenceStaticFieldsDuringLinking() const {
688 DCHECK(IsLoaded() || IsErroneous());
689 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
690 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false);
691 }
692
693 void SetNumReferenceStaticFields(size_t new_num) {
694 DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
695 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num, false);
696 }
697
698 // Gets the static fields of the class.
Brian Carlstromea46f952013-07-30 01:26:50 -0700699 ObjectArray<ArtField>* GetSFields() const;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800700
Brian Carlstromea46f952013-07-30 01:26:50 -0700701 void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800702
703 size_t NumStaticFields() const;
704
Brian Carlstromea46f952013-07-30 01:26:50 -0700705 ArtField* GetStaticField(uint32_t i) const; // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800706
Brian Carlstromea46f952013-07-30 01:26:50 -0700707 void SetStaticField(uint32_t i, ArtField* f); // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800708
709 uint32_t GetReferenceStaticOffsets() const {
710 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), false);
711 }
712
713 void SetReferenceStaticOffsets(uint32_t new_reference_offsets);
714
715 // Find a static or instance field using the JLS resolution order
Brian Carlstromea46f952013-07-30 01:26:50 -0700716 ArtField* FindField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800717 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
718
719 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700720 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800721 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
722
723 // Finds the given instance field in this class or a superclass, only searches classes that
724 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700725 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800726 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
727
Brian Carlstromea46f952013-07-30 01:26:50 -0700728 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800729 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
730
Brian Carlstromea46f952013-07-30 01:26:50 -0700731 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800732 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
733
734 // Finds the given static field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700735 ArtField* FindStaticField(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 static field in this class or superclass, only searches classes that
739 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700740 ArtField* FindStaticField(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* FindDeclaredStaticField(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* FindDeclaredStaticField(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 pid_t GetClinitThreadId() const {
750 DCHECK(IsIdxLoaded() || IsErroneous());
751 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), false);
752 }
753
754 void SetClinitThreadId(pid_t new_clinit_thread_id) {
755 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), new_clinit_thread_id, false);
756 }
757
758 Class* GetVerifyErrorClass() const {
759 // DCHECK(IsErroneous());
760 return GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), false);
761 }
762
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700763 uint16_t GetDexClassDefIndex() const {
764 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), false);
765 }
766
767 void SetDexClassDefIndex(uint16_t class_def_idx) {
768 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx, false);
769 }
770
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800771 uint16_t GetDexTypeIndex() const {
772 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), false);
773 }
774
775 void SetDexTypeIndex(uint16_t type_idx) {
776 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx, false);
777 }
778
779 static Class* GetJavaLangClass() {
780 DCHECK(java_lang_Class_ != NULL);
781 return java_lang_Class_;
782 }
783
784 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
785 static void SetClassClass(Class* java_lang_Class);
786 static void ResetClass();
787
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200788 // When class is verified, set the kAccPreverified flag on each method.
789 void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
790
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800791 private:
792 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
793
794 bool Implements(const Class* klass) const
795 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
796 bool IsArrayAssignableFromArray(const Class* klass) const
797 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
798 bool IsAssignableFromArray(const Class* klass) const
799 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
800
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700801 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
802
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800803 // defining class loader, or NULL for the "bootstrap" system loader
804 ClassLoader* class_loader_;
805
806 // For array classes, the component class object for instanceof/checkcast
807 // (for String[][][], this will be String[][]). NULL for non-array classes.
808 Class* component_type_;
809
810 // DexCache of resolved constant pool entries (will be NULL for classes generated by the
811 // runtime such as arrays and primitive classes).
812 DexCache* dex_cache_;
813
814 // static, private, and <init> methods
Brian Carlstromea46f952013-07-30 01:26:50 -0700815 ObjectArray<ArtMethod>* direct_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800816
817 // instance fields
818 //
819 // These describe the layout of the contents of an Object.
820 // Note that only the fields directly declared by this class are
821 // listed in ifields; fields declared by a superclass are listed in
822 // the superclass's Class.ifields.
823 //
824 // All instance fields that refer to objects are guaranteed to be at
825 // the beginning of the field list. num_reference_instance_fields_
826 // specifies the number of reference fields.
Brian Carlstromea46f952013-07-30 01:26:50 -0700827 ObjectArray<ArtField>* ifields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800828
829 // The interface table (iftable_) contains pairs of a interface class and an array of the
830 // interface methods. There is one pair per interface supported by this class. That means one
831 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
832 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
833 //
834 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
835 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
836 // single vtable.
837 //
838 // For every interface a concrete class implements, we create an array of the concrete vtable_
839 // methods for the methods in the interface.
840 IfTable* iftable_;
841
Jeff Hao88474b42013-10-23 16:24:40 -0700842 // Interface method table (imt), for quick "invoke-interface".
843 ObjectArray<ArtMethod>* imtable_;
844
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800845 // descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
846 String* name_;
847
848 // Static fields
Brian Carlstromea46f952013-07-30 01:26:50 -0700849 ObjectArray<ArtField>* sfields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800850
851 // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
852 Class* super_class_;
853
854 // If class verify fails, we must return same error on subsequent tries.
855 Class* verify_error_class_;
856
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700857 // Virtual methods defined in this class; invoked through vtable.
Brian Carlstromea46f952013-07-30 01:26:50 -0700858 ObjectArray<ArtMethod>* virtual_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800859
860 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
861 // copied in, and virtual methods from our class either replace those from the super or are
862 // appended. For abstract classes, methods may be created in the vtable that aren't in
863 // virtual_ methods_ for miranda methods.
Brian Carlstromea46f952013-07-30 01:26:50 -0700864 ObjectArray<ArtMethod>* vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800865
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700866 // Access flags; low 16 bits are defined by VM spec.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800867 uint32_t access_flags_;
868
869 // Total size of the Class instance; used when allocating storage on gc heap.
870 // See also object_size_.
871 size_t class_size_;
872
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700873 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800874 pid_t clinit_thread_id_;
875
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700876 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800877 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700878 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800879
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700880 // Type index in dex file.
881 // TODO: really 16bits
882 int32_t dex_type_idx_;
883
884 // Number of instance fields that are object refs.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800885 size_t num_reference_instance_fields_;
886
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700887 // Number of static fields that are object refs,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800888 size_t num_reference_static_fields_;
889
890 // Total object size; used when allocating storage on gc heap.
891 // (For interfaces and abstract classes this will be zero.)
892 // See also class_size_.
893 size_t object_size_;
894
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700895 // Primitive type value, or Primitive::kPrimNot (0); set for generated primitive classes.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800896 Primitive::Type primitive_type_;
897
898 // Bitmap of offsets of ifields.
899 uint32_t reference_instance_offsets_;
900
901 // Bitmap of offsets of sfields.
902 uint32_t reference_static_offsets_;
903
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700904 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800905 Status status_;
906
907 // TODO: ?
908 // initiating class loader list
909 // NOTE: for classes with low serialNumber, these are unused, and the
910 // values are kept in a table in gDvm.
911 // InitiatingLoaderList initiating_loader_list_;
912
913 // Location of first static field.
914 uint32_t fields_[0];
915
916 // java.lang.Class
917 static Class* java_lang_Class_;
918
919 friend struct art::ClassOffsets; // for verifying offset information
920 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
921};
922
923std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
924
925class MANAGED ClassClass : public Class {
926 private:
Jeff Hao88474b42013-10-23 16:24:40 -0700927 int32_t pad_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800928 int64_t serialVersionUID_;
929 friend struct art::ClassClassOffsets; // for verifying offset information
930 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass);
931};
932
933} // namespace mirror
934} // namespace art
935
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700936#endif // ART_RUNTIME_MIRROR_CLASS_H_