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