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