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