blob: 1451c54b8b94597a4c60e09079025156da969b0e [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"
Shih-wei Liao2fb97532011-08-11 16:17:23 -07008#include "dex_file.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07009#include "globals.h"
Brian Carlstroma40f9bc2011-07-26 21:26:07 -070010#include "heap.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070011#include "logging.h"
12#include "macros.h"
13#include "offsets.h"
14#include "stringpiece.h"
15#include "monitor.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -070016
17namespace art {
18
19class Array;
20class Class;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070021class DexCache;
Jesse Wilson35baaab2011-08-10 16:18:03 -040022class Field;
Carl Shapiro1fb86202011-06-27 17:43:13 -070023class InterfaceEntry;
24class Monitor;
25class Method;
Carl Shapiro3ee755d2011-06-28 12:11:04 -070026class Object;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -040027class String;
Brian Carlstrom4a96b602011-07-26 16:40:23 -070028template<class T> class ObjectArray;
Jesse Wilsonfd687c52011-08-04 19:27:35 -070029template<class T> class PrimitiveArray;
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 uint32_t GetOffset() const {
288 return offset_;
289 }
290
291 void SetOffset(size_t num_bytes) {
292 offset_ = num_bytes;
293 }
294
Jesse Wilson35baaab2011-08-10 16:18:03 -0400295 // static field access
Jesse Wilson7833bd22011-08-09 18:31:44 -0400296 bool GetBoolean();
Jesse Wilson7833bd22011-08-09 18:31:44 -0400297 void SetBoolean(bool z);
Jesse Wilson7833bd22011-08-09 18:31:44 -0400298 int8_t GetByte();
Jesse Wilson7833bd22011-08-09 18:31:44 -0400299 void SetByte(int8_t b);
Jesse Wilson7833bd22011-08-09 18:31:44 -0400300 uint16_t GetChar();
Jesse Wilson7833bd22011-08-09 18:31:44 -0400301 void SetChar(uint16_t c);
Jesse Wilson7833bd22011-08-09 18:31:44 -0400302 uint16_t GetShort();
Jesse Wilson7833bd22011-08-09 18:31:44 -0400303 void SetShort(uint16_t s);
Jesse Wilson7833bd22011-08-09 18:31:44 -0400304 int32_t GetInt();
Jesse Wilson7833bd22011-08-09 18:31:44 -0400305 void SetInt(int32_t i);
Jesse Wilson7833bd22011-08-09 18:31:44 -0400306 int64_t GetLong();
Jesse Wilson7833bd22011-08-09 18:31:44 -0400307 void SetLong(int64_t j);
Jesse Wilson7833bd22011-08-09 18:31:44 -0400308 float GetFloat();
Jesse Wilson7833bd22011-08-09 18:31:44 -0400309 void SetFloat(float f);
Jesse Wilson7833bd22011-08-09 18:31:44 -0400310 double GetDouble();
Jesse Wilson7833bd22011-08-09 18:31:44 -0400311 void SetDouble(double d);
Jesse Wilson7833bd22011-08-09 18:31:44 -0400312 Object* GetObject();
Jesse Wilson7833bd22011-08-09 18:31:44 -0400313 const Object* GetObject() const;
Jesse Wilson7833bd22011-08-09 18:31:44 -0400314 void SetObject(Object* l);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700315
Jesse Wilson35baaab2011-08-10 16:18:03 -0400316 public: // TODO: private
317 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
318 // The class in which this field is declared.
319 Class* declaring_class_;
320 Object* generic_type_;
321 uint32_t generic_types_are_initialized_;
322 String* name_;
323 uint32_t offset_;
324 Class* type_;
325
326 // e.g. "I", "[C", "Landroid/os/Debug;"
327 StringPiece descriptor_;
328
329 uint32_t access_flags_;
330
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700331 private:
Jesse Wilson35baaab2011-08-10 16:18:03 -0400332 DISALLOW_IMPLICIT_CONSTRUCTORS(Field);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700333};
334
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400335class Method : public AccessibleObject {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700336 public:
Brian Carlstromae3ac012011-07-27 01:30:28 -0700337 // Returns the method name, e.g. "<init>" or "eatLunch"
Jesse Wilsonf7e85a52011-08-01 18:45:58 -0700338 const String* GetName() const {
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700339 return name_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700340 }
341
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700342 const String* GetDescriptor() const {
343 return descriptor_;
344 }
345
Brian Carlstroma0808032011-07-18 00:39:23 -0700346 Class* GetDeclaringClass() const {
347 return declaring_class_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700348 }
349
Ian Rogersb033c752011-07-20 12:22:35 -0700350 static MemberOffset ClassOffset() {
351 return MemberOffset(OFFSETOF_MEMBER(Method, klass_));
352 }
353
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700354 // Returns true if the method is declared public.
355 bool IsPublic() const {
356 return (access_flags_ & kAccPublic) != 0;
357 }
358
359 // Returns true if the method is declared private.
360 bool IsPrivate() const {
361 return (access_flags_ & kAccPrivate) != 0;
362 }
363
364 // Returns true if the method is declared static.
365 bool IsStatic() const {
366 return (access_flags_ & kAccStatic) != 0;
367 }
368
369 // Returns true if the method is declared synchronized.
370 bool IsSynchronized() const {
371 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
372 return (access_flags_ & synchonized) != 0;
373 }
374
375 // Returns true if the method is declared final.
376 bool IsFinal() const {
377 return (access_flags_ & kAccFinal) != 0;
378 }
379
380 // Returns true if the method is declared native.
381 bool IsNative() const {
382 return (access_flags_ & kAccNative) != 0;
383 }
384
385 // Returns true if the method is declared abstract.
386 bool IsAbstract() const {
387 return (access_flags_ & kAccAbstract) != 0;
388 }
389
390 bool IsSynthetic() const {
391 return (access_flags_ & kAccSynthetic) != 0;
392 }
393
394 // Number of argument registers required by the prototype.
395 uint32_t NumArgRegisters();
396
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700397 public: // TODO: private
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400398 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Jesse Wilson35baaab2011-08-10 16:18:03 -0400399 // the class we are a part of
400 Class* declaring_class_;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400401 ObjectArray<Class>* java_exception_types_;
402 Object* java_formal_type_parameters_;
403 Object* java_generic_exception_types_;
404 Object* java_generic_parameter_types_;
405 Object* java_generic_return_type_;
406 Class* java_return_type_;
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700407 String* name_;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400408 ObjectArray<Class>* java_parameter_types_;
409 uint32_t java_generic_types_are_initialized_;
410 uint32_t java_slot_;
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700411
Ian Rogersb033c752011-07-20 12:22:35 -0700412 bool IsReturnAReference() const {
413 return (shorty_[0] == 'L') || (shorty_[0] == '[');
414 }
415
416 bool IsReturnAFloatOrDouble() const {
417 return (shorty_[0] == 'F') || (shorty_[0] == 'D');
418 }
419
420 bool IsReturnAFloat() const {
421 return shorty_[0] == 'F';
422 }
423
424 bool IsReturnADouble() const {
425 return shorty_[0] == 'D';
426 }
427
428 bool IsReturnALong() const {
429 return shorty_[0] == 'J';
430 }
431
Ian Rogers45a76cb2011-07-21 22:00:15 -0700432 bool IsReturnVoid() const {
433 return shorty_[0] == 'V';
434 }
435
Shih-wei Liao5381cf92011-07-27 00:28:04 -0700436 // "Args" may refer to any of the 3 levels of "Args."
437 // To avoid confusion, our code will denote which "Args" clearly:
438 // 1. UserArgs: Args that a user see.
439 // 2. Args: Logical JVM-level Args. E.g., the first in Args will be the
440 // receiver.
441 // 3. CConvArgs: Calling Convention Args, which is physical-level Args.
442 // E.g., the first in Args is Method* for both static and non-static
443 // methods. And CConvArgs doesn't deal with the receiver because
444 // receiver is hardwired in an implicit register, so CConvArgs doesn't
445 // need to deal with it.
446 //
447 // The number of Args that should be supplied to this method
Ian Rogersb033c752011-07-20 12:22:35 -0700448 size_t NumArgs() const {
Shih-wei Liao5381cf92011-07-27 00:28:04 -0700449 // "1 +" because the first in Args is the receiver.
450 // "- 1" because we don't count the return type.
Ian Rogersb033c752011-07-20 12:22:35 -0700451 return (IsStatic() ? 0 : 1) + shorty_.length() - 1;
452 }
453
454 // The number of reference arguments to this method including implicit this
455 // pointer
456 size_t NumReferenceArgs() const;
457
458 // The number of long or double arguments
459 size_t NumLongOrDoubleArgs() const;
460
461 // The number of reference arguments to this method before the given
462 // parameter index
463 size_t NumReferenceArgsBefore(unsigned int param) const;
464
465 // Is the given method parameter a reference?
466 bool IsParamAReference(unsigned int param) const;
467
468 // Is the given method parameter a long or double?
469 bool IsParamALongOrDouble(unsigned int param) const;
470
Ian Rogersdf20fe02011-07-20 20:34:16 -0700471 // Size in bytes of the given parameter
472 size_t ParamSize(unsigned int param) const;
473
474 // Size in bytes of the return value
475 size_t ReturnSize() const;
Ian Rogersb033c752011-07-20 12:22:35 -0700476
477 void SetCode(const void* code) {
478 code_ = code;
479 }
480
481 const void* GetCode() const {
482 return code_;
483 }
484
485 void RegisterNative(const void* native_method) {
486 native_method_ = native_method;
487 }
488
489 static MemberOffset NativeMethodOffset() {
490 return MemberOffset(OFFSETOF_MEMBER(Method, native_method_));
491 }
492
Carl Shapiro8860c0e2011-08-04 17:36:16 -0700493 bool HasSameNameAndDescriptor(const Method* that) const;
494
Ian Rogersb033c752011-07-20 12:22:35 -0700495 public: // TODO: private/const
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700496 // access flags; low 16 bits are defined by spec (could be uint16_t?)
497 uint32_t access_flags_;
498
499 // For concrete virtual methods, this is the offset of the method
500 // in "vtable".
501 //
502 // For abstract methods in an interface class, this is the offset
503 // of the method in "iftable[n]->methodIndexArray".
504 uint16_t method_index_;
505
506 // Method bounds; not needed for an abstract method.
507 //
508 // For a native method, we compute the size of the argument list, and
509 // set "insSize" and "registerSize" equal to it.
510 uint16_t num_registers_; // ins + locals
511 uint16_t num_outs_;
512 uint16_t num_ins_;
513
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700514 // The method descriptor. This represents the parameters a method
515 // takes and value it returns. This string is a list of the type
516 // descriptors for the parameters enclosed in parenthesis followed
517 // by the return type descriptor. For example, for the method
518 //
519 // Object mymethod(int i, double d, Thread t)
520 //
521 // the method descriptor would be
522 //
523 // (IDLjava/lang/Thread;)Ljava/lang/Object;
524 String* descriptor_;
525
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700526 // Method prototype descriptor string (return and argument types).
527 uint32_t proto_idx_;
528
Shih-wei Liao2fb97532011-08-11 16:17:23 -0700529 // Offset to the CodeItem.
530 uint32_t code_off_;
531
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700532 // The short-form method descriptor string.
533 StringPiece shorty_;
534
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700535 private:
Ian Rogersb033c752011-07-20 12:22:35 -0700536 // Compiled code associated with this method
537 const void* code_;
538
539 // Any native method registered with this method
540 const void* native_method_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700541
542 DISALLOW_IMPLICIT_CONSTRUCTORS(Method);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700543};
544
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700545class Array : public Object {
546 public:
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700547 static Array* Alloc(Class* array_class,
548 size_t component_count,
549 size_t component_size) {
550 size_t size = sizeof(Array) + component_count * component_size;
551 Array* array = down_cast<Array*>(Heap::AllocObject(array_class, size));
552 if (array != NULL) {
553 array->SetLength(component_count);
554 }
555 return array;
556 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700557
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700558 uint32_t GetLength() const {
559 return length_;
560 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700561
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700562 void SetLength(uint32_t length) {
563 length_ = length;
564 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700565
566 private:
567 // The number of array elements.
568 uint32_t length_;
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400569 // Padding to ensure the first member defined by a subclass begins on a 8-byte boundary
570 int32_t padding_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700571
Carl Shapirof88c9522011-08-06 15:47:38 -0700572 DISALLOW_IMPLICIT_CONSTRUCTORS(Array);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700573};
574
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700575template<class T>
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700576class ObjectArray : public Array {
577 public:
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700578 static ObjectArray<T>* Alloc(Class* object_array_class,
579 size_t length) {
580 return down_cast<ObjectArray<T>*>(Array::Alloc(object_array_class,
581 length,
582 sizeof(uint32_t)));
583 }
584
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700585 T* const * GetData() const {
586 return reinterpret_cast<T* const *>(&elements_);
587 }
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400588
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700589 T** GetData() {
590 return reinterpret_cast<T**>(&elements_);
591 }
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400592
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700593 T* Get(uint32_t i) const {
Brian Carlstrom0b138b22011-07-27 15:19:17 -0700594 CHECK_LT(i, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700595 return GetData()[i];
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700596 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700597
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700598 void Set(uint32_t i, T* object) {
Brian Carlstrom0b138b22011-07-27 15:19:17 -0700599 CHECK_LT(i, GetLength());
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400600 GetData()[i] = object; // TODO: write barrier
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700601 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700602
603 static void Copy(ObjectArray<T>* src, int src_pos,
604 ObjectArray<T>* dst, int dst_pos,
605 size_t length) {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700606 for (size_t i = 0; i < length; i++) {
607 dst->Set(dst_pos + i, src->Get(src_pos + i));
608 }
609 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700610
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700611 ObjectArray<T>* CopyOf(size_t new_length) {
612 ObjectArray<T>* new_array = Alloc(klass_, new_length);
613 Copy(this, 0, new_array, 0, std::min(GetLength(), new_length));
614 return new_array;
615 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700616
617 private:
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700618 // Location of first element.
619 T* elements_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -0700620
621 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700622};
623
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700624// ClassLoader objects.
625class ClassLoader : public Object {
626 public:
627 std::vector<const DexFile*>& GetClassPath() {
628 return class_path_;
629 }
630 void SetClassPath(std::vector<const DexFile*>& class_path) {
631 DCHECK_EQ(0U, class_path_.size());
632 class_path_ = class_path;
633 }
634
635 private:
636 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
637 Object* packages_;
638 ClassLoader* parent_;
639
640 // TODO remove once we can create a real PathClassLoader
641 std::vector<const DexFile*> class_path_;
642
Carl Shapirof88c9522011-08-06 15:47:38 -0700643 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700644};
645
646class BaseDexClassLoader : public ClassLoader {
647 private:
648 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
649 String* original_path_;
650 Object* path_list_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700651 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseDexClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700652};
653
654class PathClassLoader : public BaseDexClassLoader {
655 private:
Carl Shapirof88c9522011-08-06 15:47:38 -0700656 DISALLOW_IMPLICIT_CONSTRUCTORS(PathClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700657};
658
Carl Shapiro1fb86202011-06-27 17:43:13 -0700659// Class objects.
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700660class Class : public Object {
Carl Shapiro1fb86202011-06-27 17:43:13 -0700661 public:
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700662
663 // Class Status
664 //
665 // kStatusNotReady: If a Class cannot be found in the class table by
666 // FindClass, it allocates an new one with AllocClass in the
667 // kStatusNotReady and calls LoadClass. Note if it does find a
668 // class, it may not be kStatusResolved and it will try to push it
669 // forward toward kStatusResolved.
670 //
671 // kStatusIdx: LoadClass populates with Class with information from
672 // the DexFile, moving the status to kStatusIdx, indicating that the
673 // Class values in super_class_ and interfaces_ have not been
674 // populated based on super_class_idx_ and interfaces_idx_. The new
675 // Class can then be inserted into the classes table.
676 //
677 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
678 // attempt to move a kStatusIdx class forward to kStatusLoaded by
679 // using ResolveClass to initialize the super_class_ and interfaces_.
680 //
681 // kStatusResolved: Still holding the lock on Class, the ClassLinker
682 // will use LinkClass to link all members, creating Field and Method
683 // objects, setting up the vtable, etc. On success, the class is
684 // marked kStatusResolved.
685
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700686 enum Status {
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700687 kStatusError = -1,
688 kStatusNotReady = 0,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700689 kStatusIdx = 1, // loaded, DEX idx in super_class_idx_ and interfaces_idx_
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700690 kStatusLoaded = 2, // DEX idx values resolved
691 kStatusResolved = 3, // part of linking
692 kStatusVerifying = 4, // in the process of being verified
693 kStatusVerified = 5, // logically part of linking; done pre-init
694 kStatusInitializing = 6, // class init in progress
695 kStatusInitialized = 7, // ready to go
Carl Shapiro1fb86202011-06-27 17:43:13 -0700696 };
697
698 enum PrimitiveType {
699 kPrimNot = -1
700 };
701
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700702 Object* NewInstance() {
703 return Heap::AllocObject(this, this->object_size_);
704 }
705
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700706 Class* GetSuperClass() const {
707 return super_class_;
708 }
709
710 uint32_t GetSuperClassIdx() const {
711 return super_class_idx_;
712 }
713
714 bool HasSuperClass() const {
715 return super_class_ != NULL;
716 }
717
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700718 bool IsAssignableFrom(const Class* klass) const {
719 DCHECK(klass != NULL);
720 if (this == klass) {
721 return true;
722 }
723 if (IsInterface()) {
724 return klass->Implements(this);
725 }
726 if (klass->IsArray()) {
727 return IsAssignableFromArray(klass);
728 }
729 return klass->IsSubClass(this);
730 }
731
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700732 ClassLoader* GetClassLoader() const {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700733 return class_loader_;
734 }
735
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700736 DexCache* GetDexCache() const {
737 return dex_cache_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700738 }
739
740 Class* GetComponentType() const {
741 return component_type_;
742 }
743
744 const StringPiece& GetDescriptor() const {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700745 DCHECK_NE(0, descriptor_.size());
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700746 return descriptor_;
747 }
748
749 Status GetStatus() const {
750 return status_;
751 }
752
753 void SetStatus(Status new_status) {
754 // TODO: validate transition
755 status_ = new_status;
756 }
757
Carl Shapiro69759ea2011-07-21 18:13:35 -0700758 // Returns true if the class has failed to link.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700759 bool IsErroneous() const {
760 return GetStatus() == kStatusError;
761 }
762
Carl Shapiro69759ea2011-07-21 18:13:35 -0700763 // Returns true if the class has been verified.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700764 bool IsVerified() const {
765 return GetStatus() >= kStatusVerified;
766 }
767
Carl Shapiro69759ea2011-07-21 18:13:35 -0700768 // Returns true if the class has been linked.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700769 bool IsLinked() const {
770 return GetStatus() >= kStatusResolved;
771 }
772
Carl Shapiro69759ea2011-07-21 18:13:35 -0700773 bool IsLoaded() const {
774 return GetStatus() >= kStatusLoaded;
775 }
776
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700777 // Returns true if this class is in the same packages as that class.
778 bool IsInSamePackage(const Class* that) const;
779
Ian Rogersb033c752011-07-20 12:22:35 -0700780 static bool IsInSamePackage(const StringPiece& descriptor1,
781 const StringPiece& descriptor2);
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700782
783 // Returns true if this class represents an array class.
784 bool IsArray() const {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700785 return GetDescriptor()[0] == '['; // TODO: avoid parsing the descriptor
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700786 }
787
788 // Returns true if the class is an interface.
789 bool IsInterface() const {
790 return (access_flags_ & kAccInterface) != 0;
791 }
792
793 // Returns true if the class is declared public.
794 bool IsPublic() const {
795 return (access_flags_ & kAccPublic) != 0;
796 }
797
798 // Returns true if the class is declared final.
799 bool IsFinal() const {
800 return (access_flags_ & kAccFinal) != 0;
801 }
802
803 // Returns true if the class is abstract.
804 bool IsAbstract() const {
805 return (access_flags_ & kAccAbstract) != 0;
806 }
807
808 // Returns true if the class is an annotation.
809 bool IsAnnotation() const {
810 return (access_flags_ & kAccAnnotation) != 0;
811 }
812
813 // Returns true if the class is a primitive type.
814 bool IsPrimitive() const {
815 return primitive_type_ != kPrimNot;
816 }
817
Brian Carlstromae3ac012011-07-27 01:30:28 -0700818 // Returns true if the class is synthetic.
819 bool IsSynthetic() const {
820 return (access_flags_ & kAccSynthetic) != 0;
821 }
822
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700823 // Returns true if this class can access that class.
824 bool CanAccess(const Class* that) const {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700825 return that->IsPublic() || this->IsInSamePackage(that);
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700826 }
827
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700828 // Returns the number of static, private, and constructor methods.
829 size_t NumDirectMethods() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700830 return (direct_methods_ != NULL) ? direct_methods_->GetLength() : 0;
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700831 }
832
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700833 Method* GetDirectMethod(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700834 DCHECK_NE(NumDirectMethods(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700835 return direct_methods_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700836 }
837
838 void SetDirectMethod(uint32_t i, Method* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700839 DCHECK_NE(NumDirectMethods(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700840 direct_methods_->Set(i, f);
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700841 }
842
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700843 Method* FindDeclaredDirectMethod(const StringPiece& name,
844 const StringPiece& descriptor);
845
846 Method* FindDirectMethod(const StringPiece& name,
847 const StringPiece& descriptor);
848
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700849 // Returns the number of non-inherited virtual methods.
850 size_t NumVirtualMethods() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700851 return (virtual_methods_ != NULL) ? virtual_methods_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700852 }
853
854 Method* GetVirtualMethod(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700855 DCHECK_NE(NumVirtualMethods(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700856 return virtual_methods_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700857 }
858
859 void SetVirtualMethod(uint32_t i, Method* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700860 DCHECK_NE(NumVirtualMethods(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700861 virtual_methods_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700862 }
863
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700864 Method* FindDeclaredVirtualMethod(const StringPiece& name,
865 const StringPiece& descriptor);
866
867 Method* FindVirtualMethod(const StringPiece& name,
868 const StringPiece& descriptor);
869
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700870 size_t NumInstanceFields() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700871 return (ifields_ != NULL) ? ifields_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700872 }
873
Carl Shapiro69759ea2011-07-21 18:13:35 -0700874 // Returns the number of instance fields containing reference types.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700875 size_t NumReferenceInstanceFields() const {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700876 return num_reference_instance_fields_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700877 }
878
Jesse Wilson35baaab2011-08-10 16:18:03 -0400879 Field* GetInstanceField(uint32_t i) const { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700880 DCHECK_NE(NumInstanceFields(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700881 return ifields_->Get(i);
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700882 }
883
Jesse Wilson35baaab2011-08-10 16:18:03 -0400884 void SetInstanceField(uint32_t i, Field* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700885 DCHECK_NE(NumInstanceFields(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700886 ifields_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700887 }
888
889 size_t NumStaticFields() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700890 return (sfields_ != NULL) ? sfields_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700891 }
892
Jesse Wilson35baaab2011-08-10 16:18:03 -0400893 Field* GetStaticField(uint32_t i) const { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700894 DCHECK_NE(NumStaticFields(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700895 return sfields_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700896 }
897
Jesse Wilson35baaab2011-08-10 16:18:03 -0400898 void SetStaticField(uint32_t i, Field* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700899 DCHECK_NE(NumStaticFields(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700900 sfields_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700901 }
902
903 uint32_t GetReferenceOffsets() const {
904 return reference_offsets_;
905 }
906
907 void SetReferenceOffsets(uint32_t new_reference_offsets) {
908 reference_offsets_ = new_reference_offsets;
909 }
910
Carl Shapiro69759ea2011-07-21 18:13:35 -0700911 size_t NumInterfaces() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700912 return (interfaces_ != NULL) ? interfaces_->GetLength() : 0;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700913 }
914
915 Class* GetInterface(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700916 DCHECK_NE(NumInterfaces(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700917 return interfaces_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700918 }
919
920 void SetInterface(uint32_t i, Class* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700921 DCHECK_NE(NumInterfaces(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700922 interfaces_->Set(i, f);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700923 }
924
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700925 void SetVerifyErrorClass(Class* klass) {
926 // Note SetFieldObject is used rather than verify_error_class_ directly for the barrier
927 size_t field_offset = OFFSETOF_MEMBER(Class, verify_error_class_);
928 klass->SetFieldObject(field_offset, klass);
929 }
930
931 private:
932 bool Implements(const Class* klass) const;
933 bool IsArrayAssignableFromArray(const Class* klass) const;
934 bool IsAssignableFromArray(const Class* klass) const;
935 bool IsSubClass(const Class* klass) const;
936
Ian Rogersb033c752011-07-20 12:22:35 -0700937 public: // TODO: private
Carl Shapiro1fb86202011-06-27 17:43:13 -0700938 // leave space for instance data; we could access fields directly if
939 // we freeze the definition of java/lang/Class
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700940#define CLASS_FIELD_SLOTS 1
941 // Class.#0 name
Carl Shapiro1fb86202011-06-27 17:43:13 -0700942 uint32_t instance_data_[CLASS_FIELD_SLOTS];
943#undef CLASS_FIELD_SLOTS
944
945 // UTF-8 descriptor for the class from constant pool
946 // ("Ljava/lang/Class;"), or on heap if generated ("[C")
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700947 StringPiece descriptor_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700948
949 // Proxy classes have their descriptor allocated on the native heap.
950 // When this field is non-NULL it must be explicitly freed.
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700951 std::string* descriptor_alloc_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700952
953 // access flags; low 16 bits are defined by VM spec
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700954 uint32_t access_flags_; // TODO: make an instance field?
Carl Shapiro1fb86202011-06-27 17:43:13 -0700955
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700956 // DexCache of resolved constant pool entries
Carl Shapiro1fb86202011-06-27 17:43:13 -0700957 // (will be NULL for VM-generated, e.g. arrays and primitive classes)
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700958 DexCache* dex_cache_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700959
960 // state of class initialization
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700961 Status status_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700962
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700963 // If class verify fails, we must return same error on subsequent tries.
964 // Update with SetVerifyErrorClass to ensure a write barrier is used.
965 const Class* verify_error_class_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700966
967 // threadId, used to check for recursive <clinit> invocation
968 uint32_t clinit_thread_id_;
969
970 // Total object size; used when allocating storage on gc heap. (For
971 // interfaces and abstract classes this will be zero.)
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700972 size_t object_size_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700973
974 // For array classes, the class object for base element, for
975 // instanceof/checkcast (for String[][][], this will be String).
976 // Otherwise, NULL.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700977 Class* component_type_; // TODO: make an instance field
Carl Shapiro1fb86202011-06-27 17:43:13 -0700978
979 // For array classes, the number of array dimensions, e.g. int[][]
980 // is 2. Otherwise 0.
981 int32_t array_rank_;
982
983 // primitive type index, or PRIM_NOT (-1); set for generated prim classes
984 PrimitiveType primitive_type_;
985
986 // The superclass, or NULL if this is java.lang.Object or a
987 // primitive type.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700988 Class* super_class_; // TODO: make an instance field
989 uint32_t super_class_idx_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700990
991 // defining class loader, or NULL for the "bootstrap" system loader
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700992 ClassLoader* class_loader_; // TODO: make an instance field
Carl Shapiro1fb86202011-06-27 17:43:13 -0700993
994 // initiating class loader list
995 // NOTE: for classes with low serialNumber, these are unused, and the
996 // values are kept in a table in gDvm.
Ian Rogersb033c752011-07-20 12:22:35 -0700997 // InitiatingLoaderList initiating_loader_list_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700998
999 // array of interfaces this class implements directly
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001000 ObjectArray<Class>* interfaces_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001001 uint32_t* interfaces_idx_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001002
1003 // static, private, and <init> methods
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001004 ObjectArray<Method>* direct_methods_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001005
1006 // virtual methods defined in this class; invoked through vtable
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001007 ObjectArray<Method>* virtual_methods_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001008
1009 // Virtual method table (vtable), for use by "invoke-virtual". The
1010 // vtable from the superclass is copied in, and virtual methods from
1011 // our class either replace those from the super or are appended.
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001012 ObjectArray<Method>* vtable_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001013
1014 // Interface table (iftable), one entry per interface supported by
1015 // this class. That means one entry for each interface we support
1016 // directly, indirectly via superclass, or indirectly via
1017 // superinterface. This will be null if neither we nor our
1018 // superclass implement any interfaces.
1019 //
1020 // Why we need this: given "class Foo implements Face", declare
1021 // "Face faceObj = new Foo()". Invoke faceObj.blah(), where "blah"
1022 // is part of the Face interface. We can't easily use a single
1023 // vtable.
1024 //
1025 // For every interface a concrete class implements, we create a list
1026 // of virtualMethod indices for the methods in the interface.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001027 size_t iftable_count_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001028 InterfaceEntry* iftable_;
1029
1030 // The interface vtable indices for iftable get stored here. By
1031 // placing them all in a single pool for each class that implements
1032 // interfaces, we decrease the number of allocations.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001033 size_t ifvi_pool_count_;
1034 uint32_t* ifvi_pool_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001035
1036 // instance fields
1037 //
1038 // These describe the layout of the contents of a
1039 // DataObject-compatible Object. Note that only the fields directly
1040 // declared by this class are listed in ifields; fields declared by
Brian Carlstroma331b3c2011-07-18 17:47:56 -07001041 // a superclass are listed in the superclass's Class.ifields.
Carl Shapiro1fb86202011-06-27 17:43:13 -07001042 //
1043 // All instance fields that refer to objects are guaranteed to be at
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001044 // the beginning of the field list. num_reference_instance_fields_
1045 // specifies the number of reference fields.
Jesse Wilson35baaab2011-08-10 16:18:03 -04001046 ObjectArray<Field>* ifields_;
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001047
1048 // number of fields that are object refs
Carl Shapiro69759ea2011-07-21 18:13:35 -07001049 size_t num_reference_instance_fields_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001050
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001051 // Bitmap of offsets of ifields.
1052 uint32_t reference_offsets_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001053
1054 // source file name, if known. Otherwise, NULL.
1055 const char* source_file_;
1056
Jesse Wilson7833bd22011-08-09 18:31:44 -04001057 // Static fields
Jesse Wilson35baaab2011-08-10 16:18:03 -04001058 ObjectArray<Field>* sfields_;
Jesse Wilson7833bd22011-08-09 18:31:44 -04001059
1060 // static field storage
1061 //
1062 // Each static field is stored in one of three arrays:
1063 // o references are stored in static_references_
1064 // o doubles and longs are stored in static_64bit_primitives_
1065 // o everything else is in static_32bit_primitives_
1066 // Static fields select their array using their type and their index using the
1067 // Field->slot_ member. Storing static fields in arrays avoids the need for a
1068 // special case in the GC.
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001069 ObjectArray<Object>* static_references_;
1070 IntArray* static_32bit_primitives_;
1071 LongArray* static_64bit_primitives_;
1072
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001073 private:
Carl Shapirof88c9522011-08-06 15:47:38 -07001074 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001075};
Elliott Hughes1f359b02011-07-17 14:27:17 -07001076std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001077
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001078inline bool Object::InstanceOf(const Class* klass) const {
Jesse Wilson14150742011-07-29 19:04:44 -04001079 DCHECK(klass != NULL);
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001080 DCHECK(klass_ != NULL);
1081 return klass->IsAssignableFrom(klass_);
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001082}
1083
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001084
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001085class DataObject : public Object {
1086 public:
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07001087 uint32_t fields_[0];
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001088 private:
Carl Shapirof88c9522011-08-06 15:47:38 -07001089 DISALLOW_IMPLICIT_CONSTRUCTORS(DataObject);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001090};
1091
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001092template<class T>
1093class PrimitiveArray : public Array {
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001094 public:
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001095 static PrimitiveArray<T>* Alloc(Class* element_class, size_t length) {
1096 return down_cast<PrimitiveArray<T>*>(Array::Alloc(element_class,
1097 length,
1098 sizeof(T)));
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001099 }
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001100
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001101 const T* GetData() const {
1102 return reinterpret_cast<const T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001103 }
1104
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001105 T* GetData() {
1106 return reinterpret_cast<T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001107 }
1108
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001109 T Get(T i) const {
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001110 CHECK_LT(i, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001111 return GetData()[i];
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001112 }
1113
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001114 void Set(uint32_t i, T value) {
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001115 CHECK_LT(i, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001116 GetData()[i] = value;
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001117 }
1118
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001119 private:
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001120 // Location of first element.
1121 T elements_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -07001122
1123 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimitiveArray);
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001124};
Carl Shapiro5fafe2b2011-07-09 15:34:41 -07001125
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001126class String : public Object {
Carl Shapiro1fb86202011-06-27 17:43:13 -07001127 public:
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001128 const CharArray* GetCharArray() const {
Carl Shapirof88c9522011-08-06 15:47:38 -07001129 DCHECK(array_ != NULL);
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001130 return array_;
1131 }
1132
Carl Shapirof88c9522011-08-06 15:47:38 -07001133 uint32_t GetHashCode() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001134 return hash_code_;
1135 }
1136
Carl Shapirof88c9522011-08-06 15:47:38 -07001137 uint32_t GetOffset() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001138 return offset_;
1139 }
1140
Carl Shapirof88c9522011-08-06 15:47:38 -07001141 uint32_t GetLength() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001142 return count_;
1143 }
1144
Carl Shapirof88c9522011-08-06 15:47:38 -07001145 uint16_t CharAt(uint32_t index) const {
1146 DCHECK_LE(index, GetLength());
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001147 return GetCharArray()->Get(index + GetOffset());
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001148 }
1149
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001150 static String* AllocFromUtf16(int32_t utf16_length,
1151 uint16_t* utf16_data_in,
1152 int32_t hash_code) {
Carl Shapirof88c9522011-08-06 15:47:38 -07001153 String* string = Alloc(GetJavaLangString(),
1154 GetCharArrayClass(),
1155 utf16_length);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001156 // TODO use 16-bit wide memset variant
1157 for (int i = 0; i < utf16_length; i++ ) {
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001158 string->array_->Set(i, utf16_data_in[i]);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001159 }
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001160 string->ComputeHashCode();
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001161 return string;
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001162 }
1163
1164 static String* AllocFromModifiedUtf8(Class* java_lang_String,
1165 Class* char_array,
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001166 int32_t utf16_length,
1167 const char* utf8_data_in) {
1168 String* string = Alloc(java_lang_String, char_array, utf16_length);
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001169 uint16_t* utf16_data_out = string->array_->GetData();
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001170 ConvertModifiedUtf8ToUtf16(utf16_data_out, utf8_data_in);
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001171 string->ComputeHashCode();
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001172 return string;
1173 }
1174
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001175 // Creates a String of the given ASCII characters. It is an error to call this
1176 // using non-ASCII characters as this function assumes one char per byte.
1177 static String* AllocFromAscii(const char* ascii_data_in) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001178 return AllocFromModifiedUtf8(GetJavaLangString(),
1179 GetCharArrayClass(),
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001180 strlen(ascii_data_in),
1181 ascii_data_in);
1182 }
1183
Jesse Wilson8989d992011-08-02 13:39:42 -07001184 static String* AllocFromModifiedUtf8(int32_t utf16_length,
1185 const char* utf8_data_in) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001186 return AllocFromModifiedUtf8(GetJavaLangString(), GetCharArrayClass(),
1187 utf16_length, utf8_data_in);
Jesse Wilson8989d992011-08-02 13:39:42 -07001188 }
1189
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001190 static void InitClasses(Class* java_lang_String, Class* char_array);
1191
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001192 static String* Alloc(Class* java_lang_String,
1193 Class* char_array,
1194 int32_t utf16_length) {
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001195 String* string = down_cast<String*>(java_lang_String->NewInstance());
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001196 CharArray* array = CharArray::Alloc(char_array, utf16_length);
1197 string->array_ = array;
1198 string->count_ = utf16_length;
1199 return string;
1200 }
1201
1202 // Convert Modified UTF-8 to UTF-16
1203 // http://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8
1204 static void ConvertModifiedUtf8ToUtf16(uint16_t* utf16_data_out, const char* utf8_data_in) {
1205 while (*utf8_data_in != '\0') {
1206 *utf16_data_out++ = GetUtf16FromUtf8(&utf8_data_in);
1207 }
1208 }
1209
1210 // Retrieve the next UTF-16 character from a UTF-8 string.
1211 //
1212 // Advances "*pUtf8Ptr" to the start of the next character.
1213 //
1214 // WARNING: If a string is corrupted by dropping a '\0' in the middle
1215 // of a 3-byte sequence, you can end up overrunning the buffer with
1216 // reads (and possibly with the writes if the length was computed and
1217 // cached before the damage). For performance reasons, this function
1218 // assumes that the string being parsed is known to be valid (e.g., by
1219 // already being verified). Most strings we process here are coming
1220 // out of dex files or other internal translations, so the only real
1221 // risk comes from the JNI NewStringUTF call.
1222 static uint16_t GetUtf16FromUtf8(const char** utf8_data_in) {
1223 uint8_t one = *(*utf8_data_in)++;
1224 if ((one & 0x80) == 0) {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001225 // one-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001226 return one;
1227 }
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001228 // two- or three-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001229 uint8_t two = *(*utf8_data_in)++;
1230 if ((one & 0x20) == 0) {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001231 // two-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001232 return ((one & 0x1f) << 6) |
1233 (two & 0x3f);
1234 }
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001235 // three-byte encoding
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001236 uint8_t three = *(*utf8_data_in)++;
1237 return ((one & 0x0f) << 12) |
1238 ((two & 0x3f) << 6) |
1239 (three & 0x3f);
1240 }
1241
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001242 // Like "strlen", but for strings encoded with "modified" UTF-8.
1243 //
1244 // The value returned is the number of characters, which may or may not
1245 // be the same as the number of bytes.
1246 //
1247 // (If this needs optimizing, try: mask against 0xa0, shift right 5,
1248 // get increment {1-3} from table of 8 values.)
1249 static size_t ModifiedUtf8Len(const char* utf8) {
1250 size_t len = 0;
1251 int ic;
1252 while ((ic = *utf8++) != '\0') {
1253 len++;
1254 if ((ic & 0x80) == 0) {
1255 // one-byte encoding
1256 continue;
1257 }
1258 // two- or three-byte encoding
1259 utf8++;
1260 if ((ic & 0x20) == 0) {
1261 // two-byte encoding
1262 continue;
1263 }
1264 // three-byte encoding
1265 utf8++;
1266 }
1267 return len;
1268 }
1269
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001270 // The java/lang/String.computeHashCode() algorithm
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001271 static int32_t ComputeUtf16Hash(const uint16_t* string_data, size_t string_length) {
1272 int32_t hash = 0;
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001273 while (string_length--) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001274 hash = hash * 31 + *string_data++;
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001275 }
1276 return hash;
1277 }
1278
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001279 void ComputeHashCode() {
1280 hash_code_ = ComputeUtf16Hash(array_->GetData(), count_);
1281 }
1282
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001283 bool Equals(const char* modified_utf8) const {
Carl Shapirof88c9522011-08-06 15:47:38 -07001284 for (uint32_t i = 0; i < GetLength(); ++i) {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001285 uint16_t ch = GetUtf16FromUtf8(&modified_utf8);
1286 if (ch == '\0' || ch != CharAt(i)) {
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001287 return false;
1288 }
1289 }
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001290 return *modified_utf8 == '\0';
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001291 }
1292
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001293 bool Equals(const StringPiece& modified_utf8) const {
1294 // TODO: do not assume C-string representation.
1295 return Equals(modified_utf8.data());
1296 }
1297
1298 bool Equals(const String* that) const {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001299 // TODO short circuit on hash_code_
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001300 if (this->GetLength() != that->GetLength()) {
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001301 return false;
1302 }
Carl Shapirof88c9522011-08-06 15:47:38 -07001303 for (uint32_t i = 0; i < that->GetLength(); ++i) {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001304 if (this->CharAt(i) != that->CharAt(i)) {
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001305 return false;
1306 }
1307 }
1308 return true;
1309 }
1310
Carl Shapirof88c9522011-08-06 15:47:38 -07001311 bool Equals(const uint16_t* that_chars, uint32_t that_offset, uint32_t that_length) const {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001312 if (this->GetLength() != that_length) {
1313 return false;
1314 }
Carl Shapirof88c9522011-08-06 15:47:38 -07001315 for (uint32_t i = 0; i < that_length; ++i) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001316 if (this->CharAt(i) != that_chars[that_offset + i]) {
1317 return false;
1318 }
1319 }
1320 return true;
1321 }
1322
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001323 private:
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001324 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
1325 CharArray* array_;
1326
Carl Shapirof88c9522011-08-06 15:47:38 -07001327 uint32_t hash_code_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001328
Carl Shapirof88c9522011-08-06 15:47:38 -07001329 uint32_t offset_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001330
Carl Shapirof88c9522011-08-06 15:47:38 -07001331 uint32_t count_;
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001332
1333 static Class* GetJavaLangString() {
1334 DCHECK(java_lang_String_ != NULL);
1335 return java_lang_String_;
1336 }
1337 static Class* GetCharArrayClass() {
1338 DCHECK(char_array_ != NULL);
1339 return char_array_;
1340 }
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001341
1342 static Class* java_lang_String_;
1343 static Class* char_array_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001344
1345 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001346};
1347
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001348class InterfaceEntry {
Carl Shapiro1fb86202011-06-27 17:43:13 -07001349 public:
Carl Shapirof88c9522011-08-06 15:47:38 -07001350 InterfaceEntry() : klass_(NULL), method_index_array_(NULL) {
1351 }
1352
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001353 Class* GetClass() const {
1354 return klass_;
Carl Shapirof88c9522011-08-06 15:47:38 -07001355 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001356
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001357 void SetClass(Class* klass) {
1358 klass_ = klass;
Carl Shapirof88c9522011-08-06 15:47:38 -07001359 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001360
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001361 private:
1362 // Points to the interface class.
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001363 Class* klass_;
1364
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001365 public: // TODO: private
1366 // Index into array of vtable offsets. This points into the
1367 // ifviPool, which holds the vtables for all interfaces declared by
1368 // this class.
1369 uint32_t* method_index_array_;
Carl Shapirof88c9522011-08-06 15:47:38 -07001370
1371 private:
1372 DISALLOW_COPY_AND_ASSIGN(InterfaceEntry);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001373};
1374
1375} // namespace art
1376
1377#endif // ART_SRC_OBJECT_H_