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