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