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