Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_OBJECT_H_ |
| 4 | #define ART_SRC_OBJECT_H_ |
| 5 | |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 6 | #include <vector> |
| 7 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 8 | #include "UniquePtr.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 9 | #include "casts.h" |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 10 | #include "constants.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 11 | #include "globals.h" |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 12 | #include "heap.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 13 | #include "logging.h" |
| 14 | #include "macros.h" |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 15 | #include "monitor.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 16 | #include "monitor.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "offsets.h" |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 18 | #include "runtime.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 19 | #include "stringpiece.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 20 | #include "thread.h" |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 21 | #include "utf.h" |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | class Array; |
| 26 | class Class; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 27 | class ClassLoader; |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 28 | class CodeAndDirectMethods; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 29 | class DexCache; |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 30 | class Field; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 31 | class InterfaceEntry; |
| 32 | class Monitor; |
| 33 | class Method; |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 34 | class Object; |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 35 | class StaticStorageBase; |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 36 | class String; |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 37 | template<class T> class ObjectArray; |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 38 | template<class T> class PrimitiveArray; |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 39 | typedef PrimitiveArray<uint8_t> BooleanArray; |
| 40 | typedef PrimitiveArray<int8_t> ByteArray; |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 41 | typedef PrimitiveArray<uint16_t> CharArray; |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 42 | typedef PrimitiveArray<double> DoubleArray; |
| 43 | typedef PrimitiveArray<float> FloatArray; |
| 44 | typedef PrimitiveArray<int32_t> IntArray; |
| 45 | typedef PrimitiveArray<int64_t> LongArray; |
| 46 | typedef PrimitiveArray<int16_t> ShortArray; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 47 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 48 | union JValue { |
| 49 | uint8_t z; |
| 50 | int8_t b; |
| 51 | uint16_t c; |
| 52 | int16_t s; |
| 53 | int32_t i; |
| 54 | int64_t j; |
| 55 | float f; |
| 56 | double d; |
| 57 | Object* l; |
| 58 | }; |
| 59 | |
Brian Carlstrom | be97785 | 2011-07-19 14:54:54 -0700 | [diff] [blame] | 60 | static const uint32_t kAccPublic = 0x0001; // class, field, method, ic |
| 61 | static const uint32_t kAccPrivate = 0x0002; // field, method, ic |
| 62 | static const uint32_t kAccProtected = 0x0004; // field, method, ic |
| 63 | static const uint32_t kAccStatic = 0x0008; // field, method, ic |
| 64 | static const uint32_t kAccFinal = 0x0010; // class, field, method, ic |
| 65 | static const uint32_t kAccSynchronized = 0x0020; // method (only allowed on natives) |
| 66 | static const uint32_t kAccSuper = 0x0020; // class (not used in Dalvik) |
| 67 | static const uint32_t kAccVolatile = 0x0040; // field |
| 68 | static const uint32_t kAccBridge = 0x0040; // method (1.5) |
| 69 | static const uint32_t kAccTransient = 0x0080; // field |
| 70 | static const uint32_t kAccVarargs = 0x0080; // method (1.5) |
| 71 | static const uint32_t kAccNative = 0x0100; // method |
| 72 | static const uint32_t kAccInterface = 0x0200; // class, ic |
| 73 | static const uint32_t kAccAbstract = 0x0400; // class, method, ic |
| 74 | static const uint32_t kAccStrict = 0x0800; // method |
| 75 | static const uint32_t kAccSynthetic = 0x1000; // field, method, ic |
| 76 | static const uint32_t kAccAnnotation = 0x2000; // class, ic (1.5) |
| 77 | static const uint32_t kAccEnum = 0x4000; // class, field, ic (1.5) |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 78 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 79 | static const uint32_t kAccMiranda = 0x8000; // method |
| 80 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 81 | static const uint32_t kAccJavaFlagsMask = 0xffff; // bits set from Java sources (low 16) |
| 82 | |
Brian Carlstrom | be97785 | 2011-07-19 14:54:54 -0700 | [diff] [blame] | 83 | static const uint32_t kAccConstructor = 0x00010000; // method (Dalvik only) |
| 84 | static const uint32_t kAccDeclaredSynchronized = 0x00020000; // method (Dalvik only) |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 85 | |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 86 | static const uint32_t kAccClassFlagsMask = (kAccPublic |
| 87 | | kAccFinal |
| 88 | | kAccInterface |
| 89 | | kAccAbstract |
| 90 | | kAccSynthetic |
| 91 | | kAccAnnotation |
| 92 | | kAccEnum); |
| 93 | static const uint32_t kAccInnerClassFlagsMask = (kAccClassFlagsMask |
| 94 | | kAccPrivate |
| 95 | | kAccProtected |
| 96 | | kAccStatic); |
| 97 | static const uint32_t kAccFieldFlagsMask = (kAccPublic |
| 98 | | kAccPrivate |
| 99 | | kAccProtected |
| 100 | | kAccStatic |
| 101 | | kAccFinal |
| 102 | | kAccVolatile |
| 103 | | kAccTransient |
| 104 | | kAccSynthetic |
| 105 | | kAccEnum); |
| 106 | static const uint32_t kAccMethodFlagsMask = (kAccPublic |
| 107 | | kAccPrivate |
| 108 | | kAccProtected |
| 109 | | kAccStatic |
| 110 | | kAccFinal |
| 111 | | kAccSynchronized |
| 112 | | kAccBridge |
| 113 | | kAccVarargs |
| 114 | | kAccNative |
| 115 | | kAccAbstract |
| 116 | | kAccStrict |
| 117 | | kAccSynthetic |
| 118 | | kAccConstructor |
| 119 | | kAccDeclaredSynchronized); |
| 120 | |
| 121 | // if only kAccClassIsReference is set, we have a soft reference |
| 122 | static const uint32_t kAccClassIsReference = 0x8000000; // class is a soft/weak/phantom ref |
| 123 | static const uint32_t kAccClassIsWeakReference = 0x4000000; // class is a weak reference |
| 124 | static const uint32_t kAccClassIsFinalizerReference = 0x2000000; // class is a finalizer reference |
| 125 | static const uint32_t kAccClassIsPhantomReference = 0x1000000; // class is a phantom reference |
| 126 | |
| 127 | static const uint32_t kAccReferenceFlagsMask = (kAccClassIsReference |
| 128 | | kAccClassIsWeakReference |
| 129 | | kAccClassIsFinalizerReference |
| 130 | | kAccClassIsPhantomReference); |
| 131 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 132 | /* |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 133 | * Definitions for packing refOffsets in Class. |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 134 | */ |
| 135 | /* |
| 136 | * A magic value for refOffsets. Ignore the bits and walk the super |
| 137 | * chain when this is the value. |
| 138 | * [This is an unlikely "natural" value, since it would be 30 non-ref instance |
| 139 | * fields followed by 2 ref instance fields.] |
| 140 | */ |
| 141 | #define CLASS_WALK_SUPER ((unsigned int)(3)) |
| 142 | #define CLASS_SMALLEST_OFFSET (sizeof(struct Object)) |
| 143 | #define CLASS_BITS_PER_WORD (sizeof(unsigned long int) * 8) |
| 144 | #define CLASS_OFFSET_ALIGNMENT 4 |
| 145 | #define CLASS_HIGH_BIT ((unsigned int)1 << (CLASS_BITS_PER_WORD - 1)) |
| 146 | /* |
| 147 | * Given an offset, return the bit number which would encode that offset. |
| 148 | * Local use only. |
| 149 | */ |
| 150 | #define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \ |
| 151 | (((unsigned int)(byteOffset) - CLASS_SMALLEST_OFFSET) / \ |
| 152 | CLASS_OFFSET_ALIGNMENT) |
| 153 | /* |
| 154 | * Is the given offset too large to be encoded? |
| 155 | */ |
| 156 | #define CLASS_CAN_ENCODE_OFFSET(byteOffset) \ |
| 157 | (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD) |
| 158 | /* |
| 159 | * Return a single bit, encoding the offset. |
| 160 | * Undefined if the offset is too large, as defined above. |
| 161 | */ |
| 162 | #define CLASS_BIT_FROM_OFFSET(byteOffset) \ |
| 163 | (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset)) |
| 164 | /* |
| 165 | * Return an offset, given a bit number as returned from CLZ. |
| 166 | */ |
| 167 | #define CLASS_OFFSET_FROM_CLZ(rshift) \ |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 168 | MemberOffset((static_cast<int>(rshift) * CLASS_OFFSET_ALIGNMENT) + \ |
| 169 | CLASS_SMALLEST_OFFSET) |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 170 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 171 | #define OFFSET_OF_OBJECT_MEMBER(type, field) \ |
| 172 | MemberOffset(OFFSETOF_MEMBER(type, field)) |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 173 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 174 | // C++ mirror of java.lang.Object |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 175 | class Object { |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 176 | public: |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 177 | static bool InstanceOf(const Object* object, const Class* klass) { |
| 178 | if (object == NULL) { |
| 179 | return false; |
| 180 | } |
| 181 | return object->InstanceOf(klass); |
| 182 | } |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 183 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 184 | static MemberOffset ClassOffset() { |
| 185 | return OFFSET_OF_OBJECT_MEMBER(Object, klass_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 188 | Class* GetClass() const { |
| 189 | return |
| 190 | GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(Object, klass_), false); |
| 191 | } |
| 192 | |
| 193 | void SetClass(Class* new_klass); |
| 194 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 195 | bool InstanceOf(const Class* klass) const; |
| 196 | |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 197 | size_t SizeOf() const; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 198 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 199 | Object* Clone() { |
| 200 | UNIMPLEMENTED(FATAL); |
| 201 | return NULL; |
| 202 | } |
| 203 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 204 | static MemberOffset MonitorOffset() { |
| 205 | return OFFSET_OF_OBJECT_MEMBER(Object, monitor_); |
| 206 | } |
| 207 | |
| 208 | Monitor* GetMonitor() const { |
| 209 | return GetFieldPtr<Monitor*>( |
| 210 | OFFSET_OF_OBJECT_MEMBER(Object, monitor_), false); |
| 211 | } |
| 212 | |
| 213 | void SetMonitor(Monitor* monitor) { |
| 214 | // TODO: threading - compare-and-set |
| 215 | SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(Object, monitor_), monitor, false); |
| 216 | } |
| 217 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 218 | void MonitorEnter() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 219 | GetMonitor()->Enter(); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void MonitorExit() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 223 | GetMonitor()->Exit(); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | void Notify() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 227 | GetMonitor()->Notify(); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void NotifyAll() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 231 | GetMonitor()->NotifyAll(); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void Wait() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 235 | GetMonitor()->Wait(); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void Wait(int64_t timeout) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 239 | GetMonitor()->Wait(timeout); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void Wait(int64_t timeout, int32_t nanos) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 243 | GetMonitor()->Wait(timeout, nanos); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 246 | bool IsClass() const; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 247 | |
| 248 | Class* AsClass() { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 249 | DCHECK(IsClass()); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 250 | return down_cast<Class*>(this); |
| 251 | } |
| 252 | |
| 253 | const Class* AsClass() const { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 254 | DCHECK(IsClass()); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 255 | return down_cast<const Class*>(this); |
| 256 | } |
| 257 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 258 | bool IsClassClass() const; |
| 259 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 260 | bool IsObjectArray() const; |
| 261 | |
| 262 | template<class T> |
| 263 | ObjectArray<T>* AsObjectArray() { |
| 264 | DCHECK(IsObjectArray()); |
| 265 | return down_cast<ObjectArray<T>*>(this); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 268 | template<class T> |
| 269 | const ObjectArray<T>* AsObjectArray() const { |
| 270 | DCHECK(IsObjectArray()); |
| 271 | return down_cast<const ObjectArray<T>*>(this); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 274 | bool IsArrayInstance() const; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 275 | |
| 276 | Array* AsArray() { |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 277 | DCHECK(IsArrayInstance()); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 278 | return down_cast<Array*>(this); |
| 279 | } |
| 280 | |
| 281 | const Array* AsArray() const { |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 282 | DCHECK(IsArrayInstance()); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 283 | return down_cast<const Array*>(this); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 286 | bool IsString() const; |
| 287 | |
| 288 | String* AsString() { |
| 289 | DCHECK(IsString()); |
| 290 | return down_cast<String*>(this); |
| 291 | } |
| 292 | |
| 293 | bool IsMethod() const; |
| 294 | |
| 295 | Method* AsMethod() { |
| 296 | DCHECK(IsMethod()); |
| 297 | return down_cast<Method*>(this); |
| 298 | } |
| 299 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 300 | const Method* AsMethod() const { |
| 301 | DCHECK(IsMethod()); |
| 302 | return down_cast<const Method*>(this); |
| 303 | } |
| 304 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 305 | bool IsField() const; |
| 306 | |
| 307 | Field* AsField() { |
| 308 | DCHECK(IsField()); |
| 309 | return down_cast<Field*>(this); |
| 310 | } |
| 311 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 312 | const Field* AsField() const { |
| 313 | DCHECK(IsField()); |
| 314 | return down_cast<const Field*>(this); |
| 315 | } |
| 316 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 317 | bool IsReferenceInstance() const; |
| 318 | |
| 319 | bool IsWeakReferenceInstance() const; |
| 320 | |
| 321 | bool IsSoftReferenceInstance() const; |
| 322 | |
| 323 | bool IsFinalizerReferenceInstance() const; |
| 324 | |
| 325 | bool IsPhantomReferenceInstance() const; |
| 326 | |
| 327 | // Accessors for Java type fields |
| 328 | template<class T> |
| 329 | T GetFieldObject(MemberOffset field_offset, bool is_volatile) const { |
| 330 | Heap::VerifyObject(this); |
| 331 | DCHECK(Thread::Current() == NULL || |
| 332 | Thread::Current()->CanAccessDirectReferences()); |
| 333 | const byte* raw_addr = reinterpret_cast<const byte*>(this) + |
| 334 | field_offset.Int32Value(); |
| 335 | if (is_volatile) { |
| 336 | UNIMPLEMENTED(WARNING); |
| 337 | } |
| 338 | T result = *reinterpret_cast<T const *>(raw_addr); |
| 339 | Heap::VerifyObject(result); |
| 340 | return result; |
| 341 | } |
| 342 | |
| 343 | void SetFieldObject(MemberOffset offset, const Object* new_value, |
| 344 | bool is_volatile) { |
| 345 | // Avoid verifying this when initializing the Class* |
| 346 | if (offset.Int32Value() != ClassOffset().Int32Value()) { |
| 347 | Heap::VerifyObject(this); |
| 348 | } |
| 349 | Heap::VerifyObject(new_value); |
| 350 | byte* raw_addr = reinterpret_cast<byte*>(this) + offset.Int32Value(); |
| 351 | if (is_volatile) { |
| 352 | UNIMPLEMENTED(WARNING); |
| 353 | } |
| 354 | *reinterpret_cast<const Object**>(raw_addr) = new_value; |
| 355 | // TODO: write barrier |
| 356 | } |
| 357 | |
| 358 | uint32_t GetField32(MemberOffset field_offset, bool is_volatile) const { |
| 359 | Heap::VerifyObject(this); |
| 360 | const byte* raw_addr = reinterpret_cast<const byte*>(this) + |
| 361 | field_offset.Int32Value(); |
| 362 | if (is_volatile) { |
| 363 | UNIMPLEMENTED(WARNING); |
| 364 | } |
| 365 | return *reinterpret_cast<const uint32_t*>(raw_addr); |
| 366 | } |
| 367 | |
| 368 | void SetField32(MemberOffset offset, uint32_t new_value, bool is_volatile) { |
| 369 | Heap::VerifyObject(this); |
| 370 | byte* raw_addr = reinterpret_cast<byte*>(this) + offset.Int32Value(); |
| 371 | if (is_volatile) { |
| 372 | UNIMPLEMENTED(WARNING); |
| 373 | } |
| 374 | *reinterpret_cast<uint32_t*>(raw_addr) = new_value; |
| 375 | } |
| 376 | |
| 377 | uint64_t GetField64(MemberOffset field_offset, bool is_volatile) const { |
| 378 | Heap::VerifyObject(this); |
| 379 | const byte* raw_addr = reinterpret_cast<const byte*>(this) + |
| 380 | field_offset.Int32Value(); |
| 381 | if (is_volatile) { |
| 382 | UNIMPLEMENTED(WARNING); |
| 383 | } |
| 384 | return *reinterpret_cast<const uint64_t*>(raw_addr); |
| 385 | } |
| 386 | |
| 387 | void SetField64(MemberOffset offset, uint64_t new_value, |
| 388 | bool is_volatile = false) { |
| 389 | Heap::VerifyObject(this); |
| 390 | byte* raw_addr = reinterpret_cast<byte*>(this) + offset.Int32Value(); |
| 391 | if (is_volatile) { |
| 392 | UNIMPLEMENTED(WARNING); |
| 393 | } |
| 394 | *reinterpret_cast<uint64_t*>(raw_addr) = new_value; |
| 395 | } |
| 396 | |
| 397 | protected: |
| 398 | // Accessors for non-Java type fields |
| 399 | uint16_t GetField16(MemberOffset field_offset, bool is_volatile) const { |
| 400 | Heap::VerifyObject(this); |
| 401 | const byte* raw_addr = reinterpret_cast<const byte*>(this) + |
| 402 | field_offset.Int32Value(); |
| 403 | if (is_volatile) { |
| 404 | UNIMPLEMENTED(WARNING); |
| 405 | } |
| 406 | return *reinterpret_cast<const uint16_t*>(raw_addr); |
| 407 | } |
| 408 | |
| 409 | void SetField16(MemberOffset offset, uint16_t new_value, bool is_volatile) { |
| 410 | Heap::VerifyObject(this); |
| 411 | byte* raw_addr = reinterpret_cast<byte*>(this) + offset.Int32Value(); |
| 412 | if (is_volatile) { |
| 413 | UNIMPLEMENTED(WARNING); |
| 414 | } |
| 415 | *reinterpret_cast<uint16_t*>(raw_addr) = new_value; |
| 416 | } |
| 417 | |
| 418 | template<class T> |
| 419 | T GetFieldPtr(MemberOffset field_offset, bool is_volatile) const { |
| 420 | Heap::VerifyObject(this); |
| 421 | const byte* raw_addr = reinterpret_cast<const byte*>(this) + |
| 422 | field_offset.Int32Value(); |
| 423 | if (is_volatile) { |
| 424 | UNIMPLEMENTED(WARNING); |
| 425 | } |
| 426 | return *reinterpret_cast<T const *>(raw_addr); |
| 427 | } |
| 428 | |
| 429 | template<typename T> |
| 430 | void SetFieldPtr(MemberOffset offset, T new_value, bool is_volatile) { |
| 431 | Heap::VerifyObject(this); |
| 432 | byte* raw_addr = reinterpret_cast<byte*>(this) + offset.Int32Value(); |
| 433 | if (is_volatile) { |
| 434 | UNIMPLEMENTED(WARNING); |
| 435 | } |
| 436 | *reinterpret_cast<T*>(raw_addr) = new_value; |
| 437 | } |
| 438 | |
| 439 | private: |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 440 | Class* klass_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 441 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 442 | Monitor* monitor_; |
| 443 | |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 444 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | class ObjectLock { |
| 448 | public: |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 449 | explicit ObjectLock(Object* object) : obj_(object) { |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 450 | CHECK(object != NULL); |
| 451 | obj_->MonitorEnter(); |
| 452 | } |
| 453 | |
| 454 | ~ObjectLock() { |
| 455 | obj_->MonitorExit(); |
| 456 | } |
| 457 | |
| 458 | void Wait(int64_t millis = 0) { |
| 459 | return obj_->Wait(millis); |
| 460 | } |
| 461 | |
| 462 | void Notify() { |
| 463 | obj_->Notify(); |
| 464 | } |
| 465 | |
| 466 | void NotifyAll() { |
| 467 | obj_->NotifyAll(); |
| 468 | } |
| 469 | |
| 470 | private: |
| 471 | Object* obj_; |
| 472 | DISALLOW_COPY_AND_ASSIGN(ObjectLock); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 473 | }; |
| 474 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 475 | // C++ mirror of java.lang.reflect.AccessibleObject |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 476 | class AccessibleObject : public Object { |
| 477 | private: |
| 478 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 479 | uint32_t java_flag_; // can accessibility checks be bypassed |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 480 | }; |
| 481 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 482 | // C++ mirror of java.lang.reflect.Field |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 483 | class Field : public AccessibleObject { |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 484 | public: |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 485 | Class* GetDeclaringClass() const; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 486 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 487 | void SetDeclaringClass(Class *new_declaring_class); |
| 488 | |
| 489 | const String* GetName() const; |
| 490 | |
| 491 | void SetName(String* new_name); |
| 492 | |
| 493 | uint32_t GetAccessFlags() const; |
| 494 | |
| 495 | void SetAccessFlags(uint32_t new_access_flags) { |
| 496 | SetField32(OFFSET_OF_OBJECT_MEMBER(Field, access_flags_), new_access_flags, |
| 497 | false); |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | bool IsStatic() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 501 | return (GetAccessFlags() & kAccStatic) != 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 504 | uint32_t GetTypeIdx() const; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 505 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 506 | void SetTypeIdx(uint32_t type_idx); |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 507 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 508 | // Gets type using type index and resolved types in the dex cache, may be null |
| 509 | // if type isn't yet resolved |
| 510 | Class* GetTypeDuringLinking() const; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 511 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 512 | // Performs full resolution, may return null and set exceptions if type cannot |
| 513 | // be resolved |
| 514 | Class* GetType() const; |
| 515 | |
| 516 | // Offset to field within an Object |
| 517 | MemberOffset GetOffset() const; |
| 518 | |
| 519 | MemberOffset GetOffsetDuringLinking() const; |
| 520 | |
| 521 | void SetOffset(MemberOffset num_bytes); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 522 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 523 | // field access, null object for static fields |
| 524 | bool GetBoolean(const Object* object) const; |
| 525 | void SetBoolean(Object* object, bool z) const; |
| 526 | int8_t GetByte(const Object* object) const; |
| 527 | void SetByte(Object* object, int8_t b) const; |
| 528 | uint16_t GetChar(const Object* object) const; |
| 529 | void SetChar(Object* object, uint16_t c) const; |
| 530 | uint16_t GetShort(const Object* object) const; |
| 531 | void SetShort(Object* object, uint16_t s) const; |
| 532 | int32_t GetInt(const Object* object) const; |
| 533 | void SetInt(Object* object, int32_t i) const; |
| 534 | int64_t GetLong(const Object* object) const; |
| 535 | void SetLong(Object* object, int64_t j) const; |
| 536 | float GetFloat(const Object* object) const; |
| 537 | void SetFloat(Object* object, float f) const; |
| 538 | double GetDouble(const Object* object) const; |
| 539 | void SetDouble(Object* object, double d) const; |
| 540 | Object* GetObject(const Object* object) const; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 541 | void SetObject(Object* object, const Object* l) const; |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 542 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 543 | // Slow path routines for static field access when field was unresolved at |
| 544 | // compile time |
| 545 | static uint32_t Get32StaticFromCode(uint32_t field_idx, |
| 546 | const Method* referrer); |
| 547 | static void Set32StaticFromCode(uint32_t field_idx, const Method* referrer, |
| 548 | uint32_t new_value); |
| 549 | static uint64_t Get64StaticFromCode(uint32_t field_idx, |
| 550 | const Method* referrer); |
| 551 | static void Set64StaticFromCode(uint32_t field_idx, const Method* referrer, |
| 552 | uint64_t new_value); |
| 553 | static Object* GetObjStaticFromCode(uint32_t field_idx, |
| 554 | const Method* referrer); |
| 555 | static void SetObjStaticFromCode(uint32_t field_idx, const Method* referrer, |
| 556 | Object* new_value); |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 557 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 558 | static Class* GetJavaLangReflectField() { |
| 559 | DCHECK(java_lang_reflect_Field_ != NULL); |
| 560 | return java_lang_reflect_Field_; |
| 561 | } |
| 562 | |
| 563 | static void SetClass(Class* java_lang_reflect_Field); |
| 564 | static void ResetClass(); |
| 565 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 566 | bool IsVolatile() const { |
| 567 | return (GetAccessFlags() & kAccVolatile) != 0; |
| 568 | } |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 569 | |
buzbee | 1da522d | 2011-09-04 11:22:20 -0700 | [diff] [blame] | 570 | private: |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 571 | // private implementation of field access using raw data |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 572 | uint32_t Get32(const Object* object) const; |
| 573 | void Set32(Object* object, uint32_t new_value) const; |
| 574 | uint64_t Get64(const Object* object) const; |
| 575 | void Set64(Object* object, uint64_t new_value) const; |
| 576 | Object* GetObj(const Object* object) const; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 577 | void SetObj(Object* object, const Object* new_value) const; |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 578 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 579 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
| 580 | // The class in which this field is declared. |
| 581 | Class* declaring_class_; |
| 582 | Object* generic_type_; |
| 583 | uint32_t generic_types_are_initialized_; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 584 | const String* name_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 585 | // Offset of field within an instance or in the Class' static fields |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 586 | uint32_t offset_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 587 | // Type of the field |
| 588 | // TODO: unused by ART (which uses the type_idx below), remove |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 589 | Class* type_; |
| 590 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 591 | // TODO: expose these fields in the Java version of this Object |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 592 | uint32_t access_flags_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 593 | // Dex cache index of resolved type |
| 594 | uint32_t type_idx_; |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 595 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 596 | static Class* java_lang_reflect_Field_; |
| 597 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 598 | DISALLOW_IMPLICIT_CONSTRUCTORS(Field); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 599 | }; |
| 600 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 601 | // C++ mirror of java.lang.reflect.Method |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 602 | class Method : public AccessibleObject { |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 603 | public: |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 604 | // An function that invokes a method with an array of its arguments. |
| 605 | typedef void InvokeStub(Method* method, |
| 606 | Object* obj, |
| 607 | Thread* thread, |
| 608 | byte* args, |
| 609 | JValue* result); |
| 610 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 611 | Class* GetDeclaringClass() const; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 612 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 613 | void SetDeclaringClass(Class *new_declaring_class); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 614 | |
Ian Rogers | cdd1d2d | 2011-08-18 09:58:17 -0700 | [diff] [blame] | 615 | static MemberOffset DeclaringClassOffset() { |
| 616 | return MemberOffset(OFFSETOF_MEMBER(Method, declaring_class_)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 619 | // Returns the method name, e.g. "<init>" or "eatLunch" |
| 620 | const String* GetName() const; |
| 621 | |
| 622 | void SetName(String* new_name); |
| 623 | |
| 624 | const char* GetShorty() const; |
| 625 | |
| 626 | void SetShorty(const char* new_shorty) { |
| 627 | DCHECK(NULL == GetFieldPtr<const char*>( |
| 628 | OFFSET_OF_OBJECT_MEMBER(Method, shorty_), false)); |
| 629 | DCHECK_LE(1u, strlen(new_shorty)); |
| 630 | SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(Method, shorty_), new_shorty, false); |
| 631 | } |
| 632 | |
| 633 | const String* GetSignature() const; |
| 634 | |
| 635 | void SetSignature(String* new_signature); |
| 636 | |
| 637 | bool HasSameNameAndDescriptor(const Method* that) const; |
| 638 | |
| 639 | uint32_t GetAccessFlags() const; |
| 640 | |
| 641 | void SetAccessFlags(uint32_t new_access_flags) { |
| 642 | SetField32(OFFSET_OF_OBJECT_MEMBER(Method, access_flags_), new_access_flags, |
| 643 | false); |
| 644 | } |
| 645 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 646 | // Returns true if the method is declared public. |
| 647 | bool IsPublic() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 648 | return (GetAccessFlags() & kAccPublic) != 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | // Returns true if the method is declared private. |
| 652 | bool IsPrivate() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 653 | return (GetAccessFlags() & kAccPrivate) != 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | // Returns true if the method is declared static. |
| 657 | bool IsStatic() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 658 | return (GetAccessFlags() & kAccStatic) != 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 661 | // Returns true if the method is a constructor. |
| 662 | bool IsConstructor() const { |
| 663 | return (access_flags_ & kAccConstructor) != 0; |
| 664 | } |
| 665 | |
| 666 | // Returns true if the method is static, private, or a constructor. |
| 667 | bool IsDirect() const { |
| 668 | return IsStatic() || IsPrivate() || IsConstructor(); |
| 669 | } |
| 670 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 671 | // Returns true if the method is declared synchronized. |
| 672 | bool IsSynchronized() const { |
| 673 | uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 674 | return (GetAccessFlags() & synchonized) != 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // Returns true if the method is declared final. |
| 678 | bool IsFinal() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 679 | return (GetAccessFlags() & kAccFinal) != 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | // Returns true if the method is declared native. |
| 683 | bool IsNative() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 684 | return (GetAccessFlags() & kAccNative) != 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | // Returns true if the method is declared abstract. |
| 688 | bool IsAbstract() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 689 | return (GetAccessFlags() & kAccAbstract) != 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | bool IsSynthetic() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 693 | return (GetAccessFlags() & kAccSynthetic) != 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 696 | uint16_t GetMethodIndex() const; |
| 697 | |
| 698 | size_t GetVtableIndex() const { |
| 699 | return GetMethodIndex(); |
| 700 | } |
| 701 | |
| 702 | void SetMethodIndex(uint16_t new_method_index) { |
| 703 | SetField16(OFFSET_OF_OBJECT_MEMBER(Method, method_index_), |
| 704 | new_method_index, false); |
| 705 | } |
| 706 | |
| 707 | static MemberOffset MethodIndexOffset() { |
| 708 | return OFFSET_OF_OBJECT_MEMBER(Method, method_index_); |
| 709 | } |
| 710 | |
| 711 | uint32_t GetCodeItemOffset() const { |
| 712 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, code_item_offset_), false); |
| 713 | } |
| 714 | |
| 715 | void SetCodeItemOffset(uint32_t new_code_off) { |
| 716 | SetField32(OFFSET_OF_OBJECT_MEMBER(Method, code_item_offset_), |
| 717 | new_code_off, false); |
| 718 | } |
| 719 | |
| 720 | // Number of 32bit registers that would be required to hold all the arguments |
| 721 | static size_t NumArgRegisters(const StringPiece& shorty); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 722 | |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 723 | // Number of argument bytes required for densely packing the |
| 724 | // arguments into an array of arguments. |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 725 | size_t NumArgArrayBytes() const; |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 726 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 727 | uint16_t NumRegisters() const; |
| 728 | |
| 729 | void SetNumRegisters(uint16_t new_num_registers) { |
| 730 | SetField16(OFFSET_OF_OBJECT_MEMBER(Method, num_registers_), |
| 731 | new_num_registers, false); |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 734 | uint16_t NumIns() const; |
| 735 | |
| 736 | void SetNumIns(uint16_t new_num_ins) { |
| 737 | SetField16(OFFSET_OF_OBJECT_MEMBER(Method, num_ins_), |
| 738 | new_num_ins, false); |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 741 | uint16_t NumOuts() const; |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 742 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 743 | void SetNumOuts(uint16_t new_num_outs) { |
| 744 | SetField16(OFFSET_OF_OBJECT_MEMBER(Method, num_outs_), |
| 745 | new_num_outs, false); |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 748 | uint32_t GetProtoIdx() const; |
| 749 | |
| 750 | void SetProtoIdx(uint32_t new_proto_idx) { |
| 751 | SetField32(OFFSET_OF_OBJECT_MEMBER(Method, proto_idx_), new_proto_idx, false); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 754 | ObjectArray<String>* GetDexCacheStrings() const; |
| 755 | void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings); |
| 756 | |
| 757 | static MemberOffset DexCacheStringsOffset() { |
| 758 | return OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_strings_); |
| 759 | } |
| 760 | |
buzbee | 1da522d | 2011-09-04 11:22:20 -0700 | [diff] [blame] | 761 | static MemberOffset DexCacheInitializedStaticStorageOffset() { |
| 762 | return OFFSET_OF_OBJECT_MEMBER(Method, |
| 763 | dex_cache_initialized_static_storage_); |
| 764 | } |
| 765 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 766 | ObjectArray<Class>* GetDexCacheResolvedTypes() const; |
| 767 | void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types); |
| 768 | |
| 769 | ObjectArray<Method>* GetDexCacheResolvedMethods() const; |
| 770 | void SetDexCacheResolvedMethods(ObjectArray<Method>* new_dex_cache_methods); |
| 771 | |
| 772 | ObjectArray<Field>* GetDexCacheResolvedFields() const; |
| 773 | void SetDexCacheResolvedFields(ObjectArray<Field>* new_dex_cache_fields); |
| 774 | |
| 775 | CodeAndDirectMethods* GetDexCacheCodeAndDirectMethods() const; |
| 776 | void SetDexCacheCodeAndDirectMethods(CodeAndDirectMethods* new_value); |
| 777 | |
| 778 | ObjectArray<StaticStorageBase>* GetDexCacheInitializedStaticStorage() const; |
| 779 | void SetDexCacheInitializedStaticStorage(ObjectArray<StaticStorageBase>* new_value); |
| 780 | |
| 781 | void SetReturnTypeIdx(uint32_t new_return_type_idx); |
| 782 | |
| 783 | Class* GetReturnType() const; |
| 784 | |
| 785 | bool IsReturnAReference() const; |
| 786 | |
| 787 | bool IsReturnAFloat() const; |
| 788 | |
| 789 | bool IsReturnADouble() const; |
| 790 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 791 | bool IsReturnAFloatOrDouble() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 792 | return IsReturnAFloat() || IsReturnADouble(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 795 | bool IsReturnALong() const; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 796 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 797 | bool IsReturnVoid() const; |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 798 | |
Shih-wei Liao | 5381cf9 | 2011-07-27 00:28:04 -0700 | [diff] [blame] | 799 | // "Args" may refer to any of the 3 levels of "Args." |
| 800 | // To avoid confusion, our code will denote which "Args" clearly: |
| 801 | // 1. UserArgs: Args that a user see. |
| 802 | // 2. Args: Logical JVM-level Args. E.g., the first in Args will be the |
| 803 | // receiver. |
| 804 | // 3. CConvArgs: Calling Convention Args, which is physical-level Args. |
| 805 | // E.g., the first in Args is Method* for both static and non-static |
| 806 | // methods. And CConvArgs doesn't deal with the receiver because |
| 807 | // receiver is hardwired in an implicit register, so CConvArgs doesn't |
| 808 | // need to deal with it. |
| 809 | // |
| 810 | // The number of Args that should be supplied to this method |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 811 | size_t NumArgs() const { |
Shih-wei Liao | 5381cf9 | 2011-07-27 00:28:04 -0700 | [diff] [blame] | 812 | // "1 +" because the first in Args is the receiver. |
| 813 | // "- 1" because we don't count the return type. |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 814 | return (IsStatic() ? 0 : 1) + strlen(GetShorty()) - 1; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | // The number of reference arguments to this method including implicit this |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 818 | // pointer. |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 819 | size_t NumReferenceArgs() const; |
| 820 | |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 821 | // The number of long or double arguments. |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 822 | size_t NumLongOrDoubleArgs() const; |
| 823 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 824 | // Is the given method parameter a reference? |
| 825 | bool IsParamAReference(unsigned int param) const; |
| 826 | |
| 827 | // Is the given method parameter a long or double? |
| 828 | bool IsParamALongOrDouble(unsigned int param) const; |
| 829 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 830 | // Size in bytes of the given parameter |
| 831 | size_t ParamSize(unsigned int param) const; |
| 832 | |
| 833 | // Size in bytes of the return value |
| 834 | size_t ReturnSize() const; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 835 | |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 836 | const ByteArray* GetCodeArray() const { |
| 837 | return GetFieldPtr<const ByteArray*>(OFFSET_OF_OBJECT_MEMBER(Method, code_array_), false); |
| 838 | } |
| 839 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 840 | const void* GetCode() const { |
| 841 | return GetFieldPtr<const void*>(OFFSET_OF_OBJECT_MEMBER(Method, code_), false); |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 844 | bool HasCode() const { |
| 845 | return GetCode() != NULL; |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 848 | void SetCode(ByteArray* code_array, InstructionSet instruction_set); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 849 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 850 | static MemberOffset GetCodeOffset() { |
| 851 | return OFFSET_OF_OBJECT_MEMBER(Method, code_); |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Shih-wei Liao | d11af15 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 854 | size_t GetFrameSizeInBytes() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 855 | DCHECK(sizeof(size_t) == sizeof(uint32_t)); |
| 856 | size_t result = GetField32( |
| 857 | OFFSET_OF_OBJECT_MEMBER(Method, frame_size_in_bytes_), false); |
| 858 | DCHECK_LE(static_cast<size_t>(kStackAlignment), result); |
| 859 | return result; |
| 860 | } |
| 861 | |
| 862 | void SetFrameSizeInBytes(size_t new_frame_size_in_bytes) { |
| 863 | DCHECK(sizeof(size_t) == sizeof(uint32_t)); |
| 864 | DCHECK_LE(static_cast<size_t>(kStackAlignment), new_frame_size_in_bytes); |
| 865 | SetField32(OFFSET_OF_OBJECT_MEMBER(Method, frame_size_in_bytes_), |
| 866 | new_frame_size_in_bytes, false); |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Shih-wei Liao | d11af15 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 869 | size_t GetReturnPcOffsetInBytes() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 870 | DCHECK(sizeof(size_t) == sizeof(uint32_t)); |
| 871 | return GetField32( |
| 872 | OFFSET_OF_OBJECT_MEMBER(Method, return_pc_offset_in_bytes_), false); |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 875 | void SetReturnPcOffsetInBytes(size_t return_pc_offset_in_bytes) { |
| 876 | DCHECK(sizeof(size_t) == sizeof(uint32_t)); |
| 877 | DCHECK_LT(return_pc_offset_in_bytes, GetFrameSizeInBytes()); |
| 878 | SetField32(OFFSET_OF_OBJECT_MEMBER(Method, return_pc_offset_in_bytes_), |
| 879 | return_pc_offset_in_bytes, false); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 882 | void RegisterNative(const void* native_method) { |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 883 | CHECK(IsNative()); |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 884 | CHECK(native_method != NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 885 | SetFieldPtr<const void*>(OFFSET_OF_OBJECT_MEMBER(Method, native_method_), |
| 886 | native_method, false); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 889 | void UnregisterNative() { |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 890 | CHECK(IsNative()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 891 | SetFieldPtr<const void*>(OFFSET_OF_OBJECT_MEMBER(Method, native_method_), |
| 892 | NULL, false); |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 895 | static MemberOffset NativeMethodOffset() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 896 | return OFFSET_OF_OBJECT_MEMBER(Method, native_method_); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 899 | ByteArray* GetInvokeStubArray() const { |
| 900 | ByteArray* result = GetFieldPtr<ByteArray*>( |
| 901 | OFFSET_OF_OBJECT_MEMBER(Method, invoke_stub_array_), false); |
| 902 | // TODO: DCHECK(result != NULL); should be ahead of time compiled |
| 903 | return result; |
| 904 | } |
| 905 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 906 | // Native to managed invocation stub entry point |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 907 | InvokeStub* GetInvokeStub() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 908 | InvokeStub* result = GetFieldPtr<InvokeStub*>( |
| 909 | OFFSET_OF_OBJECT_MEMBER(Method, invoke_stub_), false); |
| 910 | // TODO: DCHECK(result != NULL); should be ahead of time compiled |
| 911 | return result; |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 914 | static MemberOffset GetInvokeStubOffset() { |
| 915 | return OFFSET_OF_OBJECT_MEMBER(Method, invoke_stub_); |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 916 | } |
| 917 | |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 918 | static MemberOffset GetDexCacheCodeAndDirectMethodsOffset() { |
| 919 | return OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_code_and_direct_methods_); |
| 920 | } |
| 921 | |
| 922 | static MemberOffset GetDexCacheResolvedMethodsOffset() { |
| 923 | return OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_methods_); |
| 924 | } |
| 925 | |
| 926 | static MemberOffset GetMethodIndexOffset() { |
| 927 | return OFFSET_OF_OBJECT_MEMBER(Method, method_index_); |
| 928 | } |
| 929 | |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 930 | void SetInvokeStub(const ByteArray* invoke_stub_array); |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 931 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 932 | void SetFpSpillMask(uint32_t fp_spill_mask) { |
| 933 | // Computed during compilation |
| 934 | SetField32(OFFSET_OF_OBJECT_MEMBER(Method, fp_spill_mask_), |
| 935 | fp_spill_mask, false); |
| 936 | } |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 937 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 938 | void SetCoreSpillMask(uint32_t core_spill_mask) { |
| 939 | // Computed during compilation |
| 940 | SetField32(OFFSET_OF_OBJECT_MEMBER(Method, core_spill_mask_), |
| 941 | core_spill_mask, false); |
| 942 | } |
| 943 | |
| 944 | // Converts a native PC to a dex PC. TODO: this is a no-op |
| 945 | // until we associate a PC mapping table with each method. |
| 946 | uintptr_t ToDexPC(const uintptr_t pc) const { |
| 947 | return pc; |
| 948 | } |
| 949 | |
| 950 | // Converts a dex PC to a native PC. TODO: this is a no-op |
| 951 | // until we associate a PC mapping table with each method. |
| 952 | uintptr_t ToNativePC(const uintptr_t pc) const { |
| 953 | return pc; |
| 954 | } |
| 955 | |
| 956 | static Class* GetJavaLangReflectMethod() { |
| 957 | DCHECK(java_lang_reflect_Method_ != NULL); |
| 958 | return java_lang_reflect_Method_; |
| 959 | } |
| 960 | |
| 961 | static void SetClass(Class* java_lang_reflect_Method); |
| 962 | static void ResetClass(); |
| 963 | |
| 964 | private: |
| 965 | uint32_t GetReturnTypeIdx() const; |
| 966 | |
| 967 | // TODO: the image writer should know the offsets of these fields as they |
| 968 | // should appear in the libcore Java mirror |
| 969 | friend class ImageWriter; |
| 970 | |
| 971 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
| 972 | // the class we are a part of |
| 973 | Class* declaring_class_; |
| 974 | ObjectArray<Class>* java_exception_types_; |
| 975 | Object* java_formal_type_parameters_; |
| 976 | Object* java_generic_exception_types_; |
| 977 | Object* java_generic_parameter_types_; |
| 978 | Object* java_generic_return_type_; |
| 979 | Class* java_return_type_; // Unused by ART |
| 980 | String* name_; |
| 981 | ObjectArray<Class>* java_parameter_types_; |
| 982 | uint32_t java_generic_types_are_initialized_; |
| 983 | uint32_t java_slot_; |
| 984 | |
| 985 | // TODO: start of non-Java mirror fields, place these in the Java piece |
| 986 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 987 | // access flags; low 16 bits are defined by spec (could be uint16_t?) |
| 988 | uint32_t access_flags_; |
| 989 | |
| 990 | // For concrete virtual methods, this is the offset of the method |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 991 | // in Class::vtable_. |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 992 | // |
| 993 | // For abstract methods in an interface class, this is the offset |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 994 | // of the method in "iftable_[n]->method_index_array_". |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 995 | uint16_t method_index_; |
| 996 | |
| 997 | // Method bounds; not needed for an abstract method. |
| 998 | // |
| 999 | // For a native method, we compute the size of the argument list, and |
| 1000 | // set "insSize" and "registerSize" equal to it. |
| 1001 | uint16_t num_registers_; // ins + locals |
| 1002 | uint16_t num_outs_; |
| 1003 | uint16_t num_ins_; |
| 1004 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1005 | // Total size in bytes of the frame |
Shih-wei Liao | d11af15 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 1006 | size_t frame_size_in_bytes_; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1007 | |
| 1008 | // Architecture-dependent register spill masks |
| 1009 | uint32_t core_spill_mask_; |
| 1010 | uint32_t fp_spill_mask_; |
| 1011 | |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 1012 | // The method descriptor. This represents the parameters a method |
| 1013 | // takes and value it returns. This string is a list of the type |
| 1014 | // descriptors for the parameters enclosed in parenthesis followed |
| 1015 | // by the return type descriptor. For example, for the method |
| 1016 | // |
| 1017 | // Object mymethod(int i, double d, Thread t) |
| 1018 | // |
| 1019 | // the method descriptor would be |
| 1020 | // |
| 1021 | // (IDLjava/lang/Thread;)Ljava/lang/Object; |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1022 | String* signature_; |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 1023 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1024 | // Method prototype descriptor string (return and argument types). |
| 1025 | uint32_t proto_idx_; |
| 1026 | |
Shih-wei Liao | 2fb9753 | 2011-08-11 16:17:23 -0700 | [diff] [blame] | 1027 | // Offset to the CodeItem. |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1028 | uint32_t code_item_offset_; |
Shih-wei Liao | 2fb9753 | 2011-08-11 16:17:23 -0700 | [diff] [blame] | 1029 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1030 | // Index of the return type |
| 1031 | uint32_t java_return_type_idx_; |
| 1032 | |
| 1033 | // The short-form method descriptor string. TODO: make String* |
| 1034 | const char* shorty_; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1035 | |
Ian Rogers | 762400c | 2011-08-23 12:14:16 -0700 | [diff] [blame] | 1036 | // short cuts to declaring_class_->dex_cache_ members for fast compiled code |
| 1037 | // access |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1038 | ObjectArray<String>* dex_cache_strings_; |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 1039 | ObjectArray<Class>* dex_cache_resolved_types_; |
| 1040 | ObjectArray<Method>* dex_cache_resolved_methods_; |
| 1041 | ObjectArray<Field>* dex_cache_resolved_fields_; |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 1042 | CodeAndDirectMethods* dex_cache_code_and_direct_methods_; |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 1043 | ObjectArray<StaticStorageBase>* dex_cache_initialized_static_storage_; |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 1044 | |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 1045 | private: |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 1046 | // Storage for code_ |
| 1047 | const ByteArray* code_array_; |
| 1048 | |
| 1049 | // Compiled code associated with this method for callers from managed code. |
| 1050 | // May be compiled managed code or a bridge for invoking a native method. |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 1051 | const void* code_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1052 | |
Ian Rogers | 762400c | 2011-08-23 12:14:16 -0700 | [diff] [blame] | 1053 | // Offset of return PC within frame for compiled code (in bytes) |
Shih-wei Liao | d11af15 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 1054 | size_t return_pc_offset_in_bytes_; |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 1055 | |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 1056 | // The target native method registered with this method |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1057 | const void* native_method_; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1058 | |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 1059 | // Storage for invoke_stub_ |
| 1060 | const ByteArray* invoke_stub_array_; |
| 1061 | |
| 1062 | // Native invocation stub entry point for calling from native to managed code. |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 1063 | const InvokeStub* invoke_stub_; |
| 1064 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1065 | static Class* java_lang_reflect_Method_; |
| 1066 | |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1067 | DISALLOW_IMPLICIT_CONSTRUCTORS(Method); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1068 | }; |
| 1069 | |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1070 | class Array : public Object { |
| 1071 | public: |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1072 | static size_t SizeOf(size_t component_count, |
| 1073 | size_t component_size) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 1074 | return sizeof(Array) + component_count * component_size; |
| 1075 | } |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 1076 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1077 | // Given the context of a calling Method, use its DexCache to |
| 1078 | // resolve a type to an array Class. If it cannot be resolved, throw |
| 1079 | // an error. If it can, use it to create an array. |
| 1080 | static Array* AllocFromCode(uint32_t type_idx, Method* method, int32_t component_count); |
| 1081 | |
Elliott Hughes | 68f4fa0 | 2011-08-21 10:46:59 -0700 | [diff] [blame] | 1082 | // A convenience for code that doesn't know the component size, |
| 1083 | // and doesn't want to have to work it out itself. |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1084 | static Array* Alloc(Class* array_class, int32_t component_count); |
Elliott Hughes | 68f4fa0 | 2011-08-21 10:46:59 -0700 | [diff] [blame] | 1085 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1086 | static Array* Alloc(Class* array_class, int32_t component_count, size_t component_size); |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1087 | |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 1088 | size_t SizeOf() const; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 1089 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 1090 | int32_t GetLength() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1091 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Array, length_), false); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1092 | } |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1093 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1094 | void SetLength(int32_t length) { |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 1095 | CHECK_GE(length, 0); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1096 | SetField32(OFFSET_OF_OBJECT_MEMBER(Array, length_), length, false); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1097 | } |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1098 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1099 | static MemberOffset LengthOffset() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1100 | return OFFSET_OF_OBJECT_MEMBER(Array, length_); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | static MemberOffset DataOffset() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1104 | return OFFSET_OF_OBJECT_MEMBER(Array, first_element_); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 1107 | void* GetRawData() { |
| 1108 | return reinterpret_cast<void*>(first_element_); |
| 1109 | } |
| 1110 | |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 1111 | protected: |
| 1112 | bool IsValidIndex(int32_t index) const { |
| 1113 | if (index < 0 || index >= length_) { |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 1114 | Thread* self = Thread::Current(); |
| 1115 | self->ThrowNewException("Ljava/lang/ArrayIndexOutOfBoundsException;", |
| 1116 | "length=%i; index=%i", length_, index); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 1117 | return false; |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 1118 | } |
| 1119 | return true; |
| 1120 | } |
| 1121 | |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1122 | private: |
| 1123 | // The number of array elements. |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 1124 | int32_t length_; |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 1125 | // Padding to ensure the first member defined by a subclass begins on a 8-byte boundary |
| 1126 | int32_t padding_; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1127 | // Marker for the data (used by generated code) |
| 1128 | uint32_t first_element_[0]; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1129 | |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1130 | DISALLOW_IMPLICIT_CONSTRUCTORS(Array); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1131 | }; |
| 1132 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 1133 | template<class T> |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1134 | class ObjectArray : public Array { |
| 1135 | public: |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1136 | static ObjectArray<T>* Alloc(Class* object_array_class, int32_t length); |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 1137 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1138 | T* Get(int32_t i) const; |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 1139 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1140 | void Set(int32_t i, T* object); |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 1141 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1142 | // Set element without bound and element type checks, to be used in limited |
| 1143 | // circumstances, such as during boot image writing |
| 1144 | void SetWithoutChecks(int32_t i, T* object); |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1145 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1146 | static void Copy(const ObjectArray<T>* src, int src_pos, |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1147 | ObjectArray<T>* dst, int dst_pos, |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1148 | size_t length); |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1149 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1150 | ObjectArray<T>* CopyOf(int32_t new_length); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1151 | |
| 1152 | private: |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1153 | DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1154 | }; |
| 1155 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1156 | template<class T> |
| 1157 | ObjectArray<T>* ObjectArray<T>::Alloc(Class* object_array_class, int32_t length) { |
| 1158 | return Array::Alloc(object_array_class, length, sizeof(uint32_t))->AsObjectArray<T>(); |
| 1159 | } |
| 1160 | |
| 1161 | template<class T> |
| 1162 | T* ObjectArray<T>::Get(int32_t i) const { |
| 1163 | if (!IsValidIndex(i)) { |
| 1164 | return NULL; |
| 1165 | } |
| 1166 | MemberOffset data_offset(DataOffset().Int32Value() + i * sizeof(Object*)); |
| 1167 | return GetFieldObject<T*>(data_offset, false); |
| 1168 | } |
| 1169 | |
| 1170 | template<class T> |
| 1171 | ObjectArray<T>* ObjectArray<T>::CopyOf(int32_t new_length) { |
| 1172 | ObjectArray<T>* new_array = Alloc(GetClass(), new_length); |
| 1173 | Copy(this, 0, new_array, 0, std::min(GetLength(), new_length)); |
| 1174 | return new_array; |
| 1175 | } |
| 1176 | |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 1177 | // Type for the InitializedStaticStorage table. Currently the Class |
Brian Carlstrom | 848a4b3 | 2011-09-04 11:29:27 -0700 | [diff] [blame] | 1178 | // provides the static storage. However, this might change to an Array |
| 1179 | // to improve image sharing, so we use this type to avoid assumptions |
| 1180 | // on the current storage. |
| 1181 | class StaticStorageBase : public Object {}; |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 1182 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1183 | // C++ mirror of java.lang.Class |
Brian Carlstrom | 848a4b3 | 2011-09-04 11:29:27 -0700 | [diff] [blame] | 1184 | class Class : public StaticStorageBase { |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1185 | public: |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 1186 | |
| 1187 | // Class Status |
| 1188 | // |
| 1189 | // kStatusNotReady: If a Class cannot be found in the class table by |
| 1190 | // FindClass, it allocates an new one with AllocClass in the |
| 1191 | // kStatusNotReady and calls LoadClass. Note if it does find a |
| 1192 | // class, it may not be kStatusResolved and it will try to push it |
| 1193 | // forward toward kStatusResolved. |
| 1194 | // |
| 1195 | // kStatusIdx: LoadClass populates with Class with information from |
| 1196 | // the DexFile, moving the status to kStatusIdx, indicating that the |
| 1197 | // Class values in super_class_ and interfaces_ have not been |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1198 | // populated based on super_class_type_idx_ and |
| 1199 | // interfaces_type_idx_. The new Class can then be inserted into the |
| 1200 | // classes table. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 1201 | // |
| 1202 | // kStatusLoaded: After taking a lock on Class, the ClassLinker will |
| 1203 | // attempt to move a kStatusIdx class forward to kStatusLoaded by |
| 1204 | // using ResolveClass to initialize the super_class_ and interfaces_. |
| 1205 | // |
| 1206 | // kStatusResolved: Still holding the lock on Class, the ClassLinker |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1207 | // shows linking is complete and fields of the Class populated by making |
| 1208 | // it kStatusResolved. Java allows circularities of the form where a super |
| 1209 | // class has a field that is of the type of the sub class. We need to be able |
| 1210 | // to fully resolve super classes while resolving types for fields. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 1211 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1212 | enum Status { |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1213 | kStatusError = -1, |
| 1214 | kStatusNotReady = 0, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1215 | kStatusIdx = 1, // loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_ |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1216 | kStatusLoaded = 2, // DEX idx values resolved |
| 1217 | kStatusResolved = 3, // part of linking |
| 1218 | kStatusVerifying = 4, // in the process of being verified |
| 1219 | kStatusVerified = 5, // logically part of linking; done pre-init |
| 1220 | kStatusInitializing = 6, // class init in progress |
| 1221 | kStatusInitialized = 7, // ready to go |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1222 | }; |
| 1223 | |
| 1224 | enum PrimitiveType { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1225 | kPrimNot = 0, |
| 1226 | kPrimBoolean, |
| 1227 | kPrimByte, |
| 1228 | kPrimChar, |
| 1229 | kPrimShort, |
| 1230 | kPrimInt, |
| 1231 | kPrimLong, |
| 1232 | kPrimFloat, |
| 1233 | kPrimDouble, |
| 1234 | kPrimVoid, |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1235 | }; |
| 1236 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1237 | Status GetStatus() const { |
| 1238 | CHECK(sizeof(Status) == sizeof(uint32_t)); |
| 1239 | return static_cast<Status>( |
| 1240 | GetField32(OFFSET_OF_OBJECT_MEMBER(Class, status_), false)); |
| 1241 | } |
| 1242 | |
| 1243 | void SetStatus(Status new_status); |
| 1244 | |
| 1245 | // Returns true if the class has failed to link. |
| 1246 | bool IsErroneous() const { |
| 1247 | return GetStatus() == kStatusError; |
| 1248 | } |
| 1249 | |
| 1250 | // Returns true if the class has been loaded. |
| 1251 | bool IsIdxLoaded() const { |
| 1252 | return GetStatus() >= kStatusIdx; |
| 1253 | } |
| 1254 | |
| 1255 | // Returns true if the class has been loaded. |
| 1256 | bool IsLoaded() const { |
| 1257 | return GetStatus() >= kStatusLoaded; |
| 1258 | } |
| 1259 | |
| 1260 | // Returns true if the class has been linked. |
| 1261 | bool IsLinked() const { |
| 1262 | return GetStatus() >= kStatusResolved; |
| 1263 | } |
| 1264 | |
| 1265 | // Returns true if the class has been verified. |
| 1266 | bool IsVerified() const { |
| 1267 | return GetStatus() >= kStatusVerified; |
| 1268 | } |
| 1269 | |
| 1270 | // Returns true if the class is initialized. |
| 1271 | bool IsInitialized() const { |
| 1272 | return GetStatus() == kStatusInitialized; |
| 1273 | } |
| 1274 | |
| 1275 | uint32_t GetAccessFlags() const; |
| 1276 | |
| 1277 | void SetAccessFlags(uint32_t new_access_flags) { |
| 1278 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), new_access_flags, |
| 1279 | false); |
| 1280 | } |
| 1281 | |
| 1282 | // Returns true if the class is an interface. |
| 1283 | bool IsInterface() const { |
| 1284 | return (GetAccessFlags() & kAccInterface) != 0; |
| 1285 | } |
| 1286 | |
| 1287 | // Returns true if the class is declared public. |
| 1288 | bool IsPublic() const { |
| 1289 | return (GetAccessFlags() & kAccPublic) != 0; |
| 1290 | } |
| 1291 | |
| 1292 | // Returns true if the class is declared final. |
| 1293 | bool IsFinal() const { |
| 1294 | return (GetAccessFlags() & kAccFinal) != 0; |
| 1295 | } |
| 1296 | |
| 1297 | // Returns true if the class is abstract. |
| 1298 | bool IsAbstract() const { |
| 1299 | return (GetAccessFlags() & kAccAbstract) != 0; |
| 1300 | } |
| 1301 | |
| 1302 | // Returns true if the class is an annotation. |
| 1303 | bool IsAnnotation() const { |
| 1304 | return (GetAccessFlags() & kAccAnnotation) != 0; |
| 1305 | } |
| 1306 | |
| 1307 | // Returns true if the class is synthetic. |
| 1308 | bool IsSynthetic() const { |
| 1309 | return (GetAccessFlags() & kAccSynthetic) != 0; |
| 1310 | } |
| 1311 | |
| 1312 | bool IsReferenceClass() const { |
| 1313 | return (GetAccessFlags() & kAccClassIsReference) != 0; |
| 1314 | } |
| 1315 | |
| 1316 | bool IsWeakReferenceClass() const { |
| 1317 | return (GetAccessFlags() & kAccClassIsWeakReference) != 0; |
| 1318 | } |
| 1319 | |
| 1320 | bool IsSoftReferenceClass() const { |
| 1321 | return (GetAccessFlags() & ~kAccReferenceFlagsMask) == kAccClassIsReference; |
| 1322 | } |
| 1323 | |
| 1324 | bool IsFinalizerReferenceClass() const { |
| 1325 | return (GetAccessFlags() & kAccClassIsFinalizerReference) != 0; |
| 1326 | } |
| 1327 | |
| 1328 | bool IsPhantomReferenceClass() const { |
| 1329 | return (GetAccessFlags() & kAccClassIsPhantomReference) != 0; |
| 1330 | } |
| 1331 | |
| 1332 | PrimitiveType GetPrimitiveType() const { |
| 1333 | CHECK(sizeof(PrimitiveType) == sizeof(int32_t)); |
| 1334 | return static_cast<PrimitiveType>( |
| 1335 | GetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), false)); |
| 1336 | } |
| 1337 | |
| 1338 | void SetPrimitiveType(PrimitiveType new_type) { |
| 1339 | CHECK(sizeof(PrimitiveType) == sizeof(int32_t)); |
| 1340 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), new_type, |
| 1341 | false); |
| 1342 | } |
| 1343 | |
| 1344 | // Returns true if the class is a primitive type. |
| 1345 | bool IsPrimitive() const { |
| 1346 | return GetPrimitiveType() != kPrimNot; |
| 1347 | } |
| 1348 | |
| 1349 | bool IsPrimitiveBoolean() const { |
| 1350 | return GetPrimitiveType() == kPrimBoolean; |
| 1351 | } |
| 1352 | |
| 1353 | bool IsPrimitiveByte() const { |
| 1354 | return GetPrimitiveType() == kPrimByte; |
| 1355 | } |
| 1356 | |
| 1357 | bool IsPrimitiveChar() const { |
| 1358 | return GetPrimitiveType() == kPrimChar; |
| 1359 | } |
| 1360 | |
| 1361 | bool IsPrimitiveShort() const { |
| 1362 | return GetPrimitiveType() == kPrimShort; |
| 1363 | } |
| 1364 | |
| 1365 | bool IsPrimitiveInt() const { |
| 1366 | return GetPrimitiveType() == kPrimInt; |
| 1367 | } |
| 1368 | |
| 1369 | bool IsPrimitiveLong() const { |
| 1370 | return GetPrimitiveType() == kPrimLong; |
| 1371 | } |
| 1372 | |
| 1373 | bool IsPrimitiveFloat() const { |
| 1374 | return GetPrimitiveType() == kPrimFloat; |
| 1375 | } |
| 1376 | |
| 1377 | bool IsPrimitiveDouble() const { |
| 1378 | return GetPrimitiveType() == kPrimDouble; |
| 1379 | } |
| 1380 | |
| 1381 | bool IsPrimitiveVoid() const { |
| 1382 | return GetPrimitiveType() == kPrimVoid; |
| 1383 | } |
| 1384 | |
| 1385 | size_t PrimitiveSize() const; |
| 1386 | |
| 1387 | bool IsArrayClass() const { |
| 1388 | return GetArrayRank() != 0; |
| 1389 | } |
| 1390 | |
| 1391 | int32_t GetArrayRank() const { |
| 1392 | int32_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, array_rank_), |
| 1393 | false); |
| 1394 | return result; |
| 1395 | } |
| 1396 | |
| 1397 | void SetArrayRank(int32_t new_array_rank) { |
| 1398 | DCHECK_EQ(0, GetArrayRank()); |
| 1399 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, array_rank_), new_array_rank, |
| 1400 | false); |
| 1401 | } |
| 1402 | |
| 1403 | Class* GetComponentType() const { |
| 1404 | DCHECK(IsArrayClass()); |
| 1405 | return GetFieldObject<Class*>( |
| 1406 | OFFSET_OF_OBJECT_MEMBER(Class, component_type_), false); |
| 1407 | } |
| 1408 | |
| 1409 | void SetComponentType(Class* new_component_type) { |
| 1410 | DCHECK(GetComponentType() == NULL); |
| 1411 | DCHECK(new_component_type != NULL); |
| 1412 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, component_type_), |
| 1413 | new_component_type, false); |
| 1414 | } |
| 1415 | |
| 1416 | size_t GetComponentSize() const { |
| 1417 | return GetTypeSize(GetComponentType()->GetDescriptor()); |
| 1418 | } |
| 1419 | |
| 1420 | bool IsObjectClass() const { |
| 1421 | return !IsPrimitive() && GetSuperClass() == NULL; |
| 1422 | } |
| 1423 | |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 1424 | // Tests whether an element of type 'object_class' can be |
| 1425 | // assigned into an array of type 'array_class'. |
| 1426 | static bool CanPutArrayElement(const Class* object_class, const Class* array_class); |
| 1427 | // Like CanPutArrayElement, but throws an exception and |
| 1428 | // unwinds the stack instead of returning false. |
| 1429 | static void CanPutArrayElementFromCode(const Class* object_class, const Class* array_class); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1430 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1431 | // Given the context of a calling Method, use its DexCache to |
| 1432 | // resolve a type to a Class. If it cannot be resolved, throw an |
| 1433 | // error. If it can, use it to create an instance. |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 1434 | static Object* AllocObjectFromCode(uint32_t type_idx, Method* method); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1435 | |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 1436 | // Creates a raw object instance but does not invoke the default constructor. |
| 1437 | Object* AllocObject(); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 1438 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1439 | static size_t GetTypeSize(const String* descriptor); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 1440 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1441 | const String* GetDescriptor() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1442 | 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 Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 1457 | size_t SizeOf() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1458 | CHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1459 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1462 | size_t GetClassSize() const { |
| 1463 | CHECK(sizeof(size_t) == sizeof(uint32_t)); |
| 1464 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1467 | void SetClassSize(size_t new_class_size) { |
| 1468 | DCHECK_GE(new_class_size, GetClassSize()); |
| 1469 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size, |
| 1470 | false); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1473 | size_t GetObjectSize() const { |
| 1474 | CHECK(!IsVariableSize()); |
| 1475 | CHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1476 | size_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), |
| 1477 | false); |
| 1478 | CHECK_GE(result, sizeof(Object)); |
| 1479 | return result; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1482 | void SetObjectSize(size_t new_object_size) { |
| 1483 | DCHECK(!IsVariableSize()); |
| 1484 | CHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1485 | return SetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), |
| 1486 | new_object_size, false); |
Carl Shapiro | 83ab4f3 | 2011-08-15 20:21:39 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1489 | // Returns true if this class is in the same packages as that class. |
| 1490 | bool IsInSamePackage(const Class* that) const; |
| 1491 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1492 | static bool IsInSamePackage(const String* descriptor1, |
| 1493 | const String* descriptor2); |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1494 | |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1495 | // Returns true if this class can access that class. |
| 1496 | bool CanAccess(const Class* that) const { |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1497 | return that->IsPublic() || this->IsInSamePackage(that); |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1500 | bool IsAssignableFrom(const Class* klass) const { |
| 1501 | DCHECK(klass != NULL); |
| 1502 | if (this == klass) { |
| 1503 | // Can always assign to things of the same type |
| 1504 | return true; |
| 1505 | } else if(IsObjectClass()) { |
| 1506 | // Can assign any reference to java.lang.Object |
| 1507 | return !klass->IsPrimitive(); |
| 1508 | } else if (IsInterface()) { |
| 1509 | return klass->Implements(this); |
| 1510 | } else if (klass->IsArrayClass()) { |
| 1511 | return IsAssignableFromArray(klass); |
| 1512 | } else { |
| 1513 | return klass->IsSubClass(this); |
| 1514 | } |
| 1515 | } |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 1516 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1517 | Class* GetSuperClass() const { |
| 1518 | // Can only get super class for loaded classes (hack for when runtime is |
| 1519 | // initializing) |
| 1520 | DCHECK(IsLoaded() || Runtime::Current() == NULL); |
| 1521 | return GetFieldObject<Class*>( |
| 1522 | OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false); |
| 1523 | } |
| 1524 | |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 1525 | static MemberOffset SuperClassOffset() { |
| 1526 | return MemberOffset(OFFSETOF_MEMBER(Class, super_class_)); |
| 1527 | } |
| 1528 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1529 | void SetSuperClass(Class *new_super_class) { |
| 1530 | // super class is assigned once, except during class linker initialization |
| 1531 | Class* old_super_class = GetFieldObject<Class*>( |
| 1532 | OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false); |
| 1533 | DCHECK(old_super_class == NULL || old_super_class == new_super_class); |
| 1534 | DCHECK(new_super_class != NULL); |
| 1535 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), |
| 1536 | new_super_class, false); |
| 1537 | } |
| 1538 | |
| 1539 | bool HasSuperClass() const { |
| 1540 | return GetSuperClass() != NULL; |
| 1541 | } |
| 1542 | |
| 1543 | uint32_t GetSuperClassTypeIdx() const { |
| 1544 | DCHECK(IsIdxLoaded()); |
| 1545 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, super_class_type_idx_), |
| 1546 | false); |
| 1547 | } |
| 1548 | |
| 1549 | void SetSuperClassTypeIdx(int32_t new_super_class_idx) { |
| 1550 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, super_class_type_idx_), |
| 1551 | new_super_class_idx, false); |
| 1552 | } |
| 1553 | |
| 1554 | const ClassLoader* GetClassLoader() const; |
| 1555 | |
| 1556 | void SetClassLoader(const ClassLoader* new_cl); |
| 1557 | |
| 1558 | static MemberOffset DexCacheOffset() { |
| 1559 | return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_)); |
| 1560 | } |
| 1561 | |
| 1562 | DexCache* GetDexCache() const; |
| 1563 | |
| 1564 | void SetDexCache(DexCache* new_dex_cache); |
| 1565 | |
| 1566 | ObjectArray<Method>* GetDirectMethods() const { |
| 1567 | DCHECK(IsLoaded()); |
| 1568 | return GetFieldObject<ObjectArray<Method>*>( |
| 1569 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false); |
| 1570 | } |
| 1571 | |
| 1572 | void SetDirectMethods(ObjectArray<Method>* new_direct_methods) { |
| 1573 | DCHECK(NULL == GetFieldObject<ObjectArray<Method>*>( |
| 1574 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false)); |
| 1575 | DCHECK_NE(0, new_direct_methods->GetLength()); |
| 1576 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), |
| 1577 | new_direct_methods, false); |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 1580 | Method* GetDirectMethod(int32_t i) const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1581 | return GetDirectMethods()->Get(i); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | void SetDirectMethod(uint32_t i, Method* f) { // TODO: uint16_t |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1585 | ObjectArray<Method>* direct_methods = |
| 1586 | GetFieldObject<ObjectArray<Method>*>( |
| 1587 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false); |
| 1588 | direct_methods->Set(i, f); |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1591 | // Returns the number of static, private, and constructor methods. |
| 1592 | size_t NumDirectMethods() const { |
| 1593 | return (GetDirectMethods() != NULL) ? GetDirectMethods()->GetLength() : 0; |
| 1594 | } |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 1595 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1596 | ObjectArray<Method>* GetVirtualMethods() const { |
| 1597 | DCHECK(IsLoaded()); |
| 1598 | return GetFieldObject<ObjectArray<Method>*>( |
| 1599 | OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), false); |
| 1600 | } |
| 1601 | |
| 1602 | void SetVirtualMethods(ObjectArray<Method>* new_virtual_methods) { |
| 1603 | // TODO: we reassign virtual methods to grow the table for miranda |
| 1604 | // methods.. they should really just be assigned once |
| 1605 | DCHECK_NE(0, new_virtual_methods->GetLength()); |
| 1606 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), |
| 1607 | new_virtual_methods, false); |
| 1608 | } |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 1609 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1610 | // Returns the number of non-inherited virtual methods. |
| 1611 | size_t NumVirtualMethods() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1612 | return (GetVirtualMethods() != NULL) ? GetVirtualMethods()->GetLength() : 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | Method* GetVirtualMethod(uint32_t i) const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1616 | DCHECK(IsLinked()); |
| 1617 | return GetVirtualMethods()->Get(i); |
| 1618 | } |
| 1619 | |
| 1620 | Method* GetVirtualMethodDuringLinking(uint32_t i) const { |
| 1621 | DCHECK(IsLoaded()); |
| 1622 | return GetVirtualMethods()->Get(i); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | void SetVirtualMethod(uint32_t i, Method* f) { // TODO: uint16_t |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1626 | ObjectArray<Method>* virtual_methods = |
| 1627 | GetFieldObject<ObjectArray<Method>*>( |
| 1628 | OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), false); |
| 1629 | virtual_methods->Set(i, f); |
| 1630 | } |
| 1631 | |
| 1632 | ObjectArray<Method>* GetVTable() const { |
| 1633 | DCHECK(IsLinked()); |
| 1634 | return GetFieldObject<ObjectArray<Method>*>( |
| 1635 | OFFSET_OF_OBJECT_MEMBER(Class, vtable_), false); |
| 1636 | } |
| 1637 | |
| 1638 | ObjectArray<Method>* GetVTableDuringLinking() const { |
| 1639 | DCHECK(IsLoaded()); |
| 1640 | return GetFieldObject<ObjectArray<Method>*>( |
| 1641 | OFFSET_OF_OBJECT_MEMBER(Class, vtable_), false); |
| 1642 | } |
| 1643 | |
| 1644 | void SetVTable(ObjectArray<Method>* new_vtable) { |
| 1645 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, vtable_), new_vtable, false); |
| 1646 | } |
| 1647 | |
| 1648 | static MemberOffset VTableOffset() { |
| 1649 | return OFFSET_OF_OBJECT_MEMBER(Class, vtable_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 1652 | // Given a method implemented by this class but potentially from a |
| 1653 | // super class, return the specific implementation |
| 1654 | // method for this class. |
| 1655 | Method* FindVirtualMethodForVirtual(Method* method) { |
| 1656 | DCHECK(!method->GetDeclaringClass()->IsInterface()); |
| 1657 | // The argument method may from a super class. |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1658 | // Use the index to a potentially overridden one for this instance's class. |
| 1659 | return GetVTable()->Get(method->GetMethodIndex()); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | // Given a method implemented by this class, but potentially from a |
| 1663 | // super class or interface, return the specific implementation |
| 1664 | // method for this class. |
| 1665 | Method* FindVirtualMethodForInterface(Method* method); |
| 1666 | |
| 1667 | Method* FindVirtualMethodForVirtualOrInterface(Method* method) { |
| 1668 | if (method->GetDeclaringClass()->IsInterface()) { |
| 1669 | return FindVirtualMethodForInterface(method); |
| 1670 | } |
| 1671 | return FindVirtualMethodForVirtual(method); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 1674 | Method* FindDeclaredVirtualMethod(const StringPiece& name, |
| 1675 | const StringPiece& descriptor); |
| 1676 | |
| 1677 | Method* FindVirtualMethod(const StringPiece& name, |
| 1678 | const StringPiece& descriptor); |
| 1679 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1680 | Method* FindDeclaredDirectMethod(const StringPiece& name, |
| 1681 | const StringPiece& signature); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1682 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1683 | Method* FindDirectMethod(const StringPiece& name, |
| 1684 | const StringPiece& signature); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1685 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1686 | size_t NumInterfaces() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1687 | CHECK(IsIdxLoaded()); // used during loading |
| 1688 | ObjectArray<Class>* interfaces = GetFieldObject<ObjectArray<Class>*>( |
| 1689 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false); |
| 1690 | return (interfaces != NULL) ? interfaces->GetLength() : 0; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1693 | IntArray* GetInterfacesTypeIdx() const { |
| 1694 | CHECK(IsIdxLoaded()); |
| 1695 | return GetFieldObject<IntArray*>( |
| 1696 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_type_idx_), false); |
| 1697 | } |
| 1698 | |
| 1699 | void SetInterfacesTypeIdx(IntArray* new_interfaces_idx); |
| 1700 | |
| 1701 | ObjectArray<Class>* GetInterfaces() const { |
| 1702 | CHECK(IsLoaded()); |
| 1703 | return GetFieldObject<ObjectArray<Class>*>( |
| 1704 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false); |
| 1705 | } |
| 1706 | |
| 1707 | void SetInterfaces(ObjectArray<Class>* new_interfaces) { |
| 1708 | DCHECK(NULL == GetFieldObject<Object*>( |
| 1709 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false)); |
| 1710 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), |
| 1711 | new_interfaces, false); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | void SetInterface(uint32_t i, Class* f) { // TODO: uint16_t |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 1715 | DCHECK_NE(NumInterfaces(), 0U); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1716 | ObjectArray<Class>* interfaces = |
| 1717 | GetFieldObject<ObjectArray<Class>*>( |
| 1718 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false); |
| 1719 | interfaces->Set(i, f); |
| 1720 | } |
| 1721 | |
| 1722 | Class* GetInterface(uint32_t i) const { |
| 1723 | DCHECK_NE(NumInterfaces(), 0U); |
| 1724 | return GetInterfaces()->Get(i); |
| 1725 | } |
| 1726 | |
| 1727 | size_t GetIFTableCount() const { |
| 1728 | DCHECK(IsLinked()); |
| 1729 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1730 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, iftable_count_), false); |
| 1731 | } |
| 1732 | |
| 1733 | void SetIFTableCount(size_t new_iftable_count) { |
| 1734 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1735 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, iftable_count_), |
| 1736 | new_iftable_count, false); |
| 1737 | } |
| 1738 | |
| 1739 | InterfaceEntry* GetIFTable() const { |
| 1740 | DCHECK(IsLinked()); |
| 1741 | return GetFieldPtr<InterfaceEntry*>( |
| 1742 | OFFSET_OF_OBJECT_MEMBER(Class, iftable_), false); |
| 1743 | } |
| 1744 | |
| 1745 | void SetIFTable(InterfaceEntry* new_iftable) { |
| 1746 | SetFieldPtr<InterfaceEntry*>(OFFSET_OF_OBJECT_MEMBER(Class, iftable_), |
| 1747 | new_iftable, false); |
| 1748 | } |
| 1749 | |
| 1750 | size_t GetIfviPoolCount() const { |
| 1751 | DCHECK(IsLinked()); |
| 1752 | CHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1753 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, ifvi_pool_count_), false); |
| 1754 | } |
| 1755 | |
| 1756 | void SetIfviPoolCount(size_t new_count) { |
| 1757 | CHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1758 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, ifvi_pool_count_), new_count, |
| 1759 | false); |
| 1760 | } |
| 1761 | |
| 1762 | uint32_t* GetIfviPool() const { |
| 1763 | DCHECK(IsLinked()); |
| 1764 | return GetFieldPtr<uint32_t*>( |
| 1765 | OFFSET_OF_OBJECT_MEMBER(Class, ifvi_pool_), false); |
| 1766 | } |
| 1767 | |
| 1768 | void SetIfviPool(uint32_t* new_pool) { |
| 1769 | SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(Class, ifvi_pool_), new_pool, false); |
| 1770 | } |
| 1771 | |
| 1772 | // Get instance fields |
| 1773 | ObjectArray<Field>* GetIFields() const { |
| 1774 | DCHECK(IsLoaded()); |
| 1775 | return GetFieldObject<ObjectArray<Field>*>( |
| 1776 | OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false); |
| 1777 | } |
| 1778 | |
| 1779 | void SetIFields(ObjectArray<Field>* new_ifields) { |
| 1780 | DCHECK(NULL == GetFieldObject<ObjectArray<Field>*>( |
| 1781 | OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false)); |
| 1782 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, ifields_), |
| 1783 | new_ifields, false); |
| 1784 | } |
| 1785 | |
| 1786 | size_t NumInstanceFields() const { |
| 1787 | return (GetIFields() != NULL) ? GetIFields()->GetLength() : 0; |
| 1788 | } |
| 1789 | |
| 1790 | Field* GetInstanceField(uint32_t i) const { // TODO: uint16_t |
| 1791 | DCHECK_NE(NumInstanceFields(), 0U); |
| 1792 | return GetIFields()->Get(i); |
| 1793 | } |
| 1794 | |
| 1795 | void SetInstanceField(uint32_t i, Field* f) { // TODO: uint16_t |
| 1796 | ObjectArray<Field>* ifields= GetFieldObject<ObjectArray<Field>*>( |
| 1797 | OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false); |
| 1798 | ifields->Set(i, f); |
| 1799 | } |
| 1800 | |
| 1801 | // Returns the number of instance fields containing reference types. |
| 1802 | size_t NumReferenceInstanceFields() const { |
| 1803 | DCHECK(IsLinked()); |
| 1804 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1805 | return GetField32( |
| 1806 | OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false); |
| 1807 | } |
| 1808 | |
| 1809 | size_t NumReferenceInstanceFieldsDuringLinking() const { |
| 1810 | DCHECK(IsLoaded()); |
| 1811 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1812 | return GetField32( |
| 1813 | OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false); |
| 1814 | } |
| 1815 | |
| 1816 | void SetNumReferenceInstanceFields(size_t new_num) { |
| 1817 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1818 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), |
| 1819 | new_num, false); |
| 1820 | } |
| 1821 | |
| 1822 | uint32_t GetReferenceInstanceOffsets() const { |
| 1823 | DCHECK(IsLinked()); |
| 1824 | return GetField32( |
| 1825 | OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), false); |
| 1826 | } |
| 1827 | |
| 1828 | void SetReferenceInstanceOffsets(uint32_t new_reference_offsets); |
| 1829 | |
| 1830 | // Beginning of static field data |
| 1831 | static MemberOffset FieldsOffset() { |
| 1832 | return OFFSET_OF_OBJECT_MEMBER(Class, fields_); |
| 1833 | } |
| 1834 | |
| 1835 | // Returns the number of static fields containing reference types. |
| 1836 | size_t NumReferenceStaticFields() const { |
| 1837 | DCHECK(IsLinked()); |
| 1838 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1839 | return GetField32( |
| 1840 | OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false); |
| 1841 | } |
| 1842 | |
| 1843 | size_t NumReferenceStaticFieldsDuringLinking() const { |
| 1844 | DCHECK(IsLoaded()); |
| 1845 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1846 | return GetField32( |
| 1847 | OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false); |
| 1848 | } |
| 1849 | |
| 1850 | void SetNumReferenceStaticFields(size_t new_num) { |
| 1851 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1852 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), |
| 1853 | new_num, false); |
| 1854 | } |
| 1855 | |
| 1856 | ObjectArray<Field>* GetSFields() const { |
| 1857 | DCHECK(IsLoaded()); |
| 1858 | return GetFieldObject<ObjectArray<Field>*>( |
| 1859 | OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false); |
| 1860 | } |
| 1861 | |
| 1862 | void SetSFields(ObjectArray<Field>* new_sfields) { |
| 1863 | DCHECK(NULL == GetFieldObject<ObjectArray<Field>*>( |
| 1864 | OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false)); |
| 1865 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, sfields_), |
| 1866 | new_sfields, false); |
| 1867 | } |
| 1868 | |
| 1869 | size_t NumStaticFields() const { |
| 1870 | return (GetSFields() != NULL) ? GetSFields()->GetLength() : 0; |
| 1871 | } |
| 1872 | |
| 1873 | Field* GetStaticField(uint32_t i) const { // TODO: uint16_t |
| 1874 | return GetSFields()->Get(i); |
| 1875 | } |
| 1876 | |
| 1877 | void SetStaticField(uint32_t i, Field* f) { // TODO: uint16_t |
| 1878 | ObjectArray<Field>* sfields= GetFieldObject<ObjectArray<Field>*>( |
| 1879 | OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false); |
| 1880 | sfields->Set(i, f); |
| 1881 | } |
| 1882 | |
| 1883 | uint32_t GetReferenceStaticOffsets() const { |
| 1884 | return GetField32( |
| 1885 | OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), false); |
| 1886 | } |
| 1887 | |
| 1888 | void SetReferenceStaticOffsets(uint32_t new_reference_offsets); |
| 1889 | |
| 1890 | // Finds the given instance field in this class or a superclass. |
| 1891 | Field* FindInstanceField(const StringPiece& name, Class* type); |
| 1892 | |
| 1893 | Field* FindDeclaredInstanceField(const StringPiece& name, Class* type); |
| 1894 | |
| 1895 | // Finds the given static field in this class or a superclass. |
| 1896 | Field* FindStaticField(const StringPiece& name, Class* type); |
| 1897 | |
| 1898 | Field* FindDeclaredStaticField(const StringPiece& name, Class* type); |
| 1899 | |
| 1900 | uint32_t GetClinitThreadId() const { |
| 1901 | DCHECK(IsIdxLoaded()); |
| 1902 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), false); |
| 1903 | } |
| 1904 | |
| 1905 | void SetClinitThreadId(uint32_t new_clinit_thread_id) { |
| 1906 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), |
| 1907 | new_clinit_thread_id, false); |
| 1908 | } |
| 1909 | |
| 1910 | Class* GetVerifyErrorClass() const { |
| 1911 | DCHECK(IsErroneous()); |
| 1912 | return GetFieldObject<Class*>( |
| 1913 | OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), false); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 1916 | void SetVerifyErrorClass(Class* klass) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1917 | klass->SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), |
| 1918 | klass, false); |
| 1919 | } |
| 1920 | |
| 1921 | const char* GetSourceFile() const { |
| 1922 | DCHECK(IsLoaded()); |
| 1923 | return GetFieldPtr<const char*>( |
| 1924 | OFFSET_OF_OBJECT_MEMBER(Class, source_file_), false); |
| 1925 | } |
| 1926 | |
| 1927 | void SetSourceFile(const char* new_source_file) { |
| 1928 | SetFieldPtr<const char*>(OFFSET_OF_OBJECT_MEMBER(Class, source_file_), |
| 1929 | new_source_file, false); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | private: |
| 1933 | bool Implements(const Class* klass) const; |
| 1934 | bool IsArrayAssignableFromArray(const Class* klass) const; |
| 1935 | bool IsAssignableFromArray(const Class* klass) const; |
| 1936 | bool IsSubClass(const Class* klass) const; |
| 1937 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1938 | // TODO: the image writer should know the offsets of these fields as they |
| 1939 | // should appear in the libcore Java mirror |
| 1940 | friend class ImageWriter; |
| 1941 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1942 | // descriptor for the class such as "java.lang.Class" or "[C" |
| 1943 | String* name_; // TODO initialize |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1944 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1945 | // descriptor for the class such as "Ljava/lang/Class;" or "[C" |
| 1946 | String* descriptor_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1947 | |
| 1948 | // access flags; low 16 bits are defined by VM spec |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 1949 | uint32_t access_flags_; // TODO: make an instance field? |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1950 | |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 1951 | // DexCache of resolved constant pool entries |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1952 | // (will be NULL for VM-generated, e.g. arrays and primitive classes) |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 1953 | DexCache* dex_cache_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1954 | |
| 1955 | // state of class initialization |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1956 | Status status_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1957 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 1958 | // If class verify fails, we must return same error on subsequent tries. |
| 1959 | // Update with SetVerifyErrorClass to ensure a write barrier is used. |
| 1960 | const Class* verify_error_class_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1961 | |
| 1962 | // threadId, used to check for recursive <clinit> invocation |
| 1963 | uint32_t clinit_thread_id_; |
| 1964 | |
| 1965 | // Total object size; used when allocating storage on gc heap. (For |
| 1966 | // interfaces and abstract classes this will be zero.) |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1967 | size_t object_size_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1968 | |
| 1969 | // For array classes, the class object for base element, for |
| 1970 | // instanceof/checkcast (for String[][][], this will be String). |
| 1971 | // Otherwise, NULL. |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1972 | Class* component_type_; // TODO: make an instance field |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1973 | |
| 1974 | // For array classes, the number of array dimensions, e.g. int[][] |
| 1975 | // is 2. Otherwise 0. |
| 1976 | int32_t array_rank_; |
| 1977 | |
| 1978 | // primitive type index, or PRIM_NOT (-1); set for generated prim classes |
| 1979 | PrimitiveType primitive_type_; |
| 1980 | |
| 1981 | // The superclass, or NULL if this is java.lang.Object or a |
| 1982 | // primitive type. |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1983 | Class* super_class_; // TODO: make an instance field |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1984 | uint32_t super_class_type_idx_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1985 | |
| 1986 | // defining class loader, or NULL for the "bootstrap" system loader |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1987 | const ClassLoader* class_loader_; // TODO: make an instance field |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1988 | |
| 1989 | // initiating class loader list |
| 1990 | // NOTE: for classes with low serialNumber, these are unused, and the |
| 1991 | // values are kept in a table in gDvm. |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1992 | // InitiatingLoaderList initiating_loader_list_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1993 | |
| 1994 | // array of interfaces this class implements directly |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 1995 | ObjectArray<Class>* interfaces_; |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 1996 | IntArray* interfaces_type_idx_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1997 | |
| 1998 | // static, private, and <init> methods |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 1999 | ObjectArray<Method>* direct_methods_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2000 | |
| 2001 | // virtual methods defined in this class; invoked through vtable |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 2002 | ObjectArray<Method>* virtual_methods_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2003 | |
| 2004 | // Virtual method table (vtable), for use by "invoke-virtual". The |
| 2005 | // vtable from the superclass is copied in, and virtual methods from |
| 2006 | // our class either replace those from the super or are appended. |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 2007 | ObjectArray<Method>* vtable_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2008 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2009 | // Interface table (iftable_), one entry per interface supported by |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2010 | // this class. That means one entry for each interface we support |
| 2011 | // directly, indirectly via superclass, or indirectly via |
| 2012 | // superinterface. This will be null if neither we nor our |
| 2013 | // superclass implement any interfaces. |
| 2014 | // |
| 2015 | // Why we need this: given "class Foo implements Face", declare |
| 2016 | // "Face faceObj = new Foo()". Invoke faceObj.blah(), where "blah" |
| 2017 | // is part of the Face interface. We can't easily use a single |
| 2018 | // vtable. |
| 2019 | // |
| 2020 | // For every interface a concrete class implements, we create a list |
| 2021 | // of virtualMethod indices for the methods in the interface. |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2022 | size_t iftable_count_; |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2023 | // TODO convert to ObjectArray<?> |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2024 | InterfaceEntry* iftable_; |
| 2025 | |
| 2026 | // The interface vtable indices for iftable get stored here. By |
| 2027 | // placing them all in a single pool for each class that implements |
| 2028 | // interfaces, we decrease the number of allocations. |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2029 | size_t ifvi_pool_count_; |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2030 | // TODO convert to IntArray |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2031 | uint32_t* ifvi_pool_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2032 | |
| 2033 | // instance fields |
| 2034 | // |
| 2035 | // These describe the layout of the contents of a |
| 2036 | // DataObject-compatible Object. Note that only the fields directly |
| 2037 | // declared by this class are listed in ifields; fields declared by |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 2038 | // a superclass are listed in the superclass's Class.ifields. |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2039 | // |
| 2040 | // All instance fields that refer to objects are guaranteed to be at |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 2041 | // the beginning of the field list. num_reference_instance_fields_ |
| 2042 | // specifies the number of reference fields. |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 2043 | ObjectArray<Field>* ifields_; |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 2044 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2045 | // number of instance fields that are object refs |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 2046 | size_t num_reference_instance_fields_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2047 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2048 | // Bitmap of offsets of ifields. |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2049 | uint32_t reference_instance_offsets_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2050 | |
| 2051 | // source file name, if known. Otherwise, NULL. |
| 2052 | const char* source_file_; |
| 2053 | |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 2054 | // Static fields |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 2055 | ObjectArray<Field>* sfields_; |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 2056 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2057 | // number of static fields that are object refs |
| 2058 | size_t num_reference_static_fields_; |
| 2059 | |
| 2060 | // Bitmap of offsets of sfields. |
| 2061 | uint32_t reference_static_offsets_; |
| 2062 | |
| 2063 | // Total class size; used when allocating storage on gc heap. |
| 2064 | size_t class_size_; |
| 2065 | |
| 2066 | // Location of first static field. |
| 2067 | uint32_t fields_[0]; |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2068 | |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 2069 | private: |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2070 | DISALLOW_IMPLICIT_CONSTRUCTORS(Class); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2071 | }; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2072 | |
Elliott Hughes | 1f359b0 | 2011-07-17 14:27:17 -0700 | [diff] [blame] | 2073 | std::ostream& operator<<(std::ostream& os, const Class::Status& rhs); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2074 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2075 | inline void Object::SetClass(Class* new_klass) { |
| 2076 | // new_klass may be NULL prior to class linker initialization |
| 2077 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Object, klass_), new_klass, false); |
| 2078 | } |
| 2079 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 2080 | inline bool Object::InstanceOf(const Class* klass) const { |
Jesse Wilson | 1415074 | 2011-07-29 19:04:44 -0400 | [diff] [blame] | 2081 | DCHECK(klass != NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2082 | DCHECK(GetClass() != NULL); |
| 2083 | return klass->IsAssignableFrom(GetClass()); |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2086 | inline bool Object::IsClass() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2087 | Class* java_lang_Class = GetClass()->GetClass(); |
| 2088 | return GetClass() == java_lang_Class; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2091 | inline bool Object::IsClassClass() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2092 | Class* java_lang_Class = GetClass()->GetClass(); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2093 | return this == java_lang_Class; |
| 2094 | } |
| 2095 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2096 | inline bool Object::IsObjectArray() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2097 | return IsArrayInstance() && !GetClass()->GetComponentType()->IsPrimitive(); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 2100 | inline bool Object::IsArrayInstance() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2101 | return GetClass()->IsArrayClass(); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2104 | inline bool Object::IsField() const { |
| 2105 | Class* java_lang_Class = klass_->klass_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2106 | Class* java_lang_reflect_Field = |
| 2107 | java_lang_Class->GetInstanceField(0)->GetClass(); |
| 2108 | return GetClass() == java_lang_reflect_Field; |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | inline bool Object::IsMethod() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2112 | Class* java_lang_Class = GetClass()->GetClass(); |
| 2113 | Class* java_lang_reflect_Method = |
| 2114 | java_lang_Class->GetDirectMethod(0)->GetClass(); |
| 2115 | return GetClass() == java_lang_reflect_Method; |
| 2116 | } |
| 2117 | |
| 2118 | inline bool Object::IsReferenceInstance() const { |
| 2119 | return GetClass()->IsReferenceClass(); |
| 2120 | } |
| 2121 | |
| 2122 | inline bool Object::IsWeakReferenceInstance() const { |
| 2123 | return GetClass()->IsWeakReferenceClass(); |
| 2124 | } |
| 2125 | |
| 2126 | inline bool Object::IsSoftReferenceInstance() const { |
| 2127 | return GetClass()->IsSoftReferenceClass(); |
| 2128 | } |
| 2129 | |
| 2130 | inline bool Object::IsFinalizerReferenceInstance() const { |
| 2131 | return GetClass()->IsFinalizerReferenceClass(); |
| 2132 | } |
| 2133 | |
| 2134 | inline bool Object::IsPhantomReferenceInstance() const { |
| 2135 | return GetClass()->IsPhantomReferenceClass(); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 2138 | inline size_t Object::SizeOf() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2139 | size_t result; |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 2140 | if (IsArrayInstance()) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2141 | result = AsArray()->SizeOf(); |
| 2142 | } else if (IsClass()) { |
| 2143 | result = AsClass()->SizeOf(); |
| 2144 | } else { |
| 2145 | result = GetClass()->GetObjectSize(); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2146 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2147 | DCHECK(!IsField() || result == sizeof(Field)); |
| 2148 | DCHECK(!IsMethod() || result == sizeof(Method)); |
| 2149 | return result; |
| 2150 | } |
| 2151 | |
| 2152 | inline void Field::SetOffset(MemberOffset num_bytes) { |
| 2153 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2154 | DCHECK_LE(CLASS_SMALLEST_OFFSET, num_bytes.Uint32Value()); |
| 2155 | Class* type = GetTypeDuringLinking(); |
| 2156 | if (type != NULL && (type->IsPrimitiveDouble() || type->IsPrimitiveLong())) { |
| 2157 | DCHECK(IsAligned(num_bytes.Uint32Value(), 8)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2158 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2159 | SetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_), |
| 2160 | num_bytes.Uint32Value(), false); |
| 2161 | } |
| 2162 | |
| 2163 | inline Class* Field::GetDeclaringClass() const { |
| 2164 | Class* result = GetFieldObject<Class*>( |
| 2165 | OFFSET_OF_OBJECT_MEMBER(Field, declaring_class_), false); |
| 2166 | DCHECK(result != NULL); |
| 2167 | DCHECK(result->IsLoaded()); |
| 2168 | return result; |
| 2169 | } |
| 2170 | |
| 2171 | inline void Field::SetDeclaringClass(Class *new_declaring_class) { |
| 2172 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Field, declaring_class_), |
| 2173 | new_declaring_class, false); |
| 2174 | } |
| 2175 | |
| 2176 | inline Class* Method::GetDeclaringClass() const { |
| 2177 | Class* result = |
| 2178 | GetFieldObject<Class*>( |
| 2179 | OFFSET_OF_OBJECT_MEMBER(Method, declaring_class_), false); |
| 2180 | DCHECK(result != NULL); |
| 2181 | DCHECK(result->IsLoaded()); |
| 2182 | return result; |
| 2183 | } |
| 2184 | |
| 2185 | inline void Method::SetDeclaringClass(Class *new_declaring_class) { |
| 2186 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, declaring_class_), |
| 2187 | new_declaring_class, false); |
| 2188 | } |
| 2189 | |
| 2190 | inline uint32_t Method::GetReturnTypeIdx() const { |
| 2191 | DCHECK(GetDeclaringClass()->IsLinked()); |
| 2192 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, java_return_type_idx_), |
| 2193 | false); |
| 2194 | } |
| 2195 | |
| 2196 | inline bool Method::IsReturnAReference() const { |
| 2197 | return !GetReturnType()->IsPrimitive(); |
| 2198 | } |
| 2199 | |
| 2200 | inline bool Method::IsReturnAFloat() const { |
| 2201 | return GetReturnType()->IsPrimitiveFloat(); |
| 2202 | } |
| 2203 | |
| 2204 | inline bool Method::IsReturnADouble() const { |
| 2205 | return GetReturnType()->IsPrimitiveDouble(); |
| 2206 | } |
| 2207 | |
| 2208 | inline bool Method::IsReturnALong() const { |
| 2209 | return GetReturnType()->IsPrimitiveLong(); |
| 2210 | } |
| 2211 | |
| 2212 | inline bool Method::IsReturnVoid() const { |
| 2213 | return GetReturnType()->IsPrimitiveVoid(); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 2216 | inline size_t Array::SizeOf() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2217 | return SizeOf(GetLength(), GetClass()->GetComponentSize()); |
| 2218 | } |
| 2219 | |
| 2220 | template<class T> |
| 2221 | void ObjectArray<T>::Set(int32_t i, T* object) { |
| 2222 | if (IsValidIndex(i)) { |
| 2223 | if (object != NULL) { |
| 2224 | Class* element_class = GetClass()->GetComponentType(); |
| 2225 | DCHECK(!element_class->IsPrimitive()); |
| 2226 | // TODO: ArrayStoreException |
| 2227 | CHECK(object->InstanceOf(element_class)); |
| 2228 | } |
| 2229 | MemberOffset data_offset(DataOffset().Int32Value() + i * sizeof(Object*)); |
| 2230 | SetFieldObject(data_offset, object, false); |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | template<class T> |
| 2235 | void ObjectArray<T>::SetWithoutChecks(int32_t i, T* object) { |
| 2236 | DCHECK(IsValidIndex(i)); |
| 2237 | MemberOffset data_offset(DataOffset().Int32Value() + i * sizeof(Object*)); |
| 2238 | SetFieldObject(data_offset, object, false); |
| 2239 | } |
| 2240 | |
| 2241 | template<class T> |
| 2242 | void ObjectArray<T>::Copy(const ObjectArray<T>* src, int src_pos, |
| 2243 | ObjectArray<T>* dst, int dst_pos, |
| 2244 | size_t length) { |
| 2245 | if (src->IsValidIndex(src_pos) && |
| 2246 | src->IsValidIndex(src_pos+length-1) && |
| 2247 | dst->IsValidIndex(dst_pos) && |
| 2248 | dst->IsValidIndex(dst_pos+length-1)) { |
| 2249 | MemberOffset src_offset(DataOffset().Int32Value() + |
| 2250 | src_pos * sizeof(Object*)); |
| 2251 | MemberOffset dst_offset(DataOffset().Int32Value() + |
| 2252 | dst_pos * sizeof(Object*)); |
| 2253 | Class* array_class = dst->GetClass(); |
| 2254 | if (array_class == src->GetClass()) { |
| 2255 | // No need for array store checks if arrays are of the same type |
| 2256 | for (size_t i=0; i < length; i++) { |
| 2257 | Object* object = src->GetFieldObject<Object*>(src_offset, false); |
| 2258 | dst->SetFieldObject(dst_offset, object, false); |
| 2259 | src_offset = MemberOffset(src_offset.Uint32Value() + sizeof(Object*)); |
| 2260 | dst_offset = MemberOffset(dst_offset.Uint32Value() + sizeof(Object*)); |
| 2261 | } |
| 2262 | } else { |
| 2263 | Class* element_class = array_class->GetComponentType(); |
| 2264 | CHECK(!element_class->IsPrimitive()); |
| 2265 | for (size_t i=0; i < length; i++) { |
| 2266 | Object* object = src->GetFieldObject<Object*>(src_offset, false); |
| 2267 | // TODO: ArrayStoreException |
| 2268 | CHECK(object == NULL || object->InstanceOf(element_class)); |
| 2269 | dst->SetFieldObject(dst_offset, object, false); |
| 2270 | src_offset = MemberOffset(src_offset.Uint32Value() + sizeof(Object*)); |
| 2271 | dst_offset = MemberOffset(dst_offset.Uint32Value() + sizeof(Object*)); |
| 2272 | } |
| 2273 | } |
| 2274 | // TODO: bulk write barrier |
| 2275 | } |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2276 | } |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 2277 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2278 | class ClassClass : public Class { |
| 2279 | private: |
| 2280 | // Padding to ensure the 64-bit serialVersionUID_ begins on a 8-byte boundary |
| 2281 | int32_t padding_; |
| 2282 | int64_t serialVersionUID_; |
| 2283 | DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass); |
| 2284 | }; |
| 2285 | |
| 2286 | class StringClass : public Class { |
| 2287 | private: |
| 2288 | CharArray* ASCII_; |
| 2289 | Object* CASE_INSENSITIVE_ORDER_; |
| 2290 | uint32_t REPLACEMENT_CHAR_; |
| 2291 | int64_t serialVersionUID; |
| 2292 | DISALLOW_IMPLICIT_CONSTRUCTORS(StringClass); |
| 2293 | }; |
| 2294 | |
| 2295 | class FieldClass : public Class { |
| 2296 | private: |
| 2297 | Object* ORDER_BY_NAME_AND_DECLARING_CLASS_; |
| 2298 | uint32_t TYPE_BOOLEAN_; |
| 2299 | uint32_t TYPE_BYTE_; |
| 2300 | uint32_t TYPE_CHAR_; |
| 2301 | uint32_t TYPE_DOUBLE_; |
| 2302 | uint32_t TYPE_FLOAT_; |
| 2303 | uint32_t TYPE_INTEGER_; |
| 2304 | uint32_t TYPE_LONG_; |
| 2305 | uint32_t TYPE_SHORT_; |
| 2306 | DISALLOW_IMPLICIT_CONSTRUCTORS(FieldClass); |
| 2307 | }; |
| 2308 | |
| 2309 | class MethodClass : public Class { |
| 2310 | private: |
| 2311 | int32_t DECLARED_; |
| 2312 | int32_t PUBLIC_; |
| 2313 | DISALLOW_IMPLICIT_CONSTRUCTORS(MethodClass); |
| 2314 | }; |
| 2315 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2316 | class DataObject : public Object { |
| 2317 | public: |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2318 | // Location of first instance field. |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 2319 | uint32_t fields_[0]; |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 2320 | private: |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2321 | DISALLOW_IMPLICIT_CONSTRUCTORS(DataObject); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2322 | }; |
| 2323 | |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2324 | template<class T> |
| 2325 | class PrimitiveArray : public Array { |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 2326 | public: |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 2327 | typedef T ElementType; |
| 2328 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2329 | static PrimitiveArray<T>* Alloc(size_t length); |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2330 | |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2331 | const T* GetData() const { |
| 2332 | return reinterpret_cast<const T*>(&elements_); |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2335 | T* GetData() { |
| 2336 | return reinterpret_cast<T*>(&elements_); |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2339 | T Get(int32_t i) const { |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 2340 | if (!IsValidIndex(i)) { |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 2341 | return T(0); |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 2342 | } |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2343 | return GetData()[i]; |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2346 | void Set(int32_t i, T value) { |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 2347 | // TODO: ArrayStoreException |
| 2348 | if (IsValidIndex(i)) { |
| 2349 | GetData()[i] = value; |
| 2350 | } |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2353 | static void SetArrayClass(Class* array_class) { |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2354 | CHECK(array_class_ == NULL); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2355 | CHECK(array_class != NULL); |
| 2356 | array_class_ = array_class; |
| 2357 | } |
| 2358 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2359 | static void ResetArrayClass() { |
| 2360 | CHECK(array_class_ != NULL); |
| 2361 | array_class_ = NULL; |
| 2362 | } |
| 2363 | |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 2364 | private: |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2365 | // Location of first element. |
| 2366 | T elements_[0]; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2367 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2368 | static Class* array_class_; |
| 2369 | |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2370 | DISALLOW_IMPLICIT_CONSTRUCTORS(PrimitiveArray); |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 2371 | }; |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 2372 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2373 | inline void Class::SetInterfacesTypeIdx(IntArray* new_interfaces_idx) { |
| 2374 | DCHECK(NULL == GetFieldObject<IntArray*>( |
| 2375 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_type_idx_), false)); |
| 2376 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, interfaces_type_idx_), |
| 2377 | new_interfaces_idx, false); |
| 2378 | } |
| 2379 | |
| 2380 | // C++ mirror of java.lang.String |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2381 | class String : public Object { |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2382 | public: |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2383 | const CharArray* GetCharArray() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2384 | const CharArray* result = GetFieldObject<const CharArray*>( |
| 2385 | OFFSET_OF_OBJECT_MEMBER(String, array_), false); |
| 2386 | DCHECK(result != NULL); |
| 2387 | return result; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 2390 | int32_t GetOffset() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2391 | int32_t result = GetField32( |
| 2392 | OFFSET_OF_OBJECT_MEMBER(String, offset_), false); |
| 2393 | DCHECK_LE(0, result); |
| 2394 | return result; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2397 | int32_t GetLength() const; |
| 2398 | |
| 2399 | int32_t GetHashCode() const; |
| 2400 | |
| 2401 | void ComputeHashCode() { |
| 2402 | SetHashCode(ComputeUtf16Hash(GetCharArray(), GetOffset(), GetLength())); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 2405 | int32_t GetUtfLength() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2406 | return CountUtf8Bytes(GetCharArray()->GetData(), GetLength()); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2409 | uint16_t CharAt(int32_t index) const; |
| 2410 | |
| 2411 | const String* Intern() const; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2412 | |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 2413 | static String* AllocFromUtf16(int32_t utf16_length, |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2414 | const uint16_t* utf16_data_in, |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2415 | int32_t hash_code = 0); |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 2416 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2417 | static String* AllocFromModifiedUtf8(const char* utf); |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 2418 | |
Jesse Wilson | 8989d99 | 2011-08-02 13:39:42 -0700 | [diff] [blame] | 2419 | static String* AllocFromModifiedUtf8(int32_t utf16_length, |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2420 | const char* utf8_data_in); |
| 2421 | |
| 2422 | static String* Alloc(Class* java_lang_String, int32_t utf16_length); |
| 2423 | |
| 2424 | static String* Alloc(Class* java_lang_String, CharArray* array); |
| 2425 | |
| 2426 | bool Equals(const char* modified_utf8) const; |
| 2427 | |
| 2428 | // TODO: do we need this overload? give it a more intention-revealing name. |
| 2429 | bool Equals(const StringPiece& modified_utf8) const; |
| 2430 | |
| 2431 | bool Equals(const String* that) const; |
| 2432 | |
| 2433 | // TODO: do we need this overload? give it a more intention-revealing name. |
| 2434 | bool Equals(const uint16_t* that_chars, int32_t that_offset, |
| 2435 | int32_t that_length) const; |
| 2436 | |
| 2437 | // Create a modified UTF-8 encoded std::string from a java/lang/String object. |
| 2438 | std::string ToModifiedUtf8() const; |
| 2439 | |
| 2440 | static Class* GetJavaLangString() { |
| 2441 | DCHECK(java_lang_String_ != NULL); |
| 2442 | return java_lang_String_; |
Jesse Wilson | 8989d99 | 2011-08-02 13:39:42 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2445 | static void SetClass(Class* java_lang_String); |
| 2446 | static void ResetClass(); |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 2447 | |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 2448 | private: |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2449 | void SetHashCode(int32_t new_hash_code) { |
| 2450 | DCHECK_EQ(0u, |
| 2451 | GetField32(OFFSET_OF_OBJECT_MEMBER(String, hash_code_), false)); |
| 2452 | SetField32(OFFSET_OF_OBJECT_MEMBER(String, hash_code_), |
| 2453 | new_hash_code, false); |
| 2454 | } |
| 2455 | |
| 2456 | void SetCount(int32_t new_count) { |
| 2457 | DCHECK_LE(0, new_count); |
| 2458 | SetField32(OFFSET_OF_OBJECT_MEMBER(String, count_), new_count, false); |
| 2459 | } |
| 2460 | |
| 2461 | void SetOffset(int32_t new_offset) { |
| 2462 | DCHECK_LE(0, new_offset); |
| 2463 | DCHECK_GE(GetLength(), new_offset); |
| 2464 | SetField32(OFFSET_OF_OBJECT_MEMBER(String, offset_), new_offset, false); |
| 2465 | } |
| 2466 | |
| 2467 | void SetArray(CharArray* new_array) { |
| 2468 | DCHECK(new_array != NULL); |
| 2469 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(String, array_), new_array, false); |
| 2470 | } |
| 2471 | |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2472 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
| 2473 | CharArray* array_; |
| 2474 | |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2475 | uint32_t hash_code_; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2476 | |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 2477 | int32_t offset_; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2478 | |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 2479 | int32_t count_; |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 2480 | |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 2481 | static Class* java_lang_String_; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2482 | |
| 2483 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2484 | }; |
| 2485 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2486 | inline const String* Field::GetName() const { |
| 2487 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2488 | String* result = |
| 2489 | GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(Field, name_), false); |
| 2490 | DCHECK(result != NULL); |
| 2491 | return result; |
| 2492 | } |
| 2493 | |
| 2494 | inline void Field::SetName(String* new_name) { |
| 2495 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Field, name_), |
| 2496 | new_name, false); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | inline uint32_t Field::GetAccessFlags() const { |
| 2500 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2501 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Field, access_flags_), false); |
| 2502 | } |
| 2503 | |
| 2504 | inline uint32_t Field::GetTypeIdx() const { |
| 2505 | DCHECK(GetDeclaringClass()->IsIdxLoaded()); |
| 2506 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Field, type_idx_), false); |
| 2507 | } |
| 2508 | |
| 2509 | inline MemberOffset Field::GetOffset() const { |
| 2510 | DCHECK(GetDeclaringClass()->IsLinked()); |
| 2511 | return MemberOffset( |
| 2512 | GetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_), false)); |
| 2513 | } |
| 2514 | |
| 2515 | inline MemberOffset Field::GetOffsetDuringLinking() const { |
| 2516 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2517 | return MemberOffset( |
| 2518 | GetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_), false)); |
| 2519 | } |
| 2520 | |
| 2521 | inline const String* Method::GetName() const { |
| 2522 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2523 | const String* result = |
| 2524 | GetFieldObject<const String*>( |
| 2525 | OFFSET_OF_OBJECT_MEMBER(Method, name_), false); |
| 2526 | DCHECK(result != NULL); |
| 2527 | return result; |
| 2528 | } |
| 2529 | |
| 2530 | inline void Method::SetName(String* new_name) { |
| 2531 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, name_), |
| 2532 | new_name, false); |
| 2533 | |
| 2534 | } |
| 2535 | |
| 2536 | inline const char* Method::GetShorty() const { |
| 2537 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2538 | return GetFieldPtr<const char*>( |
| 2539 | OFFSET_OF_OBJECT_MEMBER(Method, shorty_), false); |
| 2540 | } |
| 2541 | |
| 2542 | inline const String* Method::GetSignature() const { |
| 2543 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2544 | const String* result = |
| 2545 | GetFieldObject<const String*>( |
| 2546 | OFFSET_OF_OBJECT_MEMBER(Method, signature_), false); |
| 2547 | DCHECK(result != NULL); |
| 2548 | return result; |
| 2549 | } |
| 2550 | |
| 2551 | inline void Method::SetSignature(String* new_signature) { |
| 2552 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, signature_), |
| 2553 | new_signature, false); |
| 2554 | } |
| 2555 | |
| 2556 | inline uint32_t Class::GetAccessFlags() const { |
| 2557 | // Check class is loaded or this is java.lang.String that has a |
| 2558 | // circularity issue during loading the names of its members |
| 2559 | DCHECK(IsLoaded() || this == String::GetJavaLangString() || |
| 2560 | this == Field::GetJavaLangReflectField() || |
| 2561 | this == Method::GetJavaLangReflectMethod()); |
| 2562 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), false); |
| 2563 | } |
| 2564 | |
| 2565 | inline void Class::SetDescriptor(String* new_descriptor) { |
| 2566 | DCHECK(new_descriptor != NULL); |
| 2567 | DCHECK_NE(0, new_descriptor->GetLength()); |
| 2568 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, descriptor_), |
| 2569 | new_descriptor, false); |
| 2570 | } |
| 2571 | |
| 2572 | inline uint32_t Method::GetAccessFlags() const { |
| 2573 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2574 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, access_flags_), false); |
| 2575 | } |
| 2576 | |
| 2577 | inline uint16_t Method::GetMethodIndex() const { |
| 2578 | DCHECK(GetDeclaringClass()->IsLinked()); |
| 2579 | return GetField16(OFFSET_OF_OBJECT_MEMBER(Method, method_index_), false); |
| 2580 | } |
| 2581 | |
| 2582 | inline uint16_t Method::NumRegisters() const { |
| 2583 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2584 | return GetField16(OFFSET_OF_OBJECT_MEMBER(Method, num_registers_), false); |
| 2585 | } |
| 2586 | |
| 2587 | inline uint16_t Method::NumIns() const { |
| 2588 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2589 | return GetField16(OFFSET_OF_OBJECT_MEMBER(Method, num_ins_), false); |
| 2590 | } |
| 2591 | |
| 2592 | inline uint16_t Method::NumOuts() const { |
| 2593 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2594 | return GetField16(OFFSET_OF_OBJECT_MEMBER(Method, num_outs_), false); |
| 2595 | } |
| 2596 | |
| 2597 | inline uint32_t Method::GetProtoIdx() const { |
| 2598 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2599 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, proto_idx_), false); |
| 2600 | } |
| 2601 | |
| 2602 | // C++ mirror of java.lang.Throwable |
Elliott Hughes | e5b0dc8 | 2011-08-23 09:59:02 -0700 | [diff] [blame] | 2603 | class Throwable : public Object { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame^] | 2604 | public: |
| 2605 | void SetDetailMessage(String* new_detail_message) { |
| 2606 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Throwable, detail_message_), |
| 2607 | new_detail_message, false); |
| 2608 | } |
| 2609 | |
Elliott Hughes | e5b0dc8 | 2011-08-23 09:59:02 -0700 | [diff] [blame] | 2610 | private: |
| 2611 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
| 2612 | Throwable* cause_; |
| 2613 | String* detail_message_; |
| 2614 | Object* stack_state_; // Note this is Java volatile: |
| 2615 | Object* stack_trace_; |
| 2616 | Object* suppressed_exceptions_; |
| 2617 | |
| 2618 | DISALLOW_IMPLICIT_CONSTRUCTORS(Throwable); |
| 2619 | }; |
| 2620 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2621 | // C++ mirror of java.lang.StackTraceElement |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2622 | class StackTraceElement : public Object { |
| 2623 | public: |
| 2624 | const String* GetDeclaringClass() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2625 | return GetFieldObject<const String*>( |
| 2626 | OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_), false); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | const String* GetMethodName() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2630 | return GetFieldObject<const String*>( |
| 2631 | OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_), false); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | const String* GetFileName() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2635 | return GetFieldObject<const String*>( |
| 2636 | OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_), false); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2637 | } |
| 2638 | |
Shih-wei Liao | ff0f9be | 2011-08-29 15:43:53 -0700 | [diff] [blame] | 2639 | int32_t GetLineNumber() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2640 | return GetField32( |
| 2641 | OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_), false); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2644 | static StackTraceElement* Alloc(const String* declaring_class, |
| 2645 | const String* method_name, |
| 2646 | const String* file_name, |
| 2647 | int32_t line_number); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2648 | |
| 2649 | static void SetClass(Class* java_lang_StackTraceElement); |
| 2650 | |
| 2651 | static void ResetClass(); |
| 2652 | |
| 2653 | private: |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2654 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2655 | const String* declaring_class_; |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2656 | const String* file_name_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2657 | const String* method_name_; |
Shih-wei Liao | ff0f9be | 2011-08-29 15:43:53 -0700 | [diff] [blame] | 2658 | int32_t line_number_; |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2659 | |
| 2660 | static Class* GetStackTraceElement() { |
| 2661 | DCHECK(java_lang_StackTraceElement_ != NULL); |
| 2662 | return java_lang_StackTraceElement_; |
| 2663 | } |
| 2664 | |
| 2665 | static Class* java_lang_StackTraceElement_; |
| 2666 | DISALLOW_IMPLICIT_CONSTRUCTORS(StackTraceElement); |
| 2667 | }; |
| 2668 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2669 | class InterfaceEntry { |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2670 | public: |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2671 | InterfaceEntry() : interface_(NULL), method_index_array_(NULL) { |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2674 | Class* GetInterface() const { |
| 2675 | DCHECK(interface_ != NULL); |
| 2676 | return interface_; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2677 | } |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 2678 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2679 | void SetInterface(Class* interface) { |
| 2680 | DCHECK(interface->IsInterface()); |
| 2681 | interface_ = interface; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2682 | } |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 2683 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2684 | uint32_t* GetMethodIndexArray() const { |
| 2685 | return method_index_array_; |
| 2686 | } |
| 2687 | |
| 2688 | void SetMethodIndexArray(uint32_t* new_mia) { |
| 2689 | method_index_array_ = new_mia; |
| 2690 | } |
| 2691 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2692 | private: |
| 2693 | // Points to the interface class. |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2694 | Class* interface_; |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 2695 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2696 | // Index into array of vtable offsets. This points into the |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2697 | // ifvi_pool_, which holds the vtables for all interfaces declared by |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2698 | // this class. |
| 2699 | uint32_t* method_index_array_; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2700 | |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2701 | DISALLOW_COPY_AND_ASSIGN(InterfaceEntry); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2702 | }; |
| 2703 | |
| 2704 | } // namespace art |
| 2705 | |
| 2706 | #endif // ART_SRC_OBJECT_H_ |