blob: 6c8fd6b354d46f6fb0b49a8eda7c3fb39009d5b8 [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 "casts.h"
Elliott Hughes814e4032011-08-23 12:07:56 -07007#include "constants.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07008#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"
Elliott Hughes814e4032011-08-23 12:07:56 -070012#include "monitor.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070013#include "offsets.h"
14#include "stringpiece.h"
Elliott Hughes814e4032011-08-23 12:07:56 -070015#include "utf.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;
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070030typedef PrimitiveArray<uint8_t> BooleanArray;
31typedef PrimitiveArray<int8_t> ByteArray;
Jesse Wilsonfd687c52011-08-04 19:27:35 -070032typedef PrimitiveArray<uint16_t> CharArray;
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070033typedef PrimitiveArray<double> DoubleArray;
34typedef PrimitiveArray<float> FloatArray;
35typedef PrimitiveArray<int32_t> IntArray;
36typedef PrimitiveArray<int64_t> LongArray;
37typedef PrimitiveArray<int16_t> ShortArray;
Carl Shapiro1fb86202011-06-27 17:43:13 -070038
Carl Shapiro3ee755d2011-06-28 12:11:04 -070039union JValue {
40 uint8_t z;
41 int8_t b;
42 uint16_t c;
43 int16_t s;
44 int32_t i;
45 int64_t j;
46 float f;
47 double d;
48 Object* l;
49};
50
Brian Carlstrombe977852011-07-19 14:54:54 -070051static const uint32_t kAccPublic = 0x0001; // class, field, method, ic
52static const uint32_t kAccPrivate = 0x0002; // field, method, ic
53static const uint32_t kAccProtected = 0x0004; // field, method, ic
54static const uint32_t kAccStatic = 0x0008; // field, method, ic
55static const uint32_t kAccFinal = 0x0010; // class, field, method, ic
56static const uint32_t kAccSynchronized = 0x0020; // method (only allowed on natives)
57static const uint32_t kAccSuper = 0x0020; // class (not used in Dalvik)
58static const uint32_t kAccVolatile = 0x0040; // field
59static const uint32_t kAccBridge = 0x0040; // method (1.5)
60static const uint32_t kAccTransient = 0x0080; // field
61static const uint32_t kAccVarargs = 0x0080; // method (1.5)
62static const uint32_t kAccNative = 0x0100; // method
63static const uint32_t kAccInterface = 0x0200; // class, ic
64static const uint32_t kAccAbstract = 0x0400; // class, method, ic
65static const uint32_t kAccStrict = 0x0800; // method
66static const uint32_t kAccSynthetic = 0x1000; // field, method, ic
67static const uint32_t kAccAnnotation = 0x2000; // class, ic (1.5)
68static const uint32_t kAccEnum = 0x4000; // class, field, ic (1.5)
Carl Shapiro3ee755d2011-06-28 12:11:04 -070069
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070070static const uint32_t kAccMiranda = 0x8000; // method
71
Brian Carlstroma331b3c2011-07-18 17:47:56 -070072static const uint32_t kAccJavaFlagsMask = 0xffff; // bits set from Java sources (low 16)
73
Brian Carlstrombe977852011-07-19 14:54:54 -070074static const uint32_t kAccConstructor = 0x00010000; // method (Dalvik only)
75static const uint32_t kAccDeclaredSynchronized = 0x00020000; // method (Dalvik only)
Carl Shapiro3ee755d2011-06-28 12:11:04 -070076
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070077/*
Brian Carlstroma331b3c2011-07-18 17:47:56 -070078 * Definitions for packing refOffsets in Class.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070079 */
80/*
81 * A magic value for refOffsets. Ignore the bits and walk the super
82 * chain when this is the value.
83 * [This is an unlikely "natural" value, since it would be 30 non-ref instance
84 * fields followed by 2 ref instance fields.]
85 */
86#define CLASS_WALK_SUPER ((unsigned int)(3))
87#define CLASS_SMALLEST_OFFSET (sizeof(struct Object))
88#define CLASS_BITS_PER_WORD (sizeof(unsigned long int) * 8)
89#define CLASS_OFFSET_ALIGNMENT 4
90#define CLASS_HIGH_BIT ((unsigned int)1 << (CLASS_BITS_PER_WORD - 1))
91/*
92 * Given an offset, return the bit number which would encode that offset.
93 * Local use only.
94 */
95#define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \
96 (((unsigned int)(byteOffset) - CLASS_SMALLEST_OFFSET) / \
97 CLASS_OFFSET_ALIGNMENT)
98/*
99 * Is the given offset too large to be encoded?
100 */
101#define CLASS_CAN_ENCODE_OFFSET(byteOffset) \
102 (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD)
103/*
104 * Return a single bit, encoding the offset.
105 * Undefined if the offset is too large, as defined above.
106 */
107#define CLASS_BIT_FROM_OFFSET(byteOffset) \
108 (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset))
109/*
110 * Return an offset, given a bit number as returned from CLZ.
111 */
112#define CLASS_OFFSET_FROM_CLZ(rshift) \
Ian Rogersb033c752011-07-20 12:22:35 -0700113 ((static_cast<int>(rshift) * CLASS_OFFSET_ALIGNMENT) + CLASS_SMALLEST_OFFSET)
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700114
115
Carl Shapiro1fb86202011-06-27 17:43:13 -0700116class Object {
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700117 public:
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700118 static bool InstanceOf(const Object* object, const Class* klass) {
119 if (object == NULL) {
120 return false;
121 }
122 return object->InstanceOf(klass);
123 }
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700124
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700125 Class* GetClass() const {
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700126 DCHECK(klass_ != NULL);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700127 return klass_;
128 }
129
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700130 bool InstanceOf(const Class* klass) const;
131
Elliott Hughes04b63fd2011-08-16 09:40:10 -0700132 size_t SizeOf() const;
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700133
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700134 void MonitorEnter() {
135 monitor_->Enter();
136 }
137
138 void MonitorExit() {
139 monitor_->Exit();
140 }
141
142 void Notify() {
143 monitor_->Notify();
144 }
145
146 void NotifyAll() {
147 monitor_->NotifyAll();
148 }
149
150 void Wait() {
151 monitor_->Wait();
152 }
153
154 void Wait(int64_t timeout) {
155 monitor_->Wait(timeout);
156 }
157
158 void Wait(int64_t timeout, int32_t nanos) {
159 monitor_->Wait(timeout, nanos);
160 }
161
Brian Carlstrom4873d462011-08-21 15:23:39 -0700162 Object* GetFieldObject(size_t field_offset) const {
163 const byte* raw_addr = reinterpret_cast<const byte*>(this) + field_offset;
164 return *reinterpret_cast<Object* const *>(raw_addr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700165 }
166
167 void SetFieldObject(size_t offset, Object* new_value) {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700168 byte* raw_addr = reinterpret_cast<byte*>(this) + offset;
169 *reinterpret_cast<Object**>(raw_addr) = new_value;
170 // TODO: write barrier
171 }
172
Brian Carlstrom4873d462011-08-21 15:23:39 -0700173 uint32_t GetField32(size_t field_offset) const {
174 const byte* raw_addr = reinterpret_cast<const byte*>(this) + field_offset;
175 return *reinterpret_cast<const uint32_t*>(raw_addr);
176 }
177
178 void SetField32(size_t offset, uint32_t new_value) {
179 byte* raw_addr = reinterpret_cast<byte*>(this) + offset;
180 *reinterpret_cast<uint32_t*>(raw_addr) = new_value;
181 }
182
183 uint64_t GetField64(size_t field_offset) const {
184 const byte* raw_addr = reinterpret_cast<const byte*>(this) + field_offset;
185 return *reinterpret_cast<const uint64_t*>(raw_addr);
186 }
187
188 void SetField64(size_t offset, uint64_t new_value) {
189 byte* raw_addr = reinterpret_cast<byte*>(this) + offset;
190 *reinterpret_cast<uint64_t*>(raw_addr) = new_value;
191 }
192
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700193 bool IsClass() const;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700194
195 Class* AsClass() {
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700196 DCHECK(IsClass());
Carl Shapiro69759ea2011-07-21 18:13:35 -0700197 return down_cast<Class*>(this);
198 }
199
200 const Class* AsClass() const {
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700201 DCHECK(IsClass());
Carl Shapiro69759ea2011-07-21 18:13:35 -0700202 return down_cast<const Class*>(this);
203 }
204
Brian Carlstrom4873d462011-08-21 15:23:39 -0700205 bool IsClassClass() const;
206
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700207 bool IsObjectArray() const;
208
209 template<class T>
210 ObjectArray<T>* AsObjectArray() {
211 DCHECK(IsObjectArray());
212 return down_cast<ObjectArray<T>*>(this);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700213 }
214
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700215 template<class T>
216 const ObjectArray<T>* AsObjectArray() const {
217 DCHECK(IsObjectArray());
218 return down_cast<const ObjectArray<T>*>(this);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700219 }
220
221 bool IsReference() const {
Elliott Hughes53b61312011-08-12 18:28:20 -0700222 UNIMPLEMENTED(FATAL);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700223 return true;
224 }
225
226 bool IsWeakReference() const {
Elliott Hughes53b61312011-08-12 18:28:20 -0700227 UNIMPLEMENTED(FATAL);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700228 return true;
229 }
230
231 bool IsSoftReference() const {
Elliott Hughes53b61312011-08-12 18:28:20 -0700232 UNIMPLEMENTED(FATAL);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700233 return true;
234 }
235
236 bool IsFinalizerReference() const {
Elliott Hughes53b61312011-08-12 18:28:20 -0700237 UNIMPLEMENTED(FATAL);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700238 return true;
239 }
240
241 bool IsPhantomReference() const {
Elliott Hughes53b61312011-08-12 18:28:20 -0700242 UNIMPLEMENTED(FATAL);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700243 return true;
244 }
245
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700246 bool IsArray() const;
247
248 Array* AsArray() {
249 DCHECK(IsArray());
250 return down_cast<Array*>(this);
251 }
252
253 const Array* AsArray() const {
254 DCHECK(IsArray());
255 return down_cast<const Array*>(this);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700256 }
257
Brian Carlstroma663ea52011-08-19 23:33:41 -0700258 bool IsString() const;
259
260 String* AsString() {
261 DCHECK(IsString());
262 return down_cast<String*>(this);
263 }
264
265 bool IsMethod() const;
266
267 Method* AsMethod() {
268 DCHECK(IsMethod());
269 return down_cast<Method*>(this);
270 }
271
Brian Carlstrom4873d462011-08-21 15:23:39 -0700272 const Method* AsMethod() const {
273 DCHECK(IsMethod());
274 return down_cast<const Method*>(this);
275 }
276
Brian Carlstroma663ea52011-08-19 23:33:41 -0700277 bool IsField() const;
278
279 Field* AsField() {
280 DCHECK(IsField());
281 return down_cast<Field*>(this);
282 }
283
Brian Carlstrom4873d462011-08-21 15:23:39 -0700284 const Field* AsField() const {
285 DCHECK(IsField());
286 return down_cast<const Field*>(this);
287 }
288
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700289 public:
Carl Shapiro1fb86202011-06-27 17:43:13 -0700290 Class* klass_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700291
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700292 Monitor* monitor_;
293
294 private:
Carl Shapirof88c9522011-08-06 15:47:38 -0700295 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700296};
297
298class ObjectLock {
299 public:
Ian Rogersb033c752011-07-20 12:22:35 -0700300 explicit ObjectLock(Object* object) : obj_(object) {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700301 CHECK(object != NULL);
302 obj_->MonitorEnter();
303 }
304
305 ~ObjectLock() {
306 obj_->MonitorExit();
307 }
308
309 void Wait(int64_t millis = 0) {
310 return obj_->Wait(millis);
311 }
312
313 void Notify() {
314 obj_->Notify();
315 }
316
317 void NotifyAll() {
318 obj_->NotifyAll();
319 }
320
321 private:
322 Object* obj_;
323 DISALLOW_COPY_AND_ASSIGN(ObjectLock);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700324};
325
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400326class AccessibleObject : public Object {
327 private:
328 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
329 uint32_t java_flag_;
330};
331
332class Field : public AccessibleObject {
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700333 public:
Brian Carlstroma0808032011-07-18 00:39:23 -0700334 Class* GetDeclaringClass() const {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700335 DCHECK(declaring_class_ != NULL);
Brian Carlstroma0808032011-07-18 00:39:23 -0700336 return declaring_class_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700337 }
338
Jesse Wilson14150742011-07-29 19:04:44 -0400339 const String* GetName() const {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700340 DCHECK(name_ != NULL);
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700341 return name_;
342 }
343
344 bool IsStatic() const {
345 return (access_flags_ & kAccStatic) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700346 }
347
348 char GetType() const { // TODO: return type
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700349 return GetDescriptor()[0];
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700350 }
351
Brian Carlstromae3ac012011-07-27 01:30:28 -0700352 const StringPiece& GetDescriptor() const {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700353 DCHECK_NE(0, descriptor_.size());
Brian Carlstromae3ac012011-07-27 01:30:28 -0700354 return descriptor_;
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700355 }
356
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700357 uint32_t GetOffset() const {
358 return offset_;
359 }
360
361 void SetOffset(size_t num_bytes) {
362 offset_ = num_bytes;
363 }
364
Brian Carlstrom4873d462011-08-21 15:23:39 -0700365 // field access, null object for static fields
366 bool GetBoolean(const Object* object) const;
367 void SetBoolean(Object* object, bool z) const;
368 int8_t GetByte(const Object* object) const;
369 void SetByte(Object* object, int8_t b) const;
370 uint16_t GetChar(const Object* object) const;
371 void SetChar(Object* object, uint16_t c) const;
372 uint16_t GetShort(const Object* object) const;
373 void SetShort(Object* object, uint16_t s) const;
374 int32_t GetInt(const Object* object) const;
375 void SetInt(Object* object, int32_t i) const;
376 int64_t GetLong(const Object* object) const;
377 void SetLong(Object* object, int64_t j) const;
378 float GetFloat(const Object* object) const;
379 void SetFloat(Object* object, float f) const;
380 double GetDouble(const Object* object) const;
381 void SetDouble(Object* object, double d) const;
382 Object* GetObject(const Object* object) const;
383 void SetObject(Object* object, Object* l) const;
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700384
Jesse Wilson35baaab2011-08-10 16:18:03 -0400385 public: // TODO: private
Brian Carlstrom4873d462011-08-21 15:23:39 -0700386
387 // private implemention of field access using raw data
388 uint32_t Get32(const Object* object) const;
389 void Set32(Object* object, uint32_t new_value) const;
390 uint64_t Get64(const Object* object) const;
391 void Set64(Object* object, uint64_t new_value) const;
392 Object* GetObj(const Object* object) const;
393 void SetObj(Object* object, Object* new_value) const;
394
Jesse Wilson35baaab2011-08-10 16:18:03 -0400395 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
396 // The class in which this field is declared.
397 Class* declaring_class_;
398 Object* generic_type_;
399 uint32_t generic_types_are_initialized_;
400 String* name_;
401 uint32_t offset_;
402 Class* type_;
403
404 // e.g. "I", "[C", "Landroid/os/Debug;"
405 StringPiece descriptor_;
406
407 uint32_t access_flags_;
408
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700409 private:
Jesse Wilson35baaab2011-08-10 16:18:03 -0400410 DISALLOW_IMPLICIT_CONSTRUCTORS(Field);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700411};
412
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400413class Method : public AccessibleObject {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700414 public:
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700415 // An function that invokes a method with an array of its arguments.
416 typedef void InvokeStub(Method* method,
417 Object* obj,
418 Thread* thread,
419 byte* args,
420 JValue* result);
421
Brian Carlstromae3ac012011-07-27 01:30:28 -0700422 // Returns the method name, e.g. "<init>" or "eatLunch"
Jesse Wilsonf7e85a52011-08-01 18:45:58 -0700423 const String* GetName() const {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700424 DCHECK(name_ != NULL);
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700425 return name_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700426 }
427
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700428 const String* GetSignature() const {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700429 DCHECK(signature_ != NULL);
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700430 return signature_;
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700431 }
432
Brian Carlstroma0808032011-07-18 00:39:23 -0700433 Class* GetDeclaringClass() const {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700434 DCHECK(declaring_class_ != NULL);
Brian Carlstroma0808032011-07-18 00:39:23 -0700435 return declaring_class_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700436 }
437
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700438 static MemberOffset DeclaringClassOffset() {
439 return MemberOffset(OFFSETOF_MEMBER(Method, declaring_class_));
Ian Rogersb033c752011-07-20 12:22:35 -0700440 }
441
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700442 // Returns true if the method is declared public.
443 bool IsPublic() const {
444 return (access_flags_ & kAccPublic) != 0;
445 }
446
447 // Returns true if the method is declared private.
448 bool IsPrivate() const {
449 return (access_flags_ & kAccPrivate) != 0;
450 }
451
452 // Returns true if the method is declared static.
453 bool IsStatic() const {
454 return (access_flags_ & kAccStatic) != 0;
455 }
456
457 // Returns true if the method is declared synchronized.
458 bool IsSynchronized() const {
459 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
460 return (access_flags_ & synchonized) != 0;
461 }
462
463 // Returns true if the method is declared final.
464 bool IsFinal() const {
465 return (access_flags_ & kAccFinal) != 0;
466 }
467
468 // Returns true if the method is declared native.
469 bool IsNative() const {
470 return (access_flags_ & kAccNative) != 0;
471 }
472
473 // Returns true if the method is declared abstract.
474 bool IsAbstract() const {
475 return (access_flags_ & kAccAbstract) != 0;
476 }
477
478 bool IsSynthetic() const {
479 return (access_flags_ & kAccSynthetic) != 0;
480 }
481
482 // Number of argument registers required by the prototype.
Brian Carlstrom4873d462011-08-21 15:23:39 -0700483 uint32_t NumArgRegisters() const;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700484
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700485 // Number of argument bytes required for densely packing the
486 // arguments into an array of arguments.
Brian Carlstrom4873d462011-08-21 15:23:39 -0700487 size_t NumArgArrayBytes() const;
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700488
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700489 // Converts a native PC to a virtual PC. TODO: this is a no-op
490 // until we associate a PC mapping table with each method.
491 uintptr_t ToDexPC(const uintptr_t pc) const {
492 return pc;
493 }
494
495 // Converts a virtual PC to a native PC. TODO: this is a no-op
496 // until we associate a PC mapping table with each method.
497 uintptr_t ToNativePC(const uintptr_t pc) const {
498 return pc;
499 }
500
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700501 public: // TODO: private
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400502 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Jesse Wilson35baaab2011-08-10 16:18:03 -0400503 // the class we are a part of
504 Class* declaring_class_;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400505 ObjectArray<Class>* java_exception_types_;
506 Object* java_formal_type_parameters_;
507 Object* java_generic_exception_types_;
508 Object* java_generic_parameter_types_;
509 Object* java_generic_return_type_;
510 Class* java_return_type_;
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700511 String* name_;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400512 ObjectArray<Class>* java_parameter_types_;
513 uint32_t java_generic_types_are_initialized_;
514 uint32_t java_slot_;
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700515
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700516 const StringPiece& GetShorty() const {
517 return shorty_;
518 }
519
Ian Rogersb033c752011-07-20 12:22:35 -0700520 bool IsReturnAReference() const {
521 return (shorty_[0] == 'L') || (shorty_[0] == '[');
522 }
523
524 bool IsReturnAFloatOrDouble() const {
525 return (shorty_[0] == 'F') || (shorty_[0] == 'D');
526 }
527
528 bool IsReturnAFloat() const {
529 return shorty_[0] == 'F';
530 }
531
532 bool IsReturnADouble() const {
533 return shorty_[0] == 'D';
534 }
535
536 bool IsReturnALong() const {
537 return shorty_[0] == 'J';
538 }
539
Ian Rogers45a76cb2011-07-21 22:00:15 -0700540 bool IsReturnVoid() const {
541 return shorty_[0] == 'V';
542 }
543
Shih-wei Liao5381cf92011-07-27 00:28:04 -0700544 // "Args" may refer to any of the 3 levels of "Args."
545 // To avoid confusion, our code will denote which "Args" clearly:
546 // 1. UserArgs: Args that a user see.
547 // 2. Args: Logical JVM-level Args. E.g., the first in Args will be the
548 // receiver.
549 // 3. CConvArgs: Calling Convention Args, which is physical-level Args.
550 // E.g., the first in Args is Method* for both static and non-static
551 // methods. And CConvArgs doesn't deal with the receiver because
552 // receiver is hardwired in an implicit register, so CConvArgs doesn't
553 // need to deal with it.
554 //
555 // The number of Args that should be supplied to this method
Ian Rogersb033c752011-07-20 12:22:35 -0700556 size_t NumArgs() const {
Shih-wei Liao5381cf92011-07-27 00:28:04 -0700557 // "1 +" because the first in Args is the receiver.
558 // "- 1" because we don't count the return type.
Ian Rogersb033c752011-07-20 12:22:35 -0700559 return (IsStatic() ? 0 : 1) + shorty_.length() - 1;
560 }
561
562 // The number of reference arguments to this method including implicit this
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700563 // pointer.
Ian Rogersb033c752011-07-20 12:22:35 -0700564 size_t NumReferenceArgs() const;
565
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700566 // The number of long or double arguments.
Ian Rogersb033c752011-07-20 12:22:35 -0700567 size_t NumLongOrDoubleArgs() const;
568
569 // The number of reference arguments to this method before the given
570 // parameter index
571 size_t NumReferenceArgsBefore(unsigned int param) const;
572
573 // Is the given method parameter a reference?
574 bool IsParamAReference(unsigned int param) const;
575
576 // Is the given method parameter a long or double?
577 bool IsParamALongOrDouble(unsigned int param) const;
578
Ian Rogersdf20fe02011-07-20 20:34:16 -0700579 // Size in bytes of the given parameter
580 size_t ParamSize(unsigned int param) const;
581
582 // Size in bytes of the return value
583 size_t ReturnSize() const;
Ian Rogersb033c752011-07-20 12:22:35 -0700584
buzbeec143c552011-08-20 17:38:58 -0700585 bool HasCode() {
586 return code_ != NULL;
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700587 }
588
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700589 void SetCode(const byte* compiled_code,
590 size_t byte_count,
591 InstructionSet set) {
buzbeec143c552011-08-20 17:38:58 -0700592 // Copy the code into an executable region.
593 code_instruction_set_ = set;
594 code_area_.reset(MemMap::Map(byte_count,
595 PROT_READ | PROT_WRITE | PROT_EXEC));
Elliott Hughesedcc09c2011-08-21 18:47:05 -0700596 CHECK(code_area_.get());
buzbeec143c552011-08-20 17:38:58 -0700597 byte* code = code_area_->GetAddress();
598 memcpy(code, compiled_code, byte_count);
599 __builtin___clear_cache(code, code + byte_count);
600
601 uintptr_t address = reinterpret_cast<uintptr_t>(code);
602 if (code_instruction_set_ == kThumb2) {
603 // Set the low-order bit so a BLX will switch to Thumb mode
604 address |= 0x1;
605 }
606 code_ = reinterpret_cast<void*>(address);
607 }
608
Shih-wei Liaod11af152011-08-23 16:02:11 -0700609 void SetFrameSizeInBytes(size_t frame_size_in_bytes) {
610 frame_size_in_bytes_ = frame_size_in_bytes;
buzbeec143c552011-08-20 17:38:58 -0700611 }
612
Shih-wei Liaod11af152011-08-23 16:02:11 -0700613 void SetReturnPcOffsetInBytes(size_t return_pc_offset_in_bytes) {
614 return_pc_offset_in_bytes_ = return_pc_offset_in_bytes;
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700615 }
616
Shih-wei Liaod11af152011-08-23 16:02:11 -0700617 size_t GetFrameSizeInBytes() const {
618 return frame_size_in_bytes_;
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700619 }
620
Shih-wei Liaod11af152011-08-23 16:02:11 -0700621 size_t GetReturnPcOffsetInBytes() const {
622 return return_pc_offset_in_bytes_;
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700623 }
624
buzbeec143c552011-08-20 17:38:58 -0700625 void SetCoreSpillMask(uint32_t core_spill_mask) {
626 core_spill_mask_ = core_spill_mask;
Ian Rogersb033c752011-07-20 12:22:35 -0700627 }
628
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700629 static size_t GetCodeOffset() {
630 return OFFSETOF_MEMBER(Method, code_);
Ian Rogersb033c752011-07-20 12:22:35 -0700631 }
632
buzbeec143c552011-08-20 17:38:58 -0700633 void SetFpSpillMask(uint32_t fp_spill_mask) {
634 fp_spill_mask_ = fp_spill_mask;
635 }
636
Ian Rogersb033c752011-07-20 12:22:35 -0700637 void RegisterNative(const void* native_method) {
Elliott Hughes5174fe62011-08-23 15:12:35 -0700638 CHECK(native_method != NULL);
Ian Rogersb033c752011-07-20 12:22:35 -0700639 native_method_ = native_method;
640 }
641
Elliott Hughes5174fe62011-08-23 15:12:35 -0700642 void UnregisterNative() {
643 native_method_ = NULL;
644 }
645
Ian Rogersb033c752011-07-20 12:22:35 -0700646 static MemberOffset NativeMethodOffset() {
647 return MemberOffset(OFFSETOF_MEMBER(Method, native_method_));
648 }
649
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700650 InvokeStub* GetInvokeStub() const {
651 return invoke_stub_;
652 }
653
654 void SetInvokeStub(const InvokeStub* invoke_stub) {
655 invoke_stub_ = invoke_stub;
656 }
657
658 static size_t GetInvokeStubOffset() {
659 return OFFSETOF_MEMBER(Method, invoke_stub_);
660 }
661
Carl Shapiro8860c0e2011-08-04 17:36:16 -0700662 bool HasSameNameAndDescriptor(const Method* that) const;
663
Ian Rogersb033c752011-07-20 12:22:35 -0700664 public: // TODO: private/const
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700665 // access flags; low 16 bits are defined by spec (could be uint16_t?)
666 uint32_t access_flags_;
667
668 // For concrete virtual methods, this is the offset of the method
Brian Carlstrom30b94452011-08-25 21:35:26 -0700669 // in Class::vtable_.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700670 //
671 // For abstract methods in an interface class, this is the offset
Brian Carlstrom30b94452011-08-25 21:35:26 -0700672 // of the method in "iftable_[n]->method_index_array_".
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700673 uint16_t method_index_;
674
675 // Method bounds; not needed for an abstract method.
676 //
677 // For a native method, we compute the size of the argument list, and
678 // set "insSize" and "registerSize" equal to it.
679 uint16_t num_registers_; // ins + locals
680 uint16_t num_outs_;
681 uint16_t num_ins_;
682
buzbeec143c552011-08-20 17:38:58 -0700683 // Total size in bytes of the frame
Shih-wei Liaod11af152011-08-23 16:02:11 -0700684 size_t frame_size_in_bytes_;
buzbeec143c552011-08-20 17:38:58 -0700685
686 // Architecture-dependent register spill masks
687 uint32_t core_spill_mask_;
688 uint32_t fp_spill_mask_;
689
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700690 // The method descriptor. This represents the parameters a method
691 // takes and value it returns. This string is a list of the type
692 // descriptors for the parameters enclosed in parenthesis followed
693 // by the return type descriptor. For example, for the method
694 //
695 // Object mymethod(int i, double d, Thread t)
696 //
697 // the method descriptor would be
698 //
699 // (IDLjava/lang/Thread;)Ljava/lang/Object;
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700700 String* signature_;
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700701
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700702 // Method prototype descriptor string (return and argument types).
703 uint32_t proto_idx_;
704
Shih-wei Liao2fb97532011-08-11 16:17:23 -0700705 // Offset to the CodeItem.
706 uint32_t code_off_;
707
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700708 // The short-form method descriptor string.
709 StringPiece shorty_;
710
Ian Rogers762400c2011-08-23 12:14:16 -0700711 // short cuts to declaring_class_->dex_cache_ members for fast compiled code
712 // access
Brian Carlstromc4fa2c02011-08-21 03:00:12 -0700713 ObjectArray<String>* dex_cache_strings_;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700714 ObjectArray<Class>* dex_cache_types_;
Brian Carlstromc4fa2c02011-08-21 03:00:12 -0700715 ObjectArray<Method>* dex_cache_methods_;
716 ObjectArray<Field>* dex_cache_fields_;
717
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700718 private:
Ian Rogersb033c752011-07-20 12:22:35 -0700719 // Compiled code associated with this method
buzbeec143c552011-08-20 17:38:58 -0700720 scoped_ptr<MemMap> code_area_;
721 void* code_;
722 // Instruction set of the coompiled code
723 InstructionSet code_instruction_set_;
724
725 // Size in bytes of compiled code associated with this method
726 const uint32_t code_size_;
Ian Rogersb033c752011-07-20 12:22:35 -0700727
Ian Rogers762400c2011-08-23 12:14:16 -0700728 // Offset of return PC within frame for compiled code (in bytes)
Shih-wei Liaod11af152011-08-23 16:02:11 -0700729 // Offset of PC within compiled code (in bytes)
730 size_t return_pc_offset_in_bytes_;
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700731
Ian Rogersb033c752011-07-20 12:22:35 -0700732 // Any native method registered with this method
733 const void* native_method_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700734
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700735 // Native invocation stub entry point.
736 const InvokeStub* invoke_stub_;
737
Carl Shapirof88c9522011-08-06 15:47:38 -0700738 DISALLOW_IMPLICIT_CONSTRUCTORS(Method);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700739};
740
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700741class Array : public Object {
742 public:
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700743 static size_t SizeOf(size_t component_count,
744 size_t component_size) {
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700745 return sizeof(Array) + component_count * component_size;
746 }
Elliott Hughes04b63fd2011-08-16 09:40:10 -0700747
Elliott Hughes68f4fa02011-08-21 10:46:59 -0700748 // A convenience for code that doesn't know the component size,
749 // and doesn't want to have to work it out itself.
750 static Array* Alloc(Class* array_class, size_t component_count);
751
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700752 static Array* Alloc(Class* array_class,
753 size_t component_count,
754 size_t component_size) {
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700755 size_t size = SizeOf(component_count, component_size);
756 Array* array = down_cast<Array*>(Heap::AllocObject(array_class, size));
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700757 if (array != NULL) {
758 array->SetLength(component_count);
759 }
760 return array;
761 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700762
Elliott Hughes04b63fd2011-08-16 09:40:10 -0700763 size_t SizeOf() const;
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700764
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700765 int32_t GetLength() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700766 return length_;
767 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700768
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700769 void SetLength(uint32_t length) {
770 length_ = length;
771 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700772
buzbeec143c552011-08-20 17:38:58 -0700773 static MemberOffset LengthOffset() {
774 return MemberOffset(OFFSETOF_MEMBER(Array, length_));
775 }
776
777 static MemberOffset DataOffset() {
778 return MemberOffset(OFFSETOF_MEMBER(Array, first_element_));
779 }
780
Elliott Hughes289da822011-08-16 10:11:20 -0700781 protected:
782 bool IsValidIndex(int32_t index) const {
783 if (index < 0 || index >= length_) {
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700784 Thread* self = Thread::Current();
785 self->ThrowNewException("Ljava/lang/ArrayIndexOutOfBoundsException;",
786 "length=%i; index=%i", length_, index);
Elliott Hughes710a0cb2011-08-16 14:32:37 -0700787 return false;
Elliott Hughes289da822011-08-16 10:11:20 -0700788 }
789 return true;
790 }
791
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700792 private:
793 // The number of array elements.
Elliott Hughes289da822011-08-16 10:11:20 -0700794 int32_t length_;
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400795 // Padding to ensure the first member defined by a subclass begins on a 8-byte boundary
796 int32_t padding_;
buzbeec143c552011-08-20 17:38:58 -0700797 // Marker for the data (used by generated code)
798 uint32_t first_element_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -0700799
Carl Shapirof88c9522011-08-06 15:47:38 -0700800 DISALLOW_IMPLICIT_CONSTRUCTORS(Array);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700801};
802
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700803template<class T>
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700804class ObjectArray : public Array {
805 public:
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700806 static ObjectArray<T>* Alloc(Class* object_array_class,
807 size_t length) {
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700808 return Array::Alloc(object_array_class, length, sizeof(uint32_t))->AsObjectArray<T>();
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700809 }
810
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700811 T* const * GetData() const {
812 return reinterpret_cast<T* const *>(&elements_);
813 }
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400814
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700815 T** GetData() {
816 return reinterpret_cast<T**>(&elements_);
817 }
Jesse Wilsondf4189c2011-08-09 17:10:28 -0400818
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700819 T* Get(int32_t i) const {
Elliott Hughes289da822011-08-16 10:11:20 -0700820 if (!IsValidIndex(i)) {
821 return NULL;
822 }
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700823 return GetData()[i];
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700824 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700825
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700826 void Set(int32_t i, T* object) {
Elliott Hughes289da822011-08-16 10:11:20 -0700827 if (IsValidIndex(i)) {
828 // TODO: ArrayStoreException
829 GetData()[i] = object; // TODO: write barrier
830 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700831 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700832
833 static void Copy(ObjectArray<T>* src, int src_pos,
834 ObjectArray<T>* dst, int dst_pos,
835 size_t length) {
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700836 for (size_t i = 0; i < length; i++) {
837 dst->Set(dst_pos + i, src->Get(src_pos + i));
838 }
839 }
Carl Shapirof88c9522011-08-06 15:47:38 -0700840
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700841 ObjectArray<T>* CopyOf(int32_t new_length) {
Brian Carlstroma40f9bc2011-07-26 21:26:07 -0700842 ObjectArray<T>* new_array = Alloc(klass_, new_length);
843 Copy(this, 0, new_array, 0, std::min(GetLength(), new_length));
844 return new_array;
845 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700846
847 private:
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700848 // Location of first element.
849 T* elements_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -0700850
851 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700852};
853
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700854// ClassLoader objects.
855class ClassLoader : public Object {
856 public:
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700857 const std::vector<const DexFile*>& GetClassPath() const {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700858 return class_path_;
859 }
860 void SetClassPath(std::vector<const DexFile*>& class_path) {
861 DCHECK_EQ(0U, class_path_.size());
862 class_path_ = class_path;
863 }
864
865 private:
866 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
867 Object* packages_;
868 ClassLoader* parent_;
869
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700870 // TODO: remove once we can create a real PathClassLoader
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700871 std::vector<const DexFile*> class_path_;
872
Carl Shapirof88c9522011-08-06 15:47:38 -0700873 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700874};
875
876class BaseDexClassLoader : public ClassLoader {
877 private:
878 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
879 String* original_path_;
880 Object* path_list_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700881 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseDexClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700882};
883
884class PathClassLoader : public BaseDexClassLoader {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700885 public:
886 static PathClassLoader* Alloc(std::vector<const DexFile*> dex_files);
887 static void SetClass(Class* dalvik_system_PathClassLoader);
888 static void ResetClass();
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700889 private:
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700890 static Class* dalvik_system_PathClassLoader_;
Carl Shapirof88c9522011-08-06 15:47:38 -0700891 DISALLOW_IMPLICIT_CONSTRUCTORS(PathClassLoader);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700892};
893
Carl Shapiro1fb86202011-06-27 17:43:13 -0700894// Class objects.
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700895class Class : public Object {
Carl Shapiro1fb86202011-06-27 17:43:13 -0700896 public:
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700897
898 // Class Status
899 //
900 // kStatusNotReady: If a Class cannot be found in the class table by
901 // FindClass, it allocates an new one with AllocClass in the
902 // kStatusNotReady and calls LoadClass. Note if it does find a
903 // class, it may not be kStatusResolved and it will try to push it
904 // forward toward kStatusResolved.
905 //
906 // kStatusIdx: LoadClass populates with Class with information from
907 // the DexFile, moving the status to kStatusIdx, indicating that the
908 // Class values in super_class_ and interfaces_ have not been
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700909 // populated based on super_class_type_idx_ and
910 // interfaces_type_idx_. The new Class can then be inserted into the
911 // classes table.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700912 //
913 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
914 // attempt to move a kStatusIdx class forward to kStatusLoaded by
915 // using ResolveClass to initialize the super_class_ and interfaces_.
916 //
917 // kStatusResolved: Still holding the lock on Class, the ClassLinker
918 // will use LinkClass to link all members, creating Field and Method
919 // objects, setting up the vtable, etc. On success, the class is
920 // marked kStatusResolved.
921
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700922 enum Status {
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700923 kStatusError = -1,
924 kStatusNotReady = 0,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700925 kStatusIdx = 1, // loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_
Carl Shapiro894d0fa2011-06-30 14:48:49 -0700926 kStatusLoaded = 2, // DEX idx values resolved
927 kStatusResolved = 3, // part of linking
928 kStatusVerifying = 4, // in the process of being verified
929 kStatusVerified = 5, // logically part of linking; done pre-init
930 kStatusInitializing = 6, // class init in progress
931 kStatusInitialized = 7, // ready to go
Carl Shapiro1fb86202011-06-27 17:43:13 -0700932 };
933
934 enum PrimitiveType {
935 kPrimNot = -1
936 };
937
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700938 Object* NewInstance() {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700939 DCHECK(!IsAbstract());
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700940 return Heap::AllocObject(this, this->object_size_);
941 }
942
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700943 Class* GetSuperClass() const {
944 return super_class_;
945 }
946
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700947 uint32_t GetSuperClassTypeIdx() const {
948 return super_class_type_idx_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700949 }
950
951 bool HasSuperClass() const {
952 return super_class_ != NULL;
953 }
954
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700955 bool IsAssignableFrom(const Class* klass) const {
956 DCHECK(klass != NULL);
957 if (this == klass) {
958 return true;
959 }
960 if (IsInterface()) {
961 return klass->Implements(this);
962 }
963 if (klass->IsArray()) {
964 return IsAssignableFromArray(klass);
965 }
966 return klass->IsSubClass(this);
967 }
968
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700969 const ClassLoader* GetClassLoader() const {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700970 return class_loader_;
971 }
972
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700973 DexCache* GetDexCache() const {
974 return dex_cache_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700975 }
976
977 Class* GetComponentType() const {
978 return component_type_;
979 }
980
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700981 static size_t GetTypeSize(String* descriptor);
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700982
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700983 size_t GetComponentSize() const {
984 return GetTypeSize(component_type_->descriptor_);
985 }
986
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700987 const String* GetDescriptor() const {
988 DCHECK(descriptor_ != NULL);
989 // DCHECK_NE(0, descriptor_->GetLength()); // TODO: keep?
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700990 return descriptor_;
991 }
992
Brian Carlstrom4873d462011-08-21 15:23:39 -0700993 size_t SizeOf() const {
994 return class_size_;
995 }
996
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700997 Status GetStatus() const {
998 return status_;
999 }
1000
1001 void SetStatus(Status new_status) {
1002 // TODO: validate transition
1003 status_ = new_status;
1004 }
1005
Carl Shapiro69759ea2011-07-21 18:13:35 -07001006 // Returns true if the class has failed to link.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001007 bool IsErroneous() const {
1008 return GetStatus() == kStatusError;
1009 }
1010
Carl Shapiro69759ea2011-07-21 18:13:35 -07001011 // Returns true if the class has been verified.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001012 bool IsVerified() const {
1013 return GetStatus() >= kStatusVerified;
1014 }
1015
Carl Shapiro69759ea2011-07-21 18:13:35 -07001016 // Returns true if the class has been linked.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001017 bool IsLinked() const {
1018 return GetStatus() >= kStatusResolved;
1019 }
1020
Carl Shapiro83ab4f32011-08-15 20:21:39 -07001021 // Returns true if the class has been loaded.
Carl Shapiro69759ea2011-07-21 18:13:35 -07001022 bool IsLoaded() const {
1023 return GetStatus() >= kStatusLoaded;
1024 }
1025
Carl Shapiro83ab4f32011-08-15 20:21:39 -07001026 // Returns true if the class is initialized.
1027 bool IsInitialized() const {
1028 return GetStatus() == kStatusInitialized;
1029 }
1030
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001031 // Returns true if this class is in the same packages as that class.
1032 bool IsInSamePackage(const Class* that) const;
1033
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001034 static bool IsInSamePackage(const String* descriptor1,
1035 const String* descriptor2);
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001036
1037 // Returns true if this class represents an array class.
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001038 bool IsArray() const;
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001039
1040 // Returns true if the class is an interface.
1041 bool IsInterface() const {
1042 return (access_flags_ & kAccInterface) != 0;
1043 }
1044
1045 // Returns true if the class is declared public.
1046 bool IsPublic() const {
1047 return (access_flags_ & kAccPublic) != 0;
1048 }
1049
1050 // Returns true if the class is declared final.
1051 bool IsFinal() const {
1052 return (access_flags_ & kAccFinal) != 0;
1053 }
1054
1055 // Returns true if the class is abstract.
1056 bool IsAbstract() const {
1057 return (access_flags_ & kAccAbstract) != 0;
1058 }
1059
1060 // Returns true if the class is an annotation.
1061 bool IsAnnotation() const {
1062 return (access_flags_ & kAccAnnotation) != 0;
1063 }
1064
1065 // Returns true if the class is a primitive type.
1066 bool IsPrimitive() const {
1067 return primitive_type_ != kPrimNot;
1068 }
1069
Brian Carlstromae3ac012011-07-27 01:30:28 -07001070 // Returns true if the class is synthetic.
1071 bool IsSynthetic() const {
1072 return (access_flags_ & kAccSynthetic) != 0;
1073 }
1074
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001075 // Returns true if this class can access that class.
1076 bool CanAccess(const Class* that) const {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001077 return that->IsPublic() || this->IsInSamePackage(that);
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001078 }
1079
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001080 // Returns the number of static, private, and constructor methods.
1081 size_t NumDirectMethods() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001082 return (direct_methods_ != NULL) ? direct_methods_->GetLength() : 0;
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001083 }
1084
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001085 Method* GetDirectMethod(int32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001086 DCHECK_NE(NumDirectMethods(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001087 return direct_methods_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001088 }
1089
1090 void SetDirectMethod(uint32_t i, Method* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001091 DCHECK_NE(NumDirectMethods(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001092 direct_methods_->Set(i, f);
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001093 }
1094
Carl Shapiro419ec7b2011-08-03 14:48:33 -07001095 Method* FindDeclaredDirectMethod(const StringPiece& name,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07001096 const StringPiece& signature);
Carl Shapiro419ec7b2011-08-03 14:48:33 -07001097
1098 Method* FindDirectMethod(const StringPiece& name,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07001099 const StringPiece& signature);
Carl Shapiro419ec7b2011-08-03 14:48:33 -07001100
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001101 // Returns the number of non-inherited virtual methods.
1102 size_t NumVirtualMethods() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001103 return (virtual_methods_ != NULL) ? virtual_methods_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001104 }
1105
1106 Method* GetVirtualMethod(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001107 DCHECK_NE(NumVirtualMethods(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001108 return virtual_methods_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001109 }
1110
1111 void SetVirtualMethod(uint32_t i, Method* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001112 DCHECK_NE(NumVirtualMethods(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001113 virtual_methods_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001114 }
1115
Brian Carlstrom30b94452011-08-25 21:35:26 -07001116 // Given a method implemented by this class but potentially from a
1117 // super class, return the specific implementation
1118 // method for this class.
1119 Method* FindVirtualMethodForVirtual(Method* method) {
1120 DCHECK(!method->GetDeclaringClass()->IsInterface());
1121 // The argument method may from a super class.
1122 // Use the index to a potentially overriden one for this instance's class.
1123 return vtable_->Get(method->method_index_);
1124 }
1125
1126 // Given a method implemented by this class, but potentially from a
1127 // super class or interface, return the specific implementation
1128 // method for this class.
1129 Method* FindVirtualMethodForInterface(Method* method);
1130
1131 Method* FindVirtualMethodForVirtualOrInterface(Method* method) {
1132 if (method->GetDeclaringClass()->IsInterface()) {
1133 return FindVirtualMethodForInterface(method);
1134 }
1135 return FindVirtualMethodForVirtual(method);
Elliott Hughes72025e52011-08-23 17:50:30 -07001136 }
1137
Carl Shapiro419ec7b2011-08-03 14:48:33 -07001138 Method* FindDeclaredVirtualMethod(const StringPiece& name,
1139 const StringPiece& descriptor);
1140
1141 Method* FindVirtualMethod(const StringPiece& name,
1142 const StringPiece& descriptor);
1143
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001144 size_t NumInstanceFields() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001145 return (ifields_ != NULL) ? ifields_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001146 }
1147
Carl Shapiro69759ea2011-07-21 18:13:35 -07001148 // Returns the number of instance fields containing reference types.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001149 size_t NumReferenceInstanceFields() const {
Carl Shapiro69759ea2011-07-21 18:13:35 -07001150 return num_reference_instance_fields_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001151 }
1152
Brian Carlstrom4873d462011-08-21 15:23:39 -07001153 // Returns the number of static fields containing reference types.
1154 size_t NumReferenceStaticFields() const {
1155 return num_reference_static_fields_;
1156 }
1157
Elliott Hughescdf53122011-08-19 15:46:09 -07001158 // Finds the given instance field in this class or a superclass.
1159 Field* FindInstanceField(const StringPiece& name,
1160 const StringPiece& descriptor);
1161
1162 Field* FindDeclaredInstanceField(const StringPiece& name,
1163 const StringPiece& descriptor);
1164
1165 // Finds the given static field in this class or a superclass.
1166 Field* FindStaticField(const StringPiece& name,
1167 const StringPiece& descriptor);
1168
1169 Field* FindDeclaredStaticField(const StringPiece& name,
1170 const StringPiece& descriptor);
1171
Jesse Wilson35baaab2011-08-10 16:18:03 -04001172 Field* GetInstanceField(uint32_t i) const { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001173 DCHECK_NE(NumInstanceFields(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001174 return ifields_->Get(i);
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001175 }
1176
Jesse Wilson35baaab2011-08-10 16:18:03 -04001177 void SetInstanceField(uint32_t i, Field* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001178 DCHECK_NE(NumInstanceFields(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001179 ifields_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001180 }
1181
1182 size_t NumStaticFields() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001183 return (sfields_ != NULL) ? sfields_->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001184 }
1185
Jesse Wilson35baaab2011-08-10 16:18:03 -04001186 Field* GetStaticField(uint32_t i) const { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001187 DCHECK_NE(NumStaticFields(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001188 return sfields_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001189 }
1190
Jesse Wilson35baaab2011-08-10 16:18:03 -04001191 void SetStaticField(uint32_t i, Field* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001192 DCHECK_NE(NumStaticFields(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001193 sfields_->Set(i, f);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001194 }
1195
Brian Carlstrom4873d462011-08-21 15:23:39 -07001196 uint32_t GetReferenceInstanceOffsets() const {
1197 return reference_instance_offsets_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001198 }
1199
Brian Carlstrom4873d462011-08-21 15:23:39 -07001200 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets) {
1201 reference_instance_offsets_ = new_reference_offsets;
1202 }
1203
1204 uint32_t GetReferenceStaticOffsets() const {
1205 return reference_static_offsets_;
1206 }
1207
1208 void SetReferenceStaticOffsets(uint32_t new_reference_offsets) {
1209 reference_static_offsets_ = new_reference_offsets;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001210 }
1211
Carl Shapiro69759ea2011-07-21 18:13:35 -07001212 size_t NumInterfaces() const {
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001213 return (interfaces_ != NULL) ? interfaces_->GetLength() : 0;
Carl Shapiro69759ea2011-07-21 18:13:35 -07001214 }
1215
1216 Class* GetInterface(uint32_t i) const {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001217 DCHECK_NE(NumInterfaces(), 0U);
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001218 return interfaces_->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001219 }
1220
1221 void SetInterface(uint32_t i, Class* f) { // TODO: uint16_t
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001222 DCHECK_NE(NumInterfaces(), 0U);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001223 interfaces_->Set(i, f);
Carl Shapiro69759ea2011-07-21 18:13:35 -07001224 }
1225
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001226 void SetVerifyErrorClass(Class* klass) {
1227 // Note SetFieldObject is used rather than verify_error_class_ directly for the barrier
1228 size_t field_offset = OFFSETOF_MEMBER(Class, verify_error_class_);
1229 klass->SetFieldObject(field_offset, klass);
1230 }
1231
1232 private:
1233 bool Implements(const Class* klass) const;
1234 bool IsArrayAssignableFromArray(const Class* klass) const;
1235 bool IsAssignableFromArray(const Class* klass) const;
1236 bool IsSubClass(const Class* klass) const;
1237
Ian Rogersb033c752011-07-20 12:22:35 -07001238 public: // TODO: private
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001239 // descriptor for the class such as "java.lang.Class" or "[C"
1240 String* name_; // TODO initialize
Carl Shapiro1fb86202011-06-27 17:43:13 -07001241
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001242 // descriptor for the class such as "Ljava/lang/Class;" or "[C"
1243 String* descriptor_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001244
1245 // access flags; low 16 bits are defined by VM spec
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001246 uint32_t access_flags_; // TODO: make an instance field?
Carl Shapiro1fb86202011-06-27 17:43:13 -07001247
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001248 // DexCache of resolved constant pool entries
Carl Shapiro1fb86202011-06-27 17:43:13 -07001249 // (will be NULL for VM-generated, e.g. arrays and primitive classes)
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001250 DexCache* dex_cache_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001251
1252 // state of class initialization
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001253 Status status_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001254
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001255 // If class verify fails, we must return same error on subsequent tries.
1256 // Update with SetVerifyErrorClass to ensure a write barrier is used.
1257 const Class* verify_error_class_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001258
1259 // threadId, used to check for recursive <clinit> invocation
1260 uint32_t clinit_thread_id_;
1261
1262 // Total object size; used when allocating storage on gc heap. (For
1263 // interfaces and abstract classes this will be zero.)
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001264 size_t object_size_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001265
1266 // For array classes, the class object for base element, for
1267 // instanceof/checkcast (for String[][][], this will be String).
1268 // Otherwise, NULL.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001269 Class* component_type_; // TODO: make an instance field
Carl Shapiro1fb86202011-06-27 17:43:13 -07001270
1271 // For array classes, the number of array dimensions, e.g. int[][]
1272 // is 2. Otherwise 0.
1273 int32_t array_rank_;
1274
1275 // primitive type index, or PRIM_NOT (-1); set for generated prim classes
1276 PrimitiveType primitive_type_;
1277
1278 // The superclass, or NULL if this is java.lang.Object or a
1279 // primitive type.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001280 Class* super_class_; // TODO: make an instance field
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07001281 uint32_t super_class_type_idx_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001282
1283 // defining class loader, or NULL for the "bootstrap" system loader
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07001284 const ClassLoader* class_loader_; // TODO: make an instance field
Carl Shapiro1fb86202011-06-27 17:43:13 -07001285
1286 // initiating class loader list
1287 // NOTE: for classes with low serialNumber, these are unused, and the
1288 // values are kept in a table in gDvm.
Ian Rogersb033c752011-07-20 12:22:35 -07001289 // InitiatingLoaderList initiating_loader_list_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001290
1291 // array of interfaces this class implements directly
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001292 ObjectArray<Class>* interfaces_;
Elliott Hughesc1674ed2011-08-25 18:09:09 -07001293 IntArray* interfaces_type_idx_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001294
1295 // static, private, and <init> methods
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001296 ObjectArray<Method>* direct_methods_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001297
1298 // virtual methods defined in this class; invoked through vtable
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001299 ObjectArray<Method>* virtual_methods_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001300
1301 // Virtual method table (vtable), for use by "invoke-virtual". The
1302 // vtable from the superclass is copied in, and virtual methods from
1303 // our class either replace those from the super or are appended.
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001304 ObjectArray<Method>* vtable_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001305
Brian Carlstrom30b94452011-08-25 21:35:26 -07001306 // Interface table (iftable_), one entry per interface supported by
Carl Shapiro1fb86202011-06-27 17:43:13 -07001307 // this class. That means one entry for each interface we support
1308 // directly, indirectly via superclass, or indirectly via
1309 // superinterface. This will be null if neither we nor our
1310 // superclass implement any interfaces.
1311 //
1312 // Why we need this: given "class Foo implements Face", declare
1313 // "Face faceObj = new Foo()". Invoke faceObj.blah(), where "blah"
1314 // is part of the Face interface. We can't easily use a single
1315 // vtable.
1316 //
1317 // For every interface a concrete class implements, we create a list
1318 // of virtualMethod indices for the methods in the interface.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001319 size_t iftable_count_;
Brian Carlstrom30b94452011-08-25 21:35:26 -07001320 // TODO convert to ObjectArray<?>
Carl Shapiro1fb86202011-06-27 17:43:13 -07001321 InterfaceEntry* iftable_;
1322
1323 // The interface vtable indices for iftable get stored here. By
1324 // placing them all in a single pool for each class that implements
1325 // interfaces, we decrease the number of allocations.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001326 size_t ifvi_pool_count_;
Brian Carlstrom30b94452011-08-25 21:35:26 -07001327 // TODO convert to IntArray
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001328 uint32_t* ifvi_pool_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001329
1330 // instance fields
1331 //
1332 // These describe the layout of the contents of a
1333 // DataObject-compatible Object. Note that only the fields directly
1334 // declared by this class are listed in ifields; fields declared by
Brian Carlstroma331b3c2011-07-18 17:47:56 -07001335 // a superclass are listed in the superclass's Class.ifields.
Carl Shapiro1fb86202011-06-27 17:43:13 -07001336 //
1337 // All instance fields that refer to objects are guaranteed to be at
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001338 // the beginning of the field list. num_reference_instance_fields_
1339 // specifies the number of reference fields.
Jesse Wilson35baaab2011-08-10 16:18:03 -04001340 ObjectArray<Field>* ifields_;
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001341
Brian Carlstrom4873d462011-08-21 15:23:39 -07001342 // number of instance fields that are object refs
Carl Shapiro69759ea2011-07-21 18:13:35 -07001343 size_t num_reference_instance_fields_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001344
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001345 // Bitmap of offsets of ifields.
Brian Carlstrom4873d462011-08-21 15:23:39 -07001346 uint32_t reference_instance_offsets_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001347
1348 // source file name, if known. Otherwise, NULL.
1349 const char* source_file_;
1350
Jesse Wilson7833bd22011-08-09 18:31:44 -04001351 // Static fields
Jesse Wilson35baaab2011-08-10 16:18:03 -04001352 ObjectArray<Field>* sfields_;
Jesse Wilson7833bd22011-08-09 18:31:44 -04001353
Brian Carlstrom4873d462011-08-21 15:23:39 -07001354 // number of static fields that are object refs
1355 size_t num_reference_static_fields_;
1356
1357 // Bitmap of offsets of sfields.
1358 uint32_t reference_static_offsets_;
1359
1360 // Total class size; used when allocating storage on gc heap.
1361 size_t class_size_;
1362
1363 // Location of first static field.
1364 uint32_t fields_[0];
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001365
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001366 private:
Carl Shapirof88c9522011-08-06 15:47:38 -07001367 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001368};
Elliott Hughes1f359b02011-07-17 14:27:17 -07001369std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001370
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001371inline bool Object::InstanceOf(const Class* klass) const {
Jesse Wilson14150742011-07-29 19:04:44 -04001372 DCHECK(klass != NULL);
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001373 DCHECK(klass_ != NULL);
1374 return klass->IsAssignableFrom(klass_);
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001375}
1376
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001377inline bool Object::IsClass() const {
Brian Carlstroma663ea52011-08-19 23:33:41 -07001378 Class* java_lang_Class = klass_->klass_;
1379 return klass_ == java_lang_Class;
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001380}
1381
Brian Carlstrom4873d462011-08-21 15:23:39 -07001382inline bool Object::IsClassClass() const {
1383 Class* java_lang_Class = klass_->klass_;
1384 return this == java_lang_Class;
1385}
1386
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001387inline bool Object::IsObjectArray() const {
1388 return IsArray() && !klass_->component_type_->IsPrimitive();
1389}
1390
1391inline bool Object::IsArray() const {
1392 return klass_->IsArray();
1393}
1394
Brian Carlstroma663ea52011-08-19 23:33:41 -07001395inline bool Object::IsField() const {
1396 Class* java_lang_Class = klass_->klass_;
1397 Class* java_lang_reflect_Field = java_lang_Class->GetInstanceField(0)->klass_;
1398 return klass_ == java_lang_reflect_Field;
1399}
1400
1401inline bool Object::IsMethod() const {
1402 Class* java_lang_Class = klass_->klass_;
1403 Class* java_lang_reflect_Method = java_lang_Class->GetDirectMethod(0)->klass_;
1404 return klass_ == java_lang_reflect_Method;
1405}
1406
Elliott Hughes04b63fd2011-08-16 09:40:10 -07001407inline size_t Object::SizeOf() const {
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001408 if (IsArray()) {
Elliott Hughes04b63fd2011-08-16 09:40:10 -07001409 return AsArray()->SizeOf();
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001410 }
Brian Carlstrom4873d462011-08-21 15:23:39 -07001411 if (IsClass()) {
1412 return AsClass()->SizeOf();
1413 }
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001414 return klass_->object_size_;
1415}
1416
Elliott Hughes04b63fd2011-08-16 09:40:10 -07001417inline size_t Array::SizeOf() const {
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001418 return SizeOf(GetLength(), klass_->GetComponentSize());
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001419}
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001420
Brian Carlstrom4873d462011-08-21 15:23:39 -07001421class ClassClass : public Class {
1422 private:
1423 // Padding to ensure the 64-bit serialVersionUID_ begins on a 8-byte boundary
1424 int32_t padding_;
1425 int64_t serialVersionUID_;
1426 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass);
1427};
1428
1429class StringClass : public Class {
1430 private:
1431 CharArray* ASCII_;
1432 Object* CASE_INSENSITIVE_ORDER_;
1433 uint32_t REPLACEMENT_CHAR_;
1434 int64_t serialVersionUID;
1435 DISALLOW_IMPLICIT_CONSTRUCTORS(StringClass);
1436};
1437
1438class FieldClass : public Class {
1439 private:
1440 Object* ORDER_BY_NAME_AND_DECLARING_CLASS_;
1441 uint32_t TYPE_BOOLEAN_;
1442 uint32_t TYPE_BYTE_;
1443 uint32_t TYPE_CHAR_;
1444 uint32_t TYPE_DOUBLE_;
1445 uint32_t TYPE_FLOAT_;
1446 uint32_t TYPE_INTEGER_;
1447 uint32_t TYPE_LONG_;
1448 uint32_t TYPE_SHORT_;
1449 DISALLOW_IMPLICIT_CONSTRUCTORS(FieldClass);
1450};
1451
1452class MethodClass : public Class {
1453 private:
1454 int32_t DECLARED_;
1455 int32_t PUBLIC_;
1456 DISALLOW_IMPLICIT_CONSTRUCTORS(MethodClass);
1457};
1458
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001459class DataObject : public Object {
1460 public:
Brian Carlstrom4873d462011-08-21 15:23:39 -07001461 // Location of first instance field.
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07001462 uint32_t fields_[0];
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001463 private:
Carl Shapirof88c9522011-08-06 15:47:38 -07001464 DISALLOW_IMPLICIT_CONSTRUCTORS(DataObject);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001465};
1466
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001467template<class T>
1468class PrimitiveArray : public Array {
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001469 public:
Elliott Hughes710a0cb2011-08-16 14:32:37 -07001470 typedef T ElementType;
1471
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001472 static PrimitiveArray<T>* Alloc(size_t length);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001473
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001474 const T* GetData() const {
1475 return reinterpret_cast<const T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001476 }
1477
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001478 T* GetData() {
1479 return reinterpret_cast<T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001480 }
1481
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001482 T Get(int32_t i) const {
Elliott Hughes289da822011-08-16 10:11:20 -07001483 if (!IsValidIndex(i)) {
Elliott Hughes710a0cb2011-08-16 14:32:37 -07001484 return T(0);
Elliott Hughes289da822011-08-16 10:11:20 -07001485 }
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001486 return GetData()[i];
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001487 }
1488
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001489 void Set(int32_t i, T value) {
Elliott Hughes289da822011-08-16 10:11:20 -07001490 // TODO: ArrayStoreException
1491 if (IsValidIndex(i)) {
1492 GetData()[i] = value;
1493 }
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001494 }
1495
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001496 static void SetArrayClass(Class* array_class) {
Brian Carlstroma663ea52011-08-19 23:33:41 -07001497 CHECK(array_class_ == NULL);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001498 CHECK(array_class != NULL);
1499 array_class_ = array_class;
1500 }
1501
Brian Carlstroma663ea52011-08-19 23:33:41 -07001502 static void ResetArrayClass() {
1503 CHECK(array_class_ != NULL);
1504 array_class_ = NULL;
1505 }
1506
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001507 private:
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001508 // Location of first element.
1509 T elements_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -07001510
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001511 static Class* array_class_;
1512
Carl Shapirof88c9522011-08-06 15:47:38 -07001513 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimitiveArray);
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001514};
Carl Shapiro5fafe2b2011-07-09 15:34:41 -07001515
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001516class String : public Object {
Carl Shapiro1fb86202011-06-27 17:43:13 -07001517 public:
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001518 const CharArray* GetCharArray() const {
Carl Shapirof88c9522011-08-06 15:47:38 -07001519 DCHECK(array_ != NULL);
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001520 return array_;
1521 }
1522
Carl Shapirof88c9522011-08-06 15:47:38 -07001523 uint32_t GetHashCode() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001524 return hash_code_;
1525 }
1526
Elliott Hughes814e4032011-08-23 12:07:56 -07001527 int32_t GetOffset() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001528 return offset_;
1529 }
1530
Elliott Hughes814e4032011-08-23 12:07:56 -07001531 int32_t GetLength() const {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001532 return count_;
1533 }
1534
Elliott Hughes814e4032011-08-23 12:07:56 -07001535 int32_t GetUtfLength() const {
1536 return CountUtf8Bytes(array_->GetData(), count_);
1537 }
1538
Elliott Hughesa5b897e2011-08-16 11:33:06 -07001539 // TODO: do we need this? Equals is the only caller, and could
1540 // bounds check itself.
Elliott Hughes289da822011-08-16 10:11:20 -07001541 uint16_t CharAt(int32_t index) const {
1542 if (index < 0 || index >= count_) {
Elliott Hughesa5b897e2011-08-16 11:33:06 -07001543 Thread* self = Thread::Current();
1544 self->ThrowNewException("Ljava/lang/StringIndexOutOfBoundsException;",
1545 "length=%i; index=%i", count_, index);
Elliott Hughes289da822011-08-16 10:11:20 -07001546 return 0;
Elliott Hughes289da822011-08-16 10:11:20 -07001547 }
Elliott Hughes710a0cb2011-08-16 14:32:37 -07001548 return GetCharArray()->Get(index + GetOffset());
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001549 }
1550
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001551 static String* AllocFromUtf16(int32_t utf16_length,
Brian Carlstroma663ea52011-08-19 23:33:41 -07001552 const uint16_t* utf16_data_in,
Elliott Hughes814e4032011-08-23 12:07:56 -07001553 int32_t hash_code = 0) {
Carl Shapirof88c9522011-08-06 15:47:38 -07001554 String* string = Alloc(GetJavaLangString(),
Carl Shapirof88c9522011-08-06 15:47:38 -07001555 utf16_length);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -07001556 // TODO: use 16-bit wide memset variant
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001557 for (int i = 0; i < utf16_length; i++ ) {
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001558 string->array_->Set(i, utf16_data_in[i]);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001559 }
Elliott Hughes814e4032011-08-23 12:07:56 -07001560 if (hash_code != 0) {
1561 string->hash_code_ = hash_code;
1562 } else {
1563 string->ComputeHashCode();
1564 }
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001565 return string;
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001566 }
1567
Elliott Hughesbfaadc82011-08-18 17:36:58 -07001568 static String* AllocFromModifiedUtf8(const char* utf) {
Elliott Hughes814e4032011-08-23 12:07:56 -07001569 size_t char_count = CountModifiedUtf8Chars(utf);
Elliott Hughesbfaadc82011-08-18 17:36:58 -07001570 return AllocFromModifiedUtf8(char_count, utf);
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001571 }
1572
Jesse Wilson8989d992011-08-02 13:39:42 -07001573 static String* AllocFromModifiedUtf8(int32_t utf16_length,
1574 const char* utf8_data_in) {
Elliott Hughesbfaadc82011-08-18 17:36:58 -07001575 String* string = Alloc(GetJavaLangString(), utf16_length);
1576 uint16_t* utf16_data_out = string->array_->GetData();
1577 ConvertModifiedUtf8ToUtf16(utf16_data_out, utf8_data_in);
1578 string->ComputeHashCode();
1579 return string;
Jesse Wilson8989d992011-08-02 13:39:42 -07001580 }
1581
Brian Carlstroma663ea52011-08-19 23:33:41 -07001582 static void SetClass(Class* java_lang_String);
1583 static void ResetClass();
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001584
Elliott Hughes814e4032011-08-23 12:07:56 -07001585 static String* Alloc(Class* java_lang_String, int32_t utf16_length) {
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001586 return Alloc(java_lang_String, CharArray::Alloc(utf16_length));
1587 }
1588
Elliott Hughes814e4032011-08-23 12:07:56 -07001589 static String* Alloc(Class* java_lang_String, CharArray* array) {
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001590 String* string = down_cast<String*>(java_lang_String->NewInstance());
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001591 string->array_ = array;
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001592 string->count_ = array->GetLength();
Brian Carlstrom0b138b22011-07-27 15:19:17 -07001593 return string;
1594 }
1595
Jesse Wilsonfd687c52011-08-04 19:27:35 -07001596 void ComputeHashCode() {
1597 hash_code_ = ComputeUtf16Hash(array_->GetData(), count_);
1598 }
1599
Elliott Hughesa5b897e2011-08-16 11:33:06 -07001600 // TODO: do we need this overload? give it a more intention-revealing name.
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001601 bool Equals(const char* modified_utf8) const {
Elliott Hughes814e4032011-08-23 12:07:56 -07001602 for (int32_t i = 0; i < GetLength(); ++i) {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001603 uint16_t ch = GetUtf16FromUtf8(&modified_utf8);
1604 if (ch == '\0' || ch != CharAt(i)) {
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001605 return false;
1606 }
1607 }
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001608 return *modified_utf8 == '\0';
Jesse Wilsoncbe9fc02011-07-29 18:59:50 -04001609 }
1610
Elliott Hughesa5b897e2011-08-16 11:33:06 -07001611 // TODO: do we need this overload? give it a more intention-revealing name.
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001612 bool Equals(const StringPiece& modified_utf8) const {
1613 // TODO: do not assume C-string representation.
1614 return Equals(modified_utf8.data());
1615 }
1616
1617 bool Equals(const String* that) const {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -07001618 // TODO: short circuit on hash_code_
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001619 if (this->GetLength() != that->GetLength()) {
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001620 return false;
1621 }
Elliott Hughes814e4032011-08-23 12:07:56 -07001622 for (int32_t i = 0; i < that->GetLength(); ++i) {
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001623 if (this->CharAt(i) != that->CharAt(i)) {
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001624 return false;
1625 }
1626 }
1627 return true;
1628 }
1629
Elliott Hughesa5b897e2011-08-16 11:33:06 -07001630 // TODO: do we need this overload? give it a more intention-revealing name.
Elliott Hughes814e4032011-08-23 12:07:56 -07001631 bool Equals(const uint16_t* that_chars, int32_t that_offset, int32_t that_length) const {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001632 if (this->GetLength() != that_length) {
1633 return false;
1634 }
Elliott Hughes814e4032011-08-23 12:07:56 -07001635 for (int32_t i = 0; i < that_length; ++i) {
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001636 if (this->CharAt(i) != that_chars[that_offset + i]) {
1637 return false;
1638 }
1639 }
1640 return true;
1641 }
1642
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001643 // Create a modified UTF-8 encoded std::string from a java/lang/String object.
1644 std::string ToModifiedUtf8() const {
Elliott Hughesb465ab02011-08-24 11:21:21 -07001645 uint16_t* chars = array_->GetData() + offset_;
1646 size_t byte_count(CountUtf8Bytes(chars, count_));
1647 std::string result(byte_count, char(0));
1648 ConvertUtf16ToModifiedUtf8(&result[0], chars, count_);
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001649 return result;
1650 }
1651
Brian Carlstroma7f4f482011-07-17 17:01:34 -07001652 private:
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001653 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
1654 CharArray* array_;
1655
Carl Shapirof88c9522011-08-06 15:47:38 -07001656 uint32_t hash_code_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001657
Elliott Hughes289da822011-08-16 10:11:20 -07001658 int32_t offset_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001659
Elliott Hughes289da822011-08-16 10:11:20 -07001660 int32_t count_;
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001661
1662 static Class* GetJavaLangString() {
1663 DCHECK(java_lang_String_ != NULL);
1664 return java_lang_String_;
1665 }
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07001666
1667 static Class* java_lang_String_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07001668
1669 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001670};
1671
Elliott Hughese5b0dc82011-08-23 09:59:02 -07001672class Throwable : public Object {
1673 private:
1674 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
1675 Throwable* cause_;
1676 String* detail_message_;
1677 Object* stack_state_; // Note this is Java volatile:
1678 Object* stack_trace_;
1679 Object* suppressed_exceptions_;
1680
1681 DISALLOW_IMPLICIT_CONSTRUCTORS(Throwable);
1682};
1683
Brian Carlstroma663ea52011-08-19 23:33:41 -07001684inline bool Object::IsString() const {
1685 // TODO use "klass_ == String::GetJavaLangString()" instead?
1686 return klass_ == klass_->descriptor_->klass_;
1687}
1688
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001689inline size_t Class::GetTypeSize(String* descriptor) {
1690 switch (descriptor->CharAt(0)) {
1691 case 'B': return 1; // byte
1692 case 'C': return 2; // char
1693 case 'D': return 8; // double
1694 case 'F': return 4; // float
1695 case 'I': return 4; // int
1696 case 'J': return 8; // long
1697 case 'S': return 2; // short
1698 case 'Z': return 1; // boolean
1699 case 'L': return sizeof(Object*);
1700 case '[': return sizeof(Array*);
1701 default:
1702 LOG(ERROR) << "Unknown type " << descriptor;
1703 return 0;
1704 }
1705}
1706
1707inline bool Class::IsArray() const {
1708 return GetDescriptor()->CharAt(0) == '['; // TODO: avoid parsing the descriptor
1709}
1710
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001711class InterfaceEntry {
Carl Shapiro1fb86202011-06-27 17:43:13 -07001712 public:
Brian Carlstrom30b94452011-08-25 21:35:26 -07001713 InterfaceEntry() : interface_(NULL), method_index_array_(NULL) {
Carl Shapirof88c9522011-08-06 15:47:38 -07001714 }
1715
Brian Carlstrom30b94452011-08-25 21:35:26 -07001716 Class* GetInterface() const {
1717 DCHECK(interface_ != NULL);
1718 return interface_;
Carl Shapirof88c9522011-08-06 15:47:38 -07001719 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001720
Brian Carlstrom30b94452011-08-25 21:35:26 -07001721 void SetInterface(Class* interface) {
1722 DCHECK(interface->IsInterface());
1723 interface_ = interface;
Carl Shapirof88c9522011-08-06 15:47:38 -07001724 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001725
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001726 private:
1727 // Points to the interface class.
Brian Carlstrom30b94452011-08-25 21:35:26 -07001728 Class* interface_;
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001729
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001730 public: // TODO: private
1731 // Index into array of vtable offsets. This points into the
Brian Carlstrom30b94452011-08-25 21:35:26 -07001732 // ifvi_pool_, which holds the vtables for all interfaces declared by
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001733 // this class.
1734 uint32_t* method_index_array_;
Carl Shapirof88c9522011-08-06 15:47:38 -07001735
1736 private:
1737 DISALLOW_COPY_AND_ASSIGN(InterfaceEntry);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001738};
1739
1740} // namespace art
1741
1742#endif // ART_SRC_OBJECT_H_