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