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