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 | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 905 | uint32_t GetCoreSpillMask() { |
| 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 | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 915 | uint32_t GetFpSpillMask() { |
| 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 | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 925 | // Converts a native PC to a dex PC. TODO: this is a no-op |
| 926 | // until we associate a PC mapping table with each method. |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 927 | uint32_t ToDexPC(const uintptr_t pc) const; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 928 | |
| 929 | // Converts a dex PC to a native PC. TODO: this is a no-op |
| 930 | // until we associate a PC mapping table with each method. |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 931 | uintptr_t ToNativePC(const uint32_t dex_pc) const; |
| 932 | |
| 933 | // Find the catch block for the given exception type and dex_pc |
| 934 | uint32_t FindCatchBlock(Class* exception_type, uint32_t dex_pc) const; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 935 | |
| 936 | static Class* GetJavaLangReflectMethod() { |
| 937 | DCHECK(java_lang_reflect_Method_ != NULL); |
| 938 | return java_lang_reflect_Method_; |
| 939 | } |
| 940 | |
| 941 | static void SetClass(Class* java_lang_reflect_Method); |
| 942 | static void ResetClass(); |
| 943 | |
| 944 | private: |
| 945 | uint32_t GetReturnTypeIdx() const; |
| 946 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 947 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
| 948 | // the class we are a part of |
| 949 | Class* declaring_class_; |
| 950 | ObjectArray<Class>* java_exception_types_; |
| 951 | Object* java_formal_type_parameters_; |
| 952 | Object* java_generic_exception_types_; |
| 953 | Object* java_generic_parameter_types_; |
| 954 | Object* java_generic_return_type_; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 955 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 956 | String* name_; |
| 957 | |
| 958 | ObjectArray<Class>* java_parameter_types_; |
| 959 | |
| 960 | Class* java_return_type_; // Unused by ART |
| 961 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 962 | // Storage for code_ |
| 963 | const ByteArray* code_array_; |
| 964 | |
| 965 | // 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] | 966 | CodeAndDirectMethods* dex_cache_code_and_direct_methods_; |
| 967 | |
| 968 | // short cuts to declaring_class_->dex_cache_ member for fast compiled code access |
| 969 | ObjectArray<StaticStorageBase>* dex_cache_initialized_static_storage_; |
| 970 | |
| 971 | // short cuts to declaring_class_->dex_cache_ member for fast compiled code access |
| 972 | ObjectArray<Field>* dex_cache_resolved_fields_; |
| 973 | |
| 974 | // short cuts to declaring_class_->dex_cache_ member for fast compiled code access |
| 975 | ObjectArray<Method>* dex_cache_resolved_methods_; |
| 976 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 977 | // short cuts to declaring_class_->dex_cache_ member for fast compiled code access |
| 978 | ObjectArray<Class>* dex_cache_resolved_types_; |
| 979 | |
| 980 | // short cuts to declaring_class_->dex_cache_ member for fast compiled code access |
| 981 | ObjectArray<String>* dex_cache_strings_; |
| 982 | |
| 983 | // Storage for invoke_stub_ |
| 984 | const ByteArray* invoke_stub_array_; |
| 985 | |
| 986 | // Storage for mapping_table_ |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 987 | IntArray* mapping_table_; |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 988 | |
jeffhao | e23d93c | 2011-09-15 14:48:43 -0700 | [diff] [blame] | 989 | // Byte arrays that hold data for the register maps |
| 990 | const ByteArray* register_map_data_; |
| 991 | const ByteArray* register_map_header_; |
| 992 | |
Brian Carlstrom | 2ed6739 | 2011-09-09 14:53:28 -0700 | [diff] [blame] | 993 | // The short-form method descriptor string. |
| 994 | String* shorty_; |
| 995 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 996 | // The method descriptor. This represents the parameters a method |
| 997 | // takes and value it returns. This string is a list of the type |
| 998 | // descriptors for the parameters enclosed in parenthesis followed |
| 999 | // by the return type descriptor. For example, for the method |
| 1000 | // |
| 1001 | // Object mymethod(int i, double d, Thread t) |
| 1002 | // |
| 1003 | // the method descriptor would be |
| 1004 | // |
| 1005 | // (IDLjava/lang/Thread;)Ljava/lang/Object; |
| 1006 | String* signature_; |
| 1007 | |
| 1008 | uint32_t java_generic_types_are_initialized_; |
| 1009 | |
Elliott Hughes | 1d3f114 | 2011-09-13 12:00:00 -0700 | [diff] [blame] | 1010 | // Access flags; low 16 bits are defined by spec. |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1011 | uint32_t access_flags_; |
| 1012 | |
| 1013 | // Compiled code associated with this method for callers from managed code. |
| 1014 | // May be compiled managed code or a bridge for invoking a native method. |
| 1015 | const void* code_; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1016 | |
Shih-wei Liao | 2fb9753 | 2011-08-11 16:17:23 -0700 | [diff] [blame] | 1017 | // Offset to the CodeItem. |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1018 | uint32_t code_item_offset_; |
Shih-wei Liao | 2fb9753 | 2011-08-11 16:17:23 -0700 | [diff] [blame] | 1019 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1020 | // Architecture-dependent register spill mask |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1021 | uint32_t core_spill_mask_; |
| 1022 | |
| 1023 | // Architecture-dependent register spill mask |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1024 | uint32_t fp_spill_mask_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1025 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1026 | // Total size in bytes of the frame |
| 1027 | size_t frame_size_in_bytes_; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1028 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1029 | // Native invocation stub entry point for calling from native to managed code. |
| 1030 | const InvokeStub* invoke_stub_; |
buzbee | 4ef7652 | 2011-09-08 10:00:32 -0700 | [diff] [blame] | 1031 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1032 | // Index of the return type |
| 1033 | uint32_t java_return_type_idx_; |
| 1034 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1035 | // For concrete virtual methods, this is the offset of the method |
| 1036 | // in Class::vtable_. |
| 1037 | // |
| 1038 | // For abstract methods in an interface class, this is the offset |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 1039 | // of the method in "iftable_->Get(n)->GetMethodArray()". |
Elliott Hughes | 1d3f114 | 2011-09-13 12:00:00 -0700 | [diff] [blame] | 1040 | uint32_t method_index_; |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 1041 | |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 1042 | // The target native method registered with this method |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1043 | const void* native_method_; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1044 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1045 | // Method bounds; not needed for an abstract method. |
| 1046 | // |
| 1047 | // For a native method, we compute the size of the argument list, and |
| 1048 | // set "insSize" and "registerSize" equal to it. |
Elliott Hughes | 1d3f114 | 2011-09-13 12:00:00 -0700 | [diff] [blame] | 1049 | uint32_t num_ins_; |
| 1050 | uint32_t num_outs_; |
| 1051 | uint32_t num_registers_; // ins + locals |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 1052 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1053 | // Method prototype descriptor string (return and argument types). |
| 1054 | uint32_t proto_idx_; |
| 1055 | |
| 1056 | // Offset of return PC within frame for compiled code (in bytes) |
| 1057 | size_t return_pc_offset_in_bytes_; |
| 1058 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1059 | uint32_t java_slot_; |
Carl Shapiro | 9b9ba28 | 2011-08-14 15:30:39 -0700 | [diff] [blame] | 1060 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1061 | static Class* java_lang_reflect_Method_; |
| 1062 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1063 | friend class ImageWriter; // for relocating code_ and invoke_stub_ |
| 1064 | friend struct MethodOffsets; // for verifying offset information |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1065 | DISALLOW_IMPLICIT_CONSTRUCTORS(Method); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1066 | }; |
| 1067 | |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 1068 | class MANAGED Array : public Object { |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1069 | public: |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1070 | static size_t SizeOf(size_t component_count, |
| 1071 | size_t component_size) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 1072 | return sizeof(Array) + component_count * component_size; |
| 1073 | } |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 1074 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1075 | // Given the context of a calling Method, use its DexCache to |
| 1076 | // resolve a type to an array Class. If it cannot be resolved, throw |
| 1077 | // an error. If it can, use it to create an array. |
| 1078 | static Array* AllocFromCode(uint32_t type_idx, Method* method, int32_t component_count); |
| 1079 | |
Elliott Hughes | 68f4fa0 | 2011-08-21 10:46:59 -0700 | [diff] [blame] | 1080 | // A convenience for code that doesn't know the component size, |
| 1081 | // and doesn't want to have to work it out itself. |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1082 | static Array* Alloc(Class* array_class, int32_t component_count); |
Elliott Hughes | 68f4fa0 | 2011-08-21 10:46:59 -0700 | [diff] [blame] | 1083 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1084 | 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] | 1085 | |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 1086 | size_t SizeOf() const; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 1087 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 1088 | int32_t GetLength() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1089 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Array, length_), false); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1090 | } |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1091 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1092 | void SetLength(int32_t length) { |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 1093 | CHECK_GE(length, 0); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1094 | SetField32(OFFSET_OF_OBJECT_MEMBER(Array, length_), length, false); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1095 | } |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1096 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1097 | static MemberOffset LengthOffset() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1098 | return OFFSET_OF_OBJECT_MEMBER(Array, length_); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | static MemberOffset DataOffset() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1102 | return OFFSET_OF_OBJECT_MEMBER(Array, first_element_); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 1105 | void* GetRawData() { |
| 1106 | return reinterpret_cast<void*>(first_element_); |
| 1107 | } |
| 1108 | |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 1109 | protected: |
| 1110 | bool IsValidIndex(int32_t index) const { |
| 1111 | if (index < 0 || index >= length_) { |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 1112 | Thread* self = Thread::Current(); |
| 1113 | self->ThrowNewException("Ljava/lang/ArrayIndexOutOfBoundsException;", |
| 1114 | "length=%i; index=%i", length_, index); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 1115 | return false; |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 1116 | } |
| 1117 | return true; |
| 1118 | } |
| 1119 | |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1120 | private: |
| 1121 | // The number of array elements. |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 1122 | int32_t length_; |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 1123 | // Padding to ensure the first member defined by a subclass begins on a 8-byte boundary |
| 1124 | int32_t padding_; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1125 | // Marker for the data (used by generated code) |
| 1126 | uint32_t first_element_[0]; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1127 | |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1128 | DISALLOW_IMPLICIT_CONSTRUCTORS(Array); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1129 | }; |
| 1130 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 1131 | template<class T> |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 1132 | class MANAGED ObjectArray : public Array { |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1133 | public: |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1134 | static ObjectArray<T>* Alloc(Class* object_array_class, int32_t length); |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 1135 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1136 | T* Get(int32_t i) const; |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 1137 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1138 | void Set(int32_t i, T* object); |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 1139 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1140 | // Set element without bound and element type checks, to be used in limited |
| 1141 | // circumstances, such as during boot image writing |
| 1142 | void SetWithoutChecks(int32_t i, T* object); |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1143 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1144 | static void Copy(const ObjectArray<T>* src, int src_pos, |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1145 | ObjectArray<T>* dst, int dst_pos, |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1146 | size_t length); |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1147 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1148 | ObjectArray<T>* CopyOf(int32_t new_length); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1149 | |
| 1150 | private: |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 1151 | DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1152 | }; |
| 1153 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1154 | template<class T> |
| 1155 | ObjectArray<T>* ObjectArray<T>::Alloc(Class* object_array_class, int32_t length) { |
| 1156 | return Array::Alloc(object_array_class, length, sizeof(uint32_t))->AsObjectArray<T>(); |
| 1157 | } |
| 1158 | |
| 1159 | template<class T> |
| 1160 | T* ObjectArray<T>::Get(int32_t i) const { |
| 1161 | if (!IsValidIndex(i)) { |
| 1162 | return NULL; |
| 1163 | } |
| 1164 | MemberOffset data_offset(DataOffset().Int32Value() + i * sizeof(Object*)); |
| 1165 | return GetFieldObject<T*>(data_offset, false); |
| 1166 | } |
| 1167 | |
| 1168 | template<class T> |
| 1169 | ObjectArray<T>* ObjectArray<T>::CopyOf(int32_t new_length) { |
| 1170 | ObjectArray<T>* new_array = Alloc(GetClass(), new_length); |
| 1171 | Copy(this, 0, new_array, 0, std::min(GetLength(), new_length)); |
| 1172 | return new_array; |
| 1173 | } |
| 1174 | |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 1175 | // Type for the InitializedStaticStorage table. Currently the Class |
Brian Carlstrom | 848a4b3 | 2011-09-04 11:29:27 -0700 | [diff] [blame] | 1176 | // provides the static storage. However, this might change to an Array |
| 1177 | // to improve image sharing, so we use this type to avoid assumptions |
| 1178 | // on the current storage. |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 1179 | class MANAGED StaticStorageBase : public Object {}; |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 1180 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1181 | // C++ mirror of java.lang.Class |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 1182 | class MANAGED Class : public StaticStorageBase { |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1183 | public: |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 1184 | |
| 1185 | // Class Status |
| 1186 | // |
| 1187 | // kStatusNotReady: If a Class cannot be found in the class table by |
| 1188 | // FindClass, it allocates an new one with AllocClass in the |
| 1189 | // kStatusNotReady and calls LoadClass. Note if it does find a |
| 1190 | // class, it may not be kStatusResolved and it will try to push it |
| 1191 | // forward toward kStatusResolved. |
| 1192 | // |
| 1193 | // kStatusIdx: LoadClass populates with Class with information from |
| 1194 | // the DexFile, moving the status to kStatusIdx, indicating that the |
| 1195 | // Class values in super_class_ and interfaces_ have not been |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1196 | // populated based on super_class_type_idx_ and |
| 1197 | // interfaces_type_idx_. The new Class can then be inserted into the |
| 1198 | // classes table. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 1199 | // |
| 1200 | // kStatusLoaded: After taking a lock on Class, the ClassLinker will |
| 1201 | // attempt to move a kStatusIdx class forward to kStatusLoaded by |
| 1202 | // using ResolveClass to initialize the super_class_ and interfaces_. |
| 1203 | // |
| 1204 | // kStatusResolved: Still holding the lock on Class, the ClassLinker |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1205 | // shows linking is complete and fields of the Class populated by making |
| 1206 | // it kStatusResolved. Java allows circularities of the form where a super |
| 1207 | // class has a field that is of the type of the sub class. We need to be able |
| 1208 | // to fully resolve super classes while resolving types for fields. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 1209 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1210 | enum Status { |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1211 | kStatusError = -1, |
| 1212 | kStatusNotReady = 0, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1213 | 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] | 1214 | kStatusLoaded = 2, // DEX idx values resolved |
| 1215 | kStatusResolved = 3, // part of linking |
| 1216 | kStatusVerifying = 4, // in the process of being verified |
| 1217 | kStatusVerified = 5, // logically part of linking; done pre-init |
| 1218 | kStatusInitializing = 6, // class init in progress |
| 1219 | kStatusInitialized = 7, // ready to go |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1220 | }; |
| 1221 | |
| 1222 | enum PrimitiveType { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1223 | kPrimNot = 0, |
| 1224 | kPrimBoolean, |
| 1225 | kPrimByte, |
| 1226 | kPrimChar, |
| 1227 | kPrimShort, |
| 1228 | kPrimInt, |
| 1229 | kPrimLong, |
| 1230 | kPrimFloat, |
| 1231 | kPrimDouble, |
| 1232 | kPrimVoid, |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1233 | }; |
| 1234 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1235 | Status GetStatus() const { |
| 1236 | CHECK(sizeof(Status) == sizeof(uint32_t)); |
| 1237 | return static_cast<Status>( |
| 1238 | GetField32(OFFSET_OF_OBJECT_MEMBER(Class, status_), false)); |
| 1239 | } |
| 1240 | |
| 1241 | void SetStatus(Status new_status); |
| 1242 | |
| 1243 | // Returns true if the class has failed to link. |
| 1244 | bool IsErroneous() const { |
| 1245 | return GetStatus() == kStatusError; |
| 1246 | } |
| 1247 | |
| 1248 | // Returns true if the class has been loaded. |
| 1249 | bool IsIdxLoaded() const { |
| 1250 | return GetStatus() >= kStatusIdx; |
| 1251 | } |
| 1252 | |
| 1253 | // Returns true if the class has been loaded. |
| 1254 | bool IsLoaded() const { |
| 1255 | return GetStatus() >= kStatusLoaded; |
| 1256 | } |
| 1257 | |
| 1258 | // Returns true if the class has been linked. |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 1259 | bool IsResolved() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1260 | return GetStatus() >= kStatusResolved; |
| 1261 | } |
| 1262 | |
| 1263 | // Returns true if the class has been verified. |
| 1264 | bool IsVerified() const { |
| 1265 | return GetStatus() >= kStatusVerified; |
| 1266 | } |
| 1267 | |
| 1268 | // Returns true if the class is initialized. |
| 1269 | bool IsInitialized() const { |
| 1270 | return GetStatus() == kStatusInitialized; |
| 1271 | } |
| 1272 | |
| 1273 | uint32_t GetAccessFlags() const; |
| 1274 | |
| 1275 | void SetAccessFlags(uint32_t new_access_flags) { |
| 1276 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), new_access_flags, |
| 1277 | false); |
| 1278 | } |
| 1279 | |
| 1280 | // Returns true if the class is an interface. |
| 1281 | bool IsInterface() const { |
| 1282 | return (GetAccessFlags() & kAccInterface) != 0; |
| 1283 | } |
| 1284 | |
| 1285 | // Returns true if the class is declared public. |
| 1286 | bool IsPublic() const { |
| 1287 | return (GetAccessFlags() & kAccPublic) != 0; |
| 1288 | } |
| 1289 | |
| 1290 | // Returns true if the class is declared final. |
| 1291 | bool IsFinal() const { |
| 1292 | return (GetAccessFlags() & kAccFinal) != 0; |
| 1293 | } |
| 1294 | |
| 1295 | // Returns true if the class is abstract. |
| 1296 | bool IsAbstract() const { |
| 1297 | return (GetAccessFlags() & kAccAbstract) != 0; |
| 1298 | } |
| 1299 | |
| 1300 | // Returns true if the class is an annotation. |
| 1301 | bool IsAnnotation() const { |
| 1302 | return (GetAccessFlags() & kAccAnnotation) != 0; |
| 1303 | } |
| 1304 | |
| 1305 | // Returns true if the class is synthetic. |
| 1306 | bool IsSynthetic() const { |
| 1307 | return (GetAccessFlags() & kAccSynthetic) != 0; |
| 1308 | } |
| 1309 | |
| 1310 | bool IsReferenceClass() const { |
| 1311 | return (GetAccessFlags() & kAccClassIsReference) != 0; |
| 1312 | } |
| 1313 | |
| 1314 | bool IsWeakReferenceClass() const { |
| 1315 | return (GetAccessFlags() & kAccClassIsWeakReference) != 0; |
| 1316 | } |
| 1317 | |
| 1318 | bool IsSoftReferenceClass() const { |
| 1319 | return (GetAccessFlags() & ~kAccReferenceFlagsMask) == kAccClassIsReference; |
| 1320 | } |
| 1321 | |
| 1322 | bool IsFinalizerReferenceClass() const { |
| 1323 | return (GetAccessFlags() & kAccClassIsFinalizerReference) != 0; |
| 1324 | } |
| 1325 | |
| 1326 | bool IsPhantomReferenceClass() const { |
| 1327 | return (GetAccessFlags() & kAccClassIsPhantomReference) != 0; |
| 1328 | } |
| 1329 | |
| 1330 | PrimitiveType GetPrimitiveType() const { |
| 1331 | CHECK(sizeof(PrimitiveType) == sizeof(int32_t)); |
| 1332 | return static_cast<PrimitiveType>( |
| 1333 | GetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), false)); |
| 1334 | } |
| 1335 | |
| 1336 | void SetPrimitiveType(PrimitiveType new_type) { |
| 1337 | CHECK(sizeof(PrimitiveType) == sizeof(int32_t)); |
| 1338 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), new_type, |
| 1339 | false); |
| 1340 | } |
| 1341 | |
| 1342 | // Returns true if the class is a primitive type. |
| 1343 | bool IsPrimitive() const { |
| 1344 | return GetPrimitiveType() != kPrimNot; |
| 1345 | } |
| 1346 | |
| 1347 | bool IsPrimitiveBoolean() const { |
| 1348 | return GetPrimitiveType() == kPrimBoolean; |
| 1349 | } |
| 1350 | |
| 1351 | bool IsPrimitiveByte() const { |
| 1352 | return GetPrimitiveType() == kPrimByte; |
| 1353 | } |
| 1354 | |
| 1355 | bool IsPrimitiveChar() const { |
| 1356 | return GetPrimitiveType() == kPrimChar; |
| 1357 | } |
| 1358 | |
| 1359 | bool IsPrimitiveShort() const { |
| 1360 | return GetPrimitiveType() == kPrimShort; |
| 1361 | } |
| 1362 | |
| 1363 | bool IsPrimitiveInt() const { |
| 1364 | return GetPrimitiveType() == kPrimInt; |
| 1365 | } |
| 1366 | |
| 1367 | bool IsPrimitiveLong() const { |
| 1368 | return GetPrimitiveType() == kPrimLong; |
| 1369 | } |
| 1370 | |
| 1371 | bool IsPrimitiveFloat() const { |
| 1372 | return GetPrimitiveType() == kPrimFloat; |
| 1373 | } |
| 1374 | |
| 1375 | bool IsPrimitiveDouble() const { |
| 1376 | return GetPrimitiveType() == kPrimDouble; |
| 1377 | } |
| 1378 | |
| 1379 | bool IsPrimitiveVoid() const { |
| 1380 | return GetPrimitiveType() == kPrimVoid; |
| 1381 | } |
| 1382 | |
| 1383 | size_t PrimitiveSize() const; |
| 1384 | |
| 1385 | bool IsArrayClass() const { |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 1386 | return GetComponentType() != NULL; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | Class* GetComponentType() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1390 | return GetFieldObject<Class*>( |
| 1391 | OFFSET_OF_OBJECT_MEMBER(Class, component_type_), false); |
| 1392 | } |
| 1393 | |
| 1394 | void SetComponentType(Class* new_component_type) { |
| 1395 | DCHECK(GetComponentType() == NULL); |
| 1396 | DCHECK(new_component_type != NULL); |
| 1397 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, component_type_), |
| 1398 | new_component_type, false); |
| 1399 | } |
| 1400 | |
| 1401 | size_t GetComponentSize() const { |
| 1402 | return GetTypeSize(GetComponentType()->GetDescriptor()); |
| 1403 | } |
| 1404 | |
| 1405 | bool IsObjectClass() const { |
| 1406 | return !IsPrimitive() && GetSuperClass() == NULL; |
| 1407 | } |
| 1408 | |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame^] | 1409 | // Tests whether a possibly null 'element' can be |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 1410 | // assigned into an array of type 'array_class'. |
buzbee | 9a195c9 | 2011-09-16 13:26:02 -0700 | [diff] [blame] | 1411 | static void CanPutArrayElementFromCode(const Object* element, const Class* array_class); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1412 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1413 | // Given the context of a calling Method, use its DexCache to |
| 1414 | // resolve a type to a Class. If it cannot be resolved, throw an |
| 1415 | // error. If it can, use it to create an instance. |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 1416 | static Object* AllocObjectFromCode(uint32_t type_idx, Method* method); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 1417 | |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 1418 | // Creates a raw object instance but does not invoke the default constructor. |
| 1419 | Object* AllocObject(); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 1420 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1421 | static size_t GetTypeSize(const String* descriptor); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 1422 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1423 | const String* GetDescriptor() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1424 | const String* result = GetFieldObject<const String*>( |
| 1425 | OFFSET_OF_OBJECT_MEMBER(Class, descriptor_), false); |
| 1426 | // DCHECK(result != NULL); // may be NULL prior to class linker initialization |
| 1427 | // DCHECK_NE(0, result->GetLength()); // TODO: keep? |
| 1428 | return result; |
| 1429 | } |
| 1430 | |
| 1431 | void SetDescriptor(String* new_descriptor); |
| 1432 | |
| 1433 | bool IsVariableSize() const { |
| 1434 | // Classes and arrays vary in size, and so the object_size_ field cannot |
| 1435 | // be used to get their instance size |
| 1436 | return IsClassClass() || IsArrayClass(); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 1439 | size_t SizeOf() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1440 | CHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1441 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1444 | size_t GetClassSize() const { |
| 1445 | CHECK(sizeof(size_t) == sizeof(uint32_t)); |
| 1446 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1449 | void SetClassSize(size_t new_class_size) { |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 1450 | DCHECK(new_class_size >= GetClassSize()) |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 1451 | << " class=" << PrettyTypeOf(this) |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 1452 | << " new_class_size=" << new_class_size |
| 1453 | << " GetClassSize=" << GetClassSize(); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 1454 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size, false); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1457 | size_t GetObjectSize() const { |
| 1458 | CHECK(!IsVariableSize()); |
| 1459 | CHECK(sizeof(size_t) == sizeof(int32_t)); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 1460 | size_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), false); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1461 | CHECK_GE(result, sizeof(Object)); |
| 1462 | return result; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1465 | void SetObjectSize(size_t new_object_size) { |
| 1466 | DCHECK(!IsVariableSize()); |
| 1467 | CHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1468 | return SetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), |
| 1469 | new_object_size, false); |
Carl Shapiro | 83ab4f3 | 2011-08-15 20:21:39 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1472 | // Returns true if this class is in the same packages as that class. |
| 1473 | bool IsInSamePackage(const Class* that) const; |
| 1474 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1475 | static bool IsInSamePackage(const String* descriptor1, |
| 1476 | const String* descriptor2); |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1477 | |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1478 | // Returns true if this class can access that class. |
| 1479 | bool CanAccess(const Class* that) const { |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1480 | return that->IsPublic() || this->IsInSamePackage(that); |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 1483 | bool IsAssignableFrom(const Class* src) const { |
| 1484 | DCHECK(src != NULL); |
| 1485 | if (this == src) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1486 | // Can always assign to things of the same type |
| 1487 | return true; |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1488 | } else if (IsObjectClass()) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1489 | // Can assign any reference to java.lang.Object |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 1490 | return !src->IsPrimitive(); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1491 | } else if (IsInterface()) { |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 1492 | return src->Implements(this); |
| 1493 | } else if (src->IsArrayClass()) { |
| 1494 | return IsAssignableFromArray(src); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1495 | } else { |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 1496 | return src->IsSubClass(this); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1497 | } |
| 1498 | } |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 1499 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1500 | Class* GetSuperClass() const { |
| 1501 | // Can only get super class for loaded classes (hack for when runtime is |
| 1502 | // initializing) |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1503 | DCHECK(IsLoaded() || !Runtime::Current()->IsStarted()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1504 | return GetFieldObject<Class*>( |
| 1505 | OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false); |
| 1506 | } |
| 1507 | |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 1508 | static MemberOffset SuperClassOffset() { |
| 1509 | return MemberOffset(OFFSETOF_MEMBER(Class, super_class_)); |
| 1510 | } |
| 1511 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1512 | void SetSuperClass(Class *new_super_class) { |
| 1513 | // super class is assigned once, except during class linker initialization |
| 1514 | Class* old_super_class = GetFieldObject<Class*>( |
| 1515 | OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false); |
| 1516 | DCHECK(old_super_class == NULL || old_super_class == new_super_class); |
| 1517 | DCHECK(new_super_class != NULL); |
| 1518 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), |
| 1519 | new_super_class, false); |
| 1520 | } |
| 1521 | |
| 1522 | bool HasSuperClass() const { |
| 1523 | return GetSuperClass() != NULL; |
| 1524 | } |
| 1525 | |
| 1526 | uint32_t GetSuperClassTypeIdx() const { |
| 1527 | DCHECK(IsIdxLoaded()); |
| 1528 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, super_class_type_idx_), |
| 1529 | false); |
| 1530 | } |
| 1531 | |
| 1532 | void SetSuperClassTypeIdx(int32_t new_super_class_idx) { |
| 1533 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, super_class_type_idx_), |
| 1534 | new_super_class_idx, false); |
| 1535 | } |
| 1536 | |
| 1537 | const ClassLoader* GetClassLoader() const; |
| 1538 | |
| 1539 | void SetClassLoader(const ClassLoader* new_cl); |
| 1540 | |
| 1541 | static MemberOffset DexCacheOffset() { |
| 1542 | return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_)); |
| 1543 | } |
| 1544 | |
| 1545 | DexCache* GetDexCache() const; |
| 1546 | |
| 1547 | void SetDexCache(DexCache* new_dex_cache); |
| 1548 | |
| 1549 | ObjectArray<Method>* GetDirectMethods() const { |
| 1550 | DCHECK(IsLoaded()); |
| 1551 | return GetFieldObject<ObjectArray<Method>*>( |
| 1552 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false); |
| 1553 | } |
| 1554 | |
| 1555 | void SetDirectMethods(ObjectArray<Method>* new_direct_methods) { |
| 1556 | DCHECK(NULL == GetFieldObject<ObjectArray<Method>*>( |
| 1557 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false)); |
| 1558 | DCHECK_NE(0, new_direct_methods->GetLength()); |
| 1559 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), |
| 1560 | new_direct_methods, false); |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 1563 | Method* GetDirectMethod(int32_t i) const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1564 | return GetDirectMethods()->Get(i); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | void SetDirectMethod(uint32_t i, Method* f) { // TODO: uint16_t |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1568 | ObjectArray<Method>* direct_methods = |
| 1569 | GetFieldObject<ObjectArray<Method>*>( |
| 1570 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false); |
| 1571 | direct_methods->Set(i, f); |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1574 | // Returns the number of static, private, and constructor methods. |
| 1575 | size_t NumDirectMethods() const { |
| 1576 | return (GetDirectMethods() != NULL) ? GetDirectMethods()->GetLength() : 0; |
| 1577 | } |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 1578 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1579 | ObjectArray<Method>* GetVirtualMethods() const { |
| 1580 | DCHECK(IsLoaded()); |
| 1581 | return GetFieldObject<ObjectArray<Method>*>( |
| 1582 | OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), false); |
| 1583 | } |
| 1584 | |
| 1585 | void SetVirtualMethods(ObjectArray<Method>* new_virtual_methods) { |
| 1586 | // TODO: we reassign virtual methods to grow the table for miranda |
| 1587 | // methods.. they should really just be assigned once |
| 1588 | DCHECK_NE(0, new_virtual_methods->GetLength()); |
| 1589 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), |
| 1590 | new_virtual_methods, false); |
| 1591 | } |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 1592 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1593 | // Returns the number of non-inherited virtual methods. |
| 1594 | size_t NumVirtualMethods() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1595 | return (GetVirtualMethods() != NULL) ? GetVirtualMethods()->GetLength() : 0; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | Method* GetVirtualMethod(uint32_t i) const { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 1599 | DCHECK(IsResolved()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1600 | return GetVirtualMethods()->Get(i); |
| 1601 | } |
| 1602 | |
| 1603 | Method* GetVirtualMethodDuringLinking(uint32_t i) const { |
| 1604 | DCHECK(IsLoaded()); |
| 1605 | return GetVirtualMethods()->Get(i); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | void SetVirtualMethod(uint32_t i, Method* f) { // TODO: uint16_t |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1609 | ObjectArray<Method>* virtual_methods = |
| 1610 | GetFieldObject<ObjectArray<Method>*>( |
| 1611 | OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), false); |
| 1612 | virtual_methods->Set(i, f); |
| 1613 | } |
| 1614 | |
| 1615 | ObjectArray<Method>* GetVTable() const { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 1616 | DCHECK(IsResolved()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1617 | return GetFieldObject<ObjectArray<Method>*>( |
| 1618 | OFFSET_OF_OBJECT_MEMBER(Class, vtable_), false); |
| 1619 | } |
| 1620 | |
| 1621 | ObjectArray<Method>* GetVTableDuringLinking() const { |
| 1622 | DCHECK(IsLoaded()); |
| 1623 | return GetFieldObject<ObjectArray<Method>*>( |
| 1624 | OFFSET_OF_OBJECT_MEMBER(Class, vtable_), false); |
| 1625 | } |
| 1626 | |
| 1627 | void SetVTable(ObjectArray<Method>* new_vtable) { |
| 1628 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, vtable_), new_vtable, false); |
| 1629 | } |
| 1630 | |
| 1631 | static MemberOffset VTableOffset() { |
| 1632 | return OFFSET_OF_OBJECT_MEMBER(Class, vtable_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 1635 | // Given a method implemented by this class but potentially from a |
| 1636 | // super class, return the specific implementation |
| 1637 | // method for this class. |
| 1638 | Method* FindVirtualMethodForVirtual(Method* method) { |
| 1639 | DCHECK(!method->GetDeclaringClass()->IsInterface()); |
| 1640 | // The argument method may from a super class. |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1641 | // Use the index to a potentially overridden one for this instance's class. |
| 1642 | return GetVTable()->Get(method->GetMethodIndex()); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | // Given a method implemented by this class, but potentially from a |
| 1646 | // super class or interface, return the specific implementation |
| 1647 | // method for this class. |
| 1648 | Method* FindVirtualMethodForInterface(Method* method); |
| 1649 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1650 | Method* FindInterfaceMethod(const StringPiece& name, |
| 1651 | const StringPiece& descriptor); |
| 1652 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 1653 | Method* FindVirtualMethodForVirtualOrInterface(Method* method) { |
| 1654 | if (method->GetDeclaringClass()->IsInterface()) { |
| 1655 | return FindVirtualMethodForInterface(method); |
| 1656 | } |
| 1657 | return FindVirtualMethodForVirtual(method); |
Elliott Hughes | 72025e5 | 2011-08-23 17:50:30 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 1660 | Method* FindDeclaredVirtualMethod(const StringPiece& name, |
Brian Carlstrom | 3a7b4f2 | 2011-09-17 15:01:57 -0700 | [diff] [blame] | 1661 | const StringPiece& signature); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 1662 | |
| 1663 | Method* FindVirtualMethod(const StringPiece& name, |
| 1664 | const StringPiece& descriptor); |
| 1665 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1666 | Method* FindDeclaredDirectMethod(const StringPiece& name, |
| 1667 | const StringPiece& signature); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1668 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1669 | Method* FindDirectMethod(const StringPiece& name, |
| 1670 | const StringPiece& signature); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1671 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1672 | size_t NumInterfaces() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1673 | CHECK(IsIdxLoaded()); // used during loading |
| 1674 | ObjectArray<Class>* interfaces = GetFieldObject<ObjectArray<Class>*>( |
| 1675 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false); |
| 1676 | return (interfaces != NULL) ? interfaces->GetLength() : 0; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1679 | IntArray* GetInterfacesTypeIdx() const { |
| 1680 | CHECK(IsIdxLoaded()); |
| 1681 | return GetFieldObject<IntArray*>( |
| 1682 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_type_idx_), false); |
| 1683 | } |
| 1684 | |
| 1685 | void SetInterfacesTypeIdx(IntArray* new_interfaces_idx); |
| 1686 | |
| 1687 | ObjectArray<Class>* GetInterfaces() const { |
| 1688 | CHECK(IsLoaded()); |
| 1689 | return GetFieldObject<ObjectArray<Class>*>( |
| 1690 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false); |
| 1691 | } |
| 1692 | |
| 1693 | void SetInterfaces(ObjectArray<Class>* new_interfaces) { |
| 1694 | DCHECK(NULL == GetFieldObject<Object*>( |
| 1695 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false)); |
| 1696 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), |
| 1697 | new_interfaces, false); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | void SetInterface(uint32_t i, Class* f) { // TODO: uint16_t |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 1701 | DCHECK_NE(NumInterfaces(), 0U); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1702 | ObjectArray<Class>* interfaces = |
| 1703 | GetFieldObject<ObjectArray<Class>*>( |
| 1704 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_), false); |
| 1705 | interfaces->Set(i, f); |
| 1706 | } |
| 1707 | |
| 1708 | Class* GetInterface(uint32_t i) const { |
| 1709 | DCHECK_NE(NumInterfaces(), 0U); |
| 1710 | return GetInterfaces()->Get(i); |
| 1711 | } |
| 1712 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 1713 | int32_t GetIfTableCount() const { |
| 1714 | ObjectArray<InterfaceEntry>* iftable = GetIfTable(); |
| 1715 | if (iftable == NULL) { |
| 1716 | return 0; |
| 1717 | } |
| 1718 | return iftable->GetLength(); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 1721 | ObjectArray<InterfaceEntry>* GetIfTable() const { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 1722 | DCHECK(IsResolved()); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 1723 | return GetFieldObject<ObjectArray<InterfaceEntry>*>( |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1724 | OFFSET_OF_OBJECT_MEMBER(Class, iftable_), false); |
| 1725 | } |
| 1726 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 1727 | void SetIfTable(ObjectArray<InterfaceEntry>* new_iftable) { |
Elliott Hughes | 5ea047b | 2011-09-13 14:38:18 -0700 | [diff] [blame] | 1728 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, iftable_), new_iftable, false); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | // Get instance fields |
| 1732 | ObjectArray<Field>* GetIFields() const { |
| 1733 | DCHECK(IsLoaded()); |
| 1734 | return GetFieldObject<ObjectArray<Field>*>( |
| 1735 | OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false); |
| 1736 | } |
| 1737 | |
| 1738 | void SetIFields(ObjectArray<Field>* new_ifields) { |
| 1739 | DCHECK(NULL == GetFieldObject<ObjectArray<Field>*>( |
| 1740 | OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false)); |
| 1741 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, ifields_), |
| 1742 | new_ifields, false); |
| 1743 | } |
| 1744 | |
| 1745 | size_t NumInstanceFields() const { |
| 1746 | return (GetIFields() != NULL) ? GetIFields()->GetLength() : 0; |
| 1747 | } |
| 1748 | |
| 1749 | Field* GetInstanceField(uint32_t i) const { // TODO: uint16_t |
| 1750 | DCHECK_NE(NumInstanceFields(), 0U); |
| 1751 | return GetIFields()->Get(i); |
| 1752 | } |
| 1753 | |
| 1754 | void SetInstanceField(uint32_t i, Field* f) { // TODO: uint16_t |
| 1755 | ObjectArray<Field>* ifields= GetFieldObject<ObjectArray<Field>*>( |
| 1756 | OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false); |
| 1757 | ifields->Set(i, f); |
| 1758 | } |
| 1759 | |
| 1760 | // Returns the number of instance fields containing reference types. |
| 1761 | size_t NumReferenceInstanceFields() const { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 1762 | DCHECK(IsResolved()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1763 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1764 | return GetField32( |
| 1765 | OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false); |
| 1766 | } |
| 1767 | |
| 1768 | size_t NumReferenceInstanceFieldsDuringLinking() const { |
| 1769 | DCHECK(IsLoaded()); |
| 1770 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1771 | return GetField32( |
| 1772 | OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), false); |
| 1773 | } |
| 1774 | |
| 1775 | void SetNumReferenceInstanceFields(size_t new_num) { |
| 1776 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1777 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), |
| 1778 | new_num, false); |
| 1779 | } |
| 1780 | |
| 1781 | uint32_t GetReferenceInstanceOffsets() const { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 1782 | DCHECK(IsResolved()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1783 | return GetField32( |
| 1784 | OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), false); |
| 1785 | } |
| 1786 | |
| 1787 | void SetReferenceInstanceOffsets(uint32_t new_reference_offsets); |
| 1788 | |
| 1789 | // Beginning of static field data |
| 1790 | static MemberOffset FieldsOffset() { |
| 1791 | return OFFSET_OF_OBJECT_MEMBER(Class, fields_); |
| 1792 | } |
| 1793 | |
| 1794 | // Returns the number of static fields containing reference types. |
| 1795 | size_t NumReferenceStaticFields() const { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 1796 | DCHECK(IsResolved()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1797 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1798 | return GetField32( |
| 1799 | OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false); |
| 1800 | } |
| 1801 | |
| 1802 | size_t NumReferenceStaticFieldsDuringLinking() const { |
| 1803 | DCHECK(IsLoaded()); |
| 1804 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1805 | return GetField32( |
| 1806 | OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), false); |
| 1807 | } |
| 1808 | |
| 1809 | void SetNumReferenceStaticFields(size_t new_num) { |
| 1810 | DCHECK(sizeof(size_t) == sizeof(int32_t)); |
| 1811 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), |
| 1812 | new_num, false); |
| 1813 | } |
| 1814 | |
| 1815 | ObjectArray<Field>* GetSFields() const { |
| 1816 | DCHECK(IsLoaded()); |
| 1817 | return GetFieldObject<ObjectArray<Field>*>( |
| 1818 | OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false); |
| 1819 | } |
| 1820 | |
| 1821 | void SetSFields(ObjectArray<Field>* new_sfields) { |
| 1822 | DCHECK(NULL == GetFieldObject<ObjectArray<Field>*>( |
| 1823 | OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false)); |
| 1824 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, sfields_), |
| 1825 | new_sfields, false); |
| 1826 | } |
| 1827 | |
| 1828 | size_t NumStaticFields() const { |
| 1829 | return (GetSFields() != NULL) ? GetSFields()->GetLength() : 0; |
| 1830 | } |
| 1831 | |
| 1832 | Field* GetStaticField(uint32_t i) const { // TODO: uint16_t |
| 1833 | return GetSFields()->Get(i); |
| 1834 | } |
| 1835 | |
| 1836 | void SetStaticField(uint32_t i, Field* f) { // TODO: uint16_t |
| 1837 | ObjectArray<Field>* sfields= GetFieldObject<ObjectArray<Field>*>( |
| 1838 | OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false); |
| 1839 | sfields->Set(i, f); |
| 1840 | } |
| 1841 | |
| 1842 | uint32_t GetReferenceStaticOffsets() const { |
| 1843 | return GetField32( |
| 1844 | OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), false); |
| 1845 | } |
| 1846 | |
| 1847 | void SetReferenceStaticOffsets(uint32_t new_reference_offsets); |
| 1848 | |
| 1849 | // Finds the given instance field in this class or a superclass. |
| 1850 | Field* FindInstanceField(const StringPiece& name, Class* type); |
| 1851 | |
| 1852 | Field* FindDeclaredInstanceField(const StringPiece& name, Class* type); |
| 1853 | |
| 1854 | // Finds the given static field in this class or a superclass. |
| 1855 | Field* FindStaticField(const StringPiece& name, Class* type); |
| 1856 | |
| 1857 | Field* FindDeclaredStaticField(const StringPiece& name, Class* type); |
| 1858 | |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1859 | pid_t GetClinitThreadId() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1860 | DCHECK(IsIdxLoaded()); |
| 1861 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), false); |
| 1862 | } |
| 1863 | |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1864 | void SetClinitThreadId(pid_t new_clinit_thread_id) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1865 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), |
| 1866 | new_clinit_thread_id, false); |
| 1867 | } |
| 1868 | |
| 1869 | Class* GetVerifyErrorClass() const { |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1870 | // DCHECK(IsErroneous()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1871 | return GetFieldObject<Class*>( |
| 1872 | OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), false); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 1875 | void SetVerifyErrorClass(Class* klass) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1876 | klass->SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), |
| 1877 | klass, false); |
| 1878 | } |
| 1879 | |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 1880 | String* GetSourceFile() const; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1881 | |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 1882 | void SetSourceFile(String* new_source_file); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 1883 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1884 | private: |
jeffhao | 5dbddee | 2011-09-07 16:38:26 -0700 | [diff] [blame] | 1885 | bool Implements(const Class* klass) const; |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 1886 | bool IsArrayAssignableFromArray(const Class* klass) const; |
| 1887 | bool IsAssignableFromArray(const Class* klass) const; |
| 1888 | bool IsSubClass(const Class* klass) const; |
| 1889 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 1890 | // descriptor for the class such as "java.lang.Class" or "[C" |
| 1891 | String* name_; // TODO initialize |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1892 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1893 | // defining class loader, or NULL for the "bootstrap" system loader |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1894 | const ClassLoader* class_loader_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1895 | |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 1896 | // For array classes, the component class object for instanceof/checkcast |
| 1897 | // (for String[][][], this will be String[][]). NULL for non-array classes. |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 1898 | Class* component_type_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1899 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1900 | // descriptor for the class such as "Ljava/lang/Class;" or "[C" |
| 1901 | String* descriptor_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1902 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1903 | // DexCache of resolved constant pool entries |
| 1904 | // (will be NULL for VM-generated, e.g. arrays and primitive classes) |
| 1905 | DexCache* dex_cache_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1906 | |
| 1907 | // static, private, and <init> methods |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 1908 | ObjectArray<Method>* direct_methods_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1909 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1910 | // instance fields |
| 1911 | // |
| 1912 | // These describe the layout of the contents of an Object. |
| 1913 | // Note that only the fields directly declared by this class are |
| 1914 | // listed in ifields; fields declared by a superclass are listed in |
| 1915 | // the superclass's Class.ifields. |
| 1916 | // |
| 1917 | // All instance fields that refer to objects are guaranteed to be at |
| 1918 | // the beginning of the field list. num_reference_instance_fields_ |
| 1919 | // specifies the number of reference fields. |
| 1920 | ObjectArray<Field>* ifields_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1921 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 1922 | // Interface table (iftable_), one entry per interface supported by |
| 1923 | // this class. That means one entry for each interface we support |
| 1924 | // directly, indirectly via superclass, or indirectly via |
| 1925 | // superinterface. This will be null if neither we nor our |
| 1926 | // superclass implement any interfaces. |
| 1927 | // |
| 1928 | // Why we need this: given "class Foo implements Face", declare |
| 1929 | // "Face faceObj = new Foo()". Invoke faceObj.blah(), where "blah" |
| 1930 | // is part of the Face interface. We can't easily use a single |
| 1931 | // vtable. |
| 1932 | // |
| 1933 | // For every interface a concrete class implements, we create an array |
| 1934 | // of the concrete vtable_ methods for the methods in the interface. |
| 1935 | ObjectArray<InterfaceEntry>* iftable_; |
| 1936 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1937 | // array of interfaces this class implements directly |
| 1938 | // see also interfaces_type_idx_ |
| 1939 | ObjectArray<Class>* interfaces_; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1940 | |
| 1941 | // array of type_idx's for interfaces this class implements directly |
| 1942 | // see also interfaces_ |
| 1943 | IntArray* interfaces_type_idx_; |
| 1944 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1945 | // Static fields |
| 1946 | ObjectArray<Field>* sfields_; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1947 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 1948 | // source file name, if known. Otherwise, NULL. |
| 1949 | String* source_file_; |
| 1950 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1951 | // The superclass, or NULL if this is java.lang.Object or a |
| 1952 | // primitive type. |
| 1953 | // see also super_class_type_idx_; |
| 1954 | Class* super_class_; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1955 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1956 | // If class verify fails, we must return same error on subsequent tries. |
| 1957 | // Update with SetVerifyErrorClass to ensure a write barrier is used. |
| 1958 | const Class* verify_error_class_; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1959 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1960 | // virtual methods defined in this class; invoked through vtable |
| 1961 | ObjectArray<Method>* virtual_methods_; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1962 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1963 | // Virtual method table (vtable), for use by "invoke-virtual". The |
| 1964 | // vtable from the superclass is copied in, and virtual methods from |
| 1965 | // our class either replace those from the super or are appended. |
| 1966 | ObjectArray<Method>* vtable_; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1967 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1968 | // access flags; low 16 bits are defined by VM spec |
| 1969 | uint32_t access_flags_; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1970 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1971 | // Total class size; used when allocating storage on gc heap. |
| 1972 | size_t class_size_; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1973 | |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 1974 | // tid used to check for recursive <clinit> invocation |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1975 | pid_t clinit_thread_id_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1976 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 1977 | // number of instance fields that are object refs |
| 1978 | size_t num_reference_instance_fields_; |
| 1979 | |
| 1980 | // number of static fields that are object refs |
| 1981 | size_t num_reference_static_fields_; |
| 1982 | |
| 1983 | // Total object size; used when allocating storage on gc heap. |
| 1984 | // (For interfaces and abstract classes this will be zero.) |
| 1985 | size_t object_size_; |
| 1986 | |
| 1987 | // primitive type index, or kPrimNot (0); set for generated prim classes |
| 1988 | PrimitiveType primitive_type_; |
| 1989 | |
| 1990 | // Bitmap of offsets of ifields. |
| 1991 | uint32_t reference_instance_offsets_; |
| 1992 | |
| 1993 | // Bitmap of offsets of sfields. |
| 1994 | uint32_t reference_static_offsets_; |
| 1995 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1996 | // state of class initialization |
| 1997 | Status status_; |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 1998 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 1999 | // Set in LoadClass, used to LinkClass |
| 2000 | // see also super_class_ |
| 2001 | uint32_t super_class_type_idx_; |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2002 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 2003 | // TODO: ? |
| 2004 | // initiating class loader list |
| 2005 | // NOTE: for classes with low serialNumber, these are unused, and the |
| 2006 | // values are kept in a table in gDvm. |
| 2007 | // InitiatingLoaderList initiating_loader_list_; |
| 2008 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2009 | // Location of first static field. |
| 2010 | uint32_t fields_[0]; |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2011 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 2012 | friend struct ClassOffsets; // for verifying offset information |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2013 | DISALLOW_IMPLICIT_CONSTRUCTORS(Class); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2014 | }; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2015 | |
Elliott Hughes | 1f359b0 | 2011-07-17 14:27:17 -0700 | [diff] [blame] | 2016 | std::ostream& operator<<(std::ostream& os, const Class::Status& rhs); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2017 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2018 | inline void Object::SetClass(Class* new_klass) { |
| 2019 | // new_klass may be NULL prior to class linker initialization |
Elliott Hughes | 5ea047b | 2011-09-13 14:38:18 -0700 | [diff] [blame] | 2020 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Object, klass_), new_klass, false, false); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 2023 | inline bool Object::InstanceOf(const Class* klass) const { |
Jesse Wilson | 1415074 | 2011-07-29 19:04:44 -0400 | [diff] [blame] | 2024 | DCHECK(klass != NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2025 | DCHECK(GetClass() != NULL); |
| 2026 | return klass->IsAssignableFrom(GetClass()); |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2029 | inline bool Object::IsClass() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2030 | Class* java_lang_Class = GetClass()->GetClass(); |
| 2031 | return GetClass() == java_lang_Class; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2034 | inline bool Object::IsClassClass() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2035 | Class* java_lang_Class = GetClass()->GetClass(); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2036 | return this == java_lang_Class; |
| 2037 | } |
| 2038 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2039 | inline bool Object::IsObjectArray() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2040 | return IsArrayInstance() && !GetClass()->GetComponentType()->IsPrimitive(); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 2043 | inline bool Object::IsArrayInstance() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2044 | return GetClass()->IsArrayClass(); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2047 | inline bool Object::IsField() const { |
| 2048 | Class* java_lang_Class = klass_->klass_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2049 | Class* java_lang_reflect_Field = |
| 2050 | java_lang_Class->GetInstanceField(0)->GetClass(); |
| 2051 | return GetClass() == java_lang_reflect_Field; |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | inline bool Object::IsMethod() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2055 | Class* java_lang_Class = GetClass()->GetClass(); |
| 2056 | Class* java_lang_reflect_Method = |
| 2057 | java_lang_Class->GetDirectMethod(0)->GetClass(); |
| 2058 | return GetClass() == java_lang_reflect_Method; |
| 2059 | } |
| 2060 | |
| 2061 | inline bool Object::IsReferenceInstance() const { |
| 2062 | return GetClass()->IsReferenceClass(); |
| 2063 | } |
| 2064 | |
| 2065 | inline bool Object::IsWeakReferenceInstance() const { |
| 2066 | return GetClass()->IsWeakReferenceClass(); |
| 2067 | } |
| 2068 | |
| 2069 | inline bool Object::IsSoftReferenceInstance() const { |
| 2070 | return GetClass()->IsSoftReferenceClass(); |
| 2071 | } |
| 2072 | |
| 2073 | inline bool Object::IsFinalizerReferenceInstance() const { |
| 2074 | return GetClass()->IsFinalizerReferenceClass(); |
| 2075 | } |
| 2076 | |
| 2077 | inline bool Object::IsPhantomReferenceInstance() const { |
| 2078 | return GetClass()->IsPhantomReferenceClass(); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 2081 | inline size_t Object::SizeOf() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2082 | size_t result; |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 2083 | if (IsArrayInstance()) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2084 | result = AsArray()->SizeOf(); |
| 2085 | } else if (IsClass()) { |
| 2086 | result = AsClass()->SizeOf(); |
| 2087 | } else { |
| 2088 | result = GetClass()->GetObjectSize(); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2089 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2090 | DCHECK(!IsField() || result == sizeof(Field)); |
| 2091 | DCHECK(!IsMethod() || result == sizeof(Method)); |
| 2092 | return result; |
| 2093 | } |
| 2094 | |
| 2095 | inline void Field::SetOffset(MemberOffset num_bytes) { |
| 2096 | DCHECK(GetDeclaringClass()->IsLoaded()); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 2097 | Class* type = GetTypeDuringLinking(); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2098 | if (type != NULL && (type->IsPrimitiveDouble() || type->IsPrimitiveLong())) { |
| 2099 | DCHECK(IsAligned(num_bytes.Uint32Value(), 8)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2100 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2101 | SetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_), |
| 2102 | num_bytes.Uint32Value(), false); |
| 2103 | } |
| 2104 | |
| 2105 | inline Class* Field::GetDeclaringClass() const { |
| 2106 | Class* result = GetFieldObject<Class*>( |
| 2107 | OFFSET_OF_OBJECT_MEMBER(Field, declaring_class_), false); |
| 2108 | DCHECK(result != NULL); |
| 2109 | DCHECK(result->IsLoaded()); |
| 2110 | return result; |
| 2111 | } |
| 2112 | |
| 2113 | inline void Field::SetDeclaringClass(Class *new_declaring_class) { |
| 2114 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Field, declaring_class_), |
| 2115 | new_declaring_class, false); |
| 2116 | } |
| 2117 | |
| 2118 | inline Class* Method::GetDeclaringClass() const { |
| 2119 | Class* result = |
| 2120 | GetFieldObject<Class*>( |
| 2121 | OFFSET_OF_OBJECT_MEMBER(Method, declaring_class_), false); |
| 2122 | DCHECK(result != NULL); |
| 2123 | DCHECK(result->IsLoaded()); |
| 2124 | return result; |
| 2125 | } |
| 2126 | |
| 2127 | inline void Method::SetDeclaringClass(Class *new_declaring_class) { |
| 2128 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, declaring_class_), |
| 2129 | new_declaring_class, false); |
| 2130 | } |
| 2131 | |
| 2132 | inline uint32_t Method::GetReturnTypeIdx() const { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 2133 | DCHECK(GetDeclaringClass()->IsResolved()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2134 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, java_return_type_idx_), |
| 2135 | false); |
| 2136 | } |
| 2137 | |
| 2138 | inline bool Method::IsReturnAReference() const { |
| 2139 | return !GetReturnType()->IsPrimitive(); |
| 2140 | } |
| 2141 | |
| 2142 | inline bool Method::IsReturnAFloat() const { |
| 2143 | return GetReturnType()->IsPrimitiveFloat(); |
| 2144 | } |
| 2145 | |
| 2146 | inline bool Method::IsReturnADouble() const { |
| 2147 | return GetReturnType()->IsPrimitiveDouble(); |
| 2148 | } |
| 2149 | |
| 2150 | inline bool Method::IsReturnALong() const { |
| 2151 | return GetReturnType()->IsPrimitiveLong(); |
| 2152 | } |
| 2153 | |
| 2154 | inline bool Method::IsReturnVoid() const { |
| 2155 | return GetReturnType()->IsPrimitiveVoid(); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 2158 | inline size_t Array::SizeOf() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2159 | return SizeOf(GetLength(), GetClass()->GetComponentSize()); |
| 2160 | } |
| 2161 | |
| 2162 | template<class T> |
| 2163 | void ObjectArray<T>::Set(int32_t i, T* object) { |
| 2164 | if (IsValidIndex(i)) { |
| 2165 | if (object != NULL) { |
| 2166 | Class* element_class = GetClass()->GetComponentType(); |
| 2167 | DCHECK(!element_class->IsPrimitive()); |
| 2168 | // TODO: ArrayStoreException |
| 2169 | CHECK(object->InstanceOf(element_class)); |
| 2170 | } |
| 2171 | MemberOffset data_offset(DataOffset().Int32Value() + i * sizeof(Object*)); |
| 2172 | SetFieldObject(data_offset, object, false); |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | template<class T> |
| 2177 | void ObjectArray<T>::SetWithoutChecks(int32_t i, T* object) { |
| 2178 | DCHECK(IsValidIndex(i)); |
| 2179 | MemberOffset data_offset(DataOffset().Int32Value() + i * sizeof(Object*)); |
| 2180 | SetFieldObject(data_offset, object, false); |
| 2181 | } |
| 2182 | |
| 2183 | template<class T> |
| 2184 | void ObjectArray<T>::Copy(const ObjectArray<T>* src, int src_pos, |
| 2185 | ObjectArray<T>* dst, int dst_pos, |
| 2186 | size_t length) { |
| 2187 | if (src->IsValidIndex(src_pos) && |
| 2188 | src->IsValidIndex(src_pos+length-1) && |
| 2189 | dst->IsValidIndex(dst_pos) && |
| 2190 | dst->IsValidIndex(dst_pos+length-1)) { |
| 2191 | MemberOffset src_offset(DataOffset().Int32Value() + |
| 2192 | src_pos * sizeof(Object*)); |
| 2193 | MemberOffset dst_offset(DataOffset().Int32Value() + |
| 2194 | dst_pos * sizeof(Object*)); |
| 2195 | Class* array_class = dst->GetClass(); |
| 2196 | if (array_class == src->GetClass()) { |
| 2197 | // No need for array store checks if arrays are of the same type |
| 2198 | for (size_t i=0; i < length; i++) { |
| 2199 | Object* object = src->GetFieldObject<Object*>(src_offset, false); |
| 2200 | dst->SetFieldObject(dst_offset, object, false); |
| 2201 | src_offset = MemberOffset(src_offset.Uint32Value() + sizeof(Object*)); |
| 2202 | dst_offset = MemberOffset(dst_offset.Uint32Value() + sizeof(Object*)); |
| 2203 | } |
| 2204 | } else { |
| 2205 | Class* element_class = array_class->GetComponentType(); |
| 2206 | CHECK(!element_class->IsPrimitive()); |
| 2207 | for (size_t i=0; i < length; i++) { |
| 2208 | Object* object = src->GetFieldObject<Object*>(src_offset, false); |
| 2209 | // TODO: ArrayStoreException |
| 2210 | CHECK(object == NULL || object->InstanceOf(element_class)); |
| 2211 | dst->SetFieldObject(dst_offset, object, false); |
| 2212 | src_offset = MemberOffset(src_offset.Uint32Value() + sizeof(Object*)); |
| 2213 | dst_offset = MemberOffset(dst_offset.Uint32Value() + sizeof(Object*)); |
| 2214 | } |
| 2215 | } |
Elliott Hughes | 3a4f8df | 2011-09-13 15:22:36 -0700 | [diff] [blame] | 2216 | Heap::WriteBarrier(dst); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2217 | } |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 2218 | } |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 2219 | |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 2220 | class MANAGED ClassClass : public Class { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2221 | private: |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 2222 | int32_t padding_; |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2223 | int64_t serialVersionUID_; |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 2224 | friend struct ClassClassOffsets; // for verifying offset information |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2225 | DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass); |
| 2226 | }; |
| 2227 | |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 2228 | class MANAGED StringClass : public Class { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2229 | private: |
| 2230 | CharArray* ASCII_; |
| 2231 | Object* CASE_INSENSITIVE_ORDER_; |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 2232 | uint32_t REPLACEMENT_CHAR_; |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 2233 | int64_t serialVersionUID_; |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 2234 | friend struct StringClassOffsets; // for verifying offset information |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2235 | DISALLOW_IMPLICIT_CONSTRUCTORS(StringClass); |
| 2236 | }; |
| 2237 | |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 2238 | class MANAGED FieldClass : public Class { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2239 | private: |
| 2240 | Object* ORDER_BY_NAME_AND_DECLARING_CLASS_; |
| 2241 | uint32_t TYPE_BOOLEAN_; |
| 2242 | uint32_t TYPE_BYTE_; |
| 2243 | uint32_t TYPE_CHAR_; |
| 2244 | uint32_t TYPE_DOUBLE_; |
| 2245 | uint32_t TYPE_FLOAT_; |
| 2246 | uint32_t TYPE_INTEGER_; |
| 2247 | uint32_t TYPE_LONG_; |
| 2248 | uint32_t TYPE_SHORT_; |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 2249 | friend struct FieldClassOffsets; // for verifying offset information |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2250 | DISALLOW_IMPLICIT_CONSTRUCTORS(FieldClass); |
| 2251 | }; |
| 2252 | |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 2253 | class MANAGED MethodClass : public Class { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2254 | private: |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 2255 | ObjectArray<Object>* NO_ANNOTATIONS_; |
| 2256 | Object* ORDER_BY_SIGNATURE_; |
| 2257 | friend struct MethodClassOffsets; // for verifying offset information |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 2258 | DISALLOW_IMPLICIT_CONSTRUCTORS(MethodClass); |
| 2259 | }; |
| 2260 | |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2261 | template<class T> |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 2262 | class MANAGED PrimitiveArray : public Array { |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 2263 | public: |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 2264 | typedef T ElementType; |
| 2265 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2266 | static PrimitiveArray<T>* Alloc(size_t length); |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2267 | |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2268 | const T* GetData() const { |
| 2269 | return reinterpret_cast<const T*>(&elements_); |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2272 | T* GetData() { |
| 2273 | return reinterpret_cast<T*>(&elements_); |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2276 | T Get(int32_t i) const { |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 2277 | if (!IsValidIndex(i)) { |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 2278 | return T(0); |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 2279 | } |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2280 | return GetData()[i]; |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2283 | void Set(int32_t i, T value) { |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 2284 | // TODO: ArrayStoreException |
| 2285 | if (IsValidIndex(i)) { |
| 2286 | GetData()[i] = value; |
| 2287 | } |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2290 | static void SetArrayClass(Class* array_class) { |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2291 | CHECK(array_class_ == NULL); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2292 | CHECK(array_class != NULL); |
| 2293 | array_class_ = array_class; |
| 2294 | } |
| 2295 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2296 | static void ResetArrayClass() { |
| 2297 | CHECK(array_class_ != NULL); |
| 2298 | array_class_ = NULL; |
| 2299 | } |
| 2300 | |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 2301 | private: |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 2302 | // Location of first element. |
| 2303 | T elements_[0]; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2304 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 2305 | static Class* array_class_; |
| 2306 | |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2307 | DISALLOW_IMPLICIT_CONSTRUCTORS(PrimitiveArray); |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 2308 | }; |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 2309 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2310 | inline void Class::SetInterfacesTypeIdx(IntArray* new_interfaces_idx) { |
| 2311 | DCHECK(NULL == GetFieldObject<IntArray*>( |
| 2312 | OFFSET_OF_OBJECT_MEMBER(Class, interfaces_type_idx_), false)); |
| 2313 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, interfaces_type_idx_), |
| 2314 | new_interfaces_idx, false); |
| 2315 | } |
| 2316 | |
| 2317 | // C++ mirror of java.lang.String |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 2318 | class MANAGED String : public Object { |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2319 | public: |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2320 | const CharArray* GetCharArray() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2321 | const CharArray* result = GetFieldObject<const CharArray*>( |
| 2322 | OFFSET_OF_OBJECT_MEMBER(String, array_), false); |
| 2323 | DCHECK(result != NULL); |
| 2324 | return result; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 2327 | int32_t GetOffset() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2328 | int32_t result = GetField32( |
| 2329 | OFFSET_OF_OBJECT_MEMBER(String, offset_), false); |
| 2330 | DCHECK_LE(0, result); |
| 2331 | return result; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2334 | int32_t GetLength() const; |
| 2335 | |
| 2336 | int32_t GetHashCode() const; |
| 2337 | |
| 2338 | void ComputeHashCode() { |
| 2339 | SetHashCode(ComputeUtf16Hash(GetCharArray(), GetOffset(), GetLength())); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 2342 | int32_t GetUtfLength() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2343 | return CountUtf8Bytes(GetCharArray()->GetData(), GetLength()); |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2346 | uint16_t CharAt(int32_t index) const; |
| 2347 | |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 2348 | String* Intern(); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2349 | |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 2350 | static String* AllocFromUtf16(int32_t utf16_length, |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2351 | const uint16_t* utf16_data_in, |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2352 | int32_t hash_code = 0); |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 2353 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2354 | static String* AllocFromModifiedUtf8(const char* utf); |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 2355 | |
Jesse Wilson | 8989d99 | 2011-08-02 13:39:42 -0700 | [diff] [blame] | 2356 | static String* AllocFromModifiedUtf8(int32_t utf16_length, |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2357 | const char* utf8_data_in); |
| 2358 | |
| 2359 | static String* Alloc(Class* java_lang_String, int32_t utf16_length); |
| 2360 | |
| 2361 | static String* Alloc(Class* java_lang_String, CharArray* array); |
| 2362 | |
| 2363 | bool Equals(const char* modified_utf8) const; |
| 2364 | |
| 2365 | // TODO: do we need this overload? give it a more intention-revealing name. |
| 2366 | bool Equals(const StringPiece& modified_utf8) const; |
| 2367 | |
| 2368 | bool Equals(const String* that) const; |
| 2369 | |
| 2370 | // TODO: do we need this overload? give it a more intention-revealing name. |
| 2371 | bool Equals(const uint16_t* that_chars, int32_t that_offset, |
| 2372 | int32_t that_length) const; |
| 2373 | |
| 2374 | // Create a modified UTF-8 encoded std::string from a java/lang/String object. |
| 2375 | std::string ToModifiedUtf8() const; |
| 2376 | |
| 2377 | static Class* GetJavaLangString() { |
| 2378 | DCHECK(java_lang_String_ != NULL); |
| 2379 | return java_lang_String_; |
Jesse Wilson | 8989d99 | 2011-08-02 13:39:42 -0700 | [diff] [blame] | 2380 | } |
| 2381 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 2382 | static void SetClass(Class* java_lang_String); |
| 2383 | static void ResetClass(); |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 2384 | |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 2385 | private: |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2386 | void SetHashCode(int32_t new_hash_code) { |
| 2387 | DCHECK_EQ(0u, |
| 2388 | GetField32(OFFSET_OF_OBJECT_MEMBER(String, hash_code_), false)); |
| 2389 | SetField32(OFFSET_OF_OBJECT_MEMBER(String, hash_code_), |
| 2390 | new_hash_code, false); |
| 2391 | } |
| 2392 | |
| 2393 | void SetCount(int32_t new_count) { |
| 2394 | DCHECK_LE(0, new_count); |
| 2395 | SetField32(OFFSET_OF_OBJECT_MEMBER(String, count_), new_count, false); |
| 2396 | } |
| 2397 | |
| 2398 | void SetOffset(int32_t new_offset) { |
| 2399 | DCHECK_LE(0, new_offset); |
| 2400 | DCHECK_GE(GetLength(), new_offset); |
| 2401 | SetField32(OFFSET_OF_OBJECT_MEMBER(String, offset_), new_offset, false); |
| 2402 | } |
| 2403 | |
| 2404 | void SetArray(CharArray* new_array) { |
| 2405 | DCHECK(new_array != NULL); |
| 2406 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(String, array_), new_array, false); |
| 2407 | } |
| 2408 | |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2409 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
| 2410 | CharArray* array_; |
| 2411 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 2412 | int32_t count_; |
| 2413 | |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2414 | uint32_t hash_code_; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2415 | |
Elliott Hughes | 289da82 | 2011-08-16 10:11:20 -0700 | [diff] [blame] | 2416 | int32_t offset_; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2417 | |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 2418 | static Class* java_lang_String_; |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2419 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 2420 | friend struct StringOffsets; // for verifying offset information |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 2421 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2422 | }; |
| 2423 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2424 | inline const String* Field::GetName() const { |
| 2425 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2426 | String* result = |
| 2427 | GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(Field, name_), false); |
| 2428 | DCHECK(result != NULL); |
| 2429 | return result; |
| 2430 | } |
| 2431 | |
| 2432 | inline void Field::SetName(String* new_name) { |
| 2433 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Field, name_), |
| 2434 | new_name, false); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | inline uint32_t Field::GetAccessFlags() const { |
| 2438 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2439 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Field, access_flags_), false); |
| 2440 | } |
| 2441 | |
| 2442 | inline uint32_t Field::GetTypeIdx() const { |
| 2443 | DCHECK(GetDeclaringClass()->IsIdxLoaded()); |
| 2444 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Field, type_idx_), false); |
| 2445 | } |
| 2446 | |
| 2447 | inline MemberOffset Field::GetOffset() const { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 2448 | DCHECK(GetDeclaringClass()->IsResolved()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2449 | return MemberOffset( |
| 2450 | GetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_), false)); |
| 2451 | } |
| 2452 | |
| 2453 | inline MemberOffset Field::GetOffsetDuringLinking() const { |
| 2454 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2455 | return MemberOffset( |
| 2456 | GetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_), false)); |
| 2457 | } |
| 2458 | |
| 2459 | inline const String* Method::GetName() const { |
| 2460 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2461 | const String* result = |
| 2462 | GetFieldObject<const String*>( |
| 2463 | OFFSET_OF_OBJECT_MEMBER(Method, name_), false); |
| 2464 | DCHECK(result != NULL); |
| 2465 | return result; |
| 2466 | } |
| 2467 | |
| 2468 | inline void Method::SetName(String* new_name) { |
| 2469 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, name_), |
| 2470 | new_name, false); |
| 2471 | |
| 2472 | } |
| 2473 | |
jeffhao | e23d93c | 2011-09-15 14:48:43 -0700 | [diff] [blame] | 2474 | inline ByteArray* Method::GetRegisterMapData() const { |
| 2475 | return GetFieldObject<ByteArray*>( |
| 2476 | OFFSET_OF_OBJECT_MEMBER(Method, register_map_data_), false); |
| 2477 | } |
| 2478 | |
jeffhao | a0a764a | 2011-09-16 10:43:38 -0700 | [diff] [blame] | 2479 | inline void Method::SetRegisterMapData(ByteArray* data) { |
jeffhao | e23d93c | 2011-09-15 14:48:43 -0700 | [diff] [blame] | 2480 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, register_map_data_), |
jeffhao | a0a764a | 2011-09-16 10:43:38 -0700 | [diff] [blame] | 2481 | data, false); |
jeffhao | e23d93c | 2011-09-15 14:48:43 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | inline ByteArray* Method::GetRegisterMapHeader() const { |
| 2485 | return GetFieldObject<ByteArray*>( |
| 2486 | OFFSET_OF_OBJECT_MEMBER(Method, register_map_header_), false); |
| 2487 | } |
| 2488 | |
jeffhao | a0a764a | 2011-09-16 10:43:38 -0700 | [diff] [blame] | 2489 | inline void Method::SetRegisterMapHeader(ByteArray* header) { |
jeffhao | e23d93c | 2011-09-15 14:48:43 -0700 | [diff] [blame] | 2490 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, register_map_header_), |
jeffhao | a0a764a | 2011-09-16 10:43:38 -0700 | [diff] [blame] | 2491 | header, false); |
jeffhao | e23d93c | 2011-09-15 14:48:43 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
Brian Carlstrom | 2ed6739 | 2011-09-09 14:53:28 -0700 | [diff] [blame] | 2494 | inline String* Method::GetShorty() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2495 | DCHECK(GetDeclaringClass()->IsLoaded()); |
Brian Carlstrom | 2ed6739 | 2011-09-09 14:53:28 -0700 | [diff] [blame] | 2496 | return GetFieldObject<String*>( |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2497 | OFFSET_OF_OBJECT_MEMBER(Method, shorty_), false); |
| 2498 | } |
| 2499 | |
Brian Carlstrom | 2ed6739 | 2011-09-09 14:53:28 -0700 | [diff] [blame] | 2500 | inline void Method::SetShorty(String* new_shorty) { |
| 2501 | DCHECK(NULL == GetFieldObject<String*>( |
| 2502 | OFFSET_OF_OBJECT_MEMBER(Method, shorty_), false)); |
| 2503 | DCHECK_LE(1, new_shorty->GetLength()); |
| 2504 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, shorty_), new_shorty, false); |
| 2505 | } |
| 2506 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2507 | inline const String* Method::GetSignature() const { |
| 2508 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2509 | const String* result = |
| 2510 | GetFieldObject<const String*>( |
| 2511 | OFFSET_OF_OBJECT_MEMBER(Method, signature_), false); |
| 2512 | DCHECK(result != NULL); |
| 2513 | return result; |
| 2514 | } |
| 2515 | |
| 2516 | inline void Method::SetSignature(String* new_signature) { |
| 2517 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, signature_), |
| 2518 | new_signature, false); |
| 2519 | } |
| 2520 | |
| 2521 | inline uint32_t Class::GetAccessFlags() const { |
| 2522 | // Check class is loaded or this is java.lang.String that has a |
| 2523 | // circularity issue during loading the names of its members |
| 2524 | DCHECK(IsLoaded() || this == String::GetJavaLangString() || |
| 2525 | this == Field::GetJavaLangReflectField() || |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame^] | 2526 | this == Method::GetJavaLangReflectMethod()) << PrettyClass(this); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2527 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), false); |
| 2528 | } |
| 2529 | |
| 2530 | inline void Class::SetDescriptor(String* new_descriptor) { |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 2531 | DCHECK(GetDescriptor() == NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2532 | DCHECK(new_descriptor != NULL); |
| 2533 | DCHECK_NE(0, new_descriptor->GetLength()); |
| 2534 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, descriptor_), |
| 2535 | new_descriptor, false); |
| 2536 | } |
| 2537 | |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 2538 | inline String* Class::GetSourceFile() const { |
| 2539 | DCHECK(IsLoaded()); |
| 2540 | return GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(Class, source_file_), false); |
| 2541 | } |
| 2542 | |
| 2543 | inline void Class::SetSourceFile(String* new_source_file) { |
| 2544 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, source_file_), new_source_file, false); |
| 2545 | } |
| 2546 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2547 | inline uint32_t Method::GetAccessFlags() const { |
| 2548 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2549 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, access_flags_), false); |
| 2550 | } |
| 2551 | |
| 2552 | inline uint16_t Method::GetMethodIndex() const { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 2553 | DCHECK(GetDeclaringClass()->IsResolved()); |
Elliott Hughes | 1d3f114 | 2011-09-13 12:00:00 -0700 | [diff] [blame] | 2554 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, method_index_), false); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | inline uint16_t Method::NumRegisters() const { |
| 2558 | DCHECK(GetDeclaringClass()->IsLoaded()); |
Elliott Hughes | 1d3f114 | 2011-09-13 12:00:00 -0700 | [diff] [blame] | 2559 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, num_registers_), false); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | inline uint16_t Method::NumIns() const { |
| 2563 | DCHECK(GetDeclaringClass()->IsLoaded()); |
Elliott Hughes | 1d3f114 | 2011-09-13 12:00:00 -0700 | [diff] [blame] | 2564 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, num_ins_), false); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | inline uint16_t Method::NumOuts() const { |
| 2568 | DCHECK(GetDeclaringClass()->IsLoaded()); |
Elliott Hughes | 1d3f114 | 2011-09-13 12:00:00 -0700 | [diff] [blame] | 2569 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, num_outs_), false); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | inline uint32_t Method::GetProtoIdx() const { |
| 2573 | DCHECK(GetDeclaringClass()->IsLoaded()); |
| 2574 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, proto_idx_), false); |
| 2575 | } |
| 2576 | |
| 2577 | // C++ mirror of java.lang.Throwable |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 2578 | class MANAGED Throwable : public Object { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 2579 | public: |
| 2580 | void SetDetailMessage(String* new_detail_message) { |
| 2581 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Throwable, detail_message_), |
| 2582 | new_detail_message, false); |
| 2583 | } |
| 2584 | |
Elliott Hughes | e5b0dc8 | 2011-08-23 09:59:02 -0700 | [diff] [blame] | 2585 | private: |
| 2586 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
| 2587 | Throwable* cause_; |
| 2588 | String* detail_message_; |
| 2589 | Object* stack_state_; // Note this is Java volatile: |
| 2590 | Object* stack_trace_; |
| 2591 | Object* suppressed_exceptions_; |
| 2592 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 2593 | friend struct ThrowableOffsets; // for verifying offset information |
Elliott Hughes | e5b0dc8 | 2011-08-23 09:59:02 -0700 | [diff] [blame] | 2594 | DISALLOW_IMPLICIT_CONSTRUCTORS(Throwable); |
| 2595 | }; |
| 2596 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2597 | // C++ mirror of java.lang.StackTraceElement |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 2598 | class MANAGED StackTraceElement : public Object { |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2599 | public: |
| 2600 | const String* GetDeclaringClass() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2601 | return GetFieldObject<const String*>( |
| 2602 | OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_), false); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | const String* GetMethodName() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2606 | return GetFieldObject<const String*>( |
| 2607 | OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_), false); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | const String* GetFileName() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2611 | return GetFieldObject<const String*>( |
| 2612 | OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_), false); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
Shih-wei Liao | ff0f9be | 2011-08-29 15:43:53 -0700 | [diff] [blame] | 2615 | int32_t GetLineNumber() const { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2616 | return GetField32( |
| 2617 | OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_), false); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2618 | } |
| 2619 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2620 | static StackTraceElement* Alloc(const String* declaring_class, |
| 2621 | const String* method_name, |
| 2622 | const String* file_name, |
| 2623 | int32_t line_number); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2624 | |
| 2625 | static void SetClass(Class* java_lang_StackTraceElement); |
| 2626 | |
| 2627 | static void ResetClass(); |
| 2628 | |
| 2629 | private: |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2630 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2631 | const String* declaring_class_; |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2632 | const String* file_name_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2633 | const String* method_name_; |
Shih-wei Liao | ff0f9be | 2011-08-29 15:43:53 -0700 | [diff] [blame] | 2634 | int32_t line_number_; |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2635 | |
| 2636 | static Class* GetStackTraceElement() { |
| 2637 | DCHECK(java_lang_StackTraceElement_ != NULL); |
| 2638 | return java_lang_StackTraceElement_; |
| 2639 | } |
| 2640 | |
| 2641 | static Class* java_lang_StackTraceElement_; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 2642 | |
| 2643 | friend struct StackTraceElementOffsets; // for verifying offset information |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 2644 | DISALLOW_IMPLICIT_CONSTRUCTORS(StackTraceElement); |
| 2645 | }; |
| 2646 | |
Brian Carlstrom | e4f7e1d | 2011-09-11 13:21:12 -0700 | [diff] [blame] | 2647 | class MANAGED InterfaceEntry : public ObjectArray<Object> { |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2648 | public: |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2649 | Class* GetInterface() const { |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 2650 | Class* interface = Get(kInterface)->AsClass(); |
| 2651 | DCHECK(interface != NULL); |
| 2652 | return interface; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2653 | } |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 2654 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2655 | void SetInterface(Class* interface) { |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 2656 | DCHECK(interface != NULL); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 2657 | DCHECK(interface->IsInterface()); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 2658 | DCHECK(Get(kInterface) == NULL); |
| 2659 | Set(kInterface, interface); |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2660 | } |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 2661 | |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 2662 | size_t GetMethodArrayCount() const { |
| 2663 | ObjectArray<Method>* method_array = down_cast<ObjectArray<Method>*>(Get(kMethodArray)); |
| 2664 | if (method_array == 0) { |
| 2665 | return 0; |
| 2666 | } |
| 2667 | return method_array->GetLength(); |
| 2668 | } |
| 2669 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 2670 | ObjectArray<Method>* GetMethodArray() const { |
| 2671 | ObjectArray<Method>* method_array = down_cast<ObjectArray<Method>*>(Get(kMethodArray)); |
| 2672 | DCHECK(method_array != NULL); |
| 2673 | return method_array; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 2676 | void SetMethodArray(ObjectArray<Method>* new_ma) { |
| 2677 | DCHECK(new_ma != NULL); |
| 2678 | DCHECK(Get(kMethodArray) == NULL); |
| 2679 | Set(kMethodArray, new_ma); |
| 2680 | } |
| 2681 | |
| 2682 | static size_t LengthAsArray() { |
| 2683 | return kMax; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 2684 | } |
| 2685 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 2686 | private: |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 2687 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 2688 | enum ArrayIndex { |
| 2689 | // Points to the interface class. |
| 2690 | kInterface = 0, |
| 2691 | // Method pointers into the vtable, allow fast map from interface |
| 2692 | // method index to concrete instance method. |
| 2693 | kMethodArray = 1, |
| 2694 | kMax = 2, |
| 2695 | }; |
Carl Shapiro | f88c952 | 2011-08-06 15:47:38 -0700 | [diff] [blame] | 2696 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 2697 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterfaceEntry); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 2698 | }; |
| 2699 | |
| 2700 | } // namespace art |
| 2701 | |
| 2702 | #endif // ART_SRC_OBJECT_H_ |