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