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