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 | |
| 17 | #include "class.h" |
| 18 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
| 20 | #include "art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | #include "class-inl.h" |
| 22 | #include "class_linker.h" |
| 23 | #include "class_loader.h" |
| 24 | #include "dex_cache.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 25 | #include "dex_file-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 26 | #include "gc/accounting/card_table-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | #include "object-inl.h" |
| 28 | #include "object_array-inl.h" |
| 29 | #include "object_utils.h" |
| 30 | #include "runtime.h" |
| 31 | #include "sirt_ref.h" |
| 32 | #include "thread.h" |
| 33 | #include "throwable.h" |
| 34 | #include "utils.h" |
| 35 | #include "well_known_classes.h" |
| 36 | |
| 37 | namespace art { |
| 38 | namespace mirror { |
| 39 | |
| 40 | Class* Class::java_lang_Class_ = NULL; |
| 41 | |
| 42 | void Class::SetClassClass(Class* java_lang_Class) { |
| 43 | CHECK(java_lang_Class_ == NULL) << java_lang_Class_ << " " << java_lang_Class; |
| 44 | CHECK(java_lang_Class != NULL); |
| 45 | java_lang_Class_ = java_lang_Class; |
| 46 | } |
| 47 | |
| 48 | void Class::ResetClass() { |
| 49 | CHECK(java_lang_Class_ != NULL); |
| 50 | java_lang_Class_ = NULL; |
| 51 | } |
| 52 | |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 53 | void Class::VisitRoots(RootVisitor* visitor, void* arg) { |
| 54 | if (java_lang_Class_ != nullptr) { |
| 55 | java_lang_Class_ = down_cast<Class*>(visitor(java_lang_Class_, arg)); |
| 56 | } |
| 57 | } |
| 58 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 59 | void Class::SetStatus(Status new_status, Thread* self) { |
| 60 | Status old_status = GetStatus(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 61 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 62 | bool class_linker_initialized = class_linker != nullptr && class_linker->IsInitialized(); |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 63 | if (LIKELY(class_linker_initialized)) { |
| 64 | if (UNLIKELY(new_status <= old_status && new_status != kStatusError)) { |
Ian Rogers | 8f3c9ae | 2013-08-20 17:26:41 -0700 | [diff] [blame] | 65 | LOG(FATAL) << "Unexpected change back of class status for " << PrettyClass(this) << " " |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 66 | << old_status << " -> " << new_status; |
Ian Rogers | 8f3c9ae | 2013-08-20 17:26:41 -0700 | [diff] [blame] | 67 | } |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 68 | if (new_status >= kStatusResolved || old_status >= kStatusResolved) { |
| 69 | // When classes are being resolved the resolution code should hold the lock. |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 70 | CHECK_EQ(GetLockOwnerThreadId(), self->GetThreadId()) |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 71 | << "Attempt to change status of class while not holding its lock: " |
| 72 | << PrettyClass(this) << " " << old_status << " -> " << new_status; |
| 73 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 74 | } |
| 75 | if (new_status == kStatusError) { |
Ian Rogers | 8f3c9ae | 2013-08-20 17:26:41 -0700 | [diff] [blame] | 76 | CHECK_NE(GetStatus(), kStatusError) |
| 77 | << "Attempt to set as erroneous an already erroneous class " << PrettyClass(this); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 78 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 79 | // Stash current exception. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 80 | SirtRef<mirror::Object> old_throw_this_object(self, NULL); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 81 | SirtRef<mirror::ArtMethod> old_throw_method(self, NULL); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 82 | SirtRef<mirror::Throwable> old_exception(self, NULL); |
| 83 | uint32_t old_throw_dex_pc; |
| 84 | { |
| 85 | ThrowLocation old_throw_location; |
| 86 | mirror::Throwable* old_exception_obj = self->GetException(&old_throw_location); |
| 87 | old_throw_this_object.reset(old_throw_location.GetThis()); |
| 88 | old_throw_method.reset(old_throw_location.GetMethod()); |
| 89 | old_exception.reset(old_exception_obj); |
| 90 | old_throw_dex_pc = old_throw_location.GetDexPc(); |
| 91 | self->ClearException(); |
| 92 | } |
| 93 | CHECK(old_exception.get() != NULL); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 94 | |
| 95 | // clear exception to call FindSystemClass |
| 96 | self->ClearException(); |
| 97 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 98 | Class* eiie_class = class_linker->FindSystemClass("Ljava/lang/ExceptionInInitializerError;"); |
| 99 | CHECK(!self->IsExceptionPending()); |
| 100 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 101 | // Only verification errors, not initialization problems, should set a verify error. |
| 102 | // This is to ensure that ThrowEarlierClassFailure will throw NoClassDefFoundError in that case. |
| 103 | Class* exception_class = old_exception->GetClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 104 | if (!eiie_class->IsAssignableFrom(exception_class)) { |
| 105 | SetVerifyErrorClass(exception_class); |
| 106 | } |
| 107 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 108 | // Restore exception. |
| 109 | ThrowLocation gc_safe_throw_location(old_throw_this_object.get(), old_throw_method.get(), |
| 110 | old_throw_dex_pc); |
| 111 | |
| 112 | self->SetException(gc_safe_throw_location, old_exception.get()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 113 | } |
Ian Rogers | 8f3c9ae | 2013-08-20 17:26:41 -0700 | [diff] [blame] | 114 | CHECK(sizeof(Status) == sizeof(uint32_t)) << PrettyClass(this); |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 115 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status, false); |
| 116 | // Classes that are being resolved or initialized need to notify waiters that the class status |
| 117 | // changed. See ClassLinker::EnsureResolved and ClassLinker::WaitForInitializeClass. |
| 118 | if ((old_status >= kStatusResolved || new_status >= kStatusResolved) && |
| 119 | class_linker_initialized) { |
| 120 | NotifyAll(self); |
| 121 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 124 | void Class::SetDexCache(DexCache* new_dex_cache) { |
| 125 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), new_dex_cache, false); |
| 126 | } |
| 127 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 128 | void Class::SetClassSize(size_t new_class_size) { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 129 | if (kIsDebugBuild && (new_class_size < GetClassSize())) { |
| 130 | DumpClass(LOG(ERROR), kDumpClassFullDetail); |
| 131 | CHECK_GE(new_class_size, GetClassSize()) << " class=" << PrettyTypeOf(this); |
| 132 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 133 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size, false); |
| 134 | } |
| 135 | |
| 136 | // Return the class' name. The exact format is bizarre, but it's the specified behavior for |
| 137 | // Class.getName: keywords for primitive types, regular "[I" form for primitive arrays (so "int" |
| 138 | // but "[I"), and arrays of reference types written between "L" and ";" but with dots rather than |
| 139 | // slashes (so "java.lang.String" but "[Ljava.lang.String;"). Madness. |
| 140 | String* Class::ComputeName() { |
| 141 | String* name = GetName(); |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame^] | 142 | if (name != nullptr) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 143 | return name; |
| 144 | } |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame^] | 145 | Thread* self = Thread::Current(); |
| 146 | SirtRef<mirror::Class> sirt_c(self, this); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 147 | std::string descriptor(ClassHelper(this).GetDescriptor()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 148 | if ((descriptor[0] != 'L') && (descriptor[0] != '[')) { |
| 149 | // The descriptor indicates that this is the class for |
| 150 | // a primitive type; special-case the return value. |
| 151 | const char* c_name = NULL; |
| 152 | switch (descriptor[0]) { |
| 153 | case 'Z': c_name = "boolean"; break; |
| 154 | case 'B': c_name = "byte"; break; |
| 155 | case 'C': c_name = "char"; break; |
| 156 | case 'S': c_name = "short"; break; |
| 157 | case 'I': c_name = "int"; break; |
| 158 | case 'J': c_name = "long"; break; |
| 159 | case 'F': c_name = "float"; break; |
| 160 | case 'D': c_name = "double"; break; |
| 161 | case 'V': c_name = "void"; break; |
| 162 | default: |
| 163 | LOG(FATAL) << "Unknown primitive type: " << PrintableChar(descriptor[0]); |
| 164 | } |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame^] | 165 | name = String::AllocFromModifiedUtf8(self, c_name); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 166 | } else { |
| 167 | // Convert the UTF-8 name to a java.lang.String. The name must use '.' to separate package |
| 168 | // components. |
| 169 | if (descriptor.size() > 2 && descriptor[0] == 'L' && descriptor[descriptor.size() - 1] == ';') { |
| 170 | descriptor.erase(0, 1); |
| 171 | descriptor.erase(descriptor.size() - 1); |
| 172 | } |
| 173 | std::replace(descriptor.begin(), descriptor.end(), '/', '.'); |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame^] | 174 | name = String::AllocFromModifiedUtf8(self, descriptor.c_str()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 175 | } |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame^] | 176 | sirt_c->SetName(name); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 177 | return name; |
| 178 | } |
| 179 | |
| 180 | void Class::DumpClass(std::ostream& os, int flags) const { |
| 181 | if ((flags & kDumpClassFullDetail) == 0) { |
| 182 | os << PrettyClass(this); |
| 183 | if ((flags & kDumpClassClassLoader) != 0) { |
| 184 | os << ' ' << GetClassLoader(); |
| 185 | } |
| 186 | if ((flags & kDumpClassInitialized) != 0) { |
| 187 | os << ' ' << GetStatus(); |
| 188 | } |
| 189 | os << "\n"; |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | Class* super = GetSuperClass(); |
| 194 | ClassHelper kh(this); |
| 195 | os << "----- " << (IsInterface() ? "interface" : "class") << " " |
| 196 | << "'" << kh.GetDescriptor() << "' cl=" << GetClassLoader() << " -----\n", |
| 197 | os << " objectSize=" << SizeOf() << " " |
| 198 | << "(" << (super != NULL ? super->SizeOf() : -1) << " from super)\n", |
| 199 | os << StringPrintf(" access=0x%04x.%04x\n", |
| 200 | GetAccessFlags() >> 16, GetAccessFlags() & kAccJavaFlagsMask); |
| 201 | if (super != NULL) { |
| 202 | os << " super='" << PrettyClass(super) << "' (cl=" << super->GetClassLoader() << ")\n"; |
| 203 | } |
| 204 | if (IsArrayClass()) { |
| 205 | os << " componentType=" << PrettyClass(GetComponentType()) << "\n"; |
| 206 | } |
| 207 | if (kh.NumDirectInterfaces() > 0) { |
| 208 | os << " interfaces (" << kh.NumDirectInterfaces() << "):\n"; |
| 209 | for (size_t i = 0; i < kh.NumDirectInterfaces(); ++i) { |
| 210 | Class* interface = kh.GetDirectInterface(i); |
| 211 | const ClassLoader* cl = interface->GetClassLoader(); |
| 212 | os << StringPrintf(" %2zd: %s (cl=%p)\n", i, PrettyClass(interface).c_str(), cl); |
| 213 | } |
| 214 | } |
| 215 | os << " vtable (" << NumVirtualMethods() << " entries, " |
| 216 | << (super != NULL ? super->NumVirtualMethods() : 0) << " in super):\n"; |
| 217 | for (size_t i = 0; i < NumVirtualMethods(); ++i) { |
| 218 | os << StringPrintf(" %2zd: %s\n", i, PrettyMethod(GetVirtualMethodDuringLinking(i)).c_str()); |
| 219 | } |
| 220 | os << " direct methods (" << NumDirectMethods() << " entries):\n"; |
| 221 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
| 222 | os << StringPrintf(" %2zd: %s\n", i, PrettyMethod(GetDirectMethod(i)).c_str()); |
| 223 | } |
| 224 | if (NumStaticFields() > 0) { |
| 225 | os << " static fields (" << NumStaticFields() << " entries):\n"; |
| 226 | if (IsResolved() || IsErroneous()) { |
| 227 | for (size_t i = 0; i < NumStaticFields(); ++i) { |
| 228 | os << StringPrintf(" %2zd: %s\n", i, PrettyField(GetStaticField(i)).c_str()); |
| 229 | } |
| 230 | } else { |
| 231 | os << " <not yet available>"; |
| 232 | } |
| 233 | } |
| 234 | if (NumInstanceFields() > 0) { |
| 235 | os << " instance fields (" << NumInstanceFields() << " entries):\n"; |
| 236 | if (IsResolved() || IsErroneous()) { |
| 237 | for (size_t i = 0; i < NumInstanceFields(); ++i) { |
| 238 | os << StringPrintf(" %2zd: %s\n", i, PrettyField(GetInstanceField(i)).c_str()); |
| 239 | } |
| 240 | } else { |
| 241 | os << " <not yet available>"; |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | void Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) { |
| 247 | if (new_reference_offsets != CLASS_WALK_SUPER) { |
| 248 | // Sanity check that the number of bits set in the reference offset bitmap |
| 249 | // agrees with the number of references |
| 250 | size_t count = 0; |
| 251 | for (Class* c = this; c != NULL; c = c->GetSuperClass()) { |
| 252 | count += c->NumReferenceInstanceFieldsDuringLinking(); |
| 253 | } |
| 254 | CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), count); |
| 255 | } |
| 256 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), |
| 257 | new_reference_offsets, false); |
| 258 | } |
| 259 | |
| 260 | void Class::SetReferenceStaticOffsets(uint32_t new_reference_offsets) { |
| 261 | if (new_reference_offsets != CLASS_WALK_SUPER) { |
| 262 | // Sanity check that the number of bits set in the reference offset bitmap |
| 263 | // agrees with the number of references |
| 264 | CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), |
| 265 | NumReferenceStaticFieldsDuringLinking()); |
| 266 | } |
| 267 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), |
| 268 | new_reference_offsets, false); |
| 269 | } |
| 270 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 271 | bool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) { |
| 272 | size_t i = 0; |
| 273 | while (descriptor1[i] != '\0' && descriptor1[i] == descriptor2[i]) { |
| 274 | ++i; |
| 275 | } |
| 276 | if (descriptor1.find('/', i) != StringPiece::npos || |
| 277 | descriptor2.find('/', i) != StringPiece::npos) { |
| 278 | return false; |
| 279 | } else { |
| 280 | return true; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | bool Class::IsInSamePackage(const Class* that) const { |
| 285 | const Class* klass1 = this; |
| 286 | const Class* klass2 = that; |
| 287 | if (klass1 == klass2) { |
| 288 | return true; |
| 289 | } |
| 290 | // Class loaders must match. |
| 291 | if (klass1->GetClassLoader() != klass2->GetClassLoader()) { |
| 292 | return false; |
| 293 | } |
| 294 | // Arrays are in the same package when their element classes are. |
| 295 | while (klass1->IsArrayClass()) { |
| 296 | klass1 = klass1->GetComponentType(); |
| 297 | } |
| 298 | while (klass2->IsArrayClass()) { |
| 299 | klass2 = klass2->GetComponentType(); |
| 300 | } |
Anwar Ghuloum | 9fa3f20 | 2013-03-26 14:32:54 -0700 | [diff] [blame] | 301 | // trivial check again for array types |
| 302 | if (klass1 == klass2) { |
| 303 | return true; |
| 304 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 305 | // Compare the package part of the descriptor string. |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 306 | return IsInSamePackage(ClassHelper(klass1).GetDescriptor(), |
| 307 | ClassHelper(klass2).GetDescriptor()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | bool Class::IsClassClass() const { |
| 311 | Class* java_lang_Class = GetClass()->GetClass(); |
| 312 | return this == java_lang_Class; |
| 313 | } |
| 314 | |
| 315 | bool Class::IsStringClass() const { |
| 316 | return this == String::GetJavaLangString(); |
| 317 | } |
| 318 | |
| 319 | bool Class::IsThrowableClass() const { |
| 320 | return WellKnownClasses::ToClass(WellKnownClasses::java_lang_Throwable)->IsAssignableFrom(this); |
| 321 | } |
| 322 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 323 | bool Class::IsArtFieldClass() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 324 | Class* java_lang_Class = GetClass(); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 325 | Class* java_lang_reflect_ArtField = java_lang_Class->GetInstanceField(0)->GetClass(); |
| 326 | return this == java_lang_reflect_ArtField; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 329 | bool Class::IsArtMethodClass() const { |
| 330 | return this == ArtMethod::GetJavaLangReflectArtMethod(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 333 | void Class::SetClassLoader(ClassLoader* new_class_loader) { |
| 334 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false); |
| 335 | } |
| 336 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 337 | ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, const Signature& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 338 | // Check the current class before checking the interfaces. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 339 | ArtMethod* method = FindDeclaredVirtualMethod(name, signature); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 340 | if (method != NULL) { |
| 341 | return method; |
| 342 | } |
| 343 | |
| 344 | int32_t iftable_count = GetIfTableCount(); |
| 345 | IfTable* iftable = GetIfTable(); |
| 346 | for (int32_t i = 0; i < iftable_count; i++) { |
| 347 | method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature); |
| 348 | if (method != NULL) { |
| 349 | return method; |
| 350 | } |
| 351 | } |
| 352 | return NULL; |
| 353 | } |
| 354 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 355 | ArtMethod* Class::FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 356 | // Check the current class before checking the interfaces. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 357 | ArtMethod* method = FindDeclaredVirtualMethod(dex_cache, dex_method_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 358 | if (method != NULL) { |
| 359 | return method; |
| 360 | } |
| 361 | |
| 362 | int32_t iftable_count = GetIfTableCount(); |
| 363 | IfTable* iftable = GetIfTable(); |
| 364 | for (int32_t i = 0; i < iftable_count; i++) { |
| 365 | method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(dex_cache, dex_method_idx); |
| 366 | if (method != NULL) { |
| 367 | return method; |
| 368 | } |
| 369 | } |
| 370 | return NULL; |
| 371 | } |
| 372 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 373 | ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 374 | MethodHelper mh; |
| 375 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 376 | ArtMethod* method = GetDirectMethod(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 377 | mh.ChangeMethod(method); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 378 | if (name == mh.GetName() && mh.GetSignature() == signature) { |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 379 | return method; |
| 380 | } |
| 381 | } |
| 382 | return NULL; |
| 383 | } |
| 384 | |
| 385 | ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature) const { |
| 386 | MethodHelper mh; |
| 387 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
| 388 | ArtMethod* method = GetDirectMethod(i); |
| 389 | mh.ChangeMethod(method); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 390 | if (name == mh.GetName() && signature == mh.GetSignature()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 391 | return method; |
| 392 | } |
| 393 | } |
| 394 | return NULL; |
| 395 | } |
| 396 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 397 | ArtMethod* Class::FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 398 | if (GetDexCache() == dex_cache) { |
| 399 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 400 | ArtMethod* method = GetDirectMethod(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 401 | if (method->GetDexMethodIndex() == dex_method_idx) { |
| 402 | return method; |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | return NULL; |
| 407 | } |
| 408 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 409 | ArtMethod* Class::FindDirectMethod(const StringPiece& name, const StringPiece& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 410 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 411 | ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 412 | if (method != NULL) { |
| 413 | return method; |
| 414 | } |
| 415 | } |
| 416 | return NULL; |
| 417 | } |
| 418 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 419 | ArtMethod* Class::FindDirectMethod(const StringPiece& name, const Signature& signature) const { |
| 420 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
| 421 | ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature); |
| 422 | if (method != NULL) { |
| 423 | return method; |
| 424 | } |
| 425 | } |
| 426 | return NULL; |
| 427 | } |
| 428 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 429 | ArtMethod* Class::FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 430 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 431 | ArtMethod* method = klass->FindDeclaredDirectMethod(dex_cache, dex_method_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 432 | if (method != NULL) { |
| 433 | return method; |
| 434 | } |
| 435 | } |
| 436 | return NULL; |
| 437 | } |
| 438 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 439 | ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature) const { |
| 440 | MethodHelper mh; |
| 441 | for (size_t i = 0; i < NumVirtualMethods(); ++i) { |
| 442 | ArtMethod* method = GetVirtualMethod(i); |
| 443 | mh.ChangeMethod(method); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 444 | if (name == mh.GetName() && mh.GetSignature() == signature) { |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 445 | return method; |
| 446 | } |
| 447 | } |
| 448 | return NULL; |
| 449 | } |
| 450 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 451 | ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 452 | const Signature& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 453 | MethodHelper mh; |
| 454 | for (size_t i = 0; i < NumVirtualMethods(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 455 | ArtMethod* method = GetVirtualMethod(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 456 | mh.ChangeMethod(method); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 457 | if (name == mh.GetName() && signature == mh.GetSignature()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 458 | return method; |
| 459 | } |
| 460 | } |
| 461 | return NULL; |
| 462 | } |
| 463 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 464 | ArtMethod* Class::FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 465 | if (GetDexCache() == dex_cache) { |
| 466 | for (size_t i = 0; i < NumVirtualMethods(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 467 | ArtMethod* method = GetVirtualMethod(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 468 | if (method->GetDexMethodIndex() == dex_method_idx) { |
| 469 | return method; |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | return NULL; |
| 474 | } |
| 475 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 476 | ArtMethod* Class::FindVirtualMethod(const StringPiece& name, const StringPiece& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 477 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 478 | ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 479 | if (method != NULL) { |
| 480 | return method; |
| 481 | } |
| 482 | } |
| 483 | return NULL; |
| 484 | } |
| 485 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 486 | ArtMethod* Class::FindVirtualMethod(const StringPiece& name, const Signature& signature) const { |
| 487 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
| 488 | ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature); |
| 489 | if (method != NULL) { |
| 490 | return method; |
| 491 | } |
| 492 | } |
| 493 | return NULL; |
| 494 | } |
| 495 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 496 | ArtMethod* Class::FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 497 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 498 | ArtMethod* method = klass->FindDeclaredVirtualMethod(dex_cache, dex_method_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 499 | if (method != NULL) { |
| 500 | return method; |
| 501 | } |
| 502 | } |
| 503 | return NULL; |
| 504 | } |
| 505 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 506 | ArtMethod* Class::FindClassInitializer() const { |
| 507 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
| 508 | ArtMethod* method = GetDirectMethod(i); |
| 509 | if (method->IsConstructor() && method->IsStatic()) { |
| 510 | if (kIsDebugBuild) { |
| 511 | MethodHelper mh(method); |
Ian Rogers | 241b5de | 2013-10-09 17:58:57 -0700 | [diff] [blame] | 512 | CHECK(mh.IsClassInitializer()); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 513 | CHECK_STREQ(mh.GetName(), "<clinit>"); |
| 514 | CHECK_STREQ(mh.GetSignature().ToString().c_str(), "()V"); |
| 515 | } |
| 516 | return method; |
| 517 | } |
| 518 | } |
| 519 | return NULL; |
| 520 | } |
| 521 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 522 | ArtField* Class::FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 523 | // Is the field in this class? |
| 524 | // Interfaces are not relevant because they can't contain instance fields. |
| 525 | FieldHelper fh; |
| 526 | for (size_t i = 0; i < NumInstanceFields(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 527 | ArtField* f = GetInstanceField(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 528 | fh.ChangeField(f); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 529 | if (name == fh.GetName() && type == fh.GetTypeDescriptor()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 530 | return f; |
| 531 | } |
| 532 | } |
| 533 | return NULL; |
| 534 | } |
| 535 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 536 | ArtField* Class::FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 537 | if (GetDexCache() == dex_cache) { |
| 538 | for (size_t i = 0; i < NumInstanceFields(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 539 | ArtField* f = GetInstanceField(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 540 | if (f->GetDexFieldIndex() == dex_field_idx) { |
| 541 | return f; |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | return NULL; |
| 546 | } |
| 547 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 548 | ArtField* Class::FindInstanceField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 549 | // Is the field in this class, or any of its superclasses? |
| 550 | // Interfaces are not relevant because they can't contain instance fields. |
| 551 | for (Class* c = this; c != NULL; c = c->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 552 | ArtField* f = c->FindDeclaredInstanceField(name, type); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 553 | if (f != NULL) { |
| 554 | return f; |
| 555 | } |
| 556 | } |
| 557 | return NULL; |
| 558 | } |
| 559 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 560 | ArtField* Class::FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 561 | // Is the field in this class, or any of its superclasses? |
| 562 | // Interfaces are not relevant because they can't contain instance fields. |
| 563 | for (Class* c = this; c != NULL; c = c->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 564 | ArtField* f = c->FindDeclaredInstanceField(dex_cache, dex_field_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 565 | if (f != NULL) { |
| 566 | return f; |
| 567 | } |
| 568 | } |
| 569 | return NULL; |
| 570 | } |
| 571 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 572 | ArtField* Class::FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 573 | DCHECK(type != NULL); |
| 574 | FieldHelper fh; |
| 575 | for (size_t i = 0; i < NumStaticFields(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 576 | ArtField* f = GetStaticField(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 577 | fh.ChangeField(f); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 578 | if (name == fh.GetName() && type == fh.GetTypeDescriptor()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 579 | return f; |
| 580 | } |
| 581 | } |
| 582 | return NULL; |
| 583 | } |
| 584 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 585 | ArtField* Class::FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 586 | if (dex_cache == GetDexCache()) { |
| 587 | for (size_t i = 0; i < NumStaticFields(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 588 | ArtField* f = GetStaticField(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 589 | if (f->GetDexFieldIndex() == dex_field_idx) { |
| 590 | return f; |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | return NULL; |
| 595 | } |
| 596 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 597 | ArtField* Class::FindStaticField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 598 | // Is the field in this class (or its interfaces), or any of its |
| 599 | // superclasses (or their interfaces)? |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 600 | for (Class* k = this; k != NULL; k = k->GetSuperClass()) { |
| 601 | // Is the field in this class? |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 602 | ArtField* f = k->FindDeclaredStaticField(name, type); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 603 | if (f != NULL) { |
| 604 | return f; |
| 605 | } |
| 606 | // Is this field in any of this class' interfaces? |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 607 | ClassHelper kh(k); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 608 | for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) { |
| 609 | Class* interface = kh.GetDirectInterface(i); |
| 610 | f = interface->FindStaticField(name, type); |
| 611 | if (f != NULL) { |
| 612 | return f; |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | return NULL; |
| 617 | } |
| 618 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 619 | ArtField* Class::FindStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 620 | for (Class* k = this; k != NULL; k = k->GetSuperClass()) { |
| 621 | // Is the field in this class? |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 622 | ArtField* f = k->FindDeclaredStaticField(dex_cache, dex_field_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 623 | if (f != NULL) { |
| 624 | return f; |
| 625 | } |
| 626 | // Is this field in any of this class' interfaces? |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 627 | ClassHelper kh(k); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 628 | for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) { |
| 629 | Class* interface = kh.GetDirectInterface(i); |
| 630 | f = interface->FindStaticField(dex_cache, dex_field_idx); |
| 631 | if (f != NULL) { |
| 632 | return f; |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | return NULL; |
| 637 | } |
| 638 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 639 | ArtField* Class::FindField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 640 | // Find a field using the JLS field resolution order |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 641 | for (Class* k = this; k != NULL; k = k->GetSuperClass()) { |
| 642 | // Is the field in this class? |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 643 | ArtField* f = k->FindDeclaredInstanceField(name, type); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 644 | if (f != NULL) { |
| 645 | return f; |
| 646 | } |
| 647 | f = k->FindDeclaredStaticField(name, type); |
| 648 | if (f != NULL) { |
| 649 | return f; |
| 650 | } |
| 651 | // Is this field in any of this class' interfaces? |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 652 | ClassHelper kh(k); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 653 | for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) { |
| 654 | Class* interface = kh.GetDirectInterface(i); |
| 655 | f = interface->FindStaticField(name, type); |
| 656 | if (f != NULL) { |
| 657 | return f; |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | return NULL; |
| 662 | } |
| 663 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 664 | static void SetPreverifiedFlagOnMethods(mirror::ObjectArray<mirror::ArtMethod>* methods) |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 665 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 666 | if (methods != NULL) { |
| 667 | for (int32_t index = 0, end = methods->GetLength(); index < end; ++index) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 668 | mirror::ArtMethod* method = methods->GetWithoutChecks(index); |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 669 | DCHECK(method != NULL); |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 670 | if (!method->IsNative() && !method->IsAbstract()) { |
| 671 | method->SetPreverified(); |
| 672 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | void Class::SetPreverifiedFlagOnAllMethods() { |
| 678 | DCHECK(IsVerified()); |
| 679 | SetPreverifiedFlagOnMethods(GetDirectMethods()); |
| 680 | SetPreverifiedFlagOnMethods(GetVirtualMethods()); |
| 681 | } |
| 682 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 683 | } // namespace mirror |
| 684 | } // namespace art |