blob: 5cb884cc9d7c312e36a8a11de3ed21d8ef7ba563 [file] [log] [blame]
Carl Shapiro1fb86202011-06-27 17:43:13 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_OBJECT_H_
4#define ART_SRC_OBJECT_H_
5
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07006#include "constants.h"
7#include "casts.h"
8#include "globals.h"
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07009#include "heap.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070010#include "logging.h"
11#include "macros.h"
12#include "offsets.h"
13#include "stringpiece.h"
14#include "monitor.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -070015
16namespace art {
17
18class Array;
19class Class;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070020class DexCache;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070021class InstanceField;
Carl Shapiro1fb86202011-06-27 17:43:13 -070022class InterfaceEntry;
23class Monitor;
24class Method;
Carl Shapiro3ee755d2011-06-28 12:11:04 -070025class Object;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -040026class String;
Brian Carlstrom4a96b602011-07-26 16:40:23 -070027template<class T> class ObjectArray;
Jesse Wilsonfd687c52011-08-04 19:27:35 -070028template<class T> class PrimitiveArray;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070029class StaticField;
Jesse Wilsonfd687c52011-08-04 19:27:35 -070030typedef PrimitiveArray<uint16_t> CharArray;
31typedef PrimitiveArray<uint32_t> IntArray;
32typedef PrimitiveArray<uint64_t> LongArray;
Carl Shapiro1fb86202011-06-27 17:43:13 -070033
Carl Shapiro3ee755d2011-06-28 12:11:04 -070034union JValue {
35 uint8_t z;
36 int8_t b;
37 uint16_t c;
38 int16_t s;
39 int32_t i;
40 int64_t j;
41 float f;
42 double d;
43 Object* l;
44};
45
Brian Carlstrombe977852011-07-19 14:54:54 -070046static const uint32_t kAccPublic = 0x0001; // class, field, method, ic
47static const uint32_t kAccPrivate = 0x0002; // field, method, ic
48static const uint32_t kAccProtected = 0x0004; // field, method, ic
49static const uint32_t kAccStatic = 0x0008; // field, method, ic
50static const uint32_t kAccFinal = 0x0010; // class, field, method, ic
51static const uint32_t kAccSynchronized = 0x0020; // method (only allowed on natives)
52static const uint32_t kAccSuper = 0x0020; // class (not used in Dalvik)
53static const uint32_t kAccVolatile = 0x0040; // field
54static const uint32_t kAccBridge = 0x0040; // method (1.5)
55static const uint32_t kAccTransient = 0x0080; // field
56static const uint32_t kAccVarargs = 0x0080; // method (1.5)
57static const uint32_t kAccNative = 0x0100; // method
58static const uint32_t kAccInterface = 0x0200; // class, ic
59static const uint32_t kAccAbstract = 0x0400; // class, method, ic
60static const uint32_t kAccStrict = 0x0800; // method
61static const uint32_t kAccSynthetic = 0x1000; // field, method, ic
62static const uint32_t kAccAnnotation = 0x2000; // class, ic (1.5)
63static const uint32_t kAccEnum = 0x4000; // class, field, ic (1.5)
Carl Shapiro3ee755d2011-06-28 12:11:04 -070064
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070065static const uint32_t kAccMiranda = 0x8000; // method
66
Brian Carlstroma331b3c2011-07-18 17:47:56 -070067static const uint32_t kAccJavaFlagsMask = 0xffff; // bits set from Java sources (low 16)
68
Brian Carlstrombe977852011-07-19 14:54:54 -070069static const uint32_t kAccConstructor = 0x00010000; // method (Dalvik only)
70static const uint32_t kAccDeclaredSynchronized = 0x00020000; // method (Dalvik only)
Carl Shapiro3ee755d2011-06-28 12:11:04 -070071
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070072/*
Brian Carlstroma331b3c2011-07-18 17:47:56 -070073 * Definitions for packing refOffsets in Class.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070074 */
75/*
76 * A magic value for refOffsets. Ignore the bits and walk the super
77 * chain when this is the value.
78 * [This is an unlikely "natural" value, since it would be 30 non-ref instance
79 * fields followed by 2 ref instance fields.]
80 */
81#define CLASS_WALK_SUPER ((unsigned int)(3))
82#define CLASS_SMALLEST_OFFSET (sizeof(struct Object))
83#define CLASS_BITS_PER_WORD (sizeof(unsigned long int) * 8)
84#define CLASS_OFFSET_ALIGNMENT 4
85#define CLASS_HIGH_BIT ((unsigned int)1 << (CLASS_BITS_PER_WORD - 1))
86/*
87 * Given an offset, return the bit number which would encode that offset.
88 * Local use only.
89 */
90#define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \
91 (((unsigned int)(byteOffset) - CLASS_SMALLEST_OFFSET) / \
92 CLASS_OFFSET_ALIGNMENT)
93/*
94 * Is the given offset too large to be encoded?
95 */
96#define CLASS_CAN_ENCODE_OFFSET(byteOffset) \
97 (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD)
98/*
99 * Return a single bit, encoding the offset.
100 * Undefined if the offset is too large, as defined above.
101 */
102#define CLASS_BIT_FROM_OFFSET(byteOffset) \
103 (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset))
104/*
105 * Return an offset, given a bit number as returned from CLZ.
106 */
107#define CLASS_OFFSET_FROM_CLZ(rshift) \
Ian Rogersb033c752011-07-20 12:22:35 -0700108 ((static_cast<int>(rshift) * CLASS_OFFSET_ALIGNMENT) + CLASS_SMALLEST_OFFSET)
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700109
110
Carl Shapiro1fb86202011-06-27 17:43:13 -0700111class Object {
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700112 public:
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700113 static bool InstanceOf(const Object* object, const Class* klass) {
114 if (object == NULL) {
115 return false;
116 }
117 return object->InstanceOf(klass);
118 }
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700119
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700120 Class* GetClass() const {
121 return klass_;
122 }
123
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700124 bool InstanceOf(const Class* klass) const;
125
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700126 void MonitorEnter() {
127 monitor_->Enter();
128 }
129
130 void MonitorExit() {
131 monitor_->Exit();
132 }
133
134 void Notify() {
135 monitor_->Notify();
136 }
137
138 void NotifyAll() {
139 monitor_->NotifyAll();
140 }
141
142 void Wait() {
143 monitor_->Wait();
144 }
145
146 void Wait(int64_t timeout) {
147 monitor_->Wait(timeout);
148 }
149
150 void Wait(int64_t timeout, int32_t nanos) {
151 monitor_->Wait(timeout, nanos);
152 }
153
Carl Shapiro69759ea2011-07-21 18:13:35 -0700154 const Object* GetFieldObject(size_t field_offset) const {
155 const byte* raw_addr = reinterpret_cast<const byte*>(this) + field_offset;
156 return *reinterpret_cast<Object* const*>(raw_addr);
157 }
158
159 Object* GetFieldObject(size_t field_offset) {
160 return const_cast<Object*>(GetFieldObject(field_offset));
161 }
162
163 void SetFieldObject(size_t offset, Object* new_value) {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700164 byte* raw_addr = reinterpret_cast<byte*>(this) + offset;
165 *reinterpret_cast<Object**>(raw_addr) = new_value;
166 // TODO: write barrier
167 }
168
Carl Shapiro69759ea2011-07-21 18:13:35 -0700169 bool IsClass() const {
170 LOG(FATAL) << "Unimplemented";
171 return true;
172 }
173
174 Class* AsClass() {
175 return down_cast<Class*>(this);
176 }
177
178 const Class* AsClass() const {
179 return down_cast<const Class*>(this);
180 }
181
182 bool IsObjectArray() const {
183 LOG(FATAL) << "Unimplemented";
184 return true;
185 }
186
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700187 const ObjectArray<Object>* AsObjectArray() const {
188 return down_cast<const ObjectArray<Object>*>(this);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700189 }
190
191 bool IsReference() const {
192 LOG(FATAL) << "Unimplemented";
193 return true;
194 }
195
196 bool IsWeakReference() const {
197 LOG(FATAL) << "Unimplemented";
198 return true;
199 }
200
201 bool IsSoftReference() const {
202 LOG(FATAL) << "Unimplemented";
203 return true;
204 }
205
206 bool IsFinalizerReference() const {
207 LOG(FATAL) << "Unimplemented";
208 return true;
209 }
210
211 bool IsPhantomReference() const {
212 LOG(FATAL) << "Unimplemented";
213 return true;
214 }
215
216 bool IsArray() const {
217 LOG(FATAL) << "Unimplemented";
218 return true;
219 }
220
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700221 public:
Carl Shapiro1fb86202011-06-27 17:43:13 -0700222 Class* klass_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700223
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700224 Monitor* monitor_;
225
226 private:
Carl Shapirof88c9522011-08-06 15:47:38 -0700227 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700228};
229
230class ObjectLock {
231 public:
Ian Rogersb033c752011-07-20 12:22:35 -0700232 explicit ObjectLock(Object* object) : obj_(object) {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700233 CHECK(object != NULL);
234 obj_->MonitorEnter();
235 }
236
237 ~ObjectLock() {
238 obj_->MonitorExit();
239 }
240
241 void Wait(int64_t millis = 0) {
242 return obj_->Wait(millis);
243 }
244
245 void Notify() {
246 obj_->Notify();
247 }
248
249 void NotifyAll() {
250 obj_->NotifyAll();
251 }
252
253 private:
254 Object* obj_;
255 DISALLOW_COPY_AND_ASSIGN(ObjectLock);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700256};
257
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400258class AccessibleObject : public Object {
259 private:
260 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
261 uint32_t java_flag_;
262};
263
264class Field : public AccessibleObject {
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700265 public:
Brian Carlstroma0808032011-07-18 00:39:23 -0700266 Class* GetDeclaringClass() const {
267 return declaring_class_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700268 }
269
Jesse Wilson14150742011-07-29 19:04:44 -0400270 const String* GetName() const {
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700271 return name_;
272 }
273
274 bool IsStatic() const {
275 return (access_flags_ & kAccStatic) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700276 }
277
278 char GetType() const { // TODO: return type
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700279 return GetDescriptor()[0];
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700280 }
281
Brian Carlstromae3ac012011-07-27 01:30:28 -0700282 const StringPiece& GetDescriptor() const {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700283 DCHECK_NE(0, descriptor_.size());
Brian Carlstromae3ac012011-07-27 01:30:28 -0700284 return descriptor_;
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700285 }
286
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700287 public: // TODO: private
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400288 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
289 Class* java_declaring_class_;
290 Object* java_generic_type_;
291 uint32_t java_generic_types_are_initialized_;
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700292 String* name_;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400293 uint32_t java_slot_;
294 Class* java_type_;
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700295
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700296 // The class in which this field is declared.
Brian Carlstroma0808032011-07-18 00:39:23 -0700297 Class* declaring_class_;
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700298
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700299 // e.g. "I", "[C", "Landroid/os/Debug;"
Brian Carlstromae3ac012011-07-27 01:30:28 -0700300 StringPiece descriptor_;
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700301
302 uint32_t access_flags_;
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700303
304 private:
Carl Shapirof88c9522011-08-06 15:47:38 -0700305 DISALLOW_IMPLICIT_CONSTRUCTORS(Field);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700306};
307
308// Instance fields.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700309class InstanceField : public Field {
310 public:
311 uint32_t GetOffset() const {
312 return offset_;
313 }
314
315 void SetOffset(size_t num_bytes) {
316 offset_ = num_bytes;
317 }
318
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700319 private:
320 size_t offset_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700321
322 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceField);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700323};
324
325// Static fields.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700326class StaticField : public Field {
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700327 public:
Jesse Wilson7833bd22011-08-09 18:31:44 -0400328 bool GetBoolean();
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700329
Jesse Wilson7833bd22011-08-09 18:31:44 -0400330 void SetBoolean(bool z);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700331
Jesse Wilson7833bd22011-08-09 18:31:44 -0400332 int8_t GetByte();
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700333
Jesse Wilson7833bd22011-08-09 18:31:44 -0400334 void SetByte(int8_t b);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700335
Jesse Wilson7833bd22011-08-09 18:31:44 -0400336 uint16_t GetChar();
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700337
Jesse Wilson7833bd22011-08-09 18:31:44 -0400338 void SetChar(uint16_t c);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700339
Jesse Wilson7833bd22011-08-09 18:31:44 -0400340 uint16_t GetShort();
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700341
Jesse Wilson7833bd22011-08-09 18:31:44 -0400342 void SetShort(uint16_t s);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700343
Jesse Wilson7833bd22011-08-09 18:31:44 -0400344 int32_t GetInt();
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700345
Jesse Wilson7833bd22011-08-09 18:31:44 -0400346 void SetInt(int32_t i);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700347
Jesse Wilson7833bd22011-08-09 18:31:44 -0400348 int64_t GetLong();
Carl Shapiro69759ea2011-07-21 18:13:35 -0700349
Jesse Wilson7833bd22011-08-09 18:31:44 -0400350 void SetLong(int64_t j);
351
352 float GetFloat();
353
354 void SetFloat(float f);
355
356 double GetDouble();
357
358 void SetDouble(double d);
359
360 Object* GetObject();
361
362 const Object* GetObject() const;
363
364 void SetObject(Object* l);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700365
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700366 private:
Carl Shapirof88c9522011-08-06 15:47:38 -0700367 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticField);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700368};
369
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400370class Method : public AccessibleObject {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700371 public:
Brian Carlstromae3ac012011-07-27 01:30:28 -0700372 // Returns the method name, e.g. "<init>" or "eatLunch"
Jesse Wilsonf7e85a52011-08-01 18:45:58 -0700373 const String* GetName() const {
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700374 return name_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700375 }
376
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700377 const String* GetDescriptor() const {
378 return descriptor_;
379 }
380
Brian Carlstroma0808032011-07-18 00:39:23 -0700381 Class* GetDeclaringClass() const {
382 return declaring_class_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700383 }
384
Ian Rogersb033c752011-07-20 12:22:35 -0700385 static MemberOffset ClassOffset() {
386 return MemberOffset(OFFSETOF_MEMBER(Method, klass_));
387 }
388
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700389 // Returns true if the method is declared public.
390 bool IsPublic() const {
391 return (access_flags_ & kAccPublic) != 0;
392 }
393
394 // Returns true if the method is declared private.
395 bool IsPrivate() const {
396 return (access_flags_ & kAccPrivate) != 0;
397 }
398
399 // Returns true if the method is declared static.
400 bool IsStatic() const {
401 return (access_flags_ & kAccStatic) != 0;
402 }
403
404 // Returns true if the method is declared synchronized.
405 bool IsSynchronized() const {
406 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
407 return (access_flags_ & synchonized) != 0;
408 }
409
410 // Returns true if the method is declared final.
411 bool IsFinal() const {
412 return (access_flags_ & kAccFinal) != 0;
413 }
414
415 // Returns true if the method is declared native.
416 bool IsNative() const {
417 return (access_flags_ & kAccNative) != 0;
418 }
419
420 // Returns true if the method is declared abstract.
421 bool IsAbstract() const {
422 return (access_flags_ & kAccAbstract) != 0;
423 }
424
425 bool IsSynthetic() const {
426 return (access_flags_ & kAccSynthetic) != 0;
427 }
428
429 // Number of argument registers required by the prototype.
430 uint32_t NumArgRegisters();
431
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700432 public: // TODO: private
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400433 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
434 Class* java_declaring_class_;
435 ObjectArray<Class>* java_exception_types_;
436 Object* java_formal_type_parameters_;
437 Object* java_generic_exception_types_;
438 Object* java_generic_parameter_types_;
439 Object* java_generic_return_type_;
440 Class* java_return_type_;
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700441 String* name_;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400442 ObjectArray<Class>* java_parameter_types_;
443 uint32_t java_generic_types_are_initialized_;
444 uint32_t java_slot_;
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700445
Ian Rogersb033c752011-07-20 12:22:35 -0700446 bool IsReturnAReference() const {
447 return (shorty_[0] == 'L') || (shorty_[0] == '[');
448 }
449
450 bool IsReturnAFloatOrDouble() const {
451 return (shorty_[0] == 'F') || (shorty_[0] == 'D');
452 }
453
454 bool IsReturnAFloat() const {
455 return shorty_[0] == 'F';
456 }
457
458 bool IsReturnADouble() const {
459 return shorty_[0] == 'D';
460 }
461
462 bool IsReturnALong() const {
463 return shorty_[0] == 'J';
464 }
465
Ian Rogers45a76cb2011-07-21 22:00:15 -0700466 bool IsReturnVoid() const {
467 return shorty_[0] == 'V';
468 }
469
Ian Rogersb033c752011-07-20 12:22:35 -0700470 // The number of arguments that should be supplied to this method
471 size_t NumArgs() const {
472 return (IsStatic() ? 0 : 1) + shorty_.length() - 1;
473 }
474
475 // The number of reference arguments to this method including implicit this
476 // pointer
477 size_t NumReferenceArgs() const;
478
479 // The number of long or double arguments
480 size_t NumLongOrDoubleArgs() const;
481
482 // The number of reference arguments to this method before the given
483 // parameter index
484 size_t NumReferenceArgsBefore(unsigned int param) const;
485
486 // Is the given method parameter a reference?
487 bool IsParamAReference(unsigned int param) const;
488
489 // Is the given method parameter a long or double?
490 bool IsParamALongOrDouble(unsigned int param) const;
491
Ian Rogersdf20fe02011-07-20 20:34:16 -0700492 // Size in bytes of the given parameter
493 size_t ParamSize(unsigned int param) const;
494
495 // Size in bytes of the return value
496 size_t ReturnSize() const;
Ian Rogersb033c752011-07-20 12:22:35 -0700497
498 void SetCode(const void* code) {
499 code_ = code;
500 }
501
502 const void* GetCode() const {
503 return code_;
504 }
505
506 void RegisterNative(const void* native_method) {
507 native_method_ = native_method;
508 }
509
510 static MemberOffset NativeMethodOffset() {
511 return MemberOffset(OFFSETOF_MEMBER(Method, native_method_));
512 }
513
Carl Shapiro8860c0e2011-08-04 17:36:16 -0700514 bool HasSameNameAndDescriptor(const Method* that) const;
515
Ian Rogersb033c752011-07-20 12:22:35 -0700516 public: // TODO: private/const
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700517 // the class we are a part of
Brian Carlstroma0808032011-07-18 00:39:23 -0700518 Class* declaring_class_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700519
520 // access flags; low 16 bits are defined by spec (could be uint16_t?)
521 uint32_t access_flags_;
522
523 // For concrete virtual methods, this is the offset of the method
524 // in "vtable".
525 //
526 // For abstract methods in an interface class, this is the offset
527 // of the method in "iftable[n]->methodIndexArray".
528 uint16_t method_index_;
529
530 // Method bounds; not needed for an abstract method.
531 //
532 // For a native method, we compute the size of the argument list, and
533 // set "insSize" and "registerSize" equal to it.
534 uint16_t num_registers_; // ins + locals
535 uint16_t num_outs_;
536 uint16_t num_ins_;
537
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700538 // The method descriptor. This represents the parameters a method
539 // takes and value it returns. This string is a list of the type
540 // descriptors for the parameters enclosed in parenthesis followed
541 // by the return type descriptor. For example, for the method
542 //
543 // Object mymethod(int i, double d, Thread t)
544 //
545 // the method descriptor would be
546 //
547 // (IDLjava/lang/Thread;)Ljava/lang/Object;
548 String* descriptor_;
549
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700550 // Method prototype descriptor string (return and argument types).
551 uint32_t proto_idx_;
552
553 // The short-form method descriptor string.
554 StringPiece shorty_;
555
556 // A pointer to the memory-mapped DEX code.
557 const uint16_t* insns_;
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700558
559 private:
Ian Rogersb033c752011-07-20 12:22:35 -0700560 // Compiled code associated with this method
561 const void* code_;
562
563 // Any native method registered with this method
564 const void* native_method_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700565
566 DISALLOW_IMPLICIT_CONSTRUCTORS(Method);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700567};
568
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700569class Array : public Object {
570 public:
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700571 static Array* Alloc(Class* array_class,
572 size_t component_count,
573 size_t component_size) {
574 size_t size = sizeof(Array) + component_count * component_size;
575 Array* array = down_cast<Array*>(Heap::AllocObject(array_class, size));
576 if (array != NULL) {
577 array->SetLength(component_count);
578 }
579 return array;
580 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700581
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700582 uint32_t GetLength() const {
583 return length_;
584 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700585
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700586 void SetLength(uint32_t length) {
587 length_ = length;
588 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700589
590 private:
591 // The number of array elements.
592 uint32_t length_;
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400593 // Padding to ensure the first member defined by a subclass begins on a 8-byte boundary
594 int32_t padding_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700595
Carl Shapirof88c9522011-08-06 15:47:38 -0700596 DISALLOW_IMPLICIT_CONSTRUCTORS(Array);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700597};
598
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700599template<class T>
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700600class ObjectArray : public Array {
601 public:
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700602 static ObjectArray<T>* Alloc(Class* object_array_class,
603 size_t length) {
604 return down_cast<ObjectArray<T>*>(Array::Alloc(object_array_class,
605 length,
606 sizeof(uint32_t)));
607 }
608
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700609 T* const * GetData() const {
610 return reinterpret_cast<T* const *>(&elements_);
611 }
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400612
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700613 T** GetData() {
614 return reinterpret_cast<T**>(&elements_);
615 }
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400616
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700617 T* Get(uint32_t i) const {
Brian Carlstrom0b138b22011-07-27 15:19:17 -0700618 CHECK_LT(i, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700619 return GetData()[i];
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700620 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700621
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700622 void Set(uint32_t i, T* object) {
Brian Carlstrom0b138b22011-07-27 15:19:17 -0700623 CHECK_LT(i, GetLength());
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400624 GetData()[i] = object; // TODO: write barrier
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700625 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700626
627 static void Copy(ObjectArray<T>* src, int src_pos,
628 ObjectArray<T>* dst, int dst_pos,
629 size_t length) {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700630 for (size_t i = 0; i < length; i++) {
631 dst->Set(dst_pos + i, src->Get(src_pos + i));
632 }
633 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700634
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700635 ObjectArray<T>* CopyOf(size_t new_length) {
636 ObjectArray<T>* new_array = Alloc(klass_, new_length);
637 Copy(this, 0, new_array, 0, std::min(GetLength(), new_length));
638 return new_array;
639 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700640
641 private:
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700642 // Location of first element.
643 T* elements_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -0700644
645 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700646};
647
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700648// ClassLoader objects.
649class ClassLoader : public Object {
650 public:
651 std::vector<const DexFile*>& GetClassPath() {
652 return class_path_;
653 }
654 void SetClassPath(std::vector<const DexFile*>& class_path) {
655 DCHECK_EQ(0U, class_path_.size());
656 class_path_ = class_path;
657 }
658
659 private:
660 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
661 Object* packages_;
662 ClassLoader* parent_;
663
664 // TODO remove once we can create a real PathClassLoader
665 std::vector<const DexFile*> class_path_;
666
Carl Shapirof88c9522011-08-06 15:47:38 -0700667 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700668};
669
670class BaseDexClassLoader : public ClassLoader {
671 private:
672 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
673 String* original_path_;
674 Object* path_list_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700675 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseDexClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700676};
677
678class PathClassLoader : public BaseDexClassLoader {
679 private:
Carl Shapirof88c9522011-08-06 15:47:38 -0700680 DISALLOW_IMPLICIT_CONSTRUCTORS(PathClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700681};
682
Carl Shapiro1fb86202011-06-27 17:43:13 -0700683// Class objects.
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700684class Class : public Object {
Carl Shapiro1fb86202011-06-27 17:43:13 -0700685 public:
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700686
687 // Class Status
688 //
689 // kStatusNotReady: If a Class cannot be found in the class table by
690 // FindClass, it allocates an new one with AllocClass in the
691 // kStatusNotReady and calls LoadClass. Note if it does find a
692 // class, it may not be kStatusResolved and it will try to push it
693 // forward toward kStatusResolved.
694 //
695 // kStatusIdx: LoadClass populates with Class with information from
696 // the DexFile, moving the status to kStatusIdx, indicating that the
697 // Class values in super_class_ and interfaces_ have not been
698 // populated based on super_class_idx_ and interfaces_idx_. The new
699 // Class can then be inserted into the classes table.
700 //
701 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
702 // attempt to move a kStatusIdx class forward to kStatusLoaded by
703 // using ResolveClass to initialize the super_class_ and interfaces_.
704 //
705 // kStatusResolved: Still holding the lock on Class, the ClassLinker
706 // will use LinkClass to link all members, creating Field and Method
707 // objects, setting up the vtable, etc. On success, the class is
708 // marked kStatusResolved.
709
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700710 enum Status {
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700711 kStatusError = -1,
712 kStatusNotReady = 0,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700713 kStatusIdx = 1, // loaded, DEX idx in super_class_idx_ and interfaces_idx_
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700714 kStatusLoaded = 2, // DEX idx values resolved
715 kStatusResolved = 3, // part of linking
716 kStatusVerifying = 4, // in the process of being verified
717 kStatusVerified = 5, // logically part of linking; done pre-init
718 kStatusInitializing = 6, // class init in progress
719 kStatusInitialized = 7, // ready to go
Carl Shapiro1fb86202011-06-27 17:43:13 -0700720 };
721
722 enum PrimitiveType {
723 kPrimNot = -1
724 };
725
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700726 Object* NewInstance() {
727 return Heap::AllocObject(this, this->object_size_);
728 }
729
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700730 Class* GetSuperClass() const {
731 return super_class_;
732 }
733
734 uint32_t GetSuperClassIdx() const {
735 return super_class_idx_;
736 }
737
738 bool HasSuperClass() const {
739 return super_class_ != NULL;
740 }
741
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700742 bool IsAssignableFrom(const Class* klass) const {
743 DCHECK(klass != NULL);
744 if (this == klass) {
745 return true;
746 }
747 if (IsInterface()) {
748 return klass->Implements(this);
749 }
750 if (klass->IsArray()) {
751 return IsAssignableFromArray(klass);
752 }
753 return klass->IsSubClass(this);
754 }
755
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700756 ClassLoader* GetClassLoader() const {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700757 return class_loader_;
758 }
759
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700760 DexCache* GetDexCache() const {
761 return dex_cache_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700762 }
763
764 Class* GetComponentType() const {
765 return component_type_;
766 }
767
768 const StringPiece& GetDescriptor() const {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700769 DCHECK_NE(0, descriptor_.size());
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700770 return descriptor_;
771 }
772
773 Status GetStatus() const {
774 return status_;
775 }
776
777 void SetStatus(Status new_status) {
778 // TODO: validate transition
779 status_ = new_status;
780 }
781
Carl Shapiro69759ea2011-07-21 18:13:35 -0700782 // Returns true if the class has failed to link.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700783 bool IsErroneous() const {
784 return GetStatus() == kStatusError;
785 }
786
Carl Shapiro69759ea2011-07-21 18:13:35 -0700787 // Returns true if the class has been verified.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700788 bool IsVerified() const {
789 return GetStatus() >= kStatusVerified;
790 }
791
Carl Shapiro69759ea2011-07-21 18:13:35 -0700792 // Returns true if the class has been linked.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700793 bool IsLinked() const {
794 return GetStatus() >= kStatusResolved;
795 }
796
Carl Shapiro69759ea2011-07-21 18:13:35 -0700797 bool IsLoaded() const {
798 return GetStatus() >= kStatusLoaded;
799 }
800
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700801 // Returns true if this class is in the same packages as that class.
802 bool IsInSamePackage(const Class* that) const;
803
Ian Rogersb033c752011-07-20 12:22:35 -0700804 static bool IsInSamePackage(const StringPiece& descriptor1,
805 const StringPiece& descriptor2);
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700806
807 // Returns true if this class represents an array class.
808 bool IsArray() const {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700809 return GetDescriptor()[0] == '['; // TODO: avoid parsing the descriptor
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700810 }
811
812 // Returns true if the class is an interface.
813 bool IsInterface() const {
814 return (access_flags_ & kAccInterface) != 0;
815 }
816
817 // Returns true if the class is declared public.
818 bool IsPublic() const {
819 return (access_flags_ & kAccPublic) != 0;
820 }
821
822 // Returns true if the class is declared final.
823 bool IsFinal() const {
824 return (access_flags_ & kAccFinal) != 0;
825 }
826
827 // Returns true if the class is abstract.
828 bool IsAbstract() const {
829 return (access_flags_ & kAccAbstract) != 0;
830 }
831
832 // Returns true if the class is an annotation.
833 bool IsAnnotation() const {
834 return (access_flags_ & kAccAnnotation) != 0;
835 }
836
837 // Returns true if the class is a primitive type.
838 bool IsPrimitive() const {
839 return primitive_type_ != kPrimNot;
840 }
841
Brian Carlstromae3ac012011-07-27 01:30:28 -0700842 // Returns true if the class is synthetic.
843 bool IsSynthetic() const {
844 return (access_flags_ & kAccSynthetic) != 0;
845 }
846
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700847 // Returns true if this class can access that class.
848 bool CanAccess(const Class* that) const {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700849 return that->IsPublic() || this->IsInSamePackage(that);
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700850 }
851
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700852 // Returns the number of static, private, and constructor methods.
853 size_t NumDirectMethods() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700854 return (direct_methods_ != NULL) ? direct_methods_->GetLength() : 0;
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700855 }
856
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700857 Method* GetDirectMethod(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700858 DCHECK_NE(NumDirectMethods(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700859 return direct_methods_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700860 }
861
862 void SetDirectMethod(uint32_t i, Method* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700863 DCHECK_NE(NumDirectMethods(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700864 direct_methods_->Set(i, f);
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700865 }
866
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700867 Method* FindDeclaredDirectMethod(const StringPiece& name,
868 const StringPiece& descriptor);
869
870 Method* FindDirectMethod(const StringPiece& name,
871 const StringPiece& descriptor);
872
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700873 // Returns the number of non-inherited virtual methods.
874 size_t NumVirtualMethods() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700875 return (virtual_methods_ != NULL) ? virtual_methods_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700876 }
877
878 Method* GetVirtualMethod(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700879 DCHECK_NE(NumVirtualMethods(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700880 return virtual_methods_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700881 }
882
883 void SetVirtualMethod(uint32_t i, Method* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700884 DCHECK_NE(NumVirtualMethods(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700885 virtual_methods_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700886 }
887
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700888 Method* FindDeclaredVirtualMethod(const StringPiece& name,
889 const StringPiece& descriptor);
890
891 Method* FindVirtualMethod(const StringPiece& name,
892 const StringPiece& descriptor);
893
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700894 size_t NumInstanceFields() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700895 return (ifields_ != NULL) ? ifields_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700896 }
897
Carl Shapiro69759ea2011-07-21 18:13:35 -0700898 // Returns the number of instance fields containing reference types.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700899 size_t NumReferenceInstanceFields() const {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700900 return num_reference_instance_fields_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700901 }
902
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700903 InstanceField* GetInstanceField(uint32_t i) const { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700904 DCHECK_NE(NumInstanceFields(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700905 return ifields_->Get(i);
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700906 }
907
908 void SetInstanceField(uint32_t i, InstanceField* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700909 DCHECK_NE(NumInstanceFields(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700910 ifields_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700911 }
912
913 size_t NumStaticFields() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700914 return (sfields_ != NULL) ? sfields_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700915 }
916
Carl Shapiro69759ea2011-07-21 18:13:35 -0700917 StaticField* GetStaticField(uint32_t i) const { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700918 DCHECK_NE(NumStaticFields(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700919 return sfields_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700920 }
921
922 void SetStaticField(uint32_t i, StaticField* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700923 DCHECK_NE(NumStaticFields(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700924 sfields_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700925 }
926
927 uint32_t GetReferenceOffsets() const {
928 return reference_offsets_;
929 }
930
931 void SetReferenceOffsets(uint32_t new_reference_offsets) {
932 reference_offsets_ = new_reference_offsets;
933 }
934
Carl Shapiro69759ea2011-07-21 18:13:35 -0700935 size_t NumInterfaces() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700936 return (interfaces_ != NULL) ? interfaces_->GetLength() : 0;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700937 }
938
939 Class* GetInterface(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700940 DCHECK_NE(NumInterfaces(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700941 return interfaces_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700942 }
943
944 void SetInterface(uint32_t i, Class* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700945 DCHECK_NE(NumInterfaces(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700946 interfaces_->Set(i, f);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700947 }
948
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700949 void SetVerifyErrorClass(Class* klass) {
950 // Note SetFieldObject is used rather than verify_error_class_ directly for the barrier
951 size_t field_offset = OFFSETOF_MEMBER(Class, verify_error_class_);
952 klass->SetFieldObject(field_offset, klass);
953 }
954
955 private:
956 bool Implements(const Class* klass) const;
957 bool IsArrayAssignableFromArray(const Class* klass) const;
958 bool IsAssignableFromArray(const Class* klass) const;
959 bool IsSubClass(const Class* klass) const;
960
Ian Rogersb033c752011-07-20 12:22:35 -0700961 public: // TODO: private
Carl Shapiro1fb86202011-06-27 17:43:13 -0700962 // leave space for instance data; we could access fields directly if
963 // we freeze the definition of java/lang/Class
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700964#define CLASS_FIELD_SLOTS 1
965 // Class.#0 name
Carl Shapiro1fb86202011-06-27 17:43:13 -0700966 uint32_t instance_data_[CLASS_FIELD_SLOTS];
967#undef CLASS_FIELD_SLOTS
968
969 // UTF-8 descriptor for the class from constant pool
970 // ("Ljava/lang/Class;"), or on heap if generated ("[C")
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700971 StringPiece descriptor_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700972
973 // Proxy classes have their descriptor allocated on the native heap.
974 // When this field is non-NULL it must be explicitly freed.
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700975 std::string* descriptor_alloc_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700976
977 // access flags; low 16 bits are defined by VM spec
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700978 uint32_t access_flags_; // TODO: make an instance field?
Carl Shapiro1fb86202011-06-27 17:43:13 -0700979
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700980 // DexCache of resolved constant pool entries
Carl Shapiro1fb86202011-06-27 17:43:13 -0700981 // (will be NULL for VM-generated, e.g. arrays and primitive classes)
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700982 DexCache* dex_cache_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700983
984 // state of class initialization
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700985 Status status_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700986
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700987 // If class verify fails, we must return same error on subsequent tries.
988 // Update with SetVerifyErrorClass to ensure a write barrier is used.
989 const Class* verify_error_class_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700990
991 // threadId, used to check for recursive <clinit> invocation
992 uint32_t clinit_thread_id_;
993
994 // Total object size; used when allocating storage on gc heap. (For
995 // interfaces and abstract classes this will be zero.)
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700996 size_t object_size_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700997
998 // For array classes, the class object for base element, for
999 // instanceof/checkcast (for String[][][], this will be String).
1000 // Otherwise, NULL.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001001 Class* component_type_; // TODO: make an instance field
Carl Shapiro1fb86202011-06-27 17:43:13 -07001002
1003 // For array classes, the number of array dimensions, e.g. int[][]
1004 // is 2. Otherwise 0.
1005 int32_t array_rank_;
1006
1007 // primitive type index, or PRIM_NOT (-1); set for generated prim classes
1008 PrimitiveType primitive_type_;
1009
1010 // The superclass, or NULL if this is java.lang.Object or a
1011 // primitive type.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001012 Class* super_class_; // TODO: make an instance field
1013 uint32_t super_class_idx_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001014
1015 // defining class loader, or NULL for the "bootstrap" system loader
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001016 ClassLoader* class_loader_; // TODO: make an instance field
Carl Shapiro1fb86202011-06-27 17:43:13 -07001017
1018 // initiating class loader list
1019 // NOTE: for classes with low serialNumber, these are unused, and the
1020 // values are kept in a table in gDvm.
Ian Rogersb033c752011-07-20 12:22:35 -07001021 // InitiatingLoaderList initiating_loader_list_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001022
1023 // array of interfaces this class implements directly
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001024 ObjectArray<Class>* interfaces_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001025 uint32_t* interfaces_idx_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001026
1027 // static, private, and <init> methods
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001028 ObjectArray<Method>* direct_methods_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001029
1030 // virtual methods defined in this class; invoked through vtable
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001031 ObjectArray<Method>* virtual_methods_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001032
1033 // Virtual method table (vtable), for use by "invoke-virtual". The
1034 // vtable from the superclass is copied in, and virtual methods from
1035 // our class either replace those from the super or are appended.
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001036 ObjectArray<Method>* vtable_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001037
1038 // Interface table (iftable), one entry per interface supported by
1039 // this class. That means one entry for each interface we support
1040 // directly, indirectly via superclass, or indirectly via
1041 // superinterface. This will be null if neither we nor our
1042 // superclass implement any interfaces.
1043 //
1044 // Why we need this: given "class Foo implements Face", declare
1045 // "Face faceObj = new Foo()". Invoke faceObj.blah(), where "blah"
1046 // is part of the Face interface. We can't easily use a single
1047 // vtable.
1048 //
1049 // For every interface a concrete class implements, we create a list
1050 // of virtualMethod indices for the methods in the interface.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001051 size_t iftable_count_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001052 InterfaceEntry* iftable_;
1053
1054 // The interface vtable indices for iftable get stored here. By
1055 // placing them all in a single pool for each class that implements
1056 // interfaces, we decrease the number of allocations.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001057 size_t ifvi_pool_count_;
1058 uint32_t* ifvi_pool_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001059
1060 // instance fields
1061 //
1062 // These describe the layout of the contents of a
1063 // DataObject-compatible Object. Note that only the fields directly
1064 // declared by this class are listed in ifields; fields declared by
Brian Carlstroma331b3c2011-07-18 17:47:56 -07001065 // a superclass are listed in the superclass's Class.ifields.
Carl Shapiro1fb86202011-06-27 17:43:13 -07001066 //
1067 // All instance fields that refer to objects are guaranteed to be at
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001068 // the beginning of the field list. num_reference_instance_fields_
1069 // specifies the number of reference fields.
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001070 ObjectArray<InstanceField>* ifields_;
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001071
1072 // number of fields that are object refs
Carl Shapiro69759ea2011-07-21 18:13:35 -07001073 size_t num_reference_instance_fields_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001074
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001075 // Bitmap of offsets of ifields.
1076 uint32_t reference_offsets_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001077
1078 // source file name, if known. Otherwise, NULL.
1079 const char* source_file_;
1080
Jesse Wilson7833bd22011-08-09 18:31:44 -04001081 // Static fields
1082 ObjectArray<StaticField>* sfields_;
1083
1084 // static field storage
1085 //
1086 // Each static field is stored in one of three arrays:
1087 // o references are stored in static_references_
1088 // o doubles and longs are stored in static_64bit_primitives_
1089 // o everything else is in static_32bit_primitives_
1090 // Static fields select their array using their type and their index using the
1091 // Field->slot_ member. Storing static fields in arrays avoids the need for a
1092 // special case in the GC.
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001093 ObjectArray<Object>* static_references_;
1094 IntArray* static_32bit_primitives_;
1095 LongArray* static_64bit_primitives_;
1096
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001097 private:
Carl Shapirof88c9522011-08-06 15:47:38 -07001098 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001099};
Elliott Hughes1f359b02011-07-17 14:27:17 -07001100std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001101
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001102inline bool Object::InstanceOf(const Class* klass) const {
Jesse Wilson14150742011-07-29 19:04:44 -04001103 DCHECK(klass != NULL);
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001104 DCHECK(klass_ != NULL);
1105 return klass->IsAssignableFrom(klass_);
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001106}
1107
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001108
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001109class DataObject : public Object {
1110 public:
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07001111 uint32_t fields_[0];
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001112 private:
Carl Shapirof88c9522011-08-06 15:47:38 -07001113 DISALLOW_IMPLICIT_CONSTRUCTORS(DataObject);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001114};
1115
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001116template<class T>
1117class PrimitiveArray : public Array {
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001118 public:
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001119 static PrimitiveArray<T>* Alloc(Class* element_class, size_t length) {
1120 return down_cast<PrimitiveArray<T>*>(Array::Alloc(element_class,
1121 length,
1122 sizeof(T)));
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001123 }
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001124
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001125 const T* GetData() const {
1126 return reinterpret_cast<const T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001127 }
1128
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001129 T* GetData() {
1130 return reinterpret_cast<T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001131 }
1132
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001133 T Get(T i) const {
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001134 CHECK_LT(i, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001135 return GetData()[i];
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001136 }
1137
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001138 void Set(uint32_t i, T value) {
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001139 CHECK_LT(i, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001140 GetData()[i] = value;
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001141 }
1142
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001143 private:
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001144 // Location of first element.
1145 T elements_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -07001146
1147 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimitiveArray);
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001148};
Carl Shapiro5fafe2b2011-07-09 15:34:41 -07001149
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001150class String : public Object {
Carl Shapiro1fb86202011-06-27 17:43:13 -07001151 public:
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001152 const CharArray* GetCharArray() const {
Carl Shapirof88c9522011-08-06 15:47:38 -07001153 DCHECK(array_ != NULL);
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001154 return array_;
1155 }
1156
Carl Shapirof88c9522011-08-06 15:47:38 -07001157 uint32_t GetHashCode() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001158 return hash_code_;
1159 }
1160
Carl Shapirof88c9522011-08-06 15:47:38 -07001161 uint32_t GetOffset() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001162 return offset_;
1163 }
1164
Carl Shapirof88c9522011-08-06 15:47:38 -07001165 uint32_t GetLength() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001166 return count_;
1167 }
1168
Carl Shapirof88c9522011-08-06 15:47:38 -07001169 uint16_t CharAt(uint32_t index) const {
1170 DCHECK_LE(index, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001171 return GetCharArray()->Get(index + GetOffset());
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001172 }
1173
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001174 static String* AllocFromUtf16(int32_t utf16_length,
1175 uint16_t* utf16_data_in,
1176 int32_t hash_code) {
Carl Shapirof88c9522011-08-06 15:47:38 -07001177 String* string = Alloc(GetJavaLangString(),
1178 GetCharArrayClass(),
1179 utf16_length);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001180 // TODO use 16-bit wide memset variant
1181 for (int i = 0; i < utf16_length; i++ ) {
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001182 string->array_->Set(i, utf16_data_in[i]);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001183 }
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001184 string->ComputeHashCode();
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001185 return string;
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001186 }
1187
1188 static String* AllocFromModifiedUtf8(Class* java_lang_String,
1189 Class* char_array,
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001190 int32_t utf16_length,
1191 const char* utf8_data_in) {
1192 String* string = Alloc(java_lang_String, char_array, utf16_length);
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001193 uint16_t* utf16_data_out = string->array_->GetData();
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001194 ConvertModifiedUtf8ToUtf16(utf16_data_out, utf8_data_in);
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001195 string->ComputeHashCode();
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001196 return string;
1197 }
1198
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001199 // Creates a String of the given ASCII characters. It is an error to call this
1200 // using non-ASCII characters as this function assumes one char per byte.
1201 static String* AllocFromAscii(const char* ascii_data_in) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001202 return AllocFromModifiedUtf8(GetJavaLangString(),
1203 GetCharArrayClass(),
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001204 strlen(ascii_data_in),
1205 ascii_data_in);
1206 }
1207
Jesse Wilson8989d992011-08-02 13:39:42 -07001208 static String* AllocFromModifiedUtf8(int32_t utf16_length,
1209 const char* utf8_data_in) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001210 return AllocFromModifiedUtf8(GetJavaLangString(), GetCharArrayClass(),
1211 utf16_length, utf8_data_in);
Jesse Wilson8989d992011-08-02 13:39:42 -07001212 }
1213
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001214 static void InitClasses(Class* java_lang_String, Class* char_array);
1215
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001216 static String* Alloc(Class* java_lang_String,
1217 Class* char_array,
1218 int32_t utf16_length) {
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001219 String* string = down_cast<String*>(java_lang_String->NewInstance());
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001220 CharArray* array = CharArray::Alloc(char_array, utf16_length);
1221 string->array_ = array;
1222 string->count_ = utf16_length;
1223 return string;
1224 }
1225
1226 // Convert Modified UTF-8 to UTF-16
1227 // http://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8
1228 static void ConvertModifiedUtf8ToUtf16(uint16_t* utf16_data_out, const char* utf8_data_in) {
1229 while (*utf8_data_in != '\0') {
1230 *utf16_data_out++ = GetUtf16FromUtf8(&utf8_data_in);
1231 }
1232 }
1233
1234 // Retrieve the next UTF-16 character from a UTF-8 string.
1235 //
1236 // Advances "*pUtf8Ptr" to the start of the next character.
1237 //
1238 // WARNING: If a string is corrupted by dropping a '\0' in the middle
1239 // of a 3-byte sequence, you can end up overrunning the buffer with
1240 // reads (and possibly with the writes if the length was computed and
1241 // cached before the damage). For performance reasons, this function
1242 // assumes that the string being parsed is known to be valid (e.g., by
1243 // already being verified). Most strings we process here are coming
1244 // out of dex files or other internal translations, so the only real
1245 // risk comes from the JNI NewStringUTF call.
1246 static uint16_t GetUtf16FromUtf8(const char** utf8_data_in) {
1247 uint8_t one = *(*utf8_data_in)++;
1248 if ((one & 0x80) == 0) {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001249 // one-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001250 return one;
1251 }
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001252 // two- or three-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001253 uint8_t two = *(*utf8_data_in)++;
1254 if ((one & 0x20) == 0) {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001255 // two-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001256 return ((one & 0x1f) << 6) |
1257 (two & 0x3f);
1258 }
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001259 // three-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001260 uint8_t three = *(*utf8_data_in)++;
1261 return ((one & 0x0f) << 12) |
1262 ((two & 0x3f) << 6) |
1263 (three & 0x3f);
1264 }
1265
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001266 // Like "strlen", but for strings encoded with "modified" UTF-8.
1267 //
1268 // The value returned is the number of characters, which may or may not
1269 // be the same as the number of bytes.
1270 //
1271 // (If this needs optimizing, try: mask against 0xa0, shift right 5,
1272 // get increment {1-3} from table of 8 values.)
1273 static size_t ModifiedUtf8Len(const char* utf8) {
1274 size_t len = 0;
1275 int ic;
1276 while ((ic = *utf8++) != '\0') {
1277 len++;
1278 if ((ic & 0x80) == 0) {
1279 // one-byte encoding
1280 continue;
1281 }
1282 // two- or three-byte encoding
1283 utf8++;
1284 if ((ic & 0x20) == 0) {
1285 // two-byte encoding
1286 continue;
1287 }
1288 // three-byte encoding
1289 utf8++;
1290 }
1291 return len;
1292 }
1293
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001294 // The java/lang/String.computeHashCode() algorithm
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001295 static int32_t ComputeUtf16Hash(const uint16_t* string_data, size_t string_length) {
1296 int32_t hash = 0;
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001297 while (string_length--) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001298 hash = hash * 31 + *string_data++;
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001299 }
1300 return hash;
1301 }
1302
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001303 void ComputeHashCode() {
1304 hash_code_ = ComputeUtf16Hash(array_->GetData(), count_);
1305 }
1306
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001307 bool Equals(const char* modified_utf8) const {
Carl Shapirof88c9522011-08-06 15:47:38 -07001308 for (uint32_t i = 0; i < GetLength(); ++i) {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001309 uint16_t ch = GetUtf16FromUtf8(&modified_utf8);
1310 if (ch == '\0' || ch != CharAt(i)) {
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001311 return false;
1312 }
1313 }
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001314 return *modified_utf8 == '\0';
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001315 }
1316
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001317 bool Equals(const StringPiece& modified_utf8) const {
1318 // TODO: do not assume C-string representation.
1319 return Equals(modified_utf8.data());
1320 }
1321
1322 bool Equals(const String* that) const {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001323 // TODO short circuit on hash_code_
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001324 if (this->GetLength() != that->GetLength()) {
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001325 return false;
1326 }
Carl Shapirof88c9522011-08-06 15:47:38 -07001327 for (uint32_t i = 0; i < that->GetLength(); ++i) {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001328 if (this->CharAt(i) != that->CharAt(i)) {
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001329 return false;
1330 }
1331 }
1332 return true;
1333 }
1334
Carl Shapirof88c9522011-08-06 15:47:38 -07001335 bool Equals(const uint16_t* that_chars, uint32_t that_offset, uint32_t that_length) const {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001336 if (this->GetLength() != that_length) {
1337 return false;
1338 }
Carl Shapirof88c9522011-08-06 15:47:38 -07001339 for (uint32_t i = 0; i < that_length; ++i) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001340 if (this->CharAt(i) != that_chars[that_offset + i]) {
1341 return false;
1342 }
1343 }
1344 return true;
1345 }
1346
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001347 private:
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001348 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
1349 CharArray* array_;
1350
Carl Shapirof88c9522011-08-06 15:47:38 -07001351 uint32_t hash_code_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001352
Carl Shapirof88c9522011-08-06 15:47:38 -07001353 uint32_t offset_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001354
Carl Shapirof88c9522011-08-06 15:47:38 -07001355 uint32_t count_;
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001356
1357 static Class* GetJavaLangString() {
1358 DCHECK(java_lang_String_ != NULL);
1359 return java_lang_String_;
1360 }
1361 static Class* GetCharArrayClass() {
1362 DCHECK(char_array_ != NULL);
1363 return char_array_;
1364 }
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001365
1366 static Class* java_lang_String_;
1367 static Class* char_array_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001368
1369 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001370};
1371
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001372class InterfaceEntry {
Carl Shapiro1fb86202011-06-27 17:43:13 -07001373 public:
Carl Shapirof88c9522011-08-06 15:47:38 -07001374 InterfaceEntry() : klass_(NULL), method_index_array_(NULL) {
1375 }
1376
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001377 Class* GetClass() const {
1378 return klass_;
Carl Shapirof88c9522011-08-06 15:47:38 -07001379 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001380
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001381 void SetClass(Class* klass) {
1382 klass_ = klass;
Carl Shapirof88c9522011-08-06 15:47:38 -07001383 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001384
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001385 private:
1386 // Points to the interface class.
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001387 Class* klass_;
1388
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001389 public: // TODO: private
1390 // Index into array of vtable offsets. This points into the
1391 // ifviPool, which holds the vtables for all interfaces declared by
1392 // this class.
1393 uint32_t* method_index_array_;
Carl Shapirof88c9522011-08-06 15:47:38 -07001394
1395 private:
1396 DISALLOW_COPY_AND_ASSIGN(InterfaceEntry);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001397};
1398
1399} // namespace art
1400
1401#endif // ART_SRC_OBJECT_H_