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 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 22 | #include "art_field-inl.h" |
| 23 | #include "art_method-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 24 | #include "class_loader.h" |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 25 | #include "common_throws.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 26 | #include "dex_cache.h" |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 27 | #include "dex_file.h" |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 28 | #include "gc/heap-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "iftable.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 30 | #include "object_array-inl.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 31 | #include "read_barrier-inl.h" |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 32 | #include "reference-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | #include "runtime.h" |
| 34 | #include "string.h" |
| 35 | |
| 36 | namespace art { |
| 37 | namespace mirror { |
| 38 | |
Hiroshi Yamauchi | 25023c7 | 2014-05-09 11:45:53 -0700 | [diff] [blame] | 39 | template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 40 | inline uint32_t Class::GetObjectSize() { |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame^] | 41 | // Note: Extra parentheses to avoid the comma being interpreted as macro parameter separator. |
| 42 | DCHECK((!IsVariableSize<kVerifyFlags, kReadBarrierOption>())) << " class=" << PrettyTypeOf(this); |
Hiroshi Yamauchi | e01a520 | 2015-03-19 12:35:04 -0700 | [diff] [blame] | 43 | return GetField32(ObjectSizeOffset()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 46 | inline Class* Class::GetSuperClass() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 47 | // Can only get super class for loaded classes (hack for when runtime is |
| 48 | // initializing) |
Brian Carlstrom | 073278c | 2014-02-19 15:21:21 -0800 | [diff] [blame] | 49 | DCHECK(IsLoaded() || IsErroneous() || !Runtime::Current()->IsStarted()) << IsLoaded(); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 50 | return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 53 | inline ClassLoader* Class::GetClassLoader() { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 54 | return GetFieldObject<ClassLoader>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_)); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Mathieu Chartier | c2f4d02 | 2014-03-03 16:11:42 -0800 | [diff] [blame] | 57 | template<VerifyObjectFlags kVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 58 | inline DexCache* Class::GetDexCache() { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 59 | return GetFieldObject<DexCache, kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_)); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 62 | inline ObjectArray<ArtMethod>* Class::GetDirectMethods() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 63 | DCHECK(IsLoaded() || IsErroneous()); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 64 | return GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 67 | inline void Class::SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 68 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 69 | DCHECK(NULL == GetFieldObject<ObjectArray<ArtMethod>>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 70 | OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_))); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 71 | DCHECK_NE(0, new_direct_methods->GetLength()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 72 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), new_direct_methods); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 75 | inline ArtMethod* Class::GetDirectMethod(int32_t i) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 76 | return GetDirectMethods()->Get(i); |
| 77 | } |
| 78 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 79 | inline void Class::SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 80 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 81 | ObjectArray<ArtMethod>* direct_methods = |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 82 | GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 83 | direct_methods->Set<false>(i, f); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | // Returns the number of static, private, and constructor methods. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 87 | inline uint32_t Class::NumDirectMethods() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 88 | return (GetDirectMethods() != NULL) ? GetDirectMethods()->GetLength() : 0; |
| 89 | } |
| 90 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 91 | template<VerifyObjectFlags kVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 92 | inline ObjectArray<ArtMethod>* Class::GetVirtualMethods() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 93 | DCHECK(IsLoaded() || IsErroneous()); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 94 | return GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 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 |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 99 | // methods.. they should really just be assigned once. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 100 | DCHECK_NE(0, new_virtual_methods->GetLength()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 101 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), new_virtual_methods); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 104 | inline uint32_t Class::NumVirtualMethods() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 105 | return (GetVirtualMethods() != NULL) ? GetVirtualMethods()->GetLength() : 0; |
| 106 | } |
| 107 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 108 | template<VerifyObjectFlags kVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 109 | inline ArtMethod* Class::GetVirtualMethod(uint32_t i) { |
Hiroshi Yamauchi | f4c15a1 | 2014-10-20 16:56:58 -0700 | [diff] [blame] | 110 | DCHECK(IsResolved<kVerifyFlags>() || IsErroneous<kVerifyFlags>()) |
| 111 | << PrettyClass(this) << " status=" << GetStatus(); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 112 | return GetVirtualMethods()->GetWithoutChecks(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 113 | } |
| 114 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 115 | inline ArtMethod* Class::GetVirtualMethodDuringLinking(uint32_t i) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 116 | DCHECK(IsLoaded() || IsErroneous()); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 117 | return GetVirtualMethods()->GetWithoutChecks(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 120 | inline void Class::SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 121 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 122 | ObjectArray<ArtMethod>* virtual_methods = |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 123 | GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_)); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 124 | virtual_methods->SetWithoutChecks<false>(i, f); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 127 | inline ObjectArray<ArtMethod>* Class::GetVTable() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 128 | DCHECK(IsResolved() || IsErroneous()); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 129 | return GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, vtable_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 132 | inline ObjectArray<ArtMethod>* Class::GetVTableDuringLinking() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 133 | DCHECK(IsLoaded() || IsErroneous()); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 134 | return GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, vtable_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 137 | inline void Class::SetVTable(ObjectArray<ArtMethod>* new_vtable) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 138 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, vtable_), new_vtable); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 141 | inline ArtMethod* Class::GetEmbeddedImTableEntry(uint32_t i) { |
| 142 | uint32_t offset = EmbeddedImTableOffset().Uint32Value() + i * sizeof(ImTableEntry); |
| 143 | return GetFieldObject<mirror::ArtMethod>(MemberOffset(offset)); |
| 144 | } |
| 145 | |
| 146 | inline void Class::SetEmbeddedImTableEntry(uint32_t i, ArtMethod* method) { |
| 147 | uint32_t offset = EmbeddedImTableOffset().Uint32Value() + i * sizeof(ImTableEntry); |
| 148 | SetFieldObject<false>(MemberOffset(offset), method); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 151 | inline bool Class::HasVTable() { |
| 152 | return (GetVTable() != nullptr) || ShouldHaveEmbeddedImtAndVTable(); |
| 153 | } |
| 154 | |
| 155 | inline int32_t Class::GetVTableLength() { |
| 156 | if (ShouldHaveEmbeddedImtAndVTable()) { |
| 157 | return GetEmbeddedVTableLength(); |
| 158 | } |
| 159 | return (GetVTable() != nullptr) ? GetVTable()->GetLength() : 0; |
| 160 | } |
| 161 | |
| 162 | inline ArtMethod* Class::GetVTableEntry(uint32_t i) { |
| 163 | if (ShouldHaveEmbeddedImtAndVTable()) { |
| 164 | return GetEmbeddedVTableEntry(i); |
| 165 | } |
| 166 | return (GetVTable() != nullptr) ? GetVTable()->Get(i) : nullptr; |
| 167 | } |
| 168 | |
| 169 | inline int32_t Class::GetEmbeddedVTableLength() { |
| 170 | return GetField32(EmbeddedVTableLengthOffset()); |
| 171 | } |
| 172 | |
| 173 | inline void Class::SetEmbeddedVTableLength(int32_t len) { |
| 174 | SetField32<false>(EmbeddedVTableLengthOffset(), len); |
| 175 | } |
| 176 | |
| 177 | inline ArtMethod* Class::GetEmbeddedVTableEntry(uint32_t i) { |
| 178 | uint32_t offset = EmbeddedVTableOffset().Uint32Value() + i * sizeof(VTableEntry); |
| 179 | return GetFieldObject<mirror::ArtMethod>(MemberOffset(offset)); |
| 180 | } |
| 181 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 182 | inline void Class::SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method) { |
| 183 | uint32_t offset = EmbeddedVTableOffset().Uint32Value() + i * sizeof(VTableEntry); |
| 184 | SetFieldObject<false>(MemberOffset(offset), method); |
| 185 | CHECK(method == GetVTableDuringLinking()->Get(i)); |
| 186 | } |
| 187 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 188 | inline bool Class::Implements(Class* klass) { |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 189 | DCHECK(klass != NULL); |
| 190 | DCHECK(klass->IsInterface()) << PrettyClass(this); |
| 191 | // All interfaces implemented directly and by our superclass, and |
| 192 | // recursively all super-interfaces of those interfaces, are listed |
| 193 | // in iftable_, so we can just do a linear scan through that. |
| 194 | int32_t iftable_count = GetIfTableCount(); |
| 195 | IfTable* iftable = GetIfTable(); |
| 196 | for (int32_t i = 0; i < iftable_count; i++) { |
| 197 | if (iftable->GetInterface(i) == klass) { |
| 198 | return true; |
| 199 | } |
| 200 | } |
| 201 | return false; |
| 202 | } |
| 203 | |
| 204 | // Determine whether "this" is assignable from "src", where both of these |
| 205 | // are array classes. |
| 206 | // |
| 207 | // Consider an array class, e.g. Y[][], where Y is a subclass of X. |
| 208 | // Y[][] = Y[][] --> true (identity) |
| 209 | // X[][] = Y[][] --> true (element superclass) |
| 210 | // Y = Y[][] --> false |
| 211 | // Y[] = Y[][] --> false |
| 212 | // Object = Y[][] --> true (everything is an object) |
| 213 | // Object[] = Y[][] --> true |
| 214 | // Object[][] = Y[][] --> true |
| 215 | // Object[][][] = Y[][] --> false (too many []s) |
| 216 | // Serializable = Y[][] --> true (all arrays are Serializable) |
| 217 | // Serializable[] = Y[][] --> true |
| 218 | // Serializable[][] = Y[][] --> false (unless Y is Serializable) |
| 219 | // |
| 220 | // Don't forget about primitive types. |
| 221 | // Object[] = int[] --> false |
| 222 | // |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 223 | inline bool Class::IsArrayAssignableFromArray(Class* src) { |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 224 | DCHECK(IsArrayClass()) << PrettyClass(this); |
| 225 | DCHECK(src->IsArrayClass()) << PrettyClass(src); |
| 226 | return GetComponentType()->IsAssignableFrom(src->GetComponentType()); |
| 227 | } |
| 228 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 229 | inline bool Class::IsAssignableFromArray(Class* src) { |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 230 | DCHECK(!IsInterface()) << PrettyClass(this); // handled first in IsAssignableFrom |
| 231 | DCHECK(src->IsArrayClass()) << PrettyClass(src); |
| 232 | if (!IsArrayClass()) { |
| 233 | // If "this" is not also an array, it must be Object. |
| 234 | // src's super should be java_lang_Object, since it is an array. |
| 235 | Class* java_lang_Object = src->GetSuperClass(); |
| 236 | DCHECK(java_lang_Object != NULL) << PrettyClass(src); |
Ian Rogers | fa46d3e | 2013-05-15 00:16:04 -0700 | [diff] [blame] | 237 | DCHECK(java_lang_Object->GetSuperClass() == NULL) << PrettyClass(src); |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 238 | return this == java_lang_Object; |
| 239 | } |
| 240 | return IsArrayAssignableFromArray(src); |
| 241 | } |
| 242 | |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 243 | template <bool throw_on_failure, bool use_referrers_cache> |
| 244 | inline bool Class::ResolvedFieldAccessTest(Class* access_to, ArtField* field, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 245 | uint32_t field_idx, DexCache* dex_cache) { |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 246 | DCHECK_EQ(use_referrers_cache, dex_cache == nullptr); |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 247 | if (UNLIKELY(!this->CanAccess(access_to))) { |
| 248 | // The referrer class can't access the field's declaring class but may still be able |
| 249 | // to access the field if the FieldId specifies an accessible subclass of the declaring |
| 250 | // class rather than the declaring class itself. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 251 | DexCache* referrer_dex_cache = use_referrers_cache ? this->GetDexCache() : dex_cache; |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 252 | uint32_t class_idx = referrer_dex_cache->GetDexFile()->GetFieldId(field_idx).class_idx_; |
| 253 | // The referenced class has already been resolved with the field, get it from the dex cache. |
| 254 | Class* dex_access_to = referrer_dex_cache->GetResolvedType(class_idx); |
| 255 | DCHECK(dex_access_to != nullptr); |
| 256 | if (UNLIKELY(!this->CanAccess(dex_access_to))) { |
| 257 | if (throw_on_failure) { |
| 258 | ThrowIllegalAccessErrorClass(this, dex_access_to); |
| 259 | } |
| 260 | return false; |
| 261 | } |
| 262 | DCHECK_EQ(this->CanAccessMember(access_to, field->GetAccessFlags()), |
| 263 | this->CanAccessMember(dex_access_to, field->GetAccessFlags())); |
| 264 | } |
| 265 | if (LIKELY(this->CanAccessMember(access_to, field->GetAccessFlags()))) { |
| 266 | return true; |
| 267 | } |
| 268 | if (throw_on_failure) { |
| 269 | ThrowIllegalAccessErrorField(this, field); |
| 270 | } |
| 271 | return false; |
| 272 | } |
| 273 | |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 274 | template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type> |
| 275 | inline bool Class::ResolvedMethodAccessTest(Class* access_to, ArtMethod* method, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 276 | uint32_t method_idx, DexCache* dex_cache) { |
Andreas Gampe | 575e78c | 2014-11-03 23:41:03 -0800 | [diff] [blame] | 277 | static_assert(throw_on_failure || throw_invoke_type == kStatic, "Non-default throw invoke type"); |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 278 | DCHECK_EQ(use_referrers_cache, dex_cache == nullptr); |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 279 | if (UNLIKELY(!this->CanAccess(access_to))) { |
| 280 | // The referrer class can't access the method's declaring class but may still be able |
| 281 | // to access the method if the MethodId specifies an accessible subclass of the declaring |
| 282 | // class rather than the declaring class itself. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 283 | DexCache* referrer_dex_cache = use_referrers_cache ? this->GetDexCache() : dex_cache; |
Vladimir Marko | 23a2821 | 2014-01-09 19:24:37 +0000 | [diff] [blame] | 284 | uint32_t class_idx = referrer_dex_cache->GetDexFile()->GetMethodId(method_idx).class_idx_; |
| 285 | // The referenced class has already been resolved with the method, get it from the dex cache. |
| 286 | Class* dex_access_to = referrer_dex_cache->GetResolvedType(class_idx); |
| 287 | DCHECK(dex_access_to != nullptr); |
| 288 | if (UNLIKELY(!this->CanAccess(dex_access_to))) { |
| 289 | if (throw_on_failure) { |
| 290 | ThrowIllegalAccessErrorClassForMethodDispatch(this, dex_access_to, |
| 291 | method, throw_invoke_type); |
| 292 | } |
| 293 | return false; |
| 294 | } |
| 295 | DCHECK_EQ(this->CanAccessMember(access_to, method->GetAccessFlags()), |
| 296 | this->CanAccessMember(dex_access_to, method->GetAccessFlags())); |
| 297 | } |
| 298 | if (LIKELY(this->CanAccessMember(access_to, method->GetAccessFlags()))) { |
| 299 | return true; |
| 300 | } |
| 301 | if (throw_on_failure) { |
| 302 | ThrowIllegalAccessErrorMethod(this, method); |
| 303 | } |
| 304 | return false; |
| 305 | } |
| 306 | |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 307 | inline bool Class::CanAccessResolvedField(Class* access_to, ArtField* field, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 308 | DexCache* dex_cache, uint32_t field_idx) { |
| 309 | return ResolvedFieldAccessTest<false, false>(access_to, field, field_idx, dex_cache); |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | inline bool Class::CheckResolvedFieldAccess(Class* access_to, ArtField* field, |
| 313 | uint32_t field_idx) { |
| 314 | return ResolvedFieldAccessTest<true, true>(access_to, field, field_idx, nullptr); |
| 315 | } |
| 316 | |
| 317 | inline bool Class::CanAccessResolvedMethod(Class* access_to, ArtMethod* method, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 318 | DexCache* dex_cache, uint32_t method_idx) { |
| 319 | return ResolvedMethodAccessTest<false, false, kStatic>(access_to, method, method_idx, dex_cache); |
Vladimir Marko | 8978643 | 2014-01-31 15:03:55 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | template <InvokeType throw_invoke_type> |
| 323 | inline bool Class::CheckResolvedMethodAccess(Class* access_to, ArtMethod* method, |
| 324 | uint32_t method_idx) { |
| 325 | return ResolvedMethodAccessTest<true, true, throw_invoke_type>(access_to, method, method_idx, |
| 326 | nullptr); |
| 327 | } |
| 328 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 329 | inline bool Class::IsSubClass(Class* klass) { |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 330 | DCHECK(!IsInterface()) << PrettyClass(this); |
| 331 | DCHECK(!IsArrayClass()) << PrettyClass(this); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 332 | Class* current = this; |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 333 | do { |
| 334 | if (current == klass) { |
| 335 | return true; |
| 336 | } |
| 337 | current = current->GetSuperClass(); |
| 338 | } while (current != NULL); |
| 339 | return false; |
| 340 | } |
| 341 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 342 | inline ArtMethod* Class::FindVirtualMethodForInterface(ArtMethod* method) { |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 343 | Class* declaring_class = method->GetDeclaringClass(); |
| 344 | DCHECK(declaring_class != NULL) << PrettyClass(this); |
| 345 | DCHECK(declaring_class->IsInterface()) << PrettyMethod(method); |
| 346 | // TODO cache to improve lookup speed |
| 347 | int32_t iftable_count = GetIfTableCount(); |
| 348 | IfTable* iftable = GetIfTable(); |
| 349 | for (int32_t i = 0; i < iftable_count; i++) { |
| 350 | if (iftable->GetInterface(i) == declaring_class) { |
| 351 | return iftable->GetMethodArray(i)->Get(method->GetMethodIndex()); |
| 352 | } |
| 353 | } |
| 354 | return NULL; |
| 355 | } |
| 356 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 357 | inline ArtMethod* Class::FindVirtualMethodForVirtual(ArtMethod* method) { |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 358 | DCHECK(!method->GetDeclaringClass()->IsInterface() || method->IsMiranda()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 359 | // The argument method may from a super class. |
| 360 | // Use the index to a potentially overridden one for this instance's class. |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 361 | return GetVTableEntry(method->GetMethodIndex()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 364 | inline ArtMethod* Class::FindVirtualMethodForSuper(ArtMethod* method) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 365 | DCHECK(!method->GetDeclaringClass()->IsInterface()); |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 366 | return GetSuperClass()->GetVTableEntry(method->GetMethodIndex()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 369 | inline ArtMethod* Class::FindVirtualMethodForVirtualOrInterface(ArtMethod* method) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 370 | if (method->IsDirect()) { |
| 371 | return method; |
| 372 | } |
Jeff Hao | 201803f | 2013-11-20 18:11:39 -0800 | [diff] [blame] | 373 | if (method->GetDeclaringClass()->IsInterface() && !method->IsMiranda()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 374 | return FindVirtualMethodForInterface(method); |
| 375 | } |
| 376 | return FindVirtualMethodForVirtual(method); |
| 377 | } |
| 378 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 379 | inline IfTable* Class::GetIfTable() { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 380 | return GetFieldObject<IfTable>(OFFSET_OF_OBJECT_MEMBER(Class, iftable_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 383 | inline int32_t Class::GetIfTableCount() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 384 | IfTable* iftable = GetIfTable(); |
| 385 | if (iftable == NULL) { |
| 386 | return 0; |
| 387 | } |
| 388 | return iftable->Count(); |
| 389 | } |
| 390 | |
| 391 | inline void Class::SetIfTable(IfTable* new_iftable) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 392 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, iftable_), new_iftable); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 393 | } |
| 394 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 395 | inline ArtField* Class::GetIFields() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 396 | DCHECK(IsLoaded() || IsErroneous()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 397 | return GetFieldPtr<ArtField*>(OFFSET_OF_OBJECT_MEMBER(Class, ifields_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Vladimir Marko | 76649e8 | 2014-11-10 18:32:59 +0000 | [diff] [blame] | 400 | inline MemberOffset Class::GetFirstReferenceInstanceFieldOffset() { |
| 401 | Class* super_class = GetSuperClass(); |
| 402 | return (super_class != nullptr) |
| 403 | ? MemberOffset(RoundUp(super_class->GetObjectSize(), |
| 404 | sizeof(mirror::HeapReference<mirror::Object>))) |
| 405 | : ClassOffset(); |
| 406 | } |
| 407 | |
| 408 | inline MemberOffset Class::GetFirstReferenceStaticFieldOffset() { |
| 409 | DCHECK(IsResolved()); |
| 410 | uint32_t base = sizeof(mirror::Class); // Static fields come after the class. |
| 411 | if (ShouldHaveEmbeddedImtAndVTable()) { |
| 412 | // Static fields come after the embedded tables. |
| 413 | base = mirror::Class::ComputeClassSize(true, GetEmbeddedVTableLength(), |
| 414 | 0, 0, 0, 0, 0); |
| 415 | } |
| 416 | return MemberOffset(base); |
| 417 | } |
| 418 | |
| 419 | inline MemberOffset Class::GetFirstReferenceStaticFieldOffsetDuringLinking() { |
| 420 | DCHECK(IsLoaded()); |
| 421 | uint32_t base = sizeof(mirror::Class); // Static fields come after the class. |
| 422 | if (ShouldHaveEmbeddedImtAndVTable()) { |
| 423 | // Static fields come after the embedded tables. |
| 424 | base = mirror::Class::ComputeClassSize(true, GetVTableDuringLinking()->GetLength(), |
| 425 | 0, 0, 0, 0, 0); |
| 426 | } |
| 427 | return MemberOffset(base); |
| 428 | } |
| 429 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 430 | inline void Class::SetIFields(ArtField* new_ifields) { |
| 431 | DCHECK(GetIFieldsUnchecked() == nullptr); |
| 432 | return SetFieldPtr<false>(OFFSET_OF_OBJECT_MEMBER(Class, ifields_), new_ifields); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 435 | inline void Class::SetIFieldsUnchecked(ArtField* new_ifields) { |
| 436 | SetFieldPtr<false, true, kVerifyNone>(OFFSET_OF_OBJECT_MEMBER(Class, ifields_), new_ifields); |
| 437 | } |
| 438 | |
| 439 | inline ArtField* Class::GetSFieldsUnchecked() { |
| 440 | return GetFieldPtr<ArtField*>(OFFSET_OF_OBJECT_MEMBER(Class, sfields_)); |
| 441 | } |
| 442 | |
| 443 | inline ArtField* Class::GetIFieldsUnchecked() { |
| 444 | return GetFieldPtr<ArtField*>(OFFSET_OF_OBJECT_MEMBER(Class, ifields_)); |
| 445 | } |
| 446 | |
| 447 | inline ArtField* Class::GetSFields() { |
Mathieu Chartier | 987ca8b | 2015-03-15 14:19:14 -0700 | [diff] [blame] | 448 | DCHECK(IsLoaded() || IsErroneous()) << GetStatus(); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 449 | return GetSFieldsUnchecked(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 452 | inline void Class::SetSFields(ArtField* new_sfields) { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 453 | DCHECK((IsRetired() && new_sfields == nullptr) || |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 454 | GetFieldPtr<ArtField*>(OFFSET_OF_OBJECT_MEMBER(Class, sfields_)) == nullptr); |
| 455 | SetFieldPtr<false>(OFFSET_OF_OBJECT_MEMBER(Class, sfields_), new_sfields); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 456 | } |
| 457 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 458 | inline void Class::SetSFieldsUnchecked(ArtField* new_sfields) { |
| 459 | SetFieldPtr<false, true, kVerifyNone>(OFFSET_OF_OBJECT_MEMBER(Class, sfields_), new_sfields); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 462 | inline ArtField* Class::GetStaticField(uint32_t i) { |
| 463 | DCHECK_LT(i, NumStaticFields()); |
| 464 | return &GetSFields()[i]; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 465 | } |
| 466 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 467 | inline ArtField* Class::GetInstanceField(uint32_t i) { |
| 468 | DCHECK_LT(i, NumInstanceFields()); |
| 469 | return &GetIFields()[i]; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 470 | } |
| 471 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 472 | template<VerifyObjectFlags kVerifyFlags> |
| 473 | inline uint32_t Class::GetReferenceInstanceOffsets() { |
| 474 | DCHECK(IsResolved<kVerifyFlags>() || IsErroneous<kVerifyFlags>()); |
| 475 | return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_)); |
| 476 | } |
| 477 | |
| 478 | inline void Class::SetClinitThreadId(pid_t new_clinit_thread_id) { |
| 479 | if (Runtime::Current()->IsActiveTransaction()) { |
| 480 | SetField32<true>(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), new_clinit_thread_id); |
| 481 | } else { |
| 482 | SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), new_clinit_thread_id); |
| 483 | } |
| 484 | } |
| 485 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 486 | inline void Class::SetVerifyErrorClass(Class* klass) { |
| 487 | CHECK(klass != NULL) << PrettyClass(this); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 488 | if (Runtime::Current()->IsActiveTransaction()) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 489 | SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), klass); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 490 | } else { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 491 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), klass); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 492 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 495 | template<VerifyObjectFlags kVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 496 | inline uint32_t Class::GetAccessFlags() { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 497 | // Check class is loaded/retired or this is java.lang.String that has a |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 498 | // circularity issue during loading the names of its members |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 499 | DCHECK(IsIdxLoaded<kVerifyFlags>() || IsRetired<kVerifyFlags>() || |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 500 | IsErroneous<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>() || |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 501 | this == String::GetJavaLangString() || |
Andreas Gampe | a692866 | 2014-12-12 11:06:00 -0800 | [diff] [blame] | 502 | this == ArtMethod::GetJavaLangReflectArtMethod()) |
| 503 | << "IsIdxLoaded=" << IsIdxLoaded<kVerifyFlags>() |
| 504 | << " IsRetired=" << IsRetired<kVerifyFlags>() |
| 505 | << " IsErroneous=" << |
| 506 | IsErroneous<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>() |
| 507 | << " IsString=" << (this == String::GetJavaLangString()) |
Andreas Gampe | a692866 | 2014-12-12 11:06:00 -0800 | [diff] [blame] | 508 | << " IsArtMethod=" << (this == ArtMethod::GetJavaLangReflectArtMethod()) |
| 509 | << " descriptor=" << PrettyDescriptor(this); |
Hiroshi Yamauchi | e01a520 | 2015-03-19 12:35:04 -0700 | [diff] [blame] | 510 | return GetField32<kVerifyFlags>(AccessFlagsOffset()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 513 | inline String* Class::GetName() { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 514 | return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(Class, name_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 515 | } |
| 516 | inline void Class::SetName(String* name) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 517 | if (Runtime::Current()->IsActiveTransaction()) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 518 | SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, name_), name); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 519 | } else { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 520 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, name_), name); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 521 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 524 | template<VerifyObjectFlags kVerifyFlags> |
| 525 | inline Primitive::Type Class::GetPrimitiveType() { |
| 526 | DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t)); |
Hiroshi Yamauchi | f0edfc3 | 2014-09-25 11:46:46 -0700 | [diff] [blame] | 527 | int32_t v32 = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_)); |
| 528 | Primitive::Type type = static_cast<Primitive::Type>(v32 & 0xFFFF); |
| 529 | DCHECK_EQ(static_cast<size_t>(v32 >> 16), Primitive::ComponentSizeShift(type)); |
| 530 | return type; |
| 531 | } |
| 532 | |
| 533 | template<VerifyObjectFlags kVerifyFlags> |
| 534 | inline size_t Class::GetPrimitiveTypeSizeShift() { |
| 535 | DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t)); |
| 536 | int32_t v32 = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_)); |
| 537 | size_t size_shift = static_cast<Primitive::Type>(v32 >> 16); |
| 538 | DCHECK_EQ(size_shift, Primitive::ComponentSizeShift(static_cast<Primitive::Type>(v32 & 0xFFFF))); |
| 539 | return size_shift; |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 542 | inline void Class::CheckObjectAlloc() { |
Hiroshi Yamauchi | 4cd662e | 2014-04-03 16:28:10 -0700 | [diff] [blame] | 543 | DCHECK(!IsArrayClass()) |
| 544 | << PrettyClass(this) |
| 545 | << "A array shouldn't be allocated through this " |
| 546 | << "as it requires a pre-fence visitor that sets the class size."; |
| 547 | DCHECK(!IsClassClass()) |
| 548 | << PrettyClass(this) |
| 549 | << "A class object shouldn't be allocated through this " |
| 550 | << "as it requires a pre-fence visitor that sets the class size."; |
Hiroshi Yamauchi | 967a0ad | 2013-09-10 16:24:21 -0700 | [diff] [blame] | 551 | DCHECK(IsInstantiable()) << PrettyClass(this); |
| 552 | // TODO: decide whether we want this check. It currently fails during bootstrap. |
| 553 | // DCHECK(!Runtime::Current()->IsStarted() || IsInitializing()) << PrettyClass(this); |
| 554 | DCHECK_GE(this->object_size_, sizeof(Object)); |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Mathieu Chartier | 8668c3c | 2014-04-24 16:48:11 -0700 | [diff] [blame] | 557 | template<bool kIsInstrumented, bool kCheckAddFinalizer> |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 558 | inline Object* Class::Alloc(Thread* self, gc::AllocatorType allocator_type) { |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 559 | CheckObjectAlloc(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 560 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Mathieu Chartier | 8668c3c | 2014-04-24 16:48:11 -0700 | [diff] [blame] | 561 | const bool add_finalizer = kCheckAddFinalizer && IsFinalizable(); |
| 562 | if (!kCheckAddFinalizer) { |
| 563 | DCHECK(!IsFinalizable()); |
| 564 | } |
| 565 | mirror::Object* obj = |
| 566 | heap->AllocObjectWithAllocator<kIsInstrumented, false>(self, this, this->object_size_, |
| 567 | allocator_type, VoidFunctor()); |
| 568 | if (add_finalizer && LIKELY(obj != nullptr)) { |
| 569 | heap->AddFinalizerReference(self, &obj); |
Pavel Vyssotski | 3ac90da | 2014-12-02 19:54:50 +0600 | [diff] [blame] | 570 | if (UNLIKELY(self->IsExceptionPending())) { |
| 571 | // Failed to allocate finalizer reference, it means that the whole allocation failed. |
| 572 | obj = nullptr; |
| 573 | } |
Mathieu Chartier | 8668c3c | 2014-04-24 16:48:11 -0700 | [diff] [blame] | 574 | } |
| 575 | return obj; |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | inline Object* Class::AllocObject(Thread* self) { |
| 579 | return Alloc<true>(self, Runtime::Current()->GetHeap()->GetCurrentAllocator()); |
| 580 | } |
| 581 | |
| 582 | inline Object* Class::AllocNonMovableObject(Thread* self) { |
| 583 | return Alloc<true>(self, Runtime::Current()->GetHeap()->GetCurrentNonMovingAllocator()); |
Hiroshi Yamauchi | 967a0ad | 2013-09-10 16:24:21 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 586 | inline uint32_t Class::ComputeClassSize(bool has_embedded_tables, |
| 587 | uint32_t num_vtable_entries, |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 588 | uint32_t num_8bit_static_fields, |
| 589 | uint32_t num_16bit_static_fields, |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 590 | uint32_t num_32bit_static_fields, |
| 591 | uint32_t num_64bit_static_fields, |
| 592 | uint32_t num_ref_static_fields) { |
| 593 | // Space used by java.lang.Class and its instance fields. |
| 594 | uint32_t size = sizeof(Class); |
| 595 | // Space used by embedded tables. |
| 596 | if (has_embedded_tables) { |
| 597 | uint32_t embedded_imt_size = kImtSize * sizeof(ImTableEntry); |
| 598 | uint32_t embedded_vtable_size = num_vtable_entries * sizeof(VTableEntry); |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 599 | size += embedded_imt_size + |
| 600 | sizeof(int32_t) /* vtable len */ + |
| 601 | embedded_vtable_size; |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 602 | } |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 603 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 604 | // Space used by reference statics. |
| 605 | size += num_ref_static_fields * sizeof(HeapReference<Object>); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 606 | if (!IsAligned<8>(size) && num_64bit_static_fields > 0) { |
| 607 | uint32_t gap = 8 - (size & 0x7); |
| 608 | size += gap; // will be padded |
| 609 | // Shuffle 4-byte fields forward. |
| 610 | while (gap >= sizeof(uint32_t) && num_32bit_static_fields != 0) { |
| 611 | --num_32bit_static_fields; |
| 612 | gap -= sizeof(uint32_t); |
| 613 | } |
| 614 | // Shuffle 2-byte fields forward. |
| 615 | while (gap >= sizeof(uint16_t) && num_16bit_static_fields != 0) { |
| 616 | --num_16bit_static_fields; |
| 617 | gap -= sizeof(uint16_t); |
| 618 | } |
| 619 | // Shuffle byte fields forward. |
| 620 | while (gap >= sizeof(uint8_t) && num_8bit_static_fields != 0) { |
| 621 | --num_8bit_static_fields; |
| 622 | gap -= sizeof(uint8_t); |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 623 | } |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 624 | } |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 625 | // Guaranteed to be at least 4 byte aligned. No need for further alignments. |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 626 | // Space used for primitive static fields. |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 627 | size += (num_8bit_static_fields * sizeof(uint8_t)) + |
| 628 | (num_16bit_static_fields * sizeof(uint16_t)) + |
| 629 | (num_32bit_static_fields * sizeof(uint32_t)) + |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 630 | (num_64bit_static_fields * sizeof(uint64_t)); |
| 631 | return size; |
| 632 | } |
| 633 | |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 634 | template <bool kVisitClass, typename Visitor> |
| 635 | inline void Class::VisitReferences(mirror::Class* klass, const Visitor& visitor) { |
Mathieu Chartier | 52e4b43 | 2014-06-10 11:22:31 -0700 | [diff] [blame] | 636 | VisitInstanceFieldsReferences<kVisitClass>(klass, visitor); |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 637 | // Right after a class is allocated, but not yet loaded |
| 638 | // (kStatusNotReady, see ClassLinkder::LoadClass()), GC may find it |
| 639 | // and scan it. IsTemp() may call Class::GetAccessFlags() but may |
| 640 | // fail in the DCHECK in Class::GetAccessFlags() because the class |
| 641 | // status is kStatusNotReady. To avoid it, rely on IsResolved() |
| 642 | // only. This is fine because a temp class never goes into the |
| 643 | // kStatusResolved state. |
| 644 | if (IsResolved()) { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 645 | // Temp classes don't ever populate imt/vtable or static fields and they are not even |
Hiroshi Yamauchi | f4c15a1 | 2014-10-20 16:56:58 -0700 | [diff] [blame] | 646 | // allocated with the right size for those. Also, unresolved classes don't have fields |
| 647 | // linked yet. |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 648 | VisitStaticFieldsReferences<kVisitClass>(this, visitor); |
| 649 | if (ShouldHaveEmbeddedImtAndVTable()) { |
| 650 | VisitEmbeddedImtAndVTable(visitor); |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | template<typename Visitor> |
| 656 | inline void Class::VisitEmbeddedImtAndVTable(const Visitor& visitor) { |
| 657 | uint32_t pos = sizeof(mirror::Class); |
| 658 | |
| 659 | size_t count = kImtSize; |
| 660 | for (size_t i = 0; i < count; ++i) { |
| 661 | MemberOffset offset = MemberOffset(pos); |
| 662 | visitor(this, offset, true); |
| 663 | pos += sizeof(ImTableEntry); |
| 664 | } |
| 665 | |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 666 | // Skip vtable length. |
| 667 | pos += sizeof(int32_t); |
| 668 | |
| 669 | count = GetEmbeddedVTableLength(); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 670 | for (size_t i = 0; i < count; ++i) { |
| 671 | MemberOffset offset = MemberOffset(pos); |
| 672 | visitor(this, offset, true); |
| 673 | pos += sizeof(VTableEntry); |
| 674 | } |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 675 | } |
| 676 | |
Hiroshi Yamauchi | 4f1ebc2 | 2014-06-25 14:30:41 -0700 | [diff] [blame] | 677 | template<ReadBarrierOption kReadBarrierOption> |
Hiroshi Yamauchi | bd0fb61 | 2014-05-20 13:46:00 -0700 | [diff] [blame] | 678 | inline bool Class::IsArtMethodClass() const { |
Hiroshi Yamauchi | 4f1ebc2 | 2014-06-25 14:30:41 -0700 | [diff] [blame] | 679 | return this == ArtMethod::GetJavaLangReflectArtMethod<kReadBarrierOption>(); |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 682 | template<ReadBarrierOption kReadBarrierOption> |
| 683 | inline bool Class::IsReferenceClass() const { |
| 684 | return this == Reference::GetJavaLangRefReference<kReadBarrierOption>(); |
| 685 | } |
| 686 | |
Hiroshi Yamauchi | 25023c7 | 2014-05-09 11:45:53 -0700 | [diff] [blame] | 687 | template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> |
| 688 | inline bool Class::IsClassClass() { |
| 689 | Class* java_lang_Class = GetClass<kVerifyFlags, kReadBarrierOption>()-> |
| 690 | template GetClass<kVerifyFlags, kReadBarrierOption>(); |
| 691 | return this == java_lang_Class; |
| 692 | } |
| 693 | |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 694 | inline const DexFile& Class::GetDexFile() { |
| 695 | return *GetDexCache()->GetDexFile(); |
| 696 | } |
| 697 | |
| 698 | inline bool Class::DescriptorEquals(const char* match) { |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 699 | if (IsArrayClass()) { |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 700 | return match[0] == '[' && GetComponentType()->DescriptorEquals(match + 1); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 701 | } else if (IsPrimitive()) { |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 702 | return strcmp(Primitive::Descriptor(GetPrimitiveType()), match) == 0; |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 703 | } else if (IsProxyClass()) { |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame^] | 704 | return ProxyDescriptorEquals(match); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 705 | } else { |
| 706 | const DexFile& dex_file = GetDexFile(); |
| 707 | const DexFile::TypeId& type_id = dex_file.GetTypeId(GetClassDef()->class_idx_); |
| 708 | return strcmp(dex_file.GetTypeDescriptor(type_id), match) == 0; |
| 709 | } |
| 710 | } |
| 711 | |
Sebastien Hertz | 4e99b3d | 2014-06-24 14:35:40 +0200 | [diff] [blame] | 712 | inline void Class::AssertInitializedOrInitializingInThread(Thread* self) { |
| 713 | if (kIsDebugBuild && !IsInitialized()) { |
| 714 | CHECK(IsInitializing()) << PrettyClass(this) << " is not initializing: " << GetStatus(); |
| 715 | CHECK_EQ(GetClinitThreadId(), self->GetTid()) << PrettyClass(this) |
| 716 | << " is initializing in a different thread"; |
| 717 | } |
| 718 | } |
| 719 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 720 | inline ObjectArray<Class>* Class::GetInterfaces() { |
| 721 | CHECK(IsProxyClass()); |
| 722 | // First static field. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 723 | auto* field = GetStaticField(0); |
| 724 | DCHECK_STREQ(field->GetName(), "interfaces"); |
| 725 | MemberOffset field_offset = field->GetOffset(); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 726 | return GetFieldObject<ObjectArray<Class>>(field_offset); |
| 727 | } |
| 728 | |
| 729 | inline ObjectArray<ObjectArray<Class>>* Class::GetThrows() { |
| 730 | CHECK(IsProxyClass()); |
| 731 | // Second static field. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 732 | auto* field = GetStaticField(1); |
| 733 | DCHECK_STREQ(field->GetName(), "throws"); |
| 734 | MemberOffset field_offset = field->GetOffset(); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 735 | return GetFieldObject<ObjectArray<ObjectArray<Class>>>(field_offset); |
| 736 | } |
| 737 | |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 738 | inline MemberOffset Class::GetDisableIntrinsicFlagOffset() { |
| 739 | CHECK(IsReferenceClass()); |
| 740 | // First static field |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 741 | auto* field = GetStaticField(0); |
| 742 | DCHECK_STREQ(field->GetName(), "disableIntrinsic"); |
| 743 | return field->GetOffset(); |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | inline MemberOffset Class::GetSlowPathFlagOffset() { |
| 747 | CHECK(IsReferenceClass()); |
| 748 | // Second static field |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 749 | auto* field = GetStaticField(1); |
| 750 | DCHECK_STREQ(field->GetName(), "slowPathEnabled"); |
| 751 | return field->GetOffset(); |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | inline bool Class::GetSlowPathEnabled() { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 755 | return GetFieldBoolean(GetSlowPathFlagOffset()); |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | inline void Class::SetSlowPath(bool enabled) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 759 | SetFieldBoolean<false>(GetSlowPathFlagOffset(), enabled); |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 762 | inline void Class::InitializeClassVisitor::operator()( |
| 763 | mirror::Object* obj, size_t usable_size) const { |
| 764 | DCHECK_LE(class_size_, usable_size); |
| 765 | // Avoid AsClass as object is not yet in live bitmap or allocation stack. |
| 766 | mirror::Class* klass = down_cast<mirror::Class*>(obj); |
| 767 | // DCHECK(klass->IsClass()); |
| 768 | klass->SetClassSize(class_size_); |
| 769 | klass->SetPrimitiveType(Primitive::kPrimNot); // Default to not being primitive. |
| 770 | klass->SetDexClassDefIndex(DexFile::kDexNoIndex16); // Default to no valid class def index. |
| 771 | klass->SetDexTypeIndex(DexFile::kDexNoIndex16); // Default to no valid type index. |
| 772 | } |
| 773 | |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 774 | inline void Class::SetAccessFlags(uint32_t new_access_flags) { |
| 775 | // Called inside a transaction when setting pre-verified flag during boot image compilation. |
| 776 | if (Runtime::Current()->IsActiveTransaction()) { |
| 777 | SetField32<true>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), new_access_flags); |
| 778 | } else { |
| 779 | SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_), new_access_flags); |
| 780 | } |
| 781 | } |
| 782 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 783 | inline uint32_t Class::NumDirectInterfaces() { |
| 784 | if (IsPrimitive()) { |
| 785 | return 0; |
| 786 | } else if (IsArrayClass()) { |
| 787 | return 2; |
| 788 | } else if (IsProxyClass()) { |
| 789 | mirror::ObjectArray<mirror::Class>* interfaces = GetInterfaces(); |
| 790 | return interfaces != nullptr ? interfaces->GetLength() : 0; |
| 791 | } else { |
| 792 | const DexFile::TypeList* interfaces = GetInterfaceTypeList(); |
| 793 | if (interfaces == nullptr) { |
| 794 | return 0; |
| 795 | } else { |
| 796 | return interfaces->Size(); |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 801 | inline void Class::SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings) { |
| 802 | SetFieldObject<false>(DexCacheStringsOffset(), new_dex_cache_strings); |
| 803 | } |
| 804 | |
| 805 | inline ObjectArray<String>* Class::GetDexCacheStrings() { |
| 806 | return GetFieldObject<ObjectArray<String>>(DexCacheStringsOffset()); |
| 807 | } |
| 808 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 809 | template<class Visitor> |
| 810 | void mirror::Class::VisitFieldRoots(Visitor& visitor) { |
| 811 | ArtField* const sfields = GetSFieldsUnchecked(); |
| 812 | for (size_t i = 0, count = NumStaticFields(); i < count; ++i) { |
| 813 | if (kIsDebugBuild && GetStatus() != kStatusRetired) { |
| 814 | CHECK_EQ(sfields[i].GetDeclaringClass(), this); |
| 815 | } |
| 816 | visitor.VisitRoot(sfields[i].DeclaringClassRoot().AddressWithoutBarrier()); |
| 817 | } |
| 818 | ArtField* const ifields = GetIFieldsUnchecked(); |
| 819 | for (size_t i = 0, count = NumInstanceFields(); i < count; ++i) { |
| 820 | if (kIsDebugBuild && GetStatus() != kStatusRetired) { |
| 821 | CHECK_EQ(ifields[i].GetDeclaringClass(), this); |
| 822 | } |
| 823 | visitor.VisitRoot(ifields[i].DeclaringClassRoot().AddressWithoutBarrier()); |
| 824 | } |
| 825 | } |
| 826 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 827 | } // namespace mirror |
| 828 | } // namespace art |
| 829 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 830 | #endif // ART_RUNTIME_MIRROR_CLASS_INL_H_ |