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