blob: 51d7b84172730bed91c7f86bfcd63b267f9243cd [file] [log] [blame]
Elliott Hughes1d3f1142011-09-13 12:00:00 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiro1fb86202011-06-27 17:43:13 -070016
17#ifndef ART_SRC_OBJECT_H_
18#define ART_SRC_OBJECT_H_
19
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070020#include <iosfwd>
Brian Carlstrom1f870082011-08-23 16:02:11 -070021#include <vector>
22
Elliott Hughes90a33692011-08-30 13:27:07 -070023#include "UniquePtr.h"
Elliott Hughes5ea047b2011-09-13 14:38:18 -070024#include "atomic.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070025#include "casts.h"
Elliott Hughes814e4032011-08-23 12:07:56 -070026#include "constants.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070027#include "globals.h"
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070028#include "heap.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070029#include "logging.h"
30#include "macros.h"
31#include "offsets.h"
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070032#include "runtime.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070033#include "stringpiece.h"
Brian Carlstrom1f870082011-08-23 16:02:11 -070034#include "thread.h"
Elliott Hughes814e4032011-08-23 12:07:56 -070035#include "utf.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -070036
37namespace art {
38
39class Array;
40class Class;
Brian Carlstrom1f870082011-08-23 16:02:11 -070041class ClassLoader;
Brian Carlstrom9cc262e2011-08-28 12:45:30 -070042class CodeAndDirectMethods;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070043class DexCache;
Jesse Wilson35baaab2011-08-10 16:18:03 -040044class Field;
Carl Shapiro1fb86202011-06-27 17:43:13 -070045class InterfaceEntry;
46class Monitor;
47class Method;
Carl Shapiro3ee755d2011-06-28 12:11:04 -070048class Object;
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070049class StaticStorageBase;
Jesse Wilson46cdd4b2011-07-28 17:40:48 -040050class String;
Brian Carlstrom4a96b602011-07-26 16:40:23 -070051template<class T> class ObjectArray;
Jesse Wilsonfd687c52011-08-04 19:27:35 -070052template<class T> class PrimitiveArray;
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070053typedef PrimitiveArray<uint8_t> BooleanArray;
54typedef PrimitiveArray<int8_t> ByteArray;
Jesse Wilsonfd687c52011-08-04 19:27:35 -070055typedef PrimitiveArray<uint16_t> CharArray;
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070056typedef PrimitiveArray<double> DoubleArray;
57typedef PrimitiveArray<float> FloatArray;
58typedef PrimitiveArray<int32_t> IntArray;
59typedef PrimitiveArray<int64_t> LongArray;
60typedef PrimitiveArray<int16_t> ShortArray;
Carl Shapiro1fb86202011-06-27 17:43:13 -070061
Carl Shapiro3ee755d2011-06-28 12:11:04 -070062union JValue {
63 uint8_t z;
64 int8_t b;
65 uint16_t c;
66 int16_t s;
67 int32_t i;
68 int64_t j;
69 float f;
70 double d;
71 Object* l;
72};
73
Brian Carlstrombe977852011-07-19 14:54:54 -070074static const uint32_t kAccPublic = 0x0001; // class, field, method, ic
75static const uint32_t kAccPrivate = 0x0002; // field, method, ic
76static const uint32_t kAccProtected = 0x0004; // field, method, ic
77static const uint32_t kAccStatic = 0x0008; // field, method, ic
78static const uint32_t kAccFinal = 0x0010; // class, field, method, ic
79static const uint32_t kAccSynchronized = 0x0020; // method (only allowed on natives)
80static const uint32_t kAccSuper = 0x0020; // class (not used in Dalvik)
81static const uint32_t kAccVolatile = 0x0040; // field
82static const uint32_t kAccBridge = 0x0040; // method (1.5)
83static const uint32_t kAccTransient = 0x0080; // field
84static const uint32_t kAccVarargs = 0x0080; // method (1.5)
85static const uint32_t kAccNative = 0x0100; // method
86static const uint32_t kAccInterface = 0x0200; // class, ic
87static const uint32_t kAccAbstract = 0x0400; // class, method, ic
88static const uint32_t kAccStrict = 0x0800; // method
89static const uint32_t kAccSynthetic = 0x1000; // field, method, ic
90static const uint32_t kAccAnnotation = 0x2000; // class, ic (1.5)
91static const uint32_t kAccEnum = 0x4000; // class, field, ic (1.5)
Carl Shapiro3ee755d2011-06-28 12:11:04 -070092
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070093static const uint32_t kAccMiranda = 0x8000; // method
94
Brian Carlstroma331b3c2011-07-18 17:47:56 -070095static const uint32_t kAccJavaFlagsMask = 0xffff; // bits set from Java sources (low 16)
96
Brian Carlstrombe977852011-07-19 14:54:54 -070097static const uint32_t kAccConstructor = 0x00010000; // method (Dalvik only)
98static const uint32_t kAccDeclaredSynchronized = 0x00020000; // method (Dalvik only)
jeffhaobdb76512011-09-07 11:43:16 -070099static const uint32_t kAccWritable = 0x80000000; // method (Dalvik only)
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700100
Brian Carlstrom1f870082011-08-23 16:02:11 -0700101static const uint32_t kAccClassFlagsMask = (kAccPublic
102 | kAccFinal
103 | kAccInterface
104 | kAccAbstract
105 | kAccSynthetic
106 | kAccAnnotation
107 | kAccEnum);
108static const uint32_t kAccInnerClassFlagsMask = (kAccClassFlagsMask
109 | kAccPrivate
110 | kAccProtected
111 | kAccStatic);
112static const uint32_t kAccFieldFlagsMask = (kAccPublic
113 | kAccPrivate
114 | kAccProtected
115 | kAccStatic
116 | kAccFinal
117 | kAccVolatile
118 | kAccTransient
119 | kAccSynthetic
120 | kAccEnum);
121static const uint32_t kAccMethodFlagsMask = (kAccPublic
122 | kAccPrivate
123 | kAccProtected
124 | kAccStatic
125 | kAccFinal
126 | kAccSynchronized
127 | kAccBridge
128 | kAccVarargs
129 | kAccNative
130 | kAccAbstract
131 | kAccStrict
132 | kAccSynthetic
133 | kAccConstructor
134 | kAccDeclaredSynchronized);
135
136// if only kAccClassIsReference is set, we have a soft reference
137static const uint32_t kAccClassIsReference = 0x8000000; // class is a soft/weak/phantom ref
138static const uint32_t kAccClassIsWeakReference = 0x4000000; // class is a weak reference
139static const uint32_t kAccClassIsFinalizerReference = 0x2000000; // class is a finalizer reference
140static const uint32_t kAccClassIsPhantomReference = 0x1000000; // class is a phantom reference
141
142static const uint32_t kAccReferenceFlagsMask = (kAccClassIsReference
143 | kAccClassIsWeakReference
144 | kAccClassIsFinalizerReference
145 | kAccClassIsPhantomReference);
146
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700147/*
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700148 * Definitions for packing refOffsets in Class.
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700149 */
150/*
151 * A magic value for refOffsets. Ignore the bits and walk the super
152 * chain when this is the value.
153 * [This is an unlikely "natural" value, since it would be 30 non-ref instance
154 * fields followed by 2 ref instance fields.]
155 */
156#define CLASS_WALK_SUPER ((unsigned int)(3))
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700157#define CLASS_BITS_PER_WORD (sizeof(unsigned long int) * 8)
158#define CLASS_OFFSET_ALIGNMENT 4
159#define CLASS_HIGH_BIT ((unsigned int)1 << (CLASS_BITS_PER_WORD - 1))
160/*
161 * Given an offset, return the bit number which would encode that offset.
162 * Local use only.
163 */
164#define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \
Brian Carlstrom693267a2011-09-06 09:25:34 -0700165 ((unsigned int)(byteOffset) / \
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700166 CLASS_OFFSET_ALIGNMENT)
167/*
168 * Is the given offset too large to be encoded?
169 */
170#define CLASS_CAN_ENCODE_OFFSET(byteOffset) \
171 (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD)
172/*
173 * Return a single bit, encoding the offset.
174 * Undefined if the offset is too large, as defined above.
175 */
176#define CLASS_BIT_FROM_OFFSET(byteOffset) \
177 (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset))
178/*
179 * Return an offset, given a bit number as returned from CLZ.
180 */
181#define CLASS_OFFSET_FROM_CLZ(rshift) \
Brian Carlstrom693267a2011-09-06 09:25:34 -0700182 MemberOffset((static_cast<int>(rshift) * CLASS_OFFSET_ALIGNMENT))
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700183
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700184#define OFFSET_OF_OBJECT_MEMBER(type, field) \
185 MemberOffset(OFFSETOF_MEMBER(type, field))
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700186
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -0700187// Classes shared with the managed side of the world need to be packed
188// so that they don't have extra platform specific padding.
Elliott Hughes85d15452011-09-16 17:33:01 -0700189#define MANAGED PACKED
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -0700190
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700191// C++ mirror of java.lang.Object
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -0700192class MANAGED Object {
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700193 public:
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700194 static MemberOffset ClassOffset() {
195 return OFFSET_OF_OBJECT_MEMBER(Object, klass_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700196 }
197
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700198 Class* GetClass() const {
Elliott Hughes5f791332011-09-15 17:45:30 -0700199 return GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(Object, klass_), false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700200 }
201
202 void SetClass(Class* new_klass);
203
Brian Carlstromf7ed11a2011-08-09 17:55:51 -0700204 bool InstanceOf(const Class* klass) const;
205
Elliott Hughes04b63fd2011-08-16 09:40:10 -0700206 size_t SizeOf() const;
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700207
Elliott Hughes081be7f2011-09-18 16:50:26 -0700208 Object* Clone();
Elliott Hughesbf86d042011-08-31 17:53:14 -0700209
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700210 static MemberOffset MonitorOffset() {
211 return OFFSET_OF_OBJECT_MEMBER(Object, monitor_);
212 }
213
Elliott Hughes5f791332011-09-15 17:45:30 -0700214 volatile int32_t* GetRawLockWordAddress() {
215 byte* raw_addr = reinterpret_cast<byte*>(this) + OFFSET_OF_OBJECT_MEMBER(Object, monitor_).Int32Value();
216 int32_t* word_addr = reinterpret_cast<int32_t*>(raw_addr);
217 return const_cast<volatile int32_t*>(word_addr);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700218 }
219
Elliott Hughes5f791332011-09-15 17:45:30 -0700220 uint32_t GetLockOwner();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700221
Elliott Hughes5f791332011-09-15 17:45:30 -0700222 void MonitorEnter(Thread* thread);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700223
Ian Rogersff1ed472011-09-20 13:46:24 -0700224 bool MonitorExit(Thread* thread);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700225
Elliott Hughes5f791332011-09-15 17:45:30 -0700226 void Notify();
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700227
Elliott Hughes5f791332011-09-15 17:45:30 -0700228 void NotifyAll();
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700229
Elliott Hughes5f791332011-09-15 17:45:30 -0700230 void Wait(int64_t timeout);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700231
Elliott Hughes5f791332011-09-15 17:45:30 -0700232 void Wait(int64_t timeout, int32_t nanos);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700233
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700234 bool IsClass() const;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700235
236 Class* AsClass() {
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700237 DCHECK(IsClass());
Carl Shapiro69759ea2011-07-21 18:13:35 -0700238 return down_cast<Class*>(this);
239 }
240
241 const Class* AsClass() const {
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700242 DCHECK(IsClass());
Carl Shapiro69759ea2011-07-21 18:13:35 -0700243 return down_cast<const Class*>(this);
244 }
245
Brian Carlstrom4873d462011-08-21 15:23:39 -0700246 bool IsClassClass() const;
247
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700248 bool IsObjectArray() const;
249
250 template<class T>
251 ObjectArray<T>* AsObjectArray() {
252 DCHECK(IsObjectArray());
253 return down_cast<ObjectArray<T>*>(this);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700254 }
255
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700256 template<class T>
257 const ObjectArray<T>* AsObjectArray() const {
258 DCHECK(IsObjectArray());
259 return down_cast<const ObjectArray<T>*>(this);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700260 }
261
Brian Carlstromb63ec392011-08-27 17:38:27 -0700262 bool IsArrayInstance() const;
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700263
264 Array* AsArray() {
Brian Carlstromb63ec392011-08-27 17:38:27 -0700265 DCHECK(IsArrayInstance());
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700266 return down_cast<Array*>(this);
267 }
268
269 const Array* AsArray() const {
Brian Carlstromb63ec392011-08-27 17:38:27 -0700270 DCHECK(IsArrayInstance());
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700271 return down_cast<const Array*>(this);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700272 }
273
Brian Carlstroma663ea52011-08-19 23:33:41 -0700274 bool IsString() const;
275
276 String* AsString() {
277 DCHECK(IsString());
278 return down_cast<String*>(this);
279 }
280
281 bool IsMethod() const;
282
283 Method* AsMethod() {
284 DCHECK(IsMethod());
285 return down_cast<Method*>(this);
286 }
287
Brian Carlstrom4873d462011-08-21 15:23:39 -0700288 const Method* AsMethod() const {
289 DCHECK(IsMethod());
290 return down_cast<const Method*>(this);
291 }
292
Brian Carlstroma663ea52011-08-19 23:33:41 -0700293 bool IsField() const;
294
295 Field* AsField() {
296 DCHECK(IsField());
297 return down_cast<Field*>(this);
298 }
299
Brian Carlstrom4873d462011-08-21 15:23:39 -0700300 const Field* AsField() const {
301 DCHECK(IsField());
302 return down_cast<const Field*>(this);
303 }
304
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700305 bool IsReferenceInstance() const;
306
307 bool IsWeakReferenceInstance() const;
308
309 bool IsSoftReferenceInstance() const;
310
311 bool IsFinalizerReferenceInstance() const;
312
313 bool IsPhantomReferenceInstance() const;
314
315 // Accessors for Java type fields
316 template<class T>
317 T GetFieldObject(MemberOffset field_offset, bool is_volatile) const {
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700318 DCHECK(Thread::Current() == NULL || Thread::Current()->CanAccessDirectReferences());
319 T result = reinterpret_cast<T>(GetField32(field_offset, is_volatile));
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700320 Heap::VerifyObject(result);
321 return result;
322 }
323
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700324 void SetFieldObject(MemberOffset field_offset, const Object* new_value, bool is_volatile, bool this_is_valid = true) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700325 Heap::VerifyObject(new_value);
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700326 SetField32(field_offset, reinterpret_cast<uint32_t>(new_value), is_volatile, this_is_valid);
327 if (new_value != NULL) {
328 Heap::WriteBarrier(this);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700329 }
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700330 }
331
332 uint32_t GetField32(MemberOffset field_offset, bool is_volatile) const {
333 Heap::VerifyObject(this);
Elliott Hughes1d3f1142011-09-13 12:00:00 -0700334 const byte* raw_addr = reinterpret_cast<const byte*>(this) + field_offset.Int32Value();
335 const int32_t* word_addr = reinterpret_cast<const int32_t*>(raw_addr);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700336 if (is_volatile) {
Elliott Hughes1d3f1142011-09-13 12:00:00 -0700337 return android_atomic_acquire_load(word_addr);
338 } else {
339 return *word_addr;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700340 }
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700341 }
342
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700343 void SetField32(MemberOffset field_offset, uint32_t new_value, bool is_volatile, bool this_is_valid = true) {
344 if (this_is_valid) {
345 Heap::VerifyObject(this);
346 }
347 byte* raw_addr = reinterpret_cast<byte*>(this) + field_offset.Int32Value();
Elliott Hughes1d3f1142011-09-13 12:00:00 -0700348 uint32_t* word_addr = reinterpret_cast<uint32_t*>(raw_addr);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700349 if (is_volatile) {
Elliott Hughes1d3f1142011-09-13 12:00:00 -0700350 /*
351 * TODO: add an android_atomic_synchronization_store() function and
352 * use it in the 32-bit volatile set handlers. On some platforms we
353 * can use a fast atomic instruction and avoid the barriers.
354 */
355 ANDROID_MEMBAR_STORE();
356 *word_addr = new_value;
357 ANDROID_MEMBAR_FULL();
358 } else {
359 *word_addr = new_value;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700360 }
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700361 }
362
363 uint64_t GetField64(MemberOffset field_offset, bool is_volatile) const {
364 Heap::VerifyObject(this);
Elliott Hughes1d3f1142011-09-13 12:00:00 -0700365 const byte* raw_addr = reinterpret_cast<const byte*>(this) + field_offset.Int32Value();
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700366 const int64_t* addr = reinterpret_cast<const int64_t*>(raw_addr);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700367 if (is_volatile) {
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700368 uint64_t result = QuasiAtomicRead64(addr);
369 ANDROID_MEMBAR_FULL();
370 return result;
371 } else {
372 return *addr;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700373 }
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700374 }
375
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700376 void SetField64(MemberOffset field_offset, uint64_t new_value, bool is_volatile) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700377 Heap::VerifyObject(this);
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700378 byte* raw_addr = reinterpret_cast<byte*>(this) + field_offset.Int32Value();
379 int64_t* addr = reinterpret_cast<int64_t*>(raw_addr);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700380 if (is_volatile) {
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700381 ANDROID_MEMBAR_STORE();
382 QuasiAtomicSwap64(new_value, addr);
383 // Post-store barrier not required due to use of atomic op or mutex.
384 } else {
385 *addr = new_value;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700386 }
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700387 }
388
389 protected:
390 // Accessors for non-Java type fields
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700391 template<class T>
392 T GetFieldPtr(MemberOffset field_offset, bool is_volatile) const {
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700393 return reinterpret_cast<T>(GetField32(field_offset, is_volatile));
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700394 }
395
396 template<typename T>
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700397 void SetFieldPtr(MemberOffset field_offset, T new_value, bool is_volatile) {
398 SetField32(field_offset, reinterpret_cast<uint32_t>(new_value), is_volatile);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700399 }
400
401 private:
Carl Shapiro1fb86202011-06-27 17:43:13 -0700402 Class* klass_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700403
Elliott Hughes5f791332011-09-15 17:45:30 -0700404 uint32_t monitor_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700405
Elliott Hughes5f791332011-09-15 17:45:30 -0700406 friend class ImageWriter; // for abusing monitor_ directly
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700407 friend struct ObjectOffsets; // for verifying offset information
Carl Shapirof88c9522011-08-06 15:47:38 -0700408 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700409};
410
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700411// C++ mirror of java.lang.reflect.AccessibleObject
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -0700412class MANAGED AccessibleObject : public Object {
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400413 private:
414 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700415 uint32_t java_flag_; // can accessibility checks be bypassed
Brian Carlstrom693267a2011-09-06 09:25:34 -0700416 friend struct AccessibleObjectOffsets; // for verifying offset information
417 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessibleObject);
Jesse Wilson46cdd4b2011-07-28 17:40:48 -0400418};
419
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700420// C++ mirror of java.lang.reflect.Field
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -0700421class MANAGED Field : public AccessibleObject {
Carl Shapiro3ee755d2011-06-28 12:11:04 -0700422 public:
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700423 Class* GetDeclaringClass() const;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700424
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700425 void SetDeclaringClass(Class *new_declaring_class);
426
427 const String* GetName() const;
428
429 void SetName(String* new_name);
430
431 uint32_t GetAccessFlags() const;
432
433 void SetAccessFlags(uint32_t new_access_flags) {
434 SetField32(OFFSET_OF_OBJECT_MEMBER(Field, access_flags_), new_access_flags,
435 false);
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700436 }
437
Elliott Hughes80609252011-09-23 17:24:51 -0700438 bool IsPublic() const {
439 return (GetAccessFlags() & kAccPublic) != 0;
440 }
441
Jesse Wilsonfd687c52011-08-04 19:27:35 -0700442 bool IsStatic() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700443 return (GetAccessFlags() & kAccStatic) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700444 }
445
jeffhaobdb76512011-09-07 11:43:16 -0700446 bool IsFinal() const {
Elliott Hughes80609252011-09-23 17:24:51 -0700447 return (GetAccessFlags() & kAccFinal) != 0;
jeffhaobdb76512011-09-07 11:43:16 -0700448 }
449
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700450 uint32_t GetTypeIdx() const;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700451
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700452 void SetTypeIdx(uint32_t type_idx);
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700453
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700454 // Gets type using type index and resolved types in the dex cache, may be null
455 // if type isn't yet resolved
456 Class* GetTypeDuringLinking() const;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700457
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700458 // Performs full resolution, may return null and set exceptions if type cannot
459 // be resolved
460 Class* GetType() const;
461
462 // Offset to field within an Object
463 MemberOffset GetOffset() const;
464
buzbee34cd9e52011-09-08 14:31:52 -0700465 static MemberOffset OffsetOffset() {
466 return MemberOffset(OFFSETOF_MEMBER(Field, offset_));
467 }
468
Brian Carlstrom845490b2011-09-19 15:56:53 -0700469 static Field* FindInstanceFieldFromCode(uint32_t field_idx, const Method* referrer);
470 static Field* FindStaticFieldFromCode(uint32_t field_idx, const Method* referrer);
471 static Field* FindFieldFromCode(uint32_t field_idx, const Method* referrer, bool is_static);
buzbee34cd9e52011-09-08 14:31:52 -0700472
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700473 MemberOffset GetOffsetDuringLinking() const;
474
475 void SetOffset(MemberOffset num_bytes);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700476
Brian Carlstrom4873d462011-08-21 15:23:39 -0700477 // field access, null object for static fields
478 bool GetBoolean(const Object* object) const;
479 void SetBoolean(Object* object, bool z) const;
480 int8_t GetByte(const Object* object) const;
481 void SetByte(Object* object, int8_t b) const;
482 uint16_t GetChar(const Object* object) const;
483 void SetChar(Object* object, uint16_t c) const;
484 uint16_t GetShort(const Object* object) const;
485 void SetShort(Object* object, uint16_t s) const;
486 int32_t GetInt(const Object* object) const;
487 void SetInt(Object* object, int32_t i) const;
488 int64_t GetLong(const Object* object) const;
489 void SetLong(Object* object, int64_t j) const;
490 float GetFloat(const Object* object) const;
491 void SetFloat(Object* object, float f) const;
492 double GetDouble(const Object* object) const;
493 void SetDouble(Object* object, double d) const;
494 Object* GetObject(const Object* object) const;
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700495 void SetObject(Object* object, const Object* l) const;
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700496
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700497 // Slow path routines for static field access when field was unresolved at
498 // compile time
499 static uint32_t Get32StaticFromCode(uint32_t field_idx,
500 const Method* referrer);
501 static void Set32StaticFromCode(uint32_t field_idx, const Method* referrer,
502 uint32_t new_value);
503 static uint64_t Get64StaticFromCode(uint32_t field_idx,
504 const Method* referrer);
505 static void Set64StaticFromCode(uint32_t field_idx, const Method* referrer,
506 uint64_t new_value);
507 static Object* GetObjStaticFromCode(uint32_t field_idx,
508 const Method* referrer);
509 static void SetObjStaticFromCode(uint32_t field_idx, const Method* referrer,
510 Object* new_value);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700511
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700512 static Class* GetJavaLangReflectField() {
513 DCHECK(java_lang_reflect_Field_ != NULL);
514 return java_lang_reflect_Field_;
515 }
516
517 static void SetClass(Class* java_lang_reflect_Field);
518 static void ResetClass();
519
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700520 bool IsVolatile() const {
521 return (GetAccessFlags() & kAccVolatile) != 0;
522 }
Brian Carlstrom4873d462011-08-21 15:23:39 -0700523
Elliott Hughes80609252011-09-23 17:24:51 -0700524 void InitJavaFields();
525
buzbee1da522d2011-09-04 11:22:20 -0700526 private:
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700527 // private implementation of field access using raw data
Brian Carlstrom4873d462011-08-21 15:23:39 -0700528 uint32_t Get32(const Object* object) const;
529 void Set32(Object* object, uint32_t new_value) const;
530 uint64_t Get64(const Object* object) const;
531 void Set64(Object* object, uint64_t new_value) const;
532 Object* GetObj(const Object* object) const;
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700533 void SetObj(Object* object, const Object* new_value) const;
Brian Carlstrom4873d462011-08-21 15:23:39 -0700534
Elliott Hughes80609252011-09-23 17:24:51 -0700535 void InitJavaFieldsLocked();
536
Jesse Wilson35baaab2011-08-10 16:18:03 -0400537 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Brian Carlstrom693267a2011-09-06 09:25:34 -0700538
Jesse Wilson35baaab2011-08-10 16:18:03 -0400539 // The class in which this field is declared.
540 Class* declaring_class_;
Brian Carlstrom693267a2011-09-06 09:25:34 -0700541
Jesse Wilson35baaab2011-08-10 16:18:03 -0400542 Object* generic_type_;
Brian Carlstrom693267a2011-09-06 09:25:34 -0700543
Brian Carlstromdbc05252011-09-09 01:59:59 -0700544 const String* name_;
545
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700546 // Type of the field
Elliott Hughes80609252011-09-23 17:24:51 -0700547 mutable Class* type_;
Jesse Wilson35baaab2011-08-10 16:18:03 -0400548
Brian Carlstromdbc05252011-09-09 01:59:59 -0700549 uint32_t generic_types_are_initialized_;
Brian Carlstrom693267a2011-09-06 09:25:34 -0700550
Jesse Wilson35baaab2011-08-10 16:18:03 -0400551 uint32_t access_flags_;
Brian Carlstrom693267a2011-09-06 09:25:34 -0700552
553 // Offset of field within an instance or in the Class' static fields
554 uint32_t offset_;
555
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700556 // Dex cache index of resolved type
557 uint32_t type_idx_;
Jesse Wilson35baaab2011-08-10 16:18:03 -0400558
Brian Carlstrom693267a2011-09-06 09:25:34 -0700559 int32_t slot_;
560
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700561 static Class* java_lang_reflect_Field_;
562
Brian Carlstrom693267a2011-09-06 09:25:34 -0700563 friend struct FieldOffsets; // for verifying offset information
Jesse Wilson35baaab2011-08-10 16:18:03 -0400564 DISALLOW_IMPLICIT_CONSTRUCTORS(Field);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700565};
566
Jesse Wilson6bf19152011-09-29 13:12:33 -0400567// C++ mirror of java.lang.reflect.Method and java.lang.reflect.Constructor
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -0700568class MANAGED Method : public AccessibleObject {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700569 public:
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700570 // An function that invokes a method with an array of its arguments.
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700571 typedef void InvokeStub(const Method* method,
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700572 Object* obj,
573 Thread* thread,
574 byte* args,
575 JValue* result);
576
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700577 Class* GetDeclaringClass() const;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700578
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700579 void SetDeclaringClass(Class *new_declaring_class);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700580
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700581 static MemberOffset DeclaringClassOffset() {
582 return MemberOffset(OFFSETOF_MEMBER(Method, declaring_class_));
Ian Rogersb033c752011-07-20 12:22:35 -0700583 }
584
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700585 // Returns the method name, e.g. "<init>" or "eatLunch"
586 const String* GetName() const;
587
588 void SetName(String* new_name);
589
jeffhaoe23d93c2011-09-15 14:48:43 -0700590 ByteArray* GetRegisterMapData() const;
591
jeffhaoa0a764a2011-09-16 10:43:38 -0700592 void SetRegisterMapData(ByteArray* data);
jeffhaoe23d93c2011-09-15 14:48:43 -0700593
594 ByteArray* GetRegisterMapHeader() const;
595
jeffhaoa0a764a2011-09-16 10:43:38 -0700596 void SetRegisterMapHeader(ByteArray* header);
jeffhaoe23d93c2011-09-15 14:48:43 -0700597
Brian Carlstrom2ed67392011-09-09 14:53:28 -0700598 String* GetShorty() const;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700599
Brian Carlstrom2ed67392011-09-09 14:53:28 -0700600 void SetShorty(String* new_shorty);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700601
602 const String* GetSignature() const;
603
604 void SetSignature(String* new_signature);
605
606 bool HasSameNameAndDescriptor(const Method* that) const;
607
608 uint32_t GetAccessFlags() const;
609
610 void SetAccessFlags(uint32_t new_access_flags) {
611 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, access_flags_), new_access_flags,
612 false);
613 }
614
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700615 // Returns true if the method is declared public.
616 bool IsPublic() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700617 return (GetAccessFlags() & kAccPublic) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700618 }
619
620 // Returns true if the method is declared private.
621 bool IsPrivate() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700622 return (GetAccessFlags() & kAccPrivate) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700623 }
624
625 // Returns true if the method is declared static.
626 bool IsStatic() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700627 return (GetAccessFlags() & kAccStatic) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700628 }
629
Brian Carlstrom1f870082011-08-23 16:02:11 -0700630 // Returns true if the method is a constructor.
631 bool IsConstructor() const {
632 return (access_flags_ & kAccConstructor) != 0;
633 }
634
635 // Returns true if the method is static, private, or a constructor.
636 bool IsDirect() const {
637 return IsStatic() || IsPrivate() || IsConstructor();
638 }
639
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700640 // Returns true if the method is declared synchronized.
641 bool IsSynchronized() const {
642 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700643 return (GetAccessFlags() & synchonized) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700644 }
645
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700646 bool IsFinal() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700647 return (GetAccessFlags() & kAccFinal) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700648 }
649
Elliott Hughes80609252011-09-23 17:24:51 -0700650 bool IsMiranda() const {
651 return (GetAccessFlags() & kAccMiranda) != 0;
652 }
653
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700654 bool IsNative() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700655 return (GetAccessFlags() & kAccNative) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700656 }
657
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700658 bool IsAbstract() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700659 return (GetAccessFlags() & kAccAbstract) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700660 }
661
662 bool IsSynthetic() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700663 return (GetAccessFlags() & kAccSynthetic) != 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700664 }
665
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700666 uint16_t GetMethodIndex() const;
667
668 size_t GetVtableIndex() const {
669 return GetMethodIndex();
670 }
671
672 void SetMethodIndex(uint16_t new_method_index) {
Elliott Hughes1d3f1142011-09-13 12:00:00 -0700673 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, method_index_),
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700674 new_method_index, false);
675 }
676
677 static MemberOffset MethodIndexOffset() {
678 return OFFSET_OF_OBJECT_MEMBER(Method, method_index_);
679 }
680
681 uint32_t GetCodeItemOffset() const {
682 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, code_item_offset_), false);
683 }
684
685 void SetCodeItemOffset(uint32_t new_code_off) {
686 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, code_item_offset_),
687 new_code_off, false);
688 }
689
690 // Number of 32bit registers that would be required to hold all the arguments
691 static size_t NumArgRegisters(const StringPiece& shorty);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700692
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700693 // Number of argument bytes required for densely packing the
694 // arguments into an array of arguments.
Brian Carlstrom4873d462011-08-21 15:23:39 -0700695 size_t NumArgArrayBytes() const;
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700696
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700697 uint16_t NumRegisters() const;
698
699 void SetNumRegisters(uint16_t new_num_registers) {
Elliott Hughes1d3f1142011-09-13 12:00:00 -0700700 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, num_registers_),
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700701 new_num_registers, false);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700702 }
703
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700704 uint16_t NumIns() const;
705
706 void SetNumIns(uint16_t new_num_ins) {
Elliott Hughes1d3f1142011-09-13 12:00:00 -0700707 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, num_ins_),
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700708 new_num_ins, false);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700709 }
710
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700711 uint16_t NumOuts() const;
Brian Carlstroma7f4f482011-07-17 17:01:34 -0700712
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700713 void SetNumOuts(uint16_t new_num_outs) {
Elliott Hughes1d3f1142011-09-13 12:00:00 -0700714 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, num_outs_),
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700715 new_num_outs, false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700716 }
717
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700718 uint32_t GetProtoIdx() const;
719
720 void SetProtoIdx(uint32_t new_proto_idx) {
721 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, proto_idx_), new_proto_idx, false);
Ian Rogersb033c752011-07-20 12:22:35 -0700722 }
723
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700724 ObjectArray<String>* GetDexCacheStrings() const;
725 void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings);
726
727 static MemberOffset DexCacheStringsOffset() {
728 return OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_strings_);
729 }
730
buzbee2a475e72011-09-07 17:19:17 -0700731 static MemberOffset DexCacheResolvedTypesOffset() {
732 return OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_types_);
733 }
734
buzbee34cd9e52011-09-08 14:31:52 -0700735 static MemberOffset DexCacheResolvedFieldsOffset() {
736 return OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_fields_);
737 }
738
buzbee1da522d2011-09-04 11:22:20 -0700739 static MemberOffset DexCacheInitializedStaticStorageOffset() {
740 return OFFSET_OF_OBJECT_MEMBER(Method,
741 dex_cache_initialized_static_storage_);
742 }
743
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700744 ObjectArray<Class>* GetDexCacheResolvedTypes() const;
745 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types);
746
747 ObjectArray<Method>* GetDexCacheResolvedMethods() const;
748 void SetDexCacheResolvedMethods(ObjectArray<Method>* new_dex_cache_methods);
749
750 ObjectArray<Field>* GetDexCacheResolvedFields() const;
751 void SetDexCacheResolvedFields(ObjectArray<Field>* new_dex_cache_fields);
752
753 CodeAndDirectMethods* GetDexCacheCodeAndDirectMethods() const;
754 void SetDexCacheCodeAndDirectMethods(CodeAndDirectMethods* new_value);
755
756 ObjectArray<StaticStorageBase>* GetDexCacheInitializedStaticStorage() const;
757 void SetDexCacheInitializedStaticStorage(ObjectArray<StaticStorageBase>* new_value);
758
759 void SetReturnTypeIdx(uint32_t new_return_type_idx);
760
761 Class* GetReturnType() const;
762
763 bool IsReturnAReference() const;
764
765 bool IsReturnAFloat() const;
766
767 bool IsReturnADouble() const;
768
Ian Rogersb033c752011-07-20 12:22:35 -0700769 bool IsReturnAFloatOrDouble() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700770 return IsReturnAFloat() || IsReturnADouble();
Ian Rogersb033c752011-07-20 12:22:35 -0700771 }
772
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700773 bool IsReturnALong() const;
Ian Rogersb033c752011-07-20 12:22:35 -0700774
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700775 bool IsReturnVoid() const;
Ian Rogers45a76cb2011-07-21 22:00:15 -0700776
Shih-wei Liao5381cf92011-07-27 00:28:04 -0700777 // "Args" may refer to any of the 3 levels of "Args."
778 // To avoid confusion, our code will denote which "Args" clearly:
779 // 1. UserArgs: Args that a user see.
780 // 2. Args: Logical JVM-level Args. E.g., the first in Args will be the
781 // receiver.
782 // 3. CConvArgs: Calling Convention Args, which is physical-level Args.
783 // E.g., the first in Args is Method* for both static and non-static
784 // methods. And CConvArgs doesn't deal with the receiver because
785 // receiver is hardwired in an implicit register, so CConvArgs doesn't
786 // need to deal with it.
787 //
788 // The number of Args that should be supplied to this method
Brian Carlstrom2ed67392011-09-09 14:53:28 -0700789 size_t NumArgs() const;
Ian Rogersb033c752011-07-20 12:22:35 -0700790
791 // The number of reference arguments to this method including implicit this
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700792 // pointer.
Ian Rogersb033c752011-07-20 12:22:35 -0700793 size_t NumReferenceArgs() const;
794
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700795 // The number of long or double arguments.
Ian Rogersb033c752011-07-20 12:22:35 -0700796 size_t NumLongOrDoubleArgs() const;
797
Ian Rogersb033c752011-07-20 12:22:35 -0700798 // Is the given method parameter a reference?
799 bool IsParamAReference(unsigned int param) const;
800
801 // Is the given method parameter a long or double?
802 bool IsParamALongOrDouble(unsigned int param) const;
803
Ian Rogersdf20fe02011-07-20 20:34:16 -0700804 // Size in bytes of the given parameter
805 size_t ParamSize(unsigned int param) const;
806
807 // Size in bytes of the return value
808 size_t ReturnSize() const;
Ian Rogersb033c752011-07-20 12:22:35 -0700809
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700810 void Invoke(Thread* self, Object* receiver, byte* args, JValue* result) const;
811
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700812 const ByteArray* GetCodeArray() const {
813 return GetFieldPtr<const ByteArray*>(OFFSET_OF_OBJECT_MEMBER(Method, code_array_), false);
814 }
815
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700816 const void* GetCode() const {
817 return GetFieldPtr<const void*>(OFFSET_OF_OBJECT_MEMBER(Method, code_), false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700818 }
819
buzbee4ef76522011-09-08 10:00:32 -0700820 void SetCode(ByteArray* code_array, InstructionSet instruction_set,
buzbeec41e5b52011-09-23 12:46:19 -0700821 IntArray* mapping_table = NULL, ShortArray* vmap_table = NULL);
buzbeec143c552011-08-20 17:38:58 -0700822
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700823 static MemberOffset GetCodeOffset() {
824 return OFFSET_OF_OBJECT_MEMBER(Method, code_);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700825 }
826
Ian Rogersbdb03912011-09-14 00:55:44 -0700827 // Is the given PC within the code array?
828 bool IsWithinCode(uintptr_t pc) const;
829
830 IntArray* GetMappingTable() const {
831 return GetFieldObject<IntArray*>(
832 OFFSET_OF_OBJECT_MEMBER(Method, mapping_table_), false);
833 }
834
buzbeec41e5b52011-09-23 12:46:19 -0700835 ShortArray* GetVMapTable() const {
Ian Rogersd6b1f612011-09-27 13:38:14 -0700836 return GetFieldObject<ShortArray*>(OFFSET_OF_OBJECT_MEMBER(Method, vmap_table_), false);
buzbeec41e5b52011-09-23 12:46:19 -0700837 }
838
Shih-wei Liaod11af152011-08-23 16:02:11 -0700839 size_t GetFrameSizeInBytes() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700840 DCHECK(sizeof(size_t) == sizeof(uint32_t));
841 size_t result = GetField32(
842 OFFSET_OF_OBJECT_MEMBER(Method, frame_size_in_bytes_), false);
843 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
844 return result;
845 }
846
847 void SetFrameSizeInBytes(size_t new_frame_size_in_bytes) {
848 DCHECK(sizeof(size_t) == sizeof(uint32_t));
849 DCHECK_LE(static_cast<size_t>(kStackAlignment), new_frame_size_in_bytes);
850 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, frame_size_in_bytes_),
851 new_frame_size_in_bytes, false);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700852 }
853
Shih-wei Liaod11af152011-08-23 16:02:11 -0700854 size_t GetReturnPcOffsetInBytes() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700855 DCHECK(sizeof(size_t) == sizeof(uint32_t));
856 return GetField32(
857 OFFSET_OF_OBJECT_MEMBER(Method, return_pc_offset_in_bytes_), false);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700858 }
859
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700860 void SetReturnPcOffsetInBytes(size_t return_pc_offset_in_bytes) {
861 DCHECK(sizeof(size_t) == sizeof(uint32_t));
862 DCHECK_LT(return_pc_offset_in_bytes, GetFrameSizeInBytes());
863 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, return_pc_offset_in_bytes_),
864 return_pc_offset_in_bytes, false);
buzbeec143c552011-08-20 17:38:58 -0700865 }
866
Brian Carlstrom16192862011-09-12 17:50:06 -0700867 bool IsRegistered();
Elliott Hughesd369bb72011-09-12 14:41:14 -0700868
Brian Carlstrom16192862011-09-12 17:50:06 -0700869 void RegisterNative(const void* native_method);
Ian Rogersb033c752011-07-20 12:22:35 -0700870
Brian Carlstrom16192862011-09-12 17:50:06 -0700871 void UnregisterNative();
Elliott Hughes5174fe62011-08-23 15:12:35 -0700872
Ian Rogersb033c752011-07-20 12:22:35 -0700873 static MemberOffset NativeMethodOffset() {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700874 return OFFSET_OF_OBJECT_MEMBER(Method, native_method_);
Ian Rogersb033c752011-07-20 12:22:35 -0700875 }
876
Brian Carlstrom78128a62011-09-15 17:21:19 -0700877 const void* GetNativeMethod() const {
878 return reinterpret_cast<const void*>(GetField32(NativeMethodOffset(), false));
879 }
880
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700881 ByteArray* GetInvokeStubArray() const {
882 ByteArray* result = GetFieldPtr<ByteArray*>(
883 OFFSET_OF_OBJECT_MEMBER(Method, invoke_stub_array_), false);
884 // TODO: DCHECK(result != NULL); should be ahead of time compiled
885 return result;
886 }
887
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700888 // Native to managed invocation stub entry point
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700889 InvokeStub* GetInvokeStub() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700890 InvokeStub* result = GetFieldPtr<InvokeStub*>(
891 OFFSET_OF_OBJECT_MEMBER(Method, invoke_stub_), false);
892 // TODO: DCHECK(result != NULL); should be ahead of time compiled
893 return result;
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700894 }
895
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700896 static MemberOffset GetInvokeStubOffset() {
897 return OFFSET_OF_OBJECT_MEMBER(Method, invoke_stub_);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700898 }
899
buzbee561227c2011-09-02 15:28:19 -0700900 static MemberOffset GetDexCacheCodeAndDirectMethodsOffset() {
901 return OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_code_and_direct_methods_);
902 }
903
904 static MemberOffset GetDexCacheResolvedMethodsOffset() {
905 return OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_methods_);
906 }
907
908 static MemberOffset GetMethodIndexOffset() {
909 return OFFSET_OF_OBJECT_MEMBER(Method, method_index_);
910 }
911
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700912 void SetInvokeStub(const ByteArray* invoke_stub_array);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700913
Ian Rogers90865722011-09-19 11:11:44 -0700914 uint32_t GetCoreSpillMask() const {
Ian Rogersbdb03912011-09-14 00:55:44 -0700915 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, core_spill_mask_), false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700916 }
Carl Shapiro8860c0e2011-08-04 17:36:16 -0700917
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700918 void SetCoreSpillMask(uint32_t core_spill_mask) {
919 // Computed during compilation
Elliott Hughes418d20f2011-09-22 14:00:39 -0700920 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, core_spill_mask_), core_spill_mask, false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700921 }
922
Ian Rogers90865722011-09-19 11:11:44 -0700923 uint32_t GetFpSpillMask() const {
Ian Rogersbdb03912011-09-14 00:55:44 -0700924 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, fp_spill_mask_), false);
925 }
926
927 void SetFpSpillMask(uint32_t fp_spill_mask) {
928 // Computed during compilation
Elliott Hughes418d20f2011-09-22 14:00:39 -0700929 SetField32(OFFSET_OF_OBJECT_MEMBER(Method, fp_spill_mask_), fp_spill_mask, false);
Ian Rogersbdb03912011-09-14 00:55:44 -0700930 }
931
Ian Rogers90865722011-09-19 11:11:44 -0700932 // Is this a hand crafted method used for something like describing callee saves?
933 bool IsPhony() const {
Ian Rogersff1ed472011-09-20 13:46:24 -0700934 bool result = this == Runtime::Current()->GetCalleeSaveMethod();
Ian Rogers90865722011-09-19 11:11:44 -0700935 // Check that if we do think it is phony it looks like the callee save method
936 DCHECK(!result || GetCoreSpillMask() != 0);
937 return result;
938 }
939
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700940 // Converts a native PC to a dex PC. TODO: this is a no-op
941 // until we associate a PC mapping table with each method.
Ian Rogersbdb03912011-09-14 00:55:44 -0700942 uint32_t ToDexPC(const uintptr_t pc) const;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700943
944 // Converts a dex PC to a native PC. TODO: this is a no-op
945 // until we associate a PC mapping table with each method.
Ian Rogersbdb03912011-09-14 00:55:44 -0700946 uintptr_t ToNativePC(const uint32_t dex_pc) const;
947
948 // Find the catch block for the given exception type and dex_pc
949 uint32_t FindCatchBlock(Class* exception_type, uint32_t dex_pc) const;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700950
Elliott Hughes80609252011-09-23 17:24:51 -0700951 static void SetClasses(Class* java_lang_reflect_Constructor, Class* java_lang_reflect_Method);
952
953 static Class* GetConstructorClass() {
954 return java_lang_reflect_Constructor_;
955 }
956
957 static Class* GetMethodClass() {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700958 return java_lang_reflect_Method_;
959 }
960
Elliott Hughes80609252011-09-23 17:24:51 -0700961 static void ResetClasses();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700962
Elliott Hughes418d20f2011-09-22 14:00:39 -0700963 void InitJavaFields();
964
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700965 private:
966 uint32_t GetReturnTypeIdx() const;
Elliott Hughes418d20f2011-09-22 14:00:39 -0700967 void InitJavaFieldsLocked();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700968
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700969 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
970 // the class we are a part of
971 Class* declaring_class_;
Elliott Hughes418d20f2011-09-22 14:00:39 -0700972 ObjectArray<Class>* java_exception_types_; // TODO
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700973 Object* java_formal_type_parameters_;
974 Object* java_generic_exception_types_;
975 Object* java_generic_parameter_types_;
976 Object* java_generic_return_type_;
buzbeec143c552011-08-20 17:38:58 -0700977
Brian Carlstrom693267a2011-09-06 09:25:34 -0700978 String* name_;
979
Elliott Hughes418d20f2011-09-22 14:00:39 -0700980 // Initialized by InitJavaFields.
Brian Carlstrom693267a2011-09-06 09:25:34 -0700981 ObjectArray<Class>* java_parameter_types_;
Elliott Hughes418d20f2011-09-22 14:00:39 -0700982 Class* java_return_type_;
Brian Carlstrom693267a2011-09-06 09:25:34 -0700983
Brian Carlstrom693267a2011-09-06 09:25:34 -0700984 // Storage for code_
985 const ByteArray* code_array_;
986
987 // short cuts to declaring_class_->dex_cache_ member for fast compiled code access
Brian Carlstrom693267a2011-09-06 09:25:34 -0700988 CodeAndDirectMethods* dex_cache_code_and_direct_methods_;
989
990 // short cuts to declaring_class_->dex_cache_ member for fast compiled code access
991 ObjectArray<StaticStorageBase>* dex_cache_initialized_static_storage_;
992
993 // short cuts to declaring_class_->dex_cache_ member for fast compiled code access
994 ObjectArray<Field>* dex_cache_resolved_fields_;
995
996 // short cuts to declaring_class_->dex_cache_ member for fast compiled code access
997 ObjectArray<Method>* dex_cache_resolved_methods_;
998
Brian Carlstromdbc05252011-09-09 01:59:59 -0700999 // short cuts to declaring_class_->dex_cache_ member for fast compiled code access
1000 ObjectArray<Class>* dex_cache_resolved_types_;
1001
1002 // short cuts to declaring_class_->dex_cache_ member for fast compiled code access
1003 ObjectArray<String>* dex_cache_strings_;
1004
1005 // Storage for invoke_stub_
1006 const ByteArray* invoke_stub_array_;
1007
1008 // Storage for mapping_table_
Ian Rogersbdb03912011-09-14 00:55:44 -07001009 IntArray* mapping_table_;
Brian Carlstromdbc05252011-09-09 01:59:59 -07001010
jeffhaoe23d93c2011-09-15 14:48:43 -07001011 // Byte arrays that hold data for the register maps
1012 const ByteArray* register_map_data_;
1013 const ByteArray* register_map_header_;
1014
Brian Carlstrom2ed67392011-09-09 14:53:28 -07001015 // The short-form method descriptor string.
1016 String* shorty_;
1017
Brian Carlstromdbc05252011-09-09 01:59:59 -07001018 // The method descriptor. This represents the parameters a method
1019 // takes and value it returns. This string is a list of the type
1020 // descriptors for the parameters enclosed in parenthesis followed
1021 // by the return type descriptor. For example, for the method
1022 //
1023 // Object mymethod(int i, double d, Thread t)
1024 //
1025 // the method descriptor would be
1026 //
1027 // (IDLjava/lang/Thread;)Ljava/lang/Object;
1028 String* signature_;
1029
buzbeec41e5b52011-09-23 12:46:19 -07001030 // Storage for Dalvik virtual register mapping_table_
1031 ShortArray* vmap_table_;
1032
Brian Carlstromdbc05252011-09-09 01:59:59 -07001033 uint32_t java_generic_types_are_initialized_;
1034
Elliott Hughes1d3f1142011-09-13 12:00:00 -07001035 // Access flags; low 16 bits are defined by spec.
Brian Carlstromdbc05252011-09-09 01:59:59 -07001036 uint32_t access_flags_;
1037
1038 // Compiled code associated with this method for callers from managed code.
1039 // May be compiled managed code or a bridge for invoking a native method.
1040 const void* code_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001041
Shih-wei Liao2fb97532011-08-11 16:17:23 -07001042 // Offset to the CodeItem.
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001043 uint32_t code_item_offset_;
Shih-wei Liao2fb97532011-08-11 16:17:23 -07001044
Brian Carlstrom693267a2011-09-06 09:25:34 -07001045 // Architecture-dependent register spill mask
Brian Carlstromdbc05252011-09-09 01:59:59 -07001046 uint32_t core_spill_mask_;
1047
1048 // Architecture-dependent register spill mask
Brian Carlstrom693267a2011-09-06 09:25:34 -07001049 uint32_t fp_spill_mask_;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001050
Brian Carlstrom693267a2011-09-06 09:25:34 -07001051 // Total size in bytes of the frame
1052 size_t frame_size_in_bytes_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001053
Brian Carlstrom693267a2011-09-06 09:25:34 -07001054 // Native invocation stub entry point for calling from native to managed code.
1055 const InvokeStub* invoke_stub_;
buzbee4ef76522011-09-08 10:00:32 -07001056
Brian Carlstrom693267a2011-09-06 09:25:34 -07001057 // Index of the return type
1058 uint32_t java_return_type_idx_;
1059
Brian Carlstrom693267a2011-09-06 09:25:34 -07001060 // For concrete virtual methods, this is the offset of the method
1061 // in Class::vtable_.
1062 //
1063 // For abstract methods in an interface class, this is the offset
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07001064 // of the method in "iftable_->Get(n)->GetMethodArray()".
Elliott Hughes1d3f1142011-09-13 12:00:00 -07001065 uint32_t method_index_;
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -07001066
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -07001067 // The target native method registered with this method
Ian Rogersb033c752011-07-20 12:22:35 -07001068 const void* native_method_;
Carl Shapirof88c9522011-08-06 15:47:38 -07001069
Brian Carlstrom693267a2011-09-06 09:25:34 -07001070 // Method bounds; not needed for an abstract method.
1071 //
1072 // For a native method, we compute the size of the argument list, and
1073 // set "insSize" and "registerSize" equal to it.
Elliott Hughes1d3f1142011-09-13 12:00:00 -07001074 uint32_t num_ins_;
1075 uint32_t num_outs_;
1076 uint32_t num_registers_; // ins + locals
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -07001077
Brian Carlstrom693267a2011-09-06 09:25:34 -07001078 // Method prototype descriptor string (return and argument types).
1079 uint32_t proto_idx_;
1080
1081 // Offset of return PC within frame for compiled code (in bytes)
1082 size_t return_pc_offset_in_bytes_;
1083
Brian Carlstrom693267a2011-09-06 09:25:34 -07001084 uint32_t java_slot_;
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001085
Elliott Hughes80609252011-09-23 17:24:51 -07001086 static Class* java_lang_reflect_Constructor_;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001087 static Class* java_lang_reflect_Method_;
1088
Brian Carlstrom693267a2011-09-06 09:25:34 -07001089 friend class ImageWriter; // for relocating code_ and invoke_stub_
1090 friend struct MethodOffsets; // for verifying offset information
Carl Shapirof88c9522011-08-06 15:47:38 -07001091 DISALLOW_IMPLICIT_CONSTRUCTORS(Method);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001092};
1093
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07001094class MANAGED Array : public Object {
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001095 public:
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001096 static size_t SizeOf(size_t component_count,
1097 size_t component_size) {
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001098 return sizeof(Array) + component_count * component_size;
1099 }
Elliott Hughes04b63fd2011-08-16 09:40:10 -07001100
Elliott Hughes68f4fa02011-08-21 10:46:59 -07001101 // A convenience for code that doesn't know the component size,
1102 // and doesn't want to have to work it out itself.
Brian Carlstromb63ec392011-08-27 17:38:27 -07001103 static Array* Alloc(Class* array_class, int32_t component_count);
Elliott Hughes68f4fa02011-08-21 10:46:59 -07001104
Brian Carlstromb63ec392011-08-27 17:38:27 -07001105 static Array* Alloc(Class* array_class, int32_t component_count, size_t component_size);
Carl Shapirof88c9522011-08-06 15:47:38 -07001106
Elliott Hughes04b63fd2011-08-16 09:40:10 -07001107 size_t SizeOf() const;
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001108
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001109 int32_t GetLength() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001110 return GetField32(OFFSET_OF_OBJECT_MEMBER(Array, length_), false);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001111 }
Carl Shapirof88c9522011-08-06 15:47:38 -07001112
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001113 void SetLength(int32_t length) {
Elliott Hughes0f4c41d2011-09-04 14:58:03 -07001114 CHECK_GE(length, 0);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001115 SetField32(OFFSET_OF_OBJECT_MEMBER(Array, length_), length, false);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001116 }
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001117
buzbeec143c552011-08-20 17:38:58 -07001118 static MemberOffset LengthOffset() {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001119 return OFFSET_OF_OBJECT_MEMBER(Array, length_);
buzbeec143c552011-08-20 17:38:58 -07001120 }
1121
1122 static MemberOffset DataOffset() {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001123 return OFFSET_OF_OBJECT_MEMBER(Array, first_element_);
buzbeec143c552011-08-20 17:38:58 -07001124 }
1125
Elliott Hughesbf86d042011-08-31 17:53:14 -07001126 void* GetRawData() {
1127 return reinterpret_cast<void*>(first_element_);
1128 }
1129
Elliott Hughes289da822011-08-16 10:11:20 -07001130 protected:
1131 bool IsValidIndex(int32_t index) const {
1132 if (index < 0 || index >= length_) {
Elliott Hughes80609252011-09-23 17:24:51 -07001133 return ThrowArrayIndexOutOfBoundsException(index);
Elliott Hughes289da822011-08-16 10:11:20 -07001134 }
1135 return true;
1136 }
1137
Elliott Hughes80609252011-09-23 17:24:51 -07001138 protected:
1139 bool ThrowArrayIndexOutOfBoundsException(int32_t index) const;
1140 bool ThrowArrayStoreException(Object* object) const;
1141
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001142 private:
1143 // The number of array elements.
Elliott Hughes289da822011-08-16 10:11:20 -07001144 int32_t length_;
Jesse Wilsondf4189c2011-08-09 17:10:28 -04001145 // Padding to ensure the first member defined by a subclass begins on a 8-byte boundary
1146 int32_t padding_;
buzbeec143c552011-08-20 17:38:58 -07001147 // Marker for the data (used by generated code)
1148 uint32_t first_element_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -07001149
Carl Shapirof88c9522011-08-06 15:47:38 -07001150 DISALLOW_IMPLICIT_CONSTRUCTORS(Array);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001151};
1152
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001153template<class T>
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07001154class MANAGED ObjectArray : public Array {
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001155 public:
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001156 static ObjectArray<T>* Alloc(Class* object_array_class, int32_t length);
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07001157
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001158 T* Get(int32_t i) const;
Jesse Wilsondf4189c2011-08-09 17:10:28 -04001159
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001160 void Set(int32_t i, T* object);
Jesse Wilsondf4189c2011-08-09 17:10:28 -04001161
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001162 // Set element without bound and element type checks, to be used in limited
1163 // circumstances, such as during boot image writing
1164 void SetWithoutChecks(int32_t i, T* object);
Carl Shapirof88c9522011-08-06 15:47:38 -07001165
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001166 static void Copy(const ObjectArray<T>* src, int src_pos,
Carl Shapirof88c9522011-08-06 15:47:38 -07001167 ObjectArray<T>* dst, int dst_pos,
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001168 size_t length);
Carl Shapirof88c9522011-08-06 15:47:38 -07001169
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001170 ObjectArray<T>* CopyOf(int32_t new_length);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001171
1172 private:
Carl Shapirof88c9522011-08-06 15:47:38 -07001173 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001174};
1175
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001176template<class T>
1177ObjectArray<T>* ObjectArray<T>::Alloc(Class* object_array_class, int32_t length) {
1178 return Array::Alloc(object_array_class, length, sizeof(uint32_t))->AsObjectArray<T>();
1179}
1180
1181template<class T>
1182T* ObjectArray<T>::Get(int32_t i) const {
1183 if (!IsValidIndex(i)) {
1184 return NULL;
1185 }
1186 MemberOffset data_offset(DataOffset().Int32Value() + i * sizeof(Object*));
1187 return GetFieldObject<T*>(data_offset, false);
1188}
1189
1190template<class T>
1191ObjectArray<T>* ObjectArray<T>::CopyOf(int32_t new_length) {
1192 ObjectArray<T>* new_array = Alloc(GetClass(), new_length);
1193 Copy(this, 0, new_array, 0, std::min(GetLength(), new_length));
1194 return new_array;
1195}
1196
Brian Carlstrom1caa2c22011-08-28 13:02:33 -07001197// Type for the InitializedStaticStorage table. Currently the Class
Brian Carlstrom848a4b32011-09-04 11:29:27 -07001198// provides the static storage. However, this might change to an Array
1199// to improve image sharing, so we use this type to avoid assumptions
1200// on the current storage.
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07001201class MANAGED StaticStorageBase : public Object {};
Brian Carlstrom1caa2c22011-08-28 13:02:33 -07001202
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001203// C++ mirror of java.lang.Class
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07001204class MANAGED Class : public StaticStorageBase {
Carl Shapiro1fb86202011-06-27 17:43:13 -07001205 public:
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001206
1207 // Class Status
1208 //
1209 // kStatusNotReady: If a Class cannot be found in the class table by
1210 // FindClass, it allocates an new one with AllocClass in the
1211 // kStatusNotReady and calls LoadClass. Note if it does find a
1212 // class, it may not be kStatusResolved and it will try to push it
1213 // forward toward kStatusResolved.
1214 //
1215 // kStatusIdx: LoadClass populates with Class with information from
1216 // the DexFile, moving the status to kStatusIdx, indicating that the
1217 // Class values in super_class_ and interfaces_ have not been
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07001218 // populated based on super_class_type_idx_ and
1219 // interfaces_type_idx_. The new Class can then be inserted into the
1220 // classes table.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001221 //
1222 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
1223 // attempt to move a kStatusIdx class forward to kStatusLoaded by
1224 // using ResolveClass to initialize the super_class_ and interfaces_.
1225 //
1226 // kStatusResolved: Still holding the lock on Class, the ClassLinker
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001227 // shows linking is complete and fields of the Class populated by making
1228 // it kStatusResolved. Java allows circularities of the form where a super
1229 // class has a field that is of the type of the sub class. We need to be able
1230 // to fully resolve super classes while resolving types for fields.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -07001231
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001232 enum Status {
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001233 kStatusError = -1,
1234 kStatusNotReady = 0,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07001235 kStatusIdx = 1, // loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001236 kStatusLoaded = 2, // DEX idx values resolved
1237 kStatusResolved = 3, // part of linking
1238 kStatusVerifying = 4, // in the process of being verified
1239 kStatusVerified = 5, // logically part of linking; done pre-init
1240 kStatusInitializing = 6, // class init in progress
1241 kStatusInitialized = 7, // ready to go
Carl Shapiro1fb86202011-06-27 17:43:13 -07001242 };
1243
1244 enum PrimitiveType {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001245 kPrimNot = 0,
1246 kPrimBoolean,
1247 kPrimByte,
1248 kPrimChar,
1249 kPrimShort,
1250 kPrimInt,
1251 kPrimLong,
1252 kPrimFloat,
1253 kPrimDouble,
1254 kPrimVoid,
Carl Shapiro1fb86202011-06-27 17:43:13 -07001255 };
1256
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001257 Status GetStatus() const {
1258 CHECK(sizeof(Status) == sizeof(uint32_t));
1259 return static_cast<Status>(
1260 GetField32(OFFSET_OF_OBJECT_MEMBER(Class, status_), false));
1261 }
1262
1263 void SetStatus(Status new_status);
1264
1265 // Returns true if the class has failed to link.
1266 bool IsErroneous() const {
1267 return GetStatus() == kStatusError;
1268 }
1269
1270 // Returns true if the class has been loaded.
1271 bool IsIdxLoaded() const {
1272 return GetStatus() >= kStatusIdx;
1273 }
1274
1275 // Returns true if the class has been loaded.
1276 bool IsLoaded() const {
1277 return GetStatus() >= kStatusLoaded;
1278 }
1279
1280 // Returns true if the class has been linked.
Elliott Hughes5fe594f2011-09-08 12:33:17 -07001281 bool IsResolved() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001282 return GetStatus() >= kStatusResolved;
1283 }
1284
1285 // Returns true if the class has been verified.
1286 bool IsVerified() const {
1287 return GetStatus() >= kStatusVerified;
1288 }
1289
Brian Carlstrom5d40f182011-09-26 22:29:18 -07001290 // Returns true if the class is initializing.
1291 bool IsInitializing() const {
1292 return GetStatus() >= kStatusInitializing;
1293 }
1294
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001295 // Returns true if the class is initialized.
1296 bool IsInitialized() const {
1297 return GetStatus() == kStatusInitialized;
1298 }
1299
1300 uint32_t GetAccessFlags() const;
1301
1302 void SetAccessFlags(uint32_t new_access_flags) {
1303 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), new_access_flags,
1304 false);
1305 }
1306
1307 // Returns true if the class is an interface.
1308 bool IsInterface() const {
1309 return (GetAccessFlags() & kAccInterface) != 0;
1310 }
1311
1312 // Returns true if the class is declared public.
1313 bool IsPublic() const {
1314 return (GetAccessFlags() & kAccPublic) != 0;
1315 }
1316
1317 // Returns true if the class is declared final.
1318 bool IsFinal() const {
1319 return (GetAccessFlags() & kAccFinal) != 0;
1320 }
1321
1322 // Returns true if the class is abstract.
1323 bool IsAbstract() const {
1324 return (GetAccessFlags() & kAccAbstract) != 0;
1325 }
1326
1327 // Returns true if the class is an annotation.
1328 bool IsAnnotation() const {
1329 return (GetAccessFlags() & kAccAnnotation) != 0;
1330 }
1331
1332 // Returns true if the class is synthetic.
1333 bool IsSynthetic() const {
1334 return (GetAccessFlags() & kAccSynthetic) != 0;
1335 }
1336
1337 bool IsReferenceClass() const {
1338 return (GetAccessFlags() & kAccClassIsReference) != 0;
1339 }
1340
1341 bool IsWeakReferenceClass() const {
1342 return (GetAccessFlags() & kAccClassIsWeakReference) != 0;
1343 }
1344
1345 bool IsSoftReferenceClass() const {
1346 return (GetAccessFlags() & ~kAccReferenceFlagsMask) == kAccClassIsReference;
1347 }
1348
1349 bool IsFinalizerReferenceClass() const {
1350 return (GetAccessFlags() & kAccClassIsFinalizerReference) != 0;
1351 }
1352
1353 bool IsPhantomReferenceClass() const {
1354 return (GetAccessFlags() & kAccClassIsPhantomReference) != 0;
1355 }
1356
1357 PrimitiveType GetPrimitiveType() const {
1358 CHECK(sizeof(PrimitiveType) == sizeof(int32_t));
1359 return static_cast<PrimitiveType>(
1360 GetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), false));
1361 }
1362
1363 void SetPrimitiveType(PrimitiveType new_type) {
1364 CHECK(sizeof(PrimitiveType) == sizeof(int32_t));
1365 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), new_type,
1366 false);
1367 }
1368
1369 // Returns true if the class is a primitive type.
1370 bool IsPrimitive() const {
1371 return GetPrimitiveType() != kPrimNot;
1372 }
1373
1374 bool IsPrimitiveBoolean() const {
1375 return GetPrimitiveType() == kPrimBoolean;
1376 }
1377
1378 bool IsPrimitiveByte() const {
1379 return GetPrimitiveType() == kPrimByte;
1380 }
1381
1382 bool IsPrimitiveChar() const {
1383 return GetPrimitiveType() == kPrimChar;
1384 }
1385
1386 bool IsPrimitiveShort() const {
1387 return GetPrimitiveType() == kPrimShort;
1388 }
1389
1390 bool IsPrimitiveInt() const {
1391 return GetPrimitiveType() == kPrimInt;
1392 }
1393
1394 bool IsPrimitiveLong() const {
1395 return GetPrimitiveType() == kPrimLong;
1396 }
1397
1398 bool IsPrimitiveFloat() const {
1399 return GetPrimitiveType() == kPrimFloat;
1400 }
1401
1402 bool IsPrimitiveDouble() const {
1403 return GetPrimitiveType() == kPrimDouble;
1404 }
1405
1406 bool IsPrimitiveVoid() const {
1407 return GetPrimitiveType() == kPrimVoid;
1408 }
1409
1410 size_t PrimitiveSize() const;
1411
1412 bool IsArrayClass() const {
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -07001413 return GetComponentType() != NULL;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001414 }
1415
1416 Class* GetComponentType() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001417 return GetFieldObject<Class*>(
1418 OFFSET_OF_OBJECT_MEMBER(Class, component_type_), false);
1419 }
1420
1421 void SetComponentType(Class* new_component_type) {
1422 DCHECK(GetComponentType() == NULL);
1423 DCHECK(new_component_type != NULL);
1424 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, component_type_),
1425 new_component_type, false);
1426 }
1427
1428 size_t GetComponentSize() const {
1429 return GetTypeSize(GetComponentType()->GetDescriptor());
1430 }
1431
1432 bool IsObjectClass() const {
1433 return !IsPrimitive() && GetSuperClass() == NULL;
1434 }
1435
Brian Carlstrom1f870082011-08-23 16:02:11 -07001436 // Creates a raw object instance but does not invoke the default constructor.
1437 Object* AllocObject();
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001438
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001439 static size_t GetTypeSize(const String* descriptor);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001440
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001441 const String* GetDescriptor() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001442 const String* result = GetFieldObject<const String*>(
1443 OFFSET_OF_OBJECT_MEMBER(Class, descriptor_), false);
1444 // DCHECK(result != NULL); // may be NULL prior to class linker initialization
1445 // DCHECK_NE(0, result->GetLength()); // TODO: keep?
1446 return result;
1447 }
1448
1449 void SetDescriptor(String* new_descriptor);
1450
1451 bool IsVariableSize() const {
1452 // Classes and arrays vary in size, and so the object_size_ field cannot
1453 // be used to get their instance size
1454 return IsClassClass() || IsArrayClass();
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001455 }
1456
Brian Carlstrom4873d462011-08-21 15:23:39 -07001457 size_t SizeOf() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001458 CHECK(sizeof(size_t) == sizeof(int32_t));
1459 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false);
Brian Carlstrom4873d462011-08-21 15:23:39 -07001460 }
1461
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001462 size_t GetClassSize() const {
1463 CHECK(sizeof(size_t) == sizeof(uint32_t));
1464 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001465 }
1466
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001467 void SetClassSize(size_t new_class_size) {
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07001468 DCHECK(new_class_size >= GetClassSize())
Elliott Hughes54e7df12011-09-16 11:47:04 -07001469 << " class=" << PrettyTypeOf(this)
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07001470 << " new_class_size=" << new_class_size
1471 << " GetClassSize=" << GetClassSize();
Elliott Hughes54e7df12011-09-16 11:47:04 -07001472 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size, false);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001473 }
1474
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001475 size_t GetObjectSize() const {
1476 CHECK(!IsVariableSize());
1477 CHECK(sizeof(size_t) == sizeof(int32_t));
Elliott Hughes54e7df12011-09-16 11:47:04 -07001478 size_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001479 CHECK_GE(result, sizeof(Object));
1480 return result;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001481 }
1482
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001483 void SetObjectSize(size_t new_object_size) {
1484 DCHECK(!IsVariableSize());
1485 CHECK(sizeof(size_t) == sizeof(int32_t));
1486 return SetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_),
1487 new_object_size, false);
Carl Shapiro83ab4f32011-08-15 20:21:39 -07001488 }
1489
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001490 // Returns true if this class is in the same packages as that class.
1491 bool IsInSamePackage(const Class* that) const;
1492
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001493 static bool IsInSamePackage(const String* descriptor1,
1494 const String* descriptor2);
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001495
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001496 // Returns true if this class can access that class.
1497 bool CanAccess(const Class* that) const {
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001498 return that->IsPublic() || this->IsInSamePackage(that);
Carl Shapiro894d0fa2011-06-30 14:48:49 -07001499 }
1500
jeffhao4a801a42011-09-23 13:53:40 -07001501 // Validate method/field access.
1502 bool CanAccessMember(const Class* access_to, uint32_t member_flags) const {
1503 // quick accept for public access
1504 if (member_flags & kAccPublic) {
1505 return true;
1506 }
1507
1508 // quick accept for access from same class
1509 if (this == access_to) {
1510 return true;
1511 }
1512
1513 // quick reject for private access from another class
1514 if (member_flags & kAccPrivate) {
1515 return false;
1516 }
1517
1518 // Semi-quick test for protected access from a sub-class, which may or
1519 // may not be in the same package.
1520 if (member_flags & kAccProtected) {
1521 if (this->IsSubClass(access_to)) {
1522 return true;
1523 }
1524 }
1525
1526 // Allow protected and private access from other classes in the same package.
1527 return this->IsInSamePackage(access_to);
1528 }
1529
Brian Carlstromf91c8c32011-09-21 17:30:34 -07001530 bool IsSubClass(const Class* klass) const;
1531
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -07001532 bool IsAssignableFrom(const Class* src) const {
1533 DCHECK(src != NULL);
1534 if (this == src) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001535 // Can always assign to things of the same type
1536 return true;
Brian Carlstromdbc05252011-09-09 01:59:59 -07001537 } else if (IsObjectClass()) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001538 // Can assign any reference to java.lang.Object
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -07001539 return !src->IsPrimitive();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001540 } else if (IsInterface()) {
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -07001541 return src->Implements(this);
1542 } else if (src->IsArrayClass()) {
1543 return IsAssignableFromArray(src);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001544 } else {
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -07001545 return src->IsSubClass(this);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001546 }
1547 }
Elliott Hughesbf86d042011-08-31 17:53:14 -07001548
buzbee991e3ac2011-09-29 15:44:22 -07001549 // Assignable test for code, won't throw. Null and equality tests already performed
1550 static uint32_t IsAssignableFromCode(const Class* klass, const Class* ref_class)
1551 {
1552 DCHECK(klass != NULL);
1553 DCHECK(ref_class != NULL);
1554 return klass->IsAssignableFrom(ref_class) ? 1 : 0;
1555 }
1556
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001557 Class* GetSuperClass() const {
1558 // Can only get super class for loaded classes (hack for when runtime is
1559 // initializing)
Elliott Hughesdcc24742011-09-07 14:02:44 -07001560 DCHECK(IsLoaded() || !Runtime::Current()->IsStarted());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001561 return GetFieldObject<Class*>(
1562 OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false);
1563 }
1564
buzbee4a3164f2011-09-03 11:25:10 -07001565 static MemberOffset SuperClassOffset() {
1566 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
1567 }
1568
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001569 void SetSuperClass(Class *new_super_class) {
1570 // super class is assigned once, except during class linker initialization
1571 Class* old_super_class = GetFieldObject<Class*>(
1572 OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false);
1573 DCHECK(old_super_class == NULL || old_super_class == new_super_class);
1574 DCHECK(new_super_class != NULL);
1575 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, super_class_),
1576 new_super_class, false);
1577 }
1578
1579 bool HasSuperClass() const {
1580 return GetSuperClass() != NULL;
1581 }
1582
1583 uint32_t GetSuperClassTypeIdx() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001584 DCHECK(IsIdxLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001585 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, super_class_type_idx_),
1586 false);
1587 }
1588
1589 void SetSuperClassTypeIdx(int32_t new_super_class_idx) {
1590 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, super_class_type_idx_),
1591 new_super_class_idx, false);
1592 }
1593
1594 const ClassLoader* GetClassLoader() const;
1595
1596 void SetClassLoader(const ClassLoader* new_cl);
1597
1598 static MemberOffset DexCacheOffset() {
1599 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
1600 }
1601
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001602 enum {
1603 kDumpClassFullDetail = 1,
1604 kDumpClassClassLoader = (1 << 1),
1605 kDumpClassInitialized = (1 << 2),
1606 };
1607
Elliott Hughes4681c802011-09-25 18:04:37 -07001608 void DumpClass(std::ostream& os, int flags) const;
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001609
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001610 DexCache* GetDexCache() const;
1611
1612 void SetDexCache(DexCache* new_dex_cache);
1613
1614 ObjectArray<Method>* GetDirectMethods() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001615 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001616 return GetFieldObject<ObjectArray<Method>*>(
1617 OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false);
1618 }
1619
1620 void SetDirectMethods(ObjectArray<Method>* new_direct_methods) {
1621 DCHECK(NULL == GetFieldObject<ObjectArray<Method>*>(
1622 OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false));
1623 DCHECK_NE(0, new_direct_methods->GetLength());
1624 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_),
1625 new_direct_methods, false);
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001626 }
1627
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001628 Method* GetDirectMethod(int32_t i) const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001629 return GetDirectMethods()->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001630 }
1631
1632 void SetDirectMethod(uint32_t i, Method* f) { // TODO: uint16_t
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001633 ObjectArray<Method>* direct_methods =
1634 GetFieldObject<ObjectArray<Method>*>(
1635 OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false);
1636 direct_methods->Set(i, f);
Carl Shapiro3ee755d2011-06-28 12:11:04 -07001637 }
1638
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001639 // Returns the number of static, private, and constructor methods.
1640 size_t NumDirectMethods() const {
1641 return (GetDirectMethods() != NULL) ? GetDirectMethods()->GetLength() : 0;
1642 }
Carl Shapiro419ec7b2011-08-03 14:48:33 -07001643
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001644 ObjectArray<Method>* GetVirtualMethods() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001645 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001646 return GetFieldObject<ObjectArray<Method>*>(
1647 OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), false);
1648 }
1649
1650 void SetVirtualMethods(ObjectArray<Method>* new_virtual_methods) {
1651 // TODO: we reassign virtual methods to grow the table for miranda
1652 // methods.. they should really just be assigned once
1653 DCHECK_NE(0, new_virtual_methods->GetLength());
1654 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_),
1655 new_virtual_methods, false);
1656 }
Carl Shapiro419ec7b2011-08-03 14:48:33 -07001657
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001658 // Returns the number of non-inherited virtual methods.
1659 size_t NumVirtualMethods() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001660 return (GetVirtualMethods() != NULL) ? GetVirtualMethods()->GetLength() : 0;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001661 }
1662
1663 Method* GetVirtualMethod(uint32_t i) const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001664 DCHECK(IsResolved() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001665 return GetVirtualMethods()->Get(i);
1666 }
1667
1668 Method* GetVirtualMethodDuringLinking(uint32_t i) const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001669 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001670 return GetVirtualMethods()->Get(i);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001671 }
1672
1673 void SetVirtualMethod(uint32_t i, Method* f) { // TODO: uint16_t
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001674 ObjectArray<Method>* virtual_methods =
1675 GetFieldObject<ObjectArray<Method>*>(
1676 OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), false);
1677 virtual_methods->Set(i, f);
1678 }
1679
1680 ObjectArray<Method>* GetVTable() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001681 DCHECK(IsResolved() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001682 return GetFieldObject<ObjectArray<Method>*>(
1683 OFFSET_OF_OBJECT_MEMBER(Class, vtable_), false);
1684 }
1685
1686 ObjectArray<Method>* GetVTableDuringLinking() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001687 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001688 return GetFieldObject<ObjectArray<Method>*>(
1689 OFFSET_OF_OBJECT_MEMBER(Class, vtable_), false);
1690 }
1691
1692 void SetVTable(ObjectArray<Method>* new_vtable) {
1693 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, vtable_), new_vtable, false);
1694 }
1695
1696 static MemberOffset VTableOffset() {
1697 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001698 }
1699
Brian Carlstrom30b94452011-08-25 21:35:26 -07001700 // Given a method implemented by this class but potentially from a
1701 // super class, return the specific implementation
1702 // method for this class.
1703 Method* FindVirtualMethodForVirtual(Method* method) {
1704 DCHECK(!method->GetDeclaringClass()->IsInterface());
1705 // The argument method may from a super class.
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001706 // Use the index to a potentially overridden one for this instance's class.
1707 return GetVTable()->Get(method->GetMethodIndex());
Brian Carlstrom30b94452011-08-25 21:35:26 -07001708 }
1709
1710 // Given a method implemented by this class, but potentially from a
1711 // super class or interface, return the specific implementation
1712 // method for this class.
1713 Method* FindVirtualMethodForInterface(Method* method);
1714
jeffhaobdb76512011-09-07 11:43:16 -07001715 Method* FindInterfaceMethod(const StringPiece& name,
1716 const StringPiece& descriptor);
1717
Brian Carlstrom30b94452011-08-25 21:35:26 -07001718 Method* FindVirtualMethodForVirtualOrInterface(Method* method) {
Brian Carlstrom395520e2011-09-25 19:35:00 -07001719 if (method->IsDirect()) {
1720 return method;
1721 }
Brian Carlstrom30b94452011-08-25 21:35:26 -07001722 if (method->GetDeclaringClass()->IsInterface()) {
1723 return FindVirtualMethodForInterface(method);
1724 }
1725 return FindVirtualMethodForVirtual(method);
Elliott Hughes72025e52011-08-23 17:50:30 -07001726 }
1727
Carl Shapiro419ec7b2011-08-03 14:48:33 -07001728 Method* FindDeclaredVirtualMethod(const StringPiece& name,
Brian Carlstrom3a7b4f22011-09-17 15:01:57 -07001729 const StringPiece& signature);
Carl Shapiro419ec7b2011-08-03 14:48:33 -07001730
1731 Method* FindVirtualMethod(const StringPiece& name,
1732 const StringPiece& descriptor);
1733
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001734 Method* FindDeclaredDirectMethod(const StringPiece& name,
1735 const StringPiece& signature);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001736
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001737 Method* FindDirectMethod(const StringPiece& name,
1738 const StringPiece& signature);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001739
Carl Shapiro69759ea2011-07-21 18:13:35 -07001740 size_t NumInterfaces() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001741 CHECK(IsIdxLoaded() || IsErroneous()); // used during loading
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001742 ObjectArray<Class>* interfaces = GetFieldObject<ObjectArray<Class>*>(
1743 OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false);
1744 return (interfaces != NULL) ? interfaces->GetLength() : 0;
Carl Shapiro69759ea2011-07-21 18:13:35 -07001745 }
1746
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001747 IntArray* GetInterfacesTypeIdx() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001748 CHECK(IsIdxLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001749 return GetFieldObject<IntArray*>(
1750 OFFSET_OF_OBJECT_MEMBER(Class, interfaces_type_idx_), false);
1751 }
1752
1753 void SetInterfacesTypeIdx(IntArray* new_interfaces_idx);
1754
1755 ObjectArray<Class>* GetInterfaces() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001756 CHECK(IsLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001757 return GetFieldObject<ObjectArray<Class>*>(
1758 OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false);
1759 }
1760
1761 void SetInterfaces(ObjectArray<Class>* new_interfaces) {
1762 DCHECK(NULL == GetFieldObject<Object*>(
1763 OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false));
1764 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, interfaces_),
1765 new_interfaces, false);
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001766 }
1767
1768 void SetInterface(uint32_t i, Class* f) { // TODO: uint16_t
Elliott Hughes418d20f2011-09-22 14:00:39 -07001769 DCHECK_LT(i, NumInterfaces());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001770 ObjectArray<Class>* interfaces =
1771 GetFieldObject<ObjectArray<Class>*>(
1772 OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false);
1773 interfaces->Set(i, f);
1774 }
1775
1776 Class* GetInterface(uint32_t i) const {
Elliott Hughes418d20f2011-09-22 14:00:39 -07001777 DCHECK_LT(i, NumInterfaces());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001778 return GetInterfaces()->Get(i);
1779 }
1780
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07001781 int32_t GetIfTableCount() const {
1782 ObjectArray<InterfaceEntry>* iftable = GetIfTable();
1783 if (iftable == NULL) {
1784 return 0;
1785 }
1786 return iftable->GetLength();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001787 }
1788
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07001789 ObjectArray<InterfaceEntry>* GetIfTable() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001790 DCHECK(IsResolved() || IsErroneous());
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07001791 return GetFieldObject<ObjectArray<InterfaceEntry>*>(
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001792 OFFSET_OF_OBJECT_MEMBER(Class, iftable_), false);
1793 }
1794
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07001795 void SetIfTable(ObjectArray<InterfaceEntry>* new_iftable) {
Elliott Hughes5ea047b2011-09-13 14:38:18 -07001796 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, iftable_), new_iftable, false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001797 }
1798
1799 // Get instance fields
1800 ObjectArray<Field>* GetIFields() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001801 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001802 return GetFieldObject<ObjectArray<Field>*>(
1803 OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false);
1804 }
1805
1806 void SetIFields(ObjectArray<Field>* new_ifields) {
1807 DCHECK(NULL == GetFieldObject<ObjectArray<Field>*>(
1808 OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false));
1809 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, ifields_),
1810 new_ifields, false);
1811 }
1812
1813 size_t NumInstanceFields() const {
1814 return (GetIFields() != NULL) ? GetIFields()->GetLength() : 0;
1815 }
1816
1817 Field* GetInstanceField(uint32_t i) const { // TODO: uint16_t
1818 DCHECK_NE(NumInstanceFields(), 0U);
1819 return GetIFields()->Get(i);
1820 }
1821
1822 void SetInstanceField(uint32_t i, Field* f) { // TODO: uint16_t
1823 ObjectArray<Field>* ifields= GetFieldObject<ObjectArray<Field>*>(
1824 OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false);
1825 ifields->Set(i, f);
1826 }
1827
1828 // Returns the number of instance fields containing reference types.
1829 size_t NumReferenceInstanceFields() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001830 DCHECK(IsResolved() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001831 DCHECK(sizeof(size_t) == sizeof(int32_t));
1832 return GetField32(
1833 OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false);
1834 }
1835
1836 size_t NumReferenceInstanceFieldsDuringLinking() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001837 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001838 DCHECK(sizeof(size_t) == sizeof(int32_t));
1839 return GetField32(
1840 OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false);
1841 }
1842
1843 void SetNumReferenceInstanceFields(size_t new_num) {
1844 DCHECK(sizeof(size_t) == sizeof(int32_t));
1845 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_),
1846 new_num, false);
1847 }
1848
1849 uint32_t GetReferenceInstanceOffsets() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001850 DCHECK(IsResolved() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001851 return GetField32(
1852 OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), false);
1853 }
1854
1855 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets);
1856
1857 // Beginning of static field data
1858 static MemberOffset FieldsOffset() {
1859 return OFFSET_OF_OBJECT_MEMBER(Class, fields_);
1860 }
1861
1862 // Returns the number of static fields containing reference types.
1863 size_t NumReferenceStaticFields() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001864 DCHECK(IsResolved() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001865 DCHECK(sizeof(size_t) == sizeof(int32_t));
1866 return GetField32(
1867 OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false);
1868 }
1869
1870 size_t NumReferenceStaticFieldsDuringLinking() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001871 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001872 DCHECK(sizeof(size_t) == sizeof(int32_t));
1873 return GetField32(
1874 OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false);
1875 }
1876
1877 void SetNumReferenceStaticFields(size_t new_num) {
1878 DCHECK(sizeof(size_t) == sizeof(int32_t));
1879 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_),
1880 new_num, false);
1881 }
1882
1883 ObjectArray<Field>* GetSFields() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001884 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001885 return GetFieldObject<ObjectArray<Field>*>(
1886 OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false);
1887 }
1888
1889 void SetSFields(ObjectArray<Field>* new_sfields) {
1890 DCHECK(NULL == GetFieldObject<ObjectArray<Field>*>(
1891 OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false));
1892 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, sfields_),
1893 new_sfields, false);
1894 }
1895
1896 size_t NumStaticFields() const {
1897 return (GetSFields() != NULL) ? GetSFields()->GetLength() : 0;
1898 }
1899
1900 Field* GetStaticField(uint32_t i) const { // TODO: uint16_t
1901 return GetSFields()->Get(i);
1902 }
1903
1904 void SetStaticField(uint32_t i, Field* f) { // TODO: uint16_t
1905 ObjectArray<Field>* sfields= GetFieldObject<ObjectArray<Field>*>(
1906 OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false);
1907 sfields->Set(i, f);
1908 }
1909
1910 uint32_t GetReferenceStaticOffsets() const {
1911 return GetField32(
1912 OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), false);
1913 }
1914
1915 void SetReferenceStaticOffsets(uint32_t new_reference_offsets);
1916
1917 // Finds the given instance field in this class or a superclass.
1918 Field* FindInstanceField(const StringPiece& name, Class* type);
1919
1920 Field* FindDeclaredInstanceField(const StringPiece& name, Class* type);
1921
1922 // Finds the given static field in this class or a superclass.
1923 Field* FindStaticField(const StringPiece& name, Class* type);
1924
1925 Field* FindDeclaredStaticField(const StringPiece& name, Class* type);
1926
Elliott Hughesdcc24742011-09-07 14:02:44 -07001927 pid_t GetClinitThreadId() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001928 DCHECK(IsIdxLoaded() || IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001929 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), false);
1930 }
1931
Elliott Hughesdcc24742011-09-07 14:02:44 -07001932 void SetClinitThreadId(pid_t new_clinit_thread_id) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001933 SetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_),
1934 new_clinit_thread_id, false);
1935 }
1936
1937 Class* GetVerifyErrorClass() const {
Brian Carlstrom693267a2011-09-06 09:25:34 -07001938 // DCHECK(IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001939 return GetFieldObject<Class*>(
1940 OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), false);
Carl Shapiro69759ea2011-07-21 18:13:35 -07001941 }
1942
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001943 void SetVerifyErrorClass(Class* klass) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001944 klass->SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_),
1945 klass, false);
1946 }
1947
Brian Carlstromc74255f2011-09-11 22:47:39 -07001948 String* GetSourceFile() const;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001949
Brian Carlstromc74255f2011-09-11 22:47:39 -07001950 void SetSourceFile(String* new_source_file);
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001951
jeffhaobdb76512011-09-07 11:43:16 -07001952 private:
jeffhao5dbddee2011-09-07 16:38:26 -07001953 bool Implements(const Class* klass) const;
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001954 bool IsArrayAssignableFromArray(const Class* klass) const;
1955 bool IsAssignableFromArray(const Class* klass) const;
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07001956
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07001957 // descriptor for the class such as "java.lang.Class" or "[C"
1958 String* name_; // TODO initialize
Carl Shapiro1fb86202011-06-27 17:43:13 -07001959
Brian Carlstrom693267a2011-09-06 09:25:34 -07001960 // defining class loader, or NULL for the "bootstrap" system loader
Brian Carlstromdbc05252011-09-09 01:59:59 -07001961 const ClassLoader* class_loader_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001962
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -07001963 // For array classes, the component class object for instanceof/checkcast
1964 // (for String[][][], this will be String[][]). NULL for non-array classes.
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07001965 Class* component_type_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001966
Brian Carlstrom693267a2011-09-06 09:25:34 -07001967 // descriptor for the class such as "Ljava/lang/Class;" or "[C"
1968 String* descriptor_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001969
Brian Carlstrom693267a2011-09-06 09:25:34 -07001970 // DexCache of resolved constant pool entries
1971 // (will be NULL for VM-generated, e.g. arrays and primitive classes)
1972 DexCache* dex_cache_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001973
1974 // static, private, and <init> methods
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001975 ObjectArray<Method>* direct_methods_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001976
Brian Carlstrom693267a2011-09-06 09:25:34 -07001977 // instance fields
1978 //
1979 // These describe the layout of the contents of an Object.
1980 // Note that only the fields directly declared by this class are
1981 // listed in ifields; fields declared by a superclass are listed in
1982 // the superclass's Class.ifields.
1983 //
1984 // All instance fields that refer to objects are guaranteed to be at
1985 // the beginning of the field list. num_reference_instance_fields_
1986 // specifies the number of reference fields.
1987 ObjectArray<Field>* ifields_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07001988
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07001989 // Interface table (iftable_), one entry per interface supported by
1990 // this class. That means one entry for each interface we support
1991 // directly, indirectly via superclass, or indirectly via
1992 // superinterface. This will be null if neither we nor our
1993 // superclass implement any interfaces.
1994 //
1995 // Why we need this: given "class Foo implements Face", declare
1996 // "Face faceObj = new Foo()". Invoke faceObj.blah(), where "blah"
1997 // is part of the Face interface. We can't easily use a single
1998 // vtable.
1999 //
2000 // For every interface a concrete class implements, we create an array
2001 // of the concrete vtable_ methods for the methods in the interface.
2002 ObjectArray<InterfaceEntry>* iftable_;
2003
Brian Carlstromdbc05252011-09-09 01:59:59 -07002004 // array of interfaces this class implements directly
2005 // see also interfaces_type_idx_
2006 ObjectArray<Class>* interfaces_;
Brian Carlstrom693267a2011-09-06 09:25:34 -07002007
2008 // array of type_idx's for interfaces this class implements directly
2009 // see also interfaces_
2010 IntArray* interfaces_type_idx_;
2011
Brian Carlstromdbc05252011-09-09 01:59:59 -07002012 // Static fields
2013 ObjectArray<Field>* sfields_;
Brian Carlstrom693267a2011-09-06 09:25:34 -07002014
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07002015 // source file name, if known. Otherwise, NULL.
2016 String* source_file_;
2017
Brian Carlstromdbc05252011-09-09 01:59:59 -07002018 // The superclass, or NULL if this is java.lang.Object or a
2019 // primitive type.
2020 // see also super_class_type_idx_;
2021 Class* super_class_;
Brian Carlstrom693267a2011-09-06 09:25:34 -07002022
Brian Carlstromdbc05252011-09-09 01:59:59 -07002023 // If class verify fails, we must return same error on subsequent tries.
2024 // Update with SetVerifyErrorClass to ensure a write barrier is used.
2025 const Class* verify_error_class_;
Brian Carlstrom693267a2011-09-06 09:25:34 -07002026
Brian Carlstromdbc05252011-09-09 01:59:59 -07002027 // virtual methods defined in this class; invoked through vtable
2028 ObjectArray<Method>* virtual_methods_;
Brian Carlstrom693267a2011-09-06 09:25:34 -07002029
Brian Carlstromdbc05252011-09-09 01:59:59 -07002030 // Virtual method table (vtable), for use by "invoke-virtual". The
2031 // vtable from the superclass is copied in, and virtual methods from
2032 // our class either replace those from the super or are appended.
2033 ObjectArray<Method>* vtable_;
Brian Carlstrom693267a2011-09-06 09:25:34 -07002034
Brian Carlstromdbc05252011-09-09 01:59:59 -07002035 // access flags; low 16 bits are defined by VM spec
2036 uint32_t access_flags_;
Brian Carlstrom693267a2011-09-06 09:25:34 -07002037
Jesse Wilson6bf19152011-09-29 13:12:33 -04002038 // Total size of the Class instance; used when allocating storage on gc heap.
2039 // See also object_size_.
Brian Carlstromdbc05252011-09-09 01:59:59 -07002040 size_t class_size_;
Brian Carlstrom693267a2011-09-06 09:25:34 -07002041
Elliott Hughes5f791332011-09-15 17:45:30 -07002042 // tid used to check for recursive <clinit> invocation
Brian Carlstromdbc05252011-09-09 01:59:59 -07002043 pid_t clinit_thread_id_;
Carl Shapiro1fb86202011-06-27 17:43:13 -07002044
Brian Carlstromdbc05252011-09-09 01:59:59 -07002045 // number of instance fields that are object refs
2046 size_t num_reference_instance_fields_;
2047
2048 // number of static fields that are object refs
2049 size_t num_reference_static_fields_;
2050
2051 // Total object size; used when allocating storage on gc heap.
2052 // (For interfaces and abstract classes this will be zero.)
Jesse Wilson6bf19152011-09-29 13:12:33 -04002053 // See also class_size_.
Brian Carlstromdbc05252011-09-09 01:59:59 -07002054 size_t object_size_;
2055
2056 // primitive type index, or kPrimNot (0); set for generated prim classes
2057 PrimitiveType primitive_type_;
2058
2059 // Bitmap of offsets of ifields.
2060 uint32_t reference_instance_offsets_;
2061
2062 // Bitmap of offsets of sfields.
2063 uint32_t reference_static_offsets_;
2064
Brian Carlstrom693267a2011-09-06 09:25:34 -07002065 // state of class initialization
2066 Status status_;
Jesse Wilson7833bd22011-08-09 18:31:44 -04002067
Brian Carlstrom693267a2011-09-06 09:25:34 -07002068 // Set in LoadClass, used to LinkClass
2069 // see also super_class_
2070 uint32_t super_class_type_idx_;
Brian Carlstrom4873d462011-08-21 15:23:39 -07002071
Brian Carlstrom693267a2011-09-06 09:25:34 -07002072 // TODO: ?
2073 // initiating class loader list
2074 // NOTE: for classes with low serialNumber, these are unused, and the
2075 // values are kept in a table in gDvm.
2076 // InitiatingLoaderList initiating_loader_list_;
2077
Brian Carlstrom4873d462011-08-21 15:23:39 -07002078 // Location of first static field.
2079 uint32_t fields_[0];
Jesse Wilsonfd687c52011-08-04 19:27:35 -07002080
Brian Carlstrom693267a2011-09-06 09:25:34 -07002081 friend struct ClassOffsets; // for verifying offset information
Carl Shapirof88c9522011-08-06 15:47:38 -07002082 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
Carl Shapiro1fb86202011-06-27 17:43:13 -07002083};
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002084
Elliott Hughes1f359b02011-07-17 14:27:17 -07002085std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
Carl Shapiro1fb86202011-06-27 17:43:13 -07002086
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002087inline void Object::SetClass(Class* new_klass) {
2088 // new_klass may be NULL prior to class linker initialization
Elliott Hughes5ea047b2011-09-13 14:38:18 -07002089 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Object, klass_), new_klass, false, false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002090}
2091
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07002092inline bool Object::InstanceOf(const Class* klass) const {
Jesse Wilson14150742011-07-29 19:04:44 -04002093 DCHECK(klass != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002094 DCHECK(GetClass() != NULL);
2095 return klass->IsAssignableFrom(GetClass());
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07002096}
2097
Brian Carlstromdb4d5402011-08-09 12:18:28 -07002098inline bool Object::IsClass() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002099 Class* java_lang_Class = GetClass()->GetClass();
2100 return GetClass() == java_lang_Class;
Brian Carlstromdb4d5402011-08-09 12:18:28 -07002101}
2102
Brian Carlstrom4873d462011-08-21 15:23:39 -07002103inline bool Object::IsClassClass() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002104 Class* java_lang_Class = GetClass()->GetClass();
Brian Carlstrom4873d462011-08-21 15:23:39 -07002105 return this == java_lang_Class;
2106}
2107
Brian Carlstromdb4d5402011-08-09 12:18:28 -07002108inline bool Object::IsObjectArray() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002109 return IsArrayInstance() && !GetClass()->GetComponentType()->IsPrimitive();
Brian Carlstromdb4d5402011-08-09 12:18:28 -07002110}
2111
Brian Carlstromb63ec392011-08-27 17:38:27 -07002112inline bool Object::IsArrayInstance() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002113 return GetClass()->IsArrayClass();
Brian Carlstromdb4d5402011-08-09 12:18:28 -07002114}
2115
Brian Carlstroma663ea52011-08-19 23:33:41 -07002116inline bool Object::IsField() const {
2117 Class* java_lang_Class = klass_->klass_;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002118 Class* java_lang_reflect_Field =
2119 java_lang_Class->GetInstanceField(0)->GetClass();
2120 return GetClass() == java_lang_reflect_Field;
Brian Carlstroma663ea52011-08-19 23:33:41 -07002121}
2122
2123inline bool Object::IsMethod() const {
Elliott Hughes80609252011-09-23 17:24:51 -07002124 Class* c = GetClass();
2125 return c == Method::GetMethodClass() || c == Method::GetConstructorClass();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002126}
2127
2128inline bool Object::IsReferenceInstance() const {
2129 return GetClass()->IsReferenceClass();
2130}
2131
2132inline bool Object::IsWeakReferenceInstance() const {
2133 return GetClass()->IsWeakReferenceClass();
2134}
2135
2136inline bool Object::IsSoftReferenceInstance() const {
2137 return GetClass()->IsSoftReferenceClass();
2138}
2139
2140inline bool Object::IsFinalizerReferenceInstance() const {
2141 return GetClass()->IsFinalizerReferenceClass();
2142}
2143
2144inline bool Object::IsPhantomReferenceInstance() const {
2145 return GetClass()->IsPhantomReferenceClass();
Brian Carlstroma663ea52011-08-19 23:33:41 -07002146}
2147
Elliott Hughes04b63fd2011-08-16 09:40:10 -07002148inline size_t Object::SizeOf() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002149 size_t result;
Brian Carlstromb63ec392011-08-27 17:38:27 -07002150 if (IsArrayInstance()) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002151 result = AsArray()->SizeOf();
2152 } else if (IsClass()) {
2153 result = AsClass()->SizeOf();
2154 } else {
2155 result = GetClass()->GetObjectSize();
Brian Carlstromdb4d5402011-08-09 12:18:28 -07002156 }
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002157 DCHECK(!IsField() || result == sizeof(Field));
2158 DCHECK(!IsMethod() || result == sizeof(Method));
2159 return result;
2160}
2161
2162inline void Field::SetOffset(MemberOffset num_bytes) {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002163 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Brian Carlstrom693267a2011-09-06 09:25:34 -07002164 Class* type = GetTypeDuringLinking();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002165 if (type != NULL && (type->IsPrimitiveDouble() || type->IsPrimitiveLong())) {
2166 DCHECK(IsAligned(num_bytes.Uint32Value(), 8));
Brian Carlstrom4873d462011-08-21 15:23:39 -07002167 }
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002168 SetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_),
2169 num_bytes.Uint32Value(), false);
2170}
2171
2172inline Class* Field::GetDeclaringClass() const {
2173 Class* result = GetFieldObject<Class*>(
2174 OFFSET_OF_OBJECT_MEMBER(Field, declaring_class_), false);
2175 DCHECK(result != NULL);
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002176 DCHECK(result->IsLoaded() || result->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002177 return result;
2178}
2179
2180inline void Field::SetDeclaringClass(Class *new_declaring_class) {
2181 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Field, declaring_class_),
2182 new_declaring_class, false);
2183}
2184
2185inline Class* Method::GetDeclaringClass() const {
2186 Class* result =
2187 GetFieldObject<Class*>(
2188 OFFSET_OF_OBJECT_MEMBER(Method, declaring_class_), false);
2189 DCHECK(result != NULL);
Brian Carlstrom65ca0772011-09-24 16:03:08 -07002190 DCHECK(result->IsIdxLoaded() || result->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002191 return result;
2192}
2193
2194inline void Method::SetDeclaringClass(Class *new_declaring_class) {
2195 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, declaring_class_),
2196 new_declaring_class, false);
2197}
2198
2199inline uint32_t Method::GetReturnTypeIdx() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002200 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002201 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, java_return_type_idx_),
2202 false);
2203}
2204
2205inline bool Method::IsReturnAReference() const {
2206 return !GetReturnType()->IsPrimitive();
2207}
2208
2209inline bool Method::IsReturnAFloat() const {
2210 return GetReturnType()->IsPrimitiveFloat();
2211}
2212
2213inline bool Method::IsReturnADouble() const {
2214 return GetReturnType()->IsPrimitiveDouble();
2215}
2216
2217inline bool Method::IsReturnALong() const {
2218 return GetReturnType()->IsPrimitiveLong();
2219}
2220
2221inline bool Method::IsReturnVoid() const {
2222 return GetReturnType()->IsPrimitiveVoid();
Brian Carlstromdb4d5402011-08-09 12:18:28 -07002223}
2224
Elliott Hughes04b63fd2011-08-16 09:40:10 -07002225inline size_t Array::SizeOf() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002226 return SizeOf(GetLength(), GetClass()->GetComponentSize());
2227}
2228
2229template<class T>
2230void ObjectArray<T>::Set(int32_t i, T* object) {
2231 if (IsValidIndex(i)) {
2232 if (object != NULL) {
2233 Class* element_class = GetClass()->GetComponentType();
Elliott Hughes80609252011-09-23 17:24:51 -07002234 if (!object->InstanceOf(element_class)) {
2235 ThrowArrayStoreException(object);
2236 return;
2237 }
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002238 }
2239 MemberOffset data_offset(DataOffset().Int32Value() + i * sizeof(Object*));
2240 SetFieldObject(data_offset, object, false);
2241 }
2242}
2243
2244template<class T>
2245void ObjectArray<T>::SetWithoutChecks(int32_t i, T* object) {
2246 DCHECK(IsValidIndex(i));
2247 MemberOffset data_offset(DataOffset().Int32Value() + i * sizeof(Object*));
2248 SetFieldObject(data_offset, object, false);
2249}
2250
2251template<class T>
2252void ObjectArray<T>::Copy(const ObjectArray<T>* src, int src_pos,
2253 ObjectArray<T>* dst, int dst_pos,
2254 size_t length) {
2255 if (src->IsValidIndex(src_pos) &&
2256 src->IsValidIndex(src_pos+length-1) &&
2257 dst->IsValidIndex(dst_pos) &&
2258 dst->IsValidIndex(dst_pos+length-1)) {
2259 MemberOffset src_offset(DataOffset().Int32Value() +
2260 src_pos * sizeof(Object*));
2261 MemberOffset dst_offset(DataOffset().Int32Value() +
2262 dst_pos * sizeof(Object*));
2263 Class* array_class = dst->GetClass();
2264 if (array_class == src->GetClass()) {
2265 // No need for array store checks if arrays are of the same type
2266 for (size_t i=0; i < length; i++) {
2267 Object* object = src->GetFieldObject<Object*>(src_offset, false);
2268 dst->SetFieldObject(dst_offset, object, false);
2269 src_offset = MemberOffset(src_offset.Uint32Value() + sizeof(Object*));
2270 dst_offset = MemberOffset(dst_offset.Uint32Value() + sizeof(Object*));
2271 }
2272 } else {
2273 Class* element_class = array_class->GetComponentType();
2274 CHECK(!element_class->IsPrimitive());
2275 for (size_t i=0; i < length; i++) {
2276 Object* object = src->GetFieldObject<Object*>(src_offset, false);
Elliott Hughes80609252011-09-23 17:24:51 -07002277 if (object != NULL && !object->InstanceOf(element_class)) {
2278 dst->ThrowArrayStoreException(object);
2279 return;
2280 }
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002281 dst->SetFieldObject(dst_offset, object, false);
2282 src_offset = MemberOffset(src_offset.Uint32Value() + sizeof(Object*));
2283 dst_offset = MemberOffset(dst_offset.Uint32Value() + sizeof(Object*));
2284 }
2285 }
Elliott Hughes3a4f8df2011-09-13 15:22:36 -07002286 Heap::WriteBarrier(dst);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002287 }
Brian Carlstromdb4d5402011-08-09 12:18:28 -07002288}
Brian Carlstromf7ed11a2011-08-09 17:55:51 -07002289
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07002290class MANAGED ClassClass : public Class {
Brian Carlstrom4873d462011-08-21 15:23:39 -07002291 private:
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -07002292 int32_t padding_;
Brian Carlstrom4873d462011-08-21 15:23:39 -07002293 int64_t serialVersionUID_;
Brian Carlstromdbc05252011-09-09 01:59:59 -07002294 friend struct ClassClassOffsets; // for verifying offset information
Brian Carlstrom4873d462011-08-21 15:23:39 -07002295 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass);
2296};
2297
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07002298class MANAGED StringClass : public Class {
Brian Carlstrom4873d462011-08-21 15:23:39 -07002299 private:
2300 CharArray* ASCII_;
2301 Object* CASE_INSENSITIVE_ORDER_;
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07002302 uint32_t REPLACEMENT_CHAR_;
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -07002303 int64_t serialVersionUID_;
Brian Carlstromdbc05252011-09-09 01:59:59 -07002304 friend struct StringClassOffsets; // for verifying offset information
Brian Carlstrom4873d462011-08-21 15:23:39 -07002305 DISALLOW_IMPLICIT_CONSTRUCTORS(StringClass);
2306};
2307
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07002308class MANAGED FieldClass : public Class {
Brian Carlstrom4873d462011-08-21 15:23:39 -07002309 private:
2310 Object* ORDER_BY_NAME_AND_DECLARING_CLASS_;
2311 uint32_t TYPE_BOOLEAN_;
2312 uint32_t TYPE_BYTE_;
2313 uint32_t TYPE_CHAR_;
2314 uint32_t TYPE_DOUBLE_;
2315 uint32_t TYPE_FLOAT_;
2316 uint32_t TYPE_INTEGER_;
2317 uint32_t TYPE_LONG_;
2318 uint32_t TYPE_SHORT_;
Brian Carlstromdbc05252011-09-09 01:59:59 -07002319 friend struct FieldClassOffsets; // for verifying offset information
Brian Carlstrom4873d462011-08-21 15:23:39 -07002320 DISALLOW_IMPLICIT_CONSTRUCTORS(FieldClass);
2321};
2322
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07002323class MANAGED MethodClass : public Class {
Brian Carlstrom4873d462011-08-21 15:23:39 -07002324 private:
Brian Carlstromdbc05252011-09-09 01:59:59 -07002325 Object* ORDER_BY_SIGNATURE_;
2326 friend struct MethodClassOffsets; // for verifying offset information
Brian Carlstrom4873d462011-08-21 15:23:39 -07002327 DISALLOW_IMPLICIT_CONSTRUCTORS(MethodClass);
2328};
2329
Jesse Wilsonfd687c52011-08-04 19:27:35 -07002330template<class T>
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07002331class MANAGED PrimitiveArray : public Array {
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07002332 public:
Elliott Hughes710a0cb2011-08-16 14:32:37 -07002333 typedef T ElementType;
2334
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07002335 static PrimitiveArray<T>* Alloc(size_t length);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07002336
Jesse Wilsonfd687c52011-08-04 19:27:35 -07002337 const T* GetData() const {
2338 return reinterpret_cast<const T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07002339 }
2340
Jesse Wilsonfd687c52011-08-04 19:27:35 -07002341 T* GetData() {
2342 return reinterpret_cast<T*>(&elements_);
Brian Carlstrom0b138b22011-07-27 15:19:17 -07002343 }
2344
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07002345 T Get(int32_t i) const {
Elliott Hughes289da822011-08-16 10:11:20 -07002346 if (!IsValidIndex(i)) {
Elliott Hughes710a0cb2011-08-16 14:32:37 -07002347 return T(0);
Elliott Hughes289da822011-08-16 10:11:20 -07002348 }
Jesse Wilsonfd687c52011-08-04 19:27:35 -07002349 return GetData()[i];
Brian Carlstrom0b138b22011-07-27 15:19:17 -07002350 }
2351
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07002352 void Set(int32_t i, T value) {
Elliott Hughes289da822011-08-16 10:11:20 -07002353 // TODO: ArrayStoreException
2354 if (IsValidIndex(i)) {
2355 GetData()[i] = value;
2356 }
Brian Carlstrom0b138b22011-07-27 15:19:17 -07002357 }
2358
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07002359 static void SetArrayClass(Class* array_class) {
Brian Carlstroma663ea52011-08-19 23:33:41 -07002360 CHECK(array_class_ == NULL);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07002361 CHECK(array_class != NULL);
2362 array_class_ = array_class;
2363 }
2364
Brian Carlstroma663ea52011-08-19 23:33:41 -07002365 static void ResetArrayClass() {
2366 CHECK(array_class_ != NULL);
2367 array_class_ = NULL;
2368 }
2369
Brian Carlstroma7f4f482011-07-17 17:01:34 -07002370 private:
Jesse Wilsonfd687c52011-08-04 19:27:35 -07002371 // Location of first element.
2372 T elements_[0];
Carl Shapirof88c9522011-08-06 15:47:38 -07002373
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07002374 static Class* array_class_;
2375
Carl Shapirof88c9522011-08-06 15:47:38 -07002376 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimitiveArray);
Brian Carlstroma7f4f482011-07-17 17:01:34 -07002377};
Carl Shapiro5fafe2b2011-07-09 15:34:41 -07002378
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002379inline void Class::SetInterfacesTypeIdx(IntArray* new_interfaces_idx) {
2380 DCHECK(NULL == GetFieldObject<IntArray*>(
2381 OFFSET_OF_OBJECT_MEMBER(Class, interfaces_type_idx_), false));
2382 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, interfaces_type_idx_),
2383 new_interfaces_idx, false);
2384}
2385
2386// C++ mirror of java.lang.String
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07002387class MANAGED String : public Object {
Carl Shapiro1fb86202011-06-27 17:43:13 -07002388 public:
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002389 const CharArray* GetCharArray() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002390 const CharArray* result = GetFieldObject<const CharArray*>(
2391 OFFSET_OF_OBJECT_MEMBER(String, array_), false);
2392 DCHECK(result != NULL);
2393 return result;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002394 }
2395
Elliott Hughes814e4032011-08-23 12:07:56 -07002396 int32_t GetOffset() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002397 int32_t result = GetField32(
2398 OFFSET_OF_OBJECT_MEMBER(String, offset_), false);
2399 DCHECK_LE(0, result);
2400 return result;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002401 }
2402
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002403 int32_t GetLength() const;
2404
Brian Carlstrom395520e2011-09-25 19:35:00 -07002405 int32_t GetHashCode();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002406
2407 void ComputeHashCode() {
2408 SetHashCode(ComputeUtf16Hash(GetCharArray(), GetOffset(), GetLength()));
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002409 }
2410
Elliott Hughes814e4032011-08-23 12:07:56 -07002411 int32_t GetUtfLength() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002412 return CountUtf8Bytes(GetCharArray()->GetData(), GetLength());
Elliott Hughes814e4032011-08-23 12:07:56 -07002413 }
2414
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002415 uint16_t CharAt(int32_t index) const;
2416
Brian Carlstromc74255f2011-09-11 22:47:39 -07002417 String* Intern();
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002418
Brian Carlstrom7e93b502011-08-04 14:16:22 -07002419 static String* AllocFromUtf16(int32_t utf16_length,
Brian Carlstroma663ea52011-08-19 23:33:41 -07002420 const uint16_t* utf16_data_in,
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002421 int32_t hash_code = 0);
Brian Carlstroma40f9bc2011-07-26 21:26:07 -07002422
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002423 static String* AllocFromModifiedUtf8(const char* utf);
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07002424
Jesse Wilson8989d992011-08-02 13:39:42 -07002425 static String* AllocFromModifiedUtf8(int32_t utf16_length,
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002426 const char* utf8_data_in);
2427
2428 static String* Alloc(Class* java_lang_String, int32_t utf16_length);
2429
2430 static String* Alloc(Class* java_lang_String, CharArray* array);
2431
2432 bool Equals(const char* modified_utf8) const;
2433
2434 // TODO: do we need this overload? give it a more intention-revealing name.
2435 bool Equals(const StringPiece& modified_utf8) const;
2436
2437 bool Equals(const String* that) const;
2438
2439 // TODO: do we need this overload? give it a more intention-revealing name.
2440 bool Equals(const uint16_t* that_chars, int32_t that_offset,
2441 int32_t that_length) const;
2442
2443 // Create a modified UTF-8 encoded std::string from a java/lang/String object.
2444 std::string ToModifiedUtf8() const;
2445
2446 static Class* GetJavaLangString() {
2447 DCHECK(java_lang_String_ != NULL);
2448 return java_lang_String_;
Jesse Wilson8989d992011-08-02 13:39:42 -07002449 }
2450
Brian Carlstroma663ea52011-08-19 23:33:41 -07002451 static void SetClass(Class* java_lang_String);
2452 static void ResetClass();
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07002453
Brian Carlstroma7f4f482011-07-17 17:01:34 -07002454 private:
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002455 void SetHashCode(int32_t new_hash_code) {
2456 DCHECK_EQ(0u,
2457 GetField32(OFFSET_OF_OBJECT_MEMBER(String, hash_code_), false));
2458 SetField32(OFFSET_OF_OBJECT_MEMBER(String, hash_code_),
2459 new_hash_code, false);
2460 }
2461
2462 void SetCount(int32_t new_count) {
2463 DCHECK_LE(0, new_count);
2464 SetField32(OFFSET_OF_OBJECT_MEMBER(String, count_), new_count, false);
2465 }
2466
2467 void SetOffset(int32_t new_offset) {
2468 DCHECK_LE(0, new_offset);
2469 DCHECK_GE(GetLength(), new_offset);
2470 SetField32(OFFSET_OF_OBJECT_MEMBER(String, offset_), new_offset, false);
2471 }
2472
2473 void SetArray(CharArray* new_array) {
2474 DCHECK(new_array != NULL);
2475 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(String, array_), new_array, false);
2476 }
2477
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002478 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
2479 CharArray* array_;
2480
Brian Carlstromdbc05252011-09-09 01:59:59 -07002481 int32_t count_;
2482
Carl Shapirof88c9522011-08-06 15:47:38 -07002483 uint32_t hash_code_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002484
Elliott Hughes289da822011-08-16 10:11:20 -07002485 int32_t offset_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002486
Jesse Wilsonf7e85a52011-08-01 18:45:58 -07002487 static Class* java_lang_String_;
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002488
Brian Carlstrom693267a2011-09-06 09:25:34 -07002489 friend struct StringOffsets; // for verifying offset information
Carl Shapiro8860c0e2011-08-04 17:36:16 -07002490 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
Carl Shapiro1fb86202011-06-27 17:43:13 -07002491};
2492
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002493inline const String* Field::GetName() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002494 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002495 String* result =
2496 GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(Field, name_), false);
2497 DCHECK(result != NULL);
2498 return result;
2499}
2500
2501inline void Field::SetName(String* new_name) {
2502 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Field, name_),
2503 new_name, false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002504}
2505
2506inline uint32_t Field::GetAccessFlags() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002507 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002508 return GetField32(OFFSET_OF_OBJECT_MEMBER(Field, access_flags_), false);
2509}
2510
2511inline uint32_t Field::GetTypeIdx() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002512 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002513 return GetField32(OFFSET_OF_OBJECT_MEMBER(Field, type_idx_), false);
2514}
2515
2516inline MemberOffset Field::GetOffset() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002517 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002518 return MemberOffset(
2519 GetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_), false));
2520}
2521
2522inline MemberOffset Field::GetOffsetDuringLinking() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002523 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002524 return MemberOffset(
2525 GetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_), false));
2526}
2527
2528inline const String* Method::GetName() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002529 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002530 const String* result =
2531 GetFieldObject<const String*>(
2532 OFFSET_OF_OBJECT_MEMBER(Method, name_), false);
2533 DCHECK(result != NULL);
2534 return result;
2535}
2536
2537inline void Method::SetName(String* new_name) {
2538 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, name_),
2539 new_name, false);
2540
2541}
2542
jeffhaoe23d93c2011-09-15 14:48:43 -07002543inline ByteArray* Method::GetRegisterMapData() const {
2544 return GetFieldObject<ByteArray*>(
2545 OFFSET_OF_OBJECT_MEMBER(Method, register_map_data_), false);
2546}
2547
jeffhaoa0a764a2011-09-16 10:43:38 -07002548inline void Method::SetRegisterMapData(ByteArray* data) {
jeffhaoe23d93c2011-09-15 14:48:43 -07002549 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, register_map_data_),
jeffhaoa0a764a2011-09-16 10:43:38 -07002550 data, false);
jeffhaoe23d93c2011-09-15 14:48:43 -07002551}
2552
2553inline ByteArray* Method::GetRegisterMapHeader() const {
2554 return GetFieldObject<ByteArray*>(
2555 OFFSET_OF_OBJECT_MEMBER(Method, register_map_header_), false);
2556}
2557
jeffhaoa0a764a2011-09-16 10:43:38 -07002558inline void Method::SetRegisterMapHeader(ByteArray* header) {
jeffhaoe23d93c2011-09-15 14:48:43 -07002559 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, register_map_header_),
jeffhaoa0a764a2011-09-16 10:43:38 -07002560 header, false);
jeffhaoe23d93c2011-09-15 14:48:43 -07002561}
2562
Brian Carlstrom2ed67392011-09-09 14:53:28 -07002563inline String* Method::GetShorty() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002564 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Brian Carlstrom2ed67392011-09-09 14:53:28 -07002565 return GetFieldObject<String*>(
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002566 OFFSET_OF_OBJECT_MEMBER(Method, shorty_), false);
2567}
2568
Brian Carlstrom2ed67392011-09-09 14:53:28 -07002569inline void Method::SetShorty(String* new_shorty) {
2570 DCHECK(NULL == GetFieldObject<String*>(
2571 OFFSET_OF_OBJECT_MEMBER(Method, shorty_), false));
2572 DCHECK_LE(1, new_shorty->GetLength());
2573 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, shorty_), new_shorty, false);
2574}
2575
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002576inline const String* Method::GetSignature() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002577 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002578 const String* result =
2579 GetFieldObject<const String*>(
2580 OFFSET_OF_OBJECT_MEMBER(Method, signature_), false);
2581 DCHECK(result != NULL);
2582 return result;
2583}
2584
2585inline void Method::SetSignature(String* new_signature) {
2586 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, signature_),
2587 new_signature, false);
2588}
2589
2590inline uint32_t Class::GetAccessFlags() const {
2591 // Check class is loaded or this is java.lang.String that has a
2592 // circularity issue during loading the names of its members
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002593 DCHECK(IsLoaded() || IsErroneous() ||
Elliott Hughes80609252011-09-23 17:24:51 -07002594 this == String::GetJavaLangString() ||
2595 this == Field::GetJavaLangReflectField() ||
2596 this == Method::GetConstructorClass() ||
2597 this == Method::GetMethodClass()) << PrettyClass(this);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002598 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), false);
2599}
2600
2601inline void Class::SetDescriptor(String* new_descriptor) {
Brian Carlstrom693267a2011-09-06 09:25:34 -07002602 DCHECK(GetDescriptor() == NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002603 DCHECK(new_descriptor != NULL);
2604 DCHECK_NE(0, new_descriptor->GetLength());
2605 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, descriptor_),
2606 new_descriptor, false);
2607}
2608
Brian Carlstromc74255f2011-09-11 22:47:39 -07002609inline String* Class::GetSourceFile() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002610 DCHECK(IsLoaded() || IsErroneous());
Brian Carlstromc74255f2011-09-11 22:47:39 -07002611 return GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(Class, source_file_), false);
2612}
2613
2614inline void Class::SetSourceFile(String* new_source_file) {
2615 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, source_file_), new_source_file, false);
2616}
2617
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002618inline uint32_t Method::GetAccessFlags() const {
Brian Carlstrom65ca0772011-09-24 16:03:08 -07002619 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002620 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, access_flags_), false);
2621}
2622
2623inline uint16_t Method::GetMethodIndex() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002624 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Elliott Hughes1d3f1142011-09-13 12:00:00 -07002625 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, method_index_), false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002626}
2627
2628inline uint16_t Method::NumRegisters() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002629 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Elliott Hughes1d3f1142011-09-13 12:00:00 -07002630 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, num_registers_), false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002631}
2632
2633inline uint16_t Method::NumIns() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002634 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Elliott Hughes1d3f1142011-09-13 12:00:00 -07002635 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, num_ins_), false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002636}
2637
2638inline uint16_t Method::NumOuts() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002639 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Elliott Hughes1d3f1142011-09-13 12:00:00 -07002640 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, num_outs_), false);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002641}
2642
2643inline uint32_t Method::GetProtoIdx() const {
Brian Carlstrom27ec9612011-09-19 20:20:38 -07002644 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002645 return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, proto_idx_), false);
2646}
2647
2648// C++ mirror of java.lang.Throwable
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07002649class MANAGED Throwable : public Object {
Brian Carlstrom69b15fb2011-09-03 12:25:21 -07002650 public:
2651 void SetDetailMessage(String* new_detail_message) {
2652 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Throwable, detail_message_),
2653 new_detail_message, false);
2654 }
2655
Elliott Hughese5b0dc82011-08-23 09:59:02 -07002656 private:
2657 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
2658 Throwable* cause_;
2659 String* detail_message_;
2660 Object* stack_state_; // Note this is Java volatile:
2661 Object* stack_trace_;
2662 Object* suppressed_exceptions_;
2663
Brian Carlstrom693267a2011-09-06 09:25:34 -07002664 friend struct ThrowableOffsets; // for verifying offset information
Elliott Hughese5b0dc82011-08-23 09:59:02 -07002665 DISALLOW_IMPLICIT_CONSTRUCTORS(Throwable);
2666};
2667
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002668// C++ mirror of java.lang.StackTraceElement
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07002669class MANAGED StackTraceElement : public Object {
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002670 public:
2671 const String* GetDeclaringClass() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002672 return GetFieldObject<const String*>(
2673 OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_), false);
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002674 }
2675
2676 const String* GetMethodName() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002677 return GetFieldObject<const String*>(
2678 OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_), false);
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002679 }
2680
2681 const String* GetFileName() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002682 return GetFieldObject<const String*>(
2683 OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_), false);
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002684 }
2685
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07002686 int32_t GetLineNumber() const {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002687 return GetField32(
2688 OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_), false);
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002689 }
2690
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002691 static StackTraceElement* Alloc(const String* declaring_class,
2692 const String* method_name,
2693 const String* file_name,
2694 int32_t line_number);
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002695
2696 static void SetClass(Class* java_lang_StackTraceElement);
2697
2698 static void ResetClass();
2699
2700 private:
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002701 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002702 const String* declaring_class_;
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002703 const String* file_name_;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002704 const String* method_name_;
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07002705 int32_t line_number_;
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002706
2707 static Class* GetStackTraceElement() {
2708 DCHECK(java_lang_StackTraceElement_ != NULL);
2709 return java_lang_StackTraceElement_;
2710 }
2711
2712 static Class* java_lang_StackTraceElement_;
Brian Carlstrom693267a2011-09-06 09:25:34 -07002713
2714 friend struct StackTraceElementOffsets; // for verifying offset information
Shih-wei Liao55df06b2011-08-26 14:39:27 -07002715 DISALLOW_IMPLICIT_CONSTRUCTORS(StackTraceElement);
2716};
2717
Brian Carlstrome4f7e1d2011-09-11 13:21:12 -07002718class MANAGED InterfaceEntry : public ObjectArray<Object> {
Carl Shapiro1fb86202011-06-27 17:43:13 -07002719 public:
Brian Carlstrom30b94452011-08-25 21:35:26 -07002720 Class* GetInterface() const {
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07002721 Class* interface = Get(kInterface)->AsClass();
2722 DCHECK(interface != NULL);
2723 return interface;
Carl Shapirof88c9522011-08-06 15:47:38 -07002724 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07002725
Brian Carlstrom30b94452011-08-25 21:35:26 -07002726 void SetInterface(Class* interface) {
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07002727 DCHECK(interface != NULL);
Brian Carlstrom30b94452011-08-25 21:35:26 -07002728 DCHECK(interface->IsInterface());
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07002729 DCHECK(Get(kInterface) == NULL);
2730 Set(kInterface, interface);
Carl Shapirof88c9522011-08-06 15:47:38 -07002731 }
Carl Shapiro3ee755d2011-06-28 12:11:04 -07002732
Brian Carlstrom86927212011-09-15 11:31:11 -07002733 size_t GetMethodArrayCount() const {
2734 ObjectArray<Method>* method_array = down_cast<ObjectArray<Method>*>(Get(kMethodArray));
2735 if (method_array == 0) {
2736 return 0;
2737 }
2738 return method_array->GetLength();
2739 }
2740
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07002741 ObjectArray<Method>* GetMethodArray() const {
2742 ObjectArray<Method>* method_array = down_cast<ObjectArray<Method>*>(Get(kMethodArray));
2743 DCHECK(method_array != NULL);
2744 return method_array;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002745 }
2746
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07002747 void SetMethodArray(ObjectArray<Method>* new_ma) {
2748 DCHECK(new_ma != NULL);
2749 DCHECK(Get(kMethodArray) == NULL);
2750 Set(kMethodArray, new_ma);
2751 }
2752
2753 static size_t LengthAsArray() {
2754 return kMax;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07002755 }
2756
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07002757 private:
Carl Shapiro3ee755d2011-06-28 12:11:04 -07002758
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07002759 enum ArrayIndex {
2760 // Points to the interface class.
2761 kInterface = 0,
2762 // Method pointers into the vtable, allow fast map from interface
2763 // method index to concrete instance method.
2764 kMethodArray = 1,
2765 kMax = 2,
2766 };
Carl Shapirof88c9522011-08-06 15:47:38 -07002767
Brian Carlstrom4b620ff2011-09-11 01:11:01 -07002768 DISALLOW_IMPLICIT_CONSTRUCTORS(InterfaceEntry);
Carl Shapiro1fb86202011-06-27 17:43:13 -07002769};
2770
2771} // namespace art
2772
2773#endif // ART_SRC_OBJECT_H_