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