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