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