Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [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 | */ |
| 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_MIRROR_CLASS_INL_H_ |
| 18 | #define ART_RUNTIME_MIRROR_CLASS_INL_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
| 20 | #include "class.h" |
| 21 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 22 | #include "art_field.h" |
| 23 | #include "art_method.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 24 | #include "class_loader.h" |
| 25 | #include "dex_cache.h" |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame^] | 26 | #include "gc/heap-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | #include "iftable.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 28 | #include "object_array-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "runtime.h" |
| 30 | #include "string.h" |
| 31 | |
| 32 | namespace art { |
| 33 | namespace mirror { |
| 34 | |
| 35 | inline size_t Class::GetObjectSize() const { |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 36 | DCHECK(!IsVariableSize()) << " class=" << PrettyTypeOf(this); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | DCHECK_EQ(sizeof(size_t), sizeof(int32_t)); |
| 38 | size_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), false); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 39 | DCHECK_GE(result, sizeof(Object)) << " class=" << PrettyTypeOf(this); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 40 | return result; |
| 41 | } |
| 42 | |
| 43 | inline Class* Class::GetSuperClass() const { |
| 44 | // Can only get super class for loaded classes (hack for when runtime is |
| 45 | // initializing) |
| 46 | DCHECK(IsLoaded() || !Runtime::Current()->IsStarted()) << IsLoaded(); |
| 47 | return GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), false); |
| 48 | } |
| 49 | |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 50 | inline ClassLoader* Class::GetClassLoader() const { |
| 51 | return GetFieldObject<ClassLoader*>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), false); |
| 52 | } |
| 53 | |
| 54 | inline DexCache* Class::GetDexCache() const { |
| 55 | return GetFieldObject<DexCache*>(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), false); |
| 56 | } |
| 57 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 58 | inline ObjectArray<ArtMethod>* Class::GetDirectMethods() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 59 | DCHECK(IsLoaded() || IsErroneous()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 60 | return GetFieldObject<ObjectArray<ArtMethod>*>( |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 61 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false); |
| 62 | } |
| 63 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 64 | inline void Class::SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 65 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 66 | DCHECK(NULL == GetFieldObject<ObjectArray<ArtMethod>*>( |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 67 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false)); |
| 68 | DCHECK_NE(0, new_direct_methods->GetLength()); |
| 69 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), |
| 70 | new_direct_methods, false); |
| 71 | } |
| 72 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 73 | inline ArtMethod* Class::GetDirectMethod(int32_t i) const |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 74 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 75 | return GetDirectMethods()->Get(i); |
| 76 | } |
| 77 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 78 | inline void Class::SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 79 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 80 | ObjectArray<ArtMethod>* direct_methods = |
| 81 | GetFieldObject<ObjectArray<ArtMethod>*>( |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 82 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), false); |
| 83 | direct_methods->Set(i, f); |
| 84 | } |
| 85 | |
| 86 | // Returns the number of static, private, and constructor methods. |
| 87 | inline size_t Class::NumDirectMethods() const { |
| 88 | return (GetDirectMethods() != NULL) ? GetDirectMethods()->GetLength() : 0; |
| 89 | } |
| 90 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 91 | inline ObjectArray<ArtMethod>* Class::GetVirtualMethods() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 92 | DCHECK(IsLoaded() || IsErroneous()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 93 | return GetFieldObject<ObjectArray<ArtMethod>*>( |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 94 | OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), false); |
| 95 | } |
| 96 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 97 | inline void Class::SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 98 | // TODO: we reassign virtual methods to grow the table for miranda |
| 99 | // methods.. they should really just be assigned once |
| 100 | DCHECK_NE(0, new_virtual_methods->GetLength()); |
| 101 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), |
| 102 | new_virtual_methods, false); |
| 103 | } |
| 104 | |
| 105 | inline size_t Class::NumVirtualMethods() const { |
| 106 | return (GetVirtualMethods() != NULL) ? GetVirtualMethods()->GetLength() : 0; |
| 107 | } |
| 108 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 109 | inline ArtMethod* Class::GetVirtualMethod(uint32_t i) const |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 110 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 111 | DCHECK(IsResolved() || IsErroneous()); |
| 112 | return GetVirtualMethods()->Get(i); |
| 113 | } |
| 114 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 115 | inline ArtMethod* Class::GetVirtualMethodDuringLinking(uint32_t i) const |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 116 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 117 | DCHECK(IsLoaded() || IsErroneous()); |
| 118 | return GetVirtualMethods()->Get(i); |
| 119 | } |
| 120 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 121 | inline void Class::SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 122 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 123 | ObjectArray<ArtMethod>* virtual_methods = |
| 124 | GetFieldObject<ObjectArray<ArtMethod>*>( |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 125 | OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), false); |
| 126 | virtual_methods->Set(i, f); |
| 127 | } |
| 128 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 129 | inline ObjectArray<ArtMethod>* Class::GetVTable() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 130 | DCHECK(IsResolved() || IsErroneous()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 131 | return GetFieldObject<ObjectArray<ArtMethod>*>(OFFSET_OF_OBJECT_MEMBER(Class, vtable_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 134 | inline ObjectArray<ArtMethod>* Class::GetVTableDuringLinking() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 135 | DCHECK(IsLoaded() || IsErroneous()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 136 | return GetFieldObject<ObjectArray<ArtMethod>*>(OFFSET_OF_OBJECT_MEMBER(Class, vtable_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 139 | inline void Class::SetVTable(ObjectArray<ArtMethod>* new_vtable) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 140 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 141 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, vtable_), new_vtable, false); |
| 142 | } |
| 143 | |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 144 | inline bool Class::Implements(const Class* klass) const { |
| 145 | DCHECK(klass != NULL); |
| 146 | DCHECK(klass->IsInterface()) << PrettyClass(this); |
| 147 | // All interfaces implemented directly and by our superclass, and |
| 148 | // recursively all super-interfaces of those interfaces, are listed |
| 149 | // in iftable_, so we can just do a linear scan through that. |
| 150 | int32_t iftable_count = GetIfTableCount(); |
| 151 | IfTable* iftable = GetIfTable(); |
| 152 | for (int32_t i = 0; i < iftable_count; i++) { |
| 153 | if (iftable->GetInterface(i) == klass) { |
| 154 | return true; |
| 155 | } |
| 156 | } |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | // Determine whether "this" is assignable from "src", where both of these |
| 161 | // are array classes. |
| 162 | // |
| 163 | // Consider an array class, e.g. Y[][], where Y is a subclass of X. |
| 164 | // Y[][] = Y[][] --> true (identity) |
| 165 | // X[][] = Y[][] --> true (element superclass) |
| 166 | // Y = Y[][] --> false |
| 167 | // Y[] = Y[][] --> false |
| 168 | // Object = Y[][] --> true (everything is an object) |
| 169 | // Object[] = Y[][] --> true |
| 170 | // Object[][] = Y[][] --> true |
| 171 | // Object[][][] = Y[][] --> false (too many []s) |
| 172 | // Serializable = Y[][] --> true (all arrays are Serializable) |
| 173 | // Serializable[] = Y[][] --> true |
| 174 | // Serializable[][] = Y[][] --> false (unless Y is Serializable) |
| 175 | // |
| 176 | // Don't forget about primitive types. |
| 177 | // Object[] = int[] --> false |
| 178 | // |
| 179 | inline bool Class::IsArrayAssignableFromArray(const Class* src) const { |
| 180 | DCHECK(IsArrayClass()) << PrettyClass(this); |
| 181 | DCHECK(src->IsArrayClass()) << PrettyClass(src); |
| 182 | return GetComponentType()->IsAssignableFrom(src->GetComponentType()); |
| 183 | } |
| 184 | |
| 185 | inline bool Class::IsAssignableFromArray(const Class* src) const { |
| 186 | DCHECK(!IsInterface()) << PrettyClass(this); // handled first in IsAssignableFrom |
| 187 | DCHECK(src->IsArrayClass()) << PrettyClass(src); |
| 188 | if (!IsArrayClass()) { |
| 189 | // If "this" is not also an array, it must be Object. |
| 190 | // src's super should be java_lang_Object, since it is an array. |
| 191 | Class* java_lang_Object = src->GetSuperClass(); |
| 192 | DCHECK(java_lang_Object != NULL) << PrettyClass(src); |
Ian Rogers | fa46d3e | 2013-05-15 00:16:04 -0700 | [diff] [blame] | 193 | DCHECK(java_lang_Object->GetSuperClass() == NULL) << PrettyClass(src); |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 194 | return this == java_lang_Object; |
| 195 | } |
| 196 | return IsArrayAssignableFromArray(src); |
| 197 | } |
| 198 | |
| 199 | inline bool Class::IsSubClass(const Class* klass) const { |
| 200 | DCHECK(!IsInterface()) << PrettyClass(this); |
| 201 | DCHECK(!IsArrayClass()) << PrettyClass(this); |
| 202 | const Class* current = this; |
| 203 | do { |
| 204 | if (current == klass) { |
| 205 | return true; |
| 206 | } |
| 207 | current = current->GetSuperClass(); |
| 208 | } while (current != NULL); |
| 209 | return false; |
| 210 | } |
| 211 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 212 | inline ArtMethod* Class::FindVirtualMethodForInterface(ArtMethod* method) const { |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 213 | Class* declaring_class = method->GetDeclaringClass(); |
| 214 | DCHECK(declaring_class != NULL) << PrettyClass(this); |
| 215 | DCHECK(declaring_class->IsInterface()) << PrettyMethod(method); |
| 216 | // TODO cache to improve lookup speed |
| 217 | int32_t iftable_count = GetIfTableCount(); |
| 218 | IfTable* iftable = GetIfTable(); |
| 219 | for (int32_t i = 0; i < iftable_count; i++) { |
| 220 | if (iftable->GetInterface(i) == declaring_class) { |
| 221 | return iftable->GetMethodArray(i)->Get(method->GetMethodIndex()); |
| 222 | } |
| 223 | } |
| 224 | return NULL; |
| 225 | } |
| 226 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 227 | inline ArtMethod* Class::FindVirtualMethodForVirtual(ArtMethod* method) const |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 228 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 229 | DCHECK(!method->GetDeclaringClass()->IsInterface() || method->IsMiranda()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 230 | // The argument method may from a super class. |
| 231 | // Use the index to a potentially overridden one for this instance's class. |
| 232 | return GetVTable()->Get(method->GetMethodIndex()); |
| 233 | } |
| 234 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 235 | inline ArtMethod* Class::FindVirtualMethodForSuper(ArtMethod* method) const |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 236 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 237 | DCHECK(!method->GetDeclaringClass()->IsInterface()); |
| 238 | return GetSuperClass()->GetVTable()->Get(method->GetMethodIndex()); |
| 239 | } |
| 240 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 241 | inline ArtMethod* Class::FindVirtualMethodForVirtualOrInterface(ArtMethod* method) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 242 | if (method->IsDirect()) { |
| 243 | return method; |
| 244 | } |
| 245 | if (method->GetDeclaringClass()->IsInterface()) { |
| 246 | return FindVirtualMethodForInterface(method); |
| 247 | } |
| 248 | return FindVirtualMethodForVirtual(method); |
| 249 | } |
| 250 | |
| 251 | inline IfTable* Class::GetIfTable() const { |
| 252 | return GetFieldObject<IfTable*>(OFFSET_OF_OBJECT_MEMBER(Class, iftable_), false); |
| 253 | } |
| 254 | |
| 255 | inline int32_t Class::GetIfTableCount() const { |
| 256 | IfTable* iftable = GetIfTable(); |
| 257 | if (iftable == NULL) { |
| 258 | return 0; |
| 259 | } |
| 260 | return iftable->Count(); |
| 261 | } |
| 262 | |
| 263 | inline void Class::SetIfTable(IfTable* new_iftable) { |
| 264 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, iftable_), new_iftable, false); |
| 265 | } |
| 266 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 267 | inline ObjectArray<ArtField>* Class::GetIFields() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 268 | DCHECK(IsLoaded() || IsErroneous()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 269 | return GetFieldObject<ObjectArray<ArtField>*>(OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 272 | inline void Class::SetIFields(ObjectArray<ArtField>* new_ifields) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 273 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 274 | DCHECK(NULL == GetFieldObject<ObjectArray<ArtField>*>( |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 275 | OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false)); |
| 276 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, ifields_), new_ifields, false); |
| 277 | } |
| 278 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 279 | inline ObjectArray<ArtField>* Class::GetSFields() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 280 | DCHECK(IsLoaded() || IsErroneous()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 281 | return GetFieldObject<ObjectArray<ArtField>*>(OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 284 | inline void Class::SetSFields(ObjectArray<ArtField>* new_sfields) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 285 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 286 | DCHECK(NULL == GetFieldObject<ObjectArray<ArtField>*>( |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 287 | OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false)); |
| 288 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, sfields_), new_sfields, false); |
| 289 | } |
| 290 | |
| 291 | inline size_t Class::NumStaticFields() const { |
| 292 | return (GetSFields() != NULL) ? GetSFields()->GetLength() : 0; |
| 293 | } |
| 294 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 295 | inline ArtField* Class::GetStaticField(uint32_t i) const // TODO: uint16_t |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 296 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 297 | return GetSFields()->Get(i); |
| 298 | } |
| 299 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 300 | inline void Class::SetStaticField(uint32_t i, ArtField* f) // TODO: uint16_t |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 301 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 302 | ObjectArray<ArtField>* sfields= GetFieldObject<ObjectArray<ArtField>*>( |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 303 | OFFSET_OF_OBJECT_MEMBER(Class, sfields_), false); |
| 304 | sfields->Set(i, f); |
| 305 | } |
| 306 | |
| 307 | inline size_t Class::NumInstanceFields() const { |
| 308 | return (GetIFields() != NULL) ? GetIFields()->GetLength() : 0; |
| 309 | } |
| 310 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 311 | inline ArtField* Class::GetInstanceField(uint32_t i) const // TODO: uint16_t |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 312 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 313 | DCHECK_NE(NumInstanceFields(), 0U); |
| 314 | return GetIFields()->Get(i); |
| 315 | } |
| 316 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 317 | inline void Class::SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 318 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 319 | ObjectArray<ArtField>* ifields= GetFieldObject<ObjectArray<ArtField>*>( |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 320 | OFFSET_OF_OBJECT_MEMBER(Class, ifields_), false); |
| 321 | ifields->Set(i, f); |
| 322 | } |
| 323 | |
| 324 | inline void Class::SetVerifyErrorClass(Class* klass) { |
| 325 | CHECK(klass != NULL) << PrettyClass(this); |
| 326 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), klass, false); |
| 327 | } |
| 328 | |
| 329 | inline uint32_t Class::GetAccessFlags() const { |
| 330 | // Check class is loaded or this is java.lang.String that has a |
| 331 | // circularity issue during loading the names of its members |
| 332 | DCHECK(IsLoaded() || IsErroneous() || |
| 333 | this == String::GetJavaLangString() || |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 334 | this == ArtField::GetJavaLangReflectArtField() || |
| 335 | this == ArtMethod::GetJavaLangReflectArtMethod()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 336 | return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), false); |
| 337 | } |
| 338 | |
| 339 | inline String* Class::GetName() const { |
| 340 | return GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(Class, name_), false); |
| 341 | } |
| 342 | inline void Class::SetName(String* name) { |
| 343 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, name_), name, false); |
| 344 | } |
| 345 | |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame^] | 346 | inline void Class::CheckObjectAlloc() { |
Hiroshi Yamauchi | 967a0ad | 2013-09-10 16:24:21 -0700 | [diff] [blame] | 347 | DCHECK(!IsArrayClass()) << PrettyClass(this); |
| 348 | DCHECK(IsInstantiable()) << PrettyClass(this); |
| 349 | // TODO: decide whether we want this check. It currently fails during bootstrap. |
| 350 | // DCHECK(!Runtime::Current()->IsStarted() || IsInitializing()) << PrettyClass(this); |
| 351 | DCHECK_GE(this->object_size_, sizeof(Object)); |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame^] | 352 | } |
| 353 | |
| 354 | inline Object* Class::AllocObjectInstrumented(Thread* self) { |
| 355 | CheckObjectAlloc(); |
| 356 | return Runtime::Current()->GetHeap()->AllocObjectInstrumented(self, this, this->object_size_); |
| 357 | } |
| 358 | |
| 359 | inline Object* Class::AllocObjectUninstrumented(Thread* self) { |
| 360 | CheckObjectAlloc(); |
| 361 | return Runtime::Current()->GetHeap()->AllocObjectUninstrumented(self, this, this->object_size_); |
Hiroshi Yamauchi | 967a0ad | 2013-09-10 16:24:21 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 364 | } // namespace mirror |
| 365 | } // namespace art |
| 366 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 367 | #endif // ART_RUNTIME_MIRROR_CLASS_INL_H_ |