blob: c1682ecbb4ddb54abd8c7f3cab6f13d121dd90bb [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:
328 void SetBoolean(bool z) {
329 CHECK_EQ(GetType(), 'Z');
330 value_.z = z;
331 }
332
333 void SetByte(int8_t b) {
334 CHECK_EQ(GetType(), 'B');
335 value_.b = b;
336 }
337
338 void SetChar(uint16_t c) {
339 CHECK_EQ(GetType(), 'C');
340 value_.c = c;
341 }
342
343 void SetShort(uint16_t s) {
344 CHECK_EQ(GetType(), 'S');
345 value_.s = s;
346 }
347
348 void SetInt(int32_t i) {
349 CHECK_EQ(GetType(), 'I');
350 value_.i = i;
351 }
352
353 int64_t GetLong() {
354 CHECK_EQ(GetType(), 'J');
355 return value_.j;
356 }
357
358 void SetLong(int64_t j) {
359 CHECK_EQ(GetType(), 'J');
360 value_.j = j;
361 }
362
363 void SetFloat(float f) {
364 CHECK_EQ(GetType(), 'F');
365 value_.f = f;
366 }
367
368 void SetDouble(double d) {
369 CHECK_EQ(GetType(), 'D');
370 value_.d = d;
371 }
372
Carl Shapiro69759ea2011-07-21 18:13:35 -0700373 Object* GetObject() {
374 return value_.l;
375 }
376
377 const Object* GetObject() const {
378 return value_.l;
379 }
380
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700381 void SetObject(Object* l) {
Carl Shapiro565f5072011-07-10 13:39:43 -0700382 CHECK(GetType() == 'L' || GetType() == '[');
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700383 value_.l = l;
384 // TODO: write barrier
385 }
386
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700387 private:
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700388 JValue value_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700389
390 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticField);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700391};
392
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400393class Method : public AccessibleObject {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700394 public:
Brian Carlstromae3ac012011-07-27 01:30:28 -0700395 // Returns the method name, e.g. "<init>" or "eatLunch"
Jesse Wilsonf7e85a52011-08-01 18:45:58 -0700396 const String* GetName() const {
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700397 return name_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700398 }
399
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700400 const String* GetDescriptor() const {
401 return descriptor_;
402 }
403
Brian Carlstroma0808032011-07-18 00:39:23 -0700404 Class* GetDeclaringClass() const {
405 return declaring_class_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700406 }
407
Ian Rogersb033c752011-07-20 12:22:35 -0700408 static MemberOffset ClassOffset() {
409 return MemberOffset(OFFSETOF_MEMBER(Method, klass_));
410 }
411
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700412 // Returns true if the method is declared public.
413 bool IsPublic() const {
414 return (access_flags_ & kAccPublic) != 0;
415 }
416
417 // Returns true if the method is declared private.
418 bool IsPrivate() const {
419 return (access_flags_ & kAccPrivate) != 0;
420 }
421
422 // Returns true if the method is declared static.
423 bool IsStatic() const {
424 return (access_flags_ & kAccStatic) != 0;
425 }
426
427 // Returns true if the method is declared synchronized.
428 bool IsSynchronized() const {
429 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
430 return (access_flags_ & synchonized) != 0;
431 }
432
433 // Returns true if the method is declared final.
434 bool IsFinal() const {
435 return (access_flags_ & kAccFinal) != 0;
436 }
437
438 // Returns true if the method is declared native.
439 bool IsNative() const {
440 return (access_flags_ & kAccNative) != 0;
441 }
442
443 // Returns true if the method is declared abstract.
444 bool IsAbstract() const {
445 return (access_flags_ & kAccAbstract) != 0;
446 }
447
448 bool IsSynthetic() const {
449 return (access_flags_ & kAccSynthetic) != 0;
450 }
451
452 // Number of argument registers required by the prototype.
453 uint32_t NumArgRegisters();
454
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700455 public: // TODO: private
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400456 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
457 Class* java_declaring_class_;
458 ObjectArray<Class>* java_exception_types_;
459 Object* java_formal_type_parameters_;
460 Object* java_generic_exception_types_;
461 Object* java_generic_parameter_types_;
462 Object* java_generic_return_type_;
463 Class* java_return_type_;
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700464 String* name_;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400465 ObjectArray<Class>* java_parameter_types_;
466 uint32_t java_generic_types_are_initialized_;
467 uint32_t java_slot_;
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700468
Ian Rogersb033c752011-07-20 12:22:35 -0700469 bool IsReturnAReference() const {
470 return (shorty_[0] == 'L') || (shorty_[0] == '[');
471 }
472
473 bool IsReturnAFloatOrDouble() const {
474 return (shorty_[0] == 'F') || (shorty_[0] == 'D');
475 }
476
477 bool IsReturnAFloat() const {
478 return shorty_[0] == 'F';
479 }
480
481 bool IsReturnADouble() const {
482 return shorty_[0] == 'D';
483 }
484
485 bool IsReturnALong() const {
486 return shorty_[0] == 'J';
487 }
488
Ian Rogers45a76cb2011-07-21 22:00:15 -0700489 bool IsReturnVoid() const {
490 return shorty_[0] == 'V';
491 }
492
Ian Rogersb033c752011-07-20 12:22:35 -0700493 // The number of arguments that should be supplied to this method
494 size_t NumArgs() const {
495 return (IsStatic() ? 0 : 1) + shorty_.length() - 1;
496 }
497
498 // The number of reference arguments to this method including implicit this
499 // pointer
500 size_t NumReferenceArgs() const;
501
502 // The number of long or double arguments
503 size_t NumLongOrDoubleArgs() const;
504
505 // The number of reference arguments to this method before the given
506 // parameter index
507 size_t NumReferenceArgsBefore(unsigned int param) const;
508
509 // Is the given method parameter a reference?
510 bool IsParamAReference(unsigned int param) const;
511
512 // Is the given method parameter a long or double?
513 bool IsParamALongOrDouble(unsigned int param) const;
514
Ian Rogersdf20fe02011-07-20 20:34:16 -0700515 // Size in bytes of the given parameter
516 size_t ParamSize(unsigned int param) const;
517
518 // Size in bytes of the return value
519 size_t ReturnSize() const;
Ian Rogersb033c752011-07-20 12:22:35 -0700520
521 void SetCode(const void* code) {
522 code_ = code;
523 }
524
525 const void* GetCode() const {
526 return code_;
527 }
528
529 void RegisterNative(const void* native_method) {
530 native_method_ = native_method;
531 }
532
533 static MemberOffset NativeMethodOffset() {
534 return MemberOffset(OFFSETOF_MEMBER(Method, native_method_));
535 }
536
Carl Shapiro8860c0e2011-08-04 17:36:16 -0700537 bool HasSameNameAndDescriptor(const Method* that) const;
538
Ian Rogersb033c752011-07-20 12:22:35 -0700539 public: // TODO: private/const
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700540 // the class we are a part of
Brian Carlstroma0808032011-07-18 00:39:23 -0700541 Class* declaring_class_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700542
543 // access flags; low 16 bits are defined by spec (could be uint16_t?)
544 uint32_t access_flags_;
545
546 // For concrete virtual methods, this is the offset of the method
547 // in "vtable".
548 //
549 // For abstract methods in an interface class, this is the offset
550 // of the method in "iftable[n]->methodIndexArray".
551 uint16_t method_index_;
552
553 // Method bounds; not needed for an abstract method.
554 //
555 // For a native method, we compute the size of the argument list, and
556 // set "insSize" and "registerSize" equal to it.
557 uint16_t num_registers_; // ins + locals
558 uint16_t num_outs_;
559 uint16_t num_ins_;
560
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700561 // The method descriptor. This represents the parameters a method
562 // takes and value it returns. This string is a list of the type
563 // descriptors for the parameters enclosed in parenthesis followed
564 // by the return type descriptor. For example, for the method
565 //
566 // Object mymethod(int i, double d, Thread t)
567 //
568 // the method descriptor would be
569 //
570 // (IDLjava/lang/Thread;)Ljava/lang/Object;
571 String* descriptor_;
572
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700573 // Method prototype descriptor string (return and argument types).
574 uint32_t proto_idx_;
575
576 // The short-form method descriptor string.
577 StringPiece shorty_;
578
579 // A pointer to the memory-mapped DEX code.
580 const uint16_t* insns_;
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700581
582 private:
Ian Rogersb033c752011-07-20 12:22:35 -0700583 // Compiled code associated with this method
584 const void* code_;
585
586 // Any native method registered with this method
587 const void* native_method_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700588
589 DISALLOW_IMPLICIT_CONSTRUCTORS(Method);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700590};
591
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700592class Array : public Object {
593 public:
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700594 static Array* Alloc(Class* array_class,
595 size_t component_count,
596 size_t component_size) {
597 size_t size = sizeof(Array) + component_count * component_size;
598 Array* array = down_cast<Array*>(Heap::AllocObject(array_class, size));
599 if (array != NULL) {
600 array->SetLength(component_count);
601 }
602 return array;
603 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700604
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700605 uint32_t GetLength() const {
606 return length_;
607 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700608
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700609 void SetLength(uint32_t length) {
610 length_ = length;
611 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700612
613 private:
614 // The number of array elements.
615 uint32_t length_;
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400616 // Padding to ensure the first member defined by a subclass begins on a 8-byte boundary
617 int32_t padding_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700618
Carl Shapirof88c9522011-08-06 15:47:38 -0700619 DISALLOW_IMPLICIT_CONSTRUCTORS(Array);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700620};
621
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700622template<class T>
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700623class ObjectArray : public Array {
624 public:
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700625 static ObjectArray<T>* Alloc(Class* object_array_class,
626 size_t length) {
627 return down_cast<ObjectArray<T>*>(Array::Alloc(object_array_class,
628 length,
629 sizeof(uint32_t)));
630 }
631
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700632 T* const * GetData() const {
633 return reinterpret_cast<T* const *>(&elements_);
634 }
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400635
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700636 T** GetData() {
637 return reinterpret_cast<T**>(&elements_);
638 }
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400639
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700640 T* Get(uint32_t i) const {
Brian Carlstrom0b138b22011-07-27 15:19:17 -0700641 CHECK_LT(i, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700642 return GetData()[i];
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700643 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700644
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700645 void Set(uint32_t i, T* object) {
Brian Carlstrom0b138b22011-07-27 15:19:17 -0700646 CHECK_LT(i, GetLength());
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400647 GetData()[i] = object; // TODO: write barrier
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700648 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700649
650 static void Copy(ObjectArray<T>* src, int src_pos,
651 ObjectArray<T>* dst, int dst_pos,
652 size_t length) {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700653 for (size_t i = 0; i < length; i++) {
654 dst->Set(dst_pos + i, src->Get(src_pos + i));
655 }
656 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700657
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700658 ObjectArray<T>* CopyOf(size_t new_length) {
659 ObjectArray<T>* new_array = Alloc(klass_, new_length);
660 Copy(this, 0, new_array, 0, std::min(GetLength(), new_length));
661 return new_array;
662 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700663
664 private:
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700665 // Location of first element.
666 T* elements_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -0700667
668 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700669};
670
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700671// ClassLoader objects.
672class ClassLoader : public Object {
673 public:
674 std::vector<const DexFile*>& GetClassPath() {
675 return class_path_;
676 }
677 void SetClassPath(std::vector<const DexFile*>& class_path) {
678 DCHECK_EQ(0U, class_path_.size());
679 class_path_ = class_path;
680 }
681
682 private:
683 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
684 Object* packages_;
685 ClassLoader* parent_;
686
687 // TODO remove once we can create a real PathClassLoader
688 std::vector<const DexFile*> class_path_;
689
Carl Shapirof88c9522011-08-06 15:47:38 -0700690 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700691};
692
693class BaseDexClassLoader : public ClassLoader {
694 private:
695 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
696 String* original_path_;
697 Object* path_list_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700698 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseDexClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700699};
700
701class PathClassLoader : public BaseDexClassLoader {
702 private:
Carl Shapirof88c9522011-08-06 15:47:38 -0700703 DISALLOW_IMPLICIT_CONSTRUCTORS(PathClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700704};
705
Carl Shapiro1fb86202011-06-27 17:43:13 -0700706// Class objects.
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700707class Class : public Object {
Carl Shapiro1fb86202011-06-27 17:43:13 -0700708 public:
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700709
710 // Class Status
711 //
712 // kStatusNotReady: If a Class cannot be found in the class table by
713 // FindClass, it allocates an new one with AllocClass in the
714 // kStatusNotReady and calls LoadClass. Note if it does find a
715 // class, it may not be kStatusResolved and it will try to push it
716 // forward toward kStatusResolved.
717 //
718 // kStatusIdx: LoadClass populates with Class with information from
719 // the DexFile, moving the status to kStatusIdx, indicating that the
720 // Class values in super_class_ and interfaces_ have not been
721 // populated based on super_class_idx_ and interfaces_idx_. The new
722 // Class can then be inserted into the classes table.
723 //
724 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
725 // attempt to move a kStatusIdx class forward to kStatusLoaded by
726 // using ResolveClass to initialize the super_class_ and interfaces_.
727 //
728 // kStatusResolved: Still holding the lock on Class, the ClassLinker
729 // will use LinkClass to link all members, creating Field and Method
730 // objects, setting up the vtable, etc. On success, the class is
731 // marked kStatusResolved.
732
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700733 enum Status {
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700734 kStatusError = -1,
735 kStatusNotReady = 0,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700736 kStatusIdx = 1, // loaded, DEX idx in super_class_idx_ and interfaces_idx_
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700737 kStatusLoaded = 2, // DEX idx values resolved
738 kStatusResolved = 3, // part of linking
739 kStatusVerifying = 4, // in the process of being verified
740 kStatusVerified = 5, // logically part of linking; done pre-init
741 kStatusInitializing = 6, // class init in progress
742 kStatusInitialized = 7, // ready to go
Carl Shapiro1fb86202011-06-27 17:43:13 -0700743 };
744
745 enum PrimitiveType {
746 kPrimNot = -1
747 };
748
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700749 Object* NewInstance() {
750 return Heap::AllocObject(this, this->object_size_);
751 }
752
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700753 Class* GetSuperClass() const {
754 return super_class_;
755 }
756
757 uint32_t GetSuperClassIdx() const {
758 return super_class_idx_;
759 }
760
761 bool HasSuperClass() const {
762 return super_class_ != NULL;
763 }
764
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700765 bool IsAssignableFrom(const Class* klass) const {
766 DCHECK(klass != NULL);
767 if (this == klass) {
768 return true;
769 }
770 if (IsInterface()) {
771 return klass->Implements(this);
772 }
773 if (klass->IsArray()) {
774 return IsAssignableFromArray(klass);
775 }
776 return klass->IsSubClass(this);
777 }
778
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700779 ClassLoader* GetClassLoader() const {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700780 return class_loader_;
781 }
782
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700783 DexCache* GetDexCache() const {
784 return dex_cache_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700785 }
786
787 Class* GetComponentType() const {
788 return component_type_;
789 }
790
791 const StringPiece& GetDescriptor() const {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700792 DCHECK_NE(0, descriptor_.size());
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700793 return descriptor_;
794 }
795
796 Status GetStatus() const {
797 return status_;
798 }
799
800 void SetStatus(Status new_status) {
801 // TODO: validate transition
802 status_ = new_status;
803 }
804
Carl Shapiro69759ea2011-07-21 18:13:35 -0700805 // Returns true if the class has failed to link.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700806 bool IsErroneous() const {
807 return GetStatus() == kStatusError;
808 }
809
Carl Shapiro69759ea2011-07-21 18:13:35 -0700810 // Returns true if the class has been verified.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700811 bool IsVerified() const {
812 return GetStatus() >= kStatusVerified;
813 }
814
Carl Shapiro69759ea2011-07-21 18:13:35 -0700815 // Returns true if the class has been linked.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700816 bool IsLinked() const {
817 return GetStatus() >= kStatusResolved;
818 }
819
Carl Shapiro69759ea2011-07-21 18:13:35 -0700820 bool IsLoaded() const {
821 return GetStatus() >= kStatusLoaded;
822 }
823
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700824 // Returns true if this class is in the same packages as that class.
825 bool IsInSamePackage(const Class* that) const;
826
Ian Rogersb033c752011-07-20 12:22:35 -0700827 static bool IsInSamePackage(const StringPiece& descriptor1,
828 const StringPiece& descriptor2);
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700829
830 // Returns true if this class represents an array class.
831 bool IsArray() const {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700832 return GetDescriptor()[0] == '['; // TODO: avoid parsing the descriptor
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700833 }
834
835 // Returns true if the class is an interface.
836 bool IsInterface() const {
837 return (access_flags_ & kAccInterface) != 0;
838 }
839
840 // Returns true if the class is declared public.
841 bool IsPublic() const {
842 return (access_flags_ & kAccPublic) != 0;
843 }
844
845 // Returns true if the class is declared final.
846 bool IsFinal() const {
847 return (access_flags_ & kAccFinal) != 0;
848 }
849
850 // Returns true if the class is abstract.
851 bool IsAbstract() const {
852 return (access_flags_ & kAccAbstract) != 0;
853 }
854
855 // Returns true if the class is an annotation.
856 bool IsAnnotation() const {
857 return (access_flags_ & kAccAnnotation) != 0;
858 }
859
860 // Returns true if the class is a primitive type.
861 bool IsPrimitive() const {
862 return primitive_type_ != kPrimNot;
863 }
864
Brian Carlstromae3ac012011-07-27 01:30:28 -0700865 // Returns true if the class is synthetic.
866 bool IsSynthetic() const {
867 return (access_flags_ & kAccSynthetic) != 0;
868 }
869
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700870 // Returns true if this class can access that class.
871 bool CanAccess(const Class* that) const {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700872 return that->IsPublic() || this->IsInSamePackage(that);
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700873 }
874
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700875 // Returns the number of static, private, and constructor methods.
876 size_t NumDirectMethods() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700877 return (direct_methods_ != NULL) ? direct_methods_->GetLength() : 0;
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700878 }
879
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700880 Method* GetDirectMethod(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700881 DCHECK_NE(NumDirectMethods(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700882 return direct_methods_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700883 }
884
885 void SetDirectMethod(uint32_t i, Method* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700886 DCHECK_NE(NumDirectMethods(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700887 direct_methods_->Set(i, f);
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700888 }
889
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700890 Method* FindDeclaredDirectMethod(const StringPiece& name,
891 const StringPiece& descriptor);
892
893 Method* FindDirectMethod(const StringPiece& name,
894 const StringPiece& descriptor);
895
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700896 // Returns the number of non-inherited virtual methods.
897 size_t NumVirtualMethods() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700898 return (virtual_methods_ != NULL) ? virtual_methods_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700899 }
900
901 Method* GetVirtualMethod(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700902 DCHECK_NE(NumVirtualMethods(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700903 return virtual_methods_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700904 }
905
906 void SetVirtualMethod(uint32_t i, Method* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700907 DCHECK_NE(NumVirtualMethods(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700908 virtual_methods_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700909 }
910
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700911 Method* FindDeclaredVirtualMethod(const StringPiece& name,
912 const StringPiece& descriptor);
913
914 Method* FindVirtualMethod(const StringPiece& name,
915 const StringPiece& descriptor);
916
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700917 size_t NumInstanceFields() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700918 return (ifields_ != NULL) ? ifields_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700919 }
920
Carl Shapiro69759ea2011-07-21 18:13:35 -0700921 // Returns the number of instance fields containing reference types.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700922 size_t NumReferenceInstanceFields() const {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700923 return num_reference_instance_fields_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700924 }
925
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700926 InstanceField* GetInstanceField(uint32_t i) const { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700927 DCHECK_NE(NumInstanceFields(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700928 return ifields_->Get(i);
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700929 }
930
931 void SetInstanceField(uint32_t i, InstanceField* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700932 DCHECK_NE(NumInstanceFields(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700933 ifields_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700934 }
935
936 size_t NumStaticFields() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700937 return (sfields_ != NULL) ? sfields_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700938 }
939
Carl Shapiro69759ea2011-07-21 18:13:35 -0700940 StaticField* GetStaticField(uint32_t i) const { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700941 DCHECK_NE(NumStaticFields(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700942 return sfields_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700943 }
944
945 void SetStaticField(uint32_t i, StaticField* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700946 DCHECK_NE(NumStaticFields(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700947 sfields_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700948 }
949
950 uint32_t GetReferenceOffsets() const {
951 return reference_offsets_;
952 }
953
954 void SetReferenceOffsets(uint32_t new_reference_offsets) {
955 reference_offsets_ = new_reference_offsets;
956 }
957
Carl Shapiro69759ea2011-07-21 18:13:35 -0700958 size_t NumInterfaces() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700959 return (interfaces_ != NULL) ? interfaces_->GetLength() : 0;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700960 }
961
962 Class* GetInterface(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700963 DCHECK_NE(NumInterfaces(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700964 return interfaces_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700965 }
966
967 void SetInterface(uint32_t i, Class* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700968 DCHECK_NE(NumInterfaces(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700969 interfaces_->Set(i, f);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700970 }
971
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700972 void SetVerifyErrorClass(Class* klass) {
973 // Note SetFieldObject is used rather than verify_error_class_ directly for the barrier
974 size_t field_offset = OFFSETOF_MEMBER(Class, verify_error_class_);
975 klass->SetFieldObject(field_offset, klass);
976 }
977
978 private:
979 bool Implements(const Class* klass) const;
980 bool IsArrayAssignableFromArray(const Class* klass) const;
981 bool IsAssignableFromArray(const Class* klass) const;
982 bool IsSubClass(const Class* klass) const;
983
Ian Rogersb033c752011-07-20 12:22:35 -0700984 public: // TODO: private
Carl Shapiro1fb86202011-06-27 17:43:13 -0700985 // leave space for instance data; we could access fields directly if
986 // we freeze the definition of java/lang/Class
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700987#define CLASS_FIELD_SLOTS 1
988 // Class.#0 name
Carl Shapiro1fb86202011-06-27 17:43:13 -0700989 uint32_t instance_data_[CLASS_FIELD_SLOTS];
990#undef CLASS_FIELD_SLOTS
991
992 // UTF-8 descriptor for the class from constant pool
993 // ("Ljava/lang/Class;"), or on heap if generated ("[C")
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700994 StringPiece descriptor_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700995
996 // Proxy classes have their descriptor allocated on the native heap.
997 // When this field is non-NULL it must be explicitly freed.
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700998 std::string* descriptor_alloc_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700999
1000 // access flags; low 16 bits are defined by VM spec
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001001 uint32_t access_flags_; // TODO: make an instance field?
Carl Shapiro1fb86202011-06-27 17:43:13 -07001002
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001003 // DexCache of resolved constant pool entries
Carl Shapiro1fb86202011-06-27 17:43:13 -07001004 // (will be NULL for VM-generated, e.g. arrays and primitive classes)
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001005 DexCache* dex_cache_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001006
1007 // state of class initialization
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001008 Status status_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001009
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001010 // If class verify fails, we must return same error on subsequent tries.
1011 // Update with SetVerifyErrorClass to ensure a write barrier is used.
1012 const Class* verify_error_class_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001013
1014 // threadId, used to check for recursive <clinit> invocation
1015 uint32_t clinit_thread_id_;
1016
1017 // Total object size; used when allocating storage on gc heap. (For
1018 // interfaces and abstract classes this will be zero.)
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001019 size_t object_size_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001020
1021 // For array classes, the class object for base element, for
1022 // instanceof/checkcast (for String[][][], this will be String).
1023 // Otherwise, NULL.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001024 Class* component_type_; // TODO: make an instance field
Carl Shapiro1fb86202011-06-27 17:43:13 -07001025
1026 // For array classes, the number of array dimensions, e.g. int[][]
1027 // is 2. Otherwise 0.
1028 int32_t array_rank_;
1029
1030 // primitive type index, or PRIM_NOT (-1); set for generated prim classes
1031 PrimitiveType primitive_type_;
1032
1033 // The superclass, or NULL if this is java.lang.Object or a
1034 // primitive type.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001035 Class* super_class_; // TODO: make an instance field
1036 uint32_t super_class_idx_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001037
1038 // defining class loader, or NULL for the "bootstrap" system loader
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001039 ClassLoader* class_loader_; // TODO: make an instance field
Carl Shapiro1fb86202011-06-27 17:43:13 -07001040
1041 // initiating class loader list
1042 // NOTE: for classes with low serialNumber, these are unused, and the
1043 // values are kept in a table in gDvm.
Ian Rogersb033c752011-07-20 12:22:35 -07001044 // InitiatingLoaderList initiating_loader_list_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001045
1046 // array of interfaces this class implements directly
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001047 ObjectArray<Class>* interfaces_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001048 uint32_t* interfaces_idx_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001049
1050 // static, private, and <init> methods
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001051 ObjectArray<Method>* direct_methods_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001052
1053 // virtual methods defined in this class; invoked through vtable
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001054 ObjectArray<Method>* virtual_methods_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001055
1056 // Virtual method table (vtable), for use by "invoke-virtual". The
1057 // vtable from the superclass is copied in, and virtual methods from
1058 // our class either replace those from the super or are appended.
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001059 ObjectArray<Method>* vtable_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001060
1061 // Interface table (iftable), one entry per interface supported by
1062 // this class. That means one entry for each interface we support
1063 // directly, indirectly via superclass, or indirectly via
1064 // superinterface. This will be null if neither we nor our
1065 // superclass implement any interfaces.
1066 //
1067 // Why we need this: given "class Foo implements Face", declare
1068 // "Face faceObj = new Foo()". Invoke faceObj.blah(), where "blah"
1069 // is part of the Face interface. We can't easily use a single
1070 // vtable.
1071 //
1072 // For every interface a concrete class implements, we create a list
1073 // of virtualMethod indices for the methods in the interface.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001074 size_t iftable_count_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001075 InterfaceEntry* iftable_;
1076
1077 // The interface vtable indices for iftable get stored here. By
1078 // placing them all in a single pool for each class that implements
1079 // interfaces, we decrease the number of allocations.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001080 size_t ifvi_pool_count_;
1081 uint32_t* ifvi_pool_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001082
1083 // instance fields
1084 //
1085 // These describe the layout of the contents of a
1086 // DataObject-compatible Object. Note that only the fields directly
1087 // declared by this class are listed in ifields; fields declared by
Brian Carlstroma331b3c2011-07-18 17:47:56 -07001088 // a superclass are listed in the superclass's Class.ifields.
Carl Shapiro1fb86202011-06-27 17:43:13 -07001089 //
1090 // All instance fields that refer to objects are guaranteed to be at
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001091 // the beginning of the field list. num_reference_instance_fields_
1092 // specifies the number of reference fields.
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001093 ObjectArray<InstanceField>* ifields_;
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001094
1095 // number of fields that are object refs
Carl Shapiro69759ea2011-07-21 18:13:35 -07001096 size_t num_reference_instance_fields_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001097
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001098 // Bitmap of offsets of ifields.
1099 uint32_t reference_offsets_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001100
1101 // source file name, if known. Otherwise, NULL.
1102 const char* source_file_;
1103
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001104 ObjectArray<Object>* static_references_;
1105 IntArray* static_32bit_primitives_;
1106 LongArray* static_64bit_primitives_;
1107
Carl Shapiro1fb86202011-06-27 17:43:13 -07001108 // Static fields
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001109 ObjectArray<StaticField>* sfields_;
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001110
1111 private:
Carl Shapirof88c9522011-08-06 15:47:38 -07001112 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001113};
Elliott Hughes1f359b02011-07-17 14:27:17 -07001114std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001115
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001116inline bool Object::InstanceOf(const Class* klass) const {
Jesse Wilson14150742011-07-29 19:04:44 -04001117 DCHECK(klass != NULL);
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001118 DCHECK(klass_ != NULL);
1119 return klass->IsAssignableFrom(klass_);
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001120}
1121
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001122
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001123class DataObject : public Object {
1124 public:
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07001125 uint32_t fields_[0];
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001126 private:
Carl Shapirof88c9522011-08-06 15:47:38 -07001127 DISALLOW_IMPLICIT_CONSTRUCTORS(DataObject);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001128};
1129
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001130template<class T>
1131class PrimitiveArray : public Array {
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001132 public:
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001133 static PrimitiveArray<T>* Alloc(Class* element_class, size_t length) {
1134 return down_cast<PrimitiveArray<T>*>(Array::Alloc(element_class,
1135 length,
1136 sizeof(T)));
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001137 }
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001138
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001139 const T* GetData() const {
1140 return reinterpret_cast<const T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001141 }
1142
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001143 T* GetData() {
1144 return reinterpret_cast<T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001145 }
1146
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001147 T Get(T i) const {
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001148 CHECK_LT(i, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001149 return GetData()[i];
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001150 }
1151
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001152 void Set(uint32_t i, T value) {
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001153 CHECK_LT(i, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001154 GetData()[i] = value;
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001155 }
1156
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001157 private:
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001158 // Location of first element.
1159 T elements_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -07001160
1161 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimitiveArray);
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001162};
Carl Shapiro5fafe2b2011-07-09 15:34:41 -07001163
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001164class String : public Object {
Carl Shapiro1fb86202011-06-27 17:43:13 -07001165 public:
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001166 const CharArray* GetCharArray() const {
Carl Shapirof88c9522011-08-06 15:47:38 -07001167 DCHECK(array_ != NULL);
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001168 return array_;
1169 }
1170
Carl Shapirof88c9522011-08-06 15:47:38 -07001171 uint32_t GetHashCode() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001172 return hash_code_;
1173 }
1174
Carl Shapirof88c9522011-08-06 15:47:38 -07001175 uint32_t GetOffset() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001176 return offset_;
1177 }
1178
Carl Shapirof88c9522011-08-06 15:47:38 -07001179 uint32_t GetLength() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001180 return count_;
1181 }
1182
Carl Shapirof88c9522011-08-06 15:47:38 -07001183 uint16_t CharAt(uint32_t index) const {
1184 DCHECK_LE(index, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001185 return GetCharArray()->Get(index + GetOffset());
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001186 }
1187
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001188 static String* AllocFromUtf16(int32_t utf16_length,
1189 uint16_t* utf16_data_in,
1190 int32_t hash_code) {
Carl Shapirof88c9522011-08-06 15:47:38 -07001191 String* string = Alloc(GetJavaLangString(),
1192 GetCharArrayClass(),
1193 utf16_length);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001194 // TODO use 16-bit wide memset variant
1195 for (int i = 0; i < utf16_length; i++ ) {
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001196 string->array_->Set(i, utf16_data_in[i]);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001197 }
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001198 string->ComputeHashCode();
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001199 return string;
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001200 }
1201
1202 static String* AllocFromModifiedUtf8(Class* java_lang_String,
1203 Class* char_array,
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001204 int32_t utf16_length,
1205 const char* utf8_data_in) {
1206 String* string = Alloc(java_lang_String, char_array, utf16_length);
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001207 uint16_t* utf16_data_out = string->array_->GetData();
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001208 ConvertModifiedUtf8ToUtf16(utf16_data_out, utf8_data_in);
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001209 string->ComputeHashCode();
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001210 return string;
1211 }
1212
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001213 // Creates a String of the given ASCII characters. It is an error to call this
1214 // using non-ASCII characters as this function assumes one char per byte.
1215 static String* AllocFromAscii(const char* ascii_data_in) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001216 return AllocFromModifiedUtf8(GetJavaLangString(),
1217 GetCharArrayClass(),
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001218 strlen(ascii_data_in),
1219 ascii_data_in);
1220 }
1221
Jesse Wilson8989d992011-08-02 13:39:42 -07001222 static String* AllocFromModifiedUtf8(int32_t utf16_length,
1223 const char* utf8_data_in) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001224 return AllocFromModifiedUtf8(GetJavaLangString(), GetCharArrayClass(),
1225 utf16_length, utf8_data_in);
Jesse Wilson8989d992011-08-02 13:39:42 -07001226 }
1227
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001228 static void InitClasses(Class* java_lang_String, Class* char_array);
1229
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001230 static String* Alloc(Class* java_lang_String,
1231 Class* char_array,
1232 int32_t utf16_length) {
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001233 String* string = down_cast<String*>(java_lang_String->NewInstance());
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001234 CharArray* array = CharArray::Alloc(char_array, utf16_length);
1235 string->array_ = array;
1236 string->count_ = utf16_length;
1237 return string;
1238 }
1239
1240 // Convert Modified UTF-8 to UTF-16
1241 // http://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8
1242 static void ConvertModifiedUtf8ToUtf16(uint16_t* utf16_data_out, const char* utf8_data_in) {
1243 while (*utf8_data_in != '\0') {
1244 *utf16_data_out++ = GetUtf16FromUtf8(&utf8_data_in);
1245 }
1246 }
1247
1248 // Retrieve the next UTF-16 character from a UTF-8 string.
1249 //
1250 // Advances "*pUtf8Ptr" to the start of the next character.
1251 //
1252 // WARNING: If a string is corrupted by dropping a '\0' in the middle
1253 // of a 3-byte sequence, you can end up overrunning the buffer with
1254 // reads (and possibly with the writes if the length was computed and
1255 // cached before the damage). For performance reasons, this function
1256 // assumes that the string being parsed is known to be valid (e.g., by
1257 // already being verified). Most strings we process here are coming
1258 // out of dex files or other internal translations, so the only real
1259 // risk comes from the JNI NewStringUTF call.
1260 static uint16_t GetUtf16FromUtf8(const char** utf8_data_in) {
1261 uint8_t one = *(*utf8_data_in)++;
1262 if ((one & 0x80) == 0) {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001263 // one-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001264 return one;
1265 }
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001266 // two- or three-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001267 uint8_t two = *(*utf8_data_in)++;
1268 if ((one & 0x20) == 0) {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001269 // two-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001270 return ((one & 0x1f) << 6) |
1271 (two & 0x3f);
1272 }
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001273 // three-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001274 uint8_t three = *(*utf8_data_in)++;
1275 return ((one & 0x0f) << 12) |
1276 ((two & 0x3f) << 6) |
1277 (three & 0x3f);
1278 }
1279
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001280 // Like "strlen", but for strings encoded with "modified" UTF-8.
1281 //
1282 // The value returned is the number of characters, which may or may not
1283 // be the same as the number of bytes.
1284 //
1285 // (If this needs optimizing, try: mask against 0xa0, shift right 5,
1286 // get increment {1-3} from table of 8 values.)
1287 static size_t ModifiedUtf8Len(const char* utf8) {
1288 size_t len = 0;
1289 int ic;
1290 while ((ic = *utf8++) != '\0') {
1291 len++;
1292 if ((ic & 0x80) == 0) {
1293 // one-byte encoding
1294 continue;
1295 }
1296 // two- or three-byte encoding
1297 utf8++;
1298 if ((ic & 0x20) == 0) {
1299 // two-byte encoding
1300 continue;
1301 }
1302 // three-byte encoding
1303 utf8++;
1304 }
1305 return len;
1306 }
1307
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001308 // The java/lang/String.computeHashCode() algorithm
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001309 static int32_t ComputeUtf16Hash(const uint16_t* string_data, size_t string_length) {
1310 int32_t hash = 0;
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001311 while (string_length--) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001312 hash = hash * 31 + *string_data++;
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001313 }
1314 return hash;
1315 }
1316
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001317 void ComputeHashCode() {
1318 hash_code_ = ComputeUtf16Hash(array_->GetData(), count_);
1319 }
1320
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001321 bool Equals(const char* modified_utf8) const {
Carl Shapirof88c9522011-08-06 15:47:38 -07001322 for (uint32_t i = 0; i < GetLength(); ++i) {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001323 uint16_t ch = GetUtf16FromUtf8(&modified_utf8);
1324 if (ch == '\0' || ch != CharAt(i)) {
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001325 return false;
1326 }
1327 }
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001328 return *modified_utf8 == '\0';
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001329 }
1330
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001331 bool Equals(const StringPiece& modified_utf8) const {
1332 // TODO: do not assume C-string representation.
1333 return Equals(modified_utf8.data());
1334 }
1335
1336 bool Equals(const String* that) const {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001337 // TODO short circuit on hash_code_
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001338 if (this->GetLength() != that->GetLength()) {
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001339 return false;
1340 }
Carl Shapirof88c9522011-08-06 15:47:38 -07001341 for (uint32_t i = 0; i < that->GetLength(); ++i) {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001342 if (this->CharAt(i) != that->CharAt(i)) {
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001343 return false;
1344 }
1345 }
1346 return true;
1347 }
1348
Carl Shapirof88c9522011-08-06 15:47:38 -07001349 bool Equals(const uint16_t* that_chars, uint32_t that_offset, uint32_t that_length) const {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001350 if (this->GetLength() != that_length) {
1351 return false;
1352 }
Carl Shapirof88c9522011-08-06 15:47:38 -07001353 for (uint32_t i = 0; i < that_length; ++i) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001354 if (this->CharAt(i) != that_chars[that_offset + i]) {
1355 return false;
1356 }
1357 }
1358 return true;
1359 }
1360
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001361 private:
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001362 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
1363 CharArray* array_;
1364
Carl Shapirof88c9522011-08-06 15:47:38 -07001365 uint32_t hash_code_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001366
Carl Shapirof88c9522011-08-06 15:47:38 -07001367 uint32_t offset_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001368
Carl Shapirof88c9522011-08-06 15:47:38 -07001369 uint32_t count_;
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001370
1371 static Class* GetJavaLangString() {
1372 DCHECK(java_lang_String_ != NULL);
1373 return java_lang_String_;
1374 }
1375 static Class* GetCharArrayClass() {
1376 DCHECK(char_array_ != NULL);
1377 return char_array_;
1378 }
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001379
1380 static Class* java_lang_String_;
1381 static Class* char_array_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001382
1383 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001384};
1385
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001386class InterfaceEntry {
Carl Shapiro1fb86202011-06-27 17:43:13 -07001387 public:
Carl Shapirof88c9522011-08-06 15:47:38 -07001388 InterfaceEntry() : klass_(NULL), method_index_array_(NULL) {
1389 }
1390
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001391 Class* GetClass() const {
1392 return klass_;
Carl Shapirof88c9522011-08-06 15:47:38 -07001393 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001394
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001395 void SetClass(Class* klass) {
1396 klass_ = klass;
Carl Shapirof88c9522011-08-06 15:47:38 -07001397 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001398
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001399 private:
1400 // Points to the interface class.
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001401 Class* klass_;
1402
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001403 public: // TODO: private
1404 // Index into array of vtable offsets. This points into the
1405 // ifviPool, which holds the vtables for all interfaces declared by
1406 // this class.
1407 uint32_t* method_index_array_;
Carl Shapirof88c9522011-08-06 15:47:38 -07001408
1409 private:
1410 DISALLOW_COPY_AND_ASSIGN(InterfaceEntry);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001411};
1412
1413} // namespace art
1414
1415#endif // ART_SRC_OBJECT_H_