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(); |
| 142 | if (name != NULL) { |
| 143 | return name; |
| 144 | } |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 145 | std::string descriptor(ClassHelper(this).GetDescriptor()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 146 | if ((descriptor[0] != 'L') && (descriptor[0] != '[')) { |
| 147 | // The descriptor indicates that this is the class for |
| 148 | // a primitive type; special-case the return value. |
| 149 | const char* c_name = NULL; |
| 150 | switch (descriptor[0]) { |
| 151 | case 'Z': c_name = "boolean"; break; |
| 152 | case 'B': c_name = "byte"; break; |
| 153 | case 'C': c_name = "char"; break; |
| 154 | case 'S': c_name = "short"; break; |
| 155 | case 'I': c_name = "int"; break; |
| 156 | case 'J': c_name = "long"; break; |
| 157 | case 'F': c_name = "float"; break; |
| 158 | case 'D': c_name = "double"; break; |
| 159 | case 'V': c_name = "void"; break; |
| 160 | default: |
| 161 | LOG(FATAL) << "Unknown primitive type: " << PrintableChar(descriptor[0]); |
| 162 | } |
| 163 | name = String::AllocFromModifiedUtf8(Thread::Current(), c_name); |
| 164 | } else { |
| 165 | // Convert the UTF-8 name to a java.lang.String. The name must use '.' to separate package |
| 166 | // components. |
| 167 | if (descriptor.size() > 2 && descriptor[0] == 'L' && descriptor[descriptor.size() - 1] == ';') { |
| 168 | descriptor.erase(0, 1); |
| 169 | descriptor.erase(descriptor.size() - 1); |
| 170 | } |
| 171 | std::replace(descriptor.begin(), descriptor.end(), '/', '.'); |
| 172 | name = String::AllocFromModifiedUtf8(Thread::Current(), descriptor.c_str()); |
| 173 | } |
| 174 | SetName(name); |
| 175 | return name; |
| 176 | } |
| 177 | |
| 178 | void Class::DumpClass(std::ostream& os, int flags) const { |
| 179 | if ((flags & kDumpClassFullDetail) == 0) { |
| 180 | os << PrettyClass(this); |
| 181 | if ((flags & kDumpClassClassLoader) != 0) { |
| 182 | os << ' ' << GetClassLoader(); |
| 183 | } |
| 184 | if ((flags & kDumpClassInitialized) != 0) { |
| 185 | os << ' ' << GetStatus(); |
| 186 | } |
| 187 | os << "\n"; |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | Class* super = GetSuperClass(); |
| 192 | ClassHelper kh(this); |
| 193 | os << "----- " << (IsInterface() ? "interface" : "class") << " " |
| 194 | << "'" << kh.GetDescriptor() << "' cl=" << GetClassLoader() << " -----\n", |
| 195 | os << " objectSize=" << SizeOf() << " " |
| 196 | << "(" << (super != NULL ? super->SizeOf() : -1) << " from super)\n", |
| 197 | os << StringPrintf(" access=0x%04x.%04x\n", |
| 198 | GetAccessFlags() >> 16, GetAccessFlags() & kAccJavaFlagsMask); |
| 199 | if (super != NULL) { |
| 200 | os << " super='" << PrettyClass(super) << "' (cl=" << super->GetClassLoader() << ")\n"; |
| 201 | } |
| 202 | if (IsArrayClass()) { |
| 203 | os << " componentType=" << PrettyClass(GetComponentType()) << "\n"; |
| 204 | } |
| 205 | if (kh.NumDirectInterfaces() > 0) { |
| 206 | os << " interfaces (" << kh.NumDirectInterfaces() << "):\n"; |
| 207 | for (size_t i = 0; i < kh.NumDirectInterfaces(); ++i) { |
| 208 | Class* interface = kh.GetDirectInterface(i); |
| 209 | const ClassLoader* cl = interface->GetClassLoader(); |
| 210 | os << StringPrintf(" %2zd: %s (cl=%p)\n", i, PrettyClass(interface).c_str(), cl); |
| 211 | } |
| 212 | } |
| 213 | os << " vtable (" << NumVirtualMethods() << " entries, " |
| 214 | << (super != NULL ? super->NumVirtualMethods() : 0) << " in super):\n"; |
| 215 | for (size_t i = 0; i < NumVirtualMethods(); ++i) { |
| 216 | os << StringPrintf(" %2zd: %s\n", i, PrettyMethod(GetVirtualMethodDuringLinking(i)).c_str()); |
| 217 | } |
| 218 | os << " direct methods (" << NumDirectMethods() << " entries):\n"; |
| 219 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
| 220 | os << StringPrintf(" %2zd: %s\n", i, PrettyMethod(GetDirectMethod(i)).c_str()); |
| 221 | } |
| 222 | if (NumStaticFields() > 0) { |
| 223 | os << " static fields (" << NumStaticFields() << " entries):\n"; |
| 224 | if (IsResolved() || IsErroneous()) { |
| 225 | for (size_t i = 0; i < NumStaticFields(); ++i) { |
| 226 | os << StringPrintf(" %2zd: %s\n", i, PrettyField(GetStaticField(i)).c_str()); |
| 227 | } |
| 228 | } else { |
| 229 | os << " <not yet available>"; |
| 230 | } |
| 231 | } |
| 232 | if (NumInstanceFields() > 0) { |
| 233 | os << " instance fields (" << NumInstanceFields() << " entries):\n"; |
| 234 | if (IsResolved() || IsErroneous()) { |
| 235 | for (size_t i = 0; i < NumInstanceFields(); ++i) { |
| 236 | os << StringPrintf(" %2zd: %s\n", i, PrettyField(GetInstanceField(i)).c_str()); |
| 237 | } |
| 238 | } else { |
| 239 | os << " <not yet available>"; |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | void Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) { |
| 245 | if (new_reference_offsets != CLASS_WALK_SUPER) { |
| 246 | // Sanity check that the number of bits set in the reference offset bitmap |
| 247 | // agrees with the number of references |
| 248 | size_t count = 0; |
| 249 | for (Class* c = this; c != NULL; c = c->GetSuperClass()) { |
| 250 | count += c->NumReferenceInstanceFieldsDuringLinking(); |
| 251 | } |
| 252 | CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), count); |
| 253 | } |
| 254 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), |
| 255 | new_reference_offsets, false); |
| 256 | } |
| 257 | |
| 258 | void Class::SetReferenceStaticOffsets(uint32_t new_reference_offsets) { |
| 259 | if (new_reference_offsets != CLASS_WALK_SUPER) { |
| 260 | // Sanity check that the number of bits set in the reference offset bitmap |
| 261 | // agrees with the number of references |
| 262 | CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), |
| 263 | NumReferenceStaticFieldsDuringLinking()); |
| 264 | } |
| 265 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), |
| 266 | new_reference_offsets, false); |
| 267 | } |
| 268 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 269 | bool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) { |
| 270 | size_t i = 0; |
| 271 | while (descriptor1[i] != '\0' && descriptor1[i] == descriptor2[i]) { |
| 272 | ++i; |
| 273 | } |
| 274 | if (descriptor1.find('/', i) != StringPiece::npos || |
| 275 | descriptor2.find('/', i) != StringPiece::npos) { |
| 276 | return false; |
| 277 | } else { |
| 278 | return true; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | bool Class::IsInSamePackage(const Class* that) const { |
| 283 | const Class* klass1 = this; |
| 284 | const Class* klass2 = that; |
| 285 | if (klass1 == klass2) { |
| 286 | return true; |
| 287 | } |
| 288 | // Class loaders must match. |
| 289 | if (klass1->GetClassLoader() != klass2->GetClassLoader()) { |
| 290 | return false; |
| 291 | } |
| 292 | // Arrays are in the same package when their element classes are. |
| 293 | while (klass1->IsArrayClass()) { |
| 294 | klass1 = klass1->GetComponentType(); |
| 295 | } |
| 296 | while (klass2->IsArrayClass()) { |
| 297 | klass2 = klass2->GetComponentType(); |
| 298 | } |
Anwar Ghuloum | 9fa3f20 | 2013-03-26 14:32:54 -0700 | [diff] [blame] | 299 | // trivial check again for array types |
| 300 | if (klass1 == klass2) { |
| 301 | return true; |
| 302 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 303 | // Compare the package part of the descriptor string. |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 304 | return IsInSamePackage(ClassHelper(klass1).GetDescriptor(), |
| 305 | ClassHelper(klass2).GetDescriptor()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | bool Class::IsClassClass() const { |
| 309 | Class* java_lang_Class = GetClass()->GetClass(); |
| 310 | return this == java_lang_Class; |
| 311 | } |
| 312 | |
| 313 | bool Class::IsStringClass() const { |
| 314 | return this == String::GetJavaLangString(); |
| 315 | } |
| 316 | |
| 317 | bool Class::IsThrowableClass() const { |
| 318 | return WellKnownClasses::ToClass(WellKnownClasses::java_lang_Throwable)->IsAssignableFrom(this); |
| 319 | } |
| 320 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 321 | bool Class::IsArtFieldClass() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 322 | Class* java_lang_Class = GetClass(); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 323 | Class* java_lang_reflect_ArtField = java_lang_Class->GetInstanceField(0)->GetClass(); |
| 324 | return this == java_lang_reflect_ArtField; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 327 | bool Class::IsArtMethodClass() const { |
| 328 | return this == ArtMethod::GetJavaLangReflectArtMethod(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 331 | void Class::SetClassLoader(ClassLoader* new_class_loader) { |
| 332 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false); |
| 333 | } |
| 334 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 335 | ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, const Signature& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 336 | // Check the current class before checking the interfaces. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 337 | ArtMethod* method = FindDeclaredVirtualMethod(name, signature); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 338 | if (method != NULL) { |
| 339 | return method; |
| 340 | } |
| 341 | |
| 342 | int32_t iftable_count = GetIfTableCount(); |
| 343 | IfTable* iftable = GetIfTable(); |
| 344 | for (int32_t i = 0; i < iftable_count; i++) { |
| 345 | method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature); |
| 346 | if (method != NULL) { |
| 347 | return method; |
| 348 | } |
| 349 | } |
| 350 | return NULL; |
| 351 | } |
| 352 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 353 | 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] | 354 | // Check the current class before checking the interfaces. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 355 | ArtMethod* method = FindDeclaredVirtualMethod(dex_cache, dex_method_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 356 | if (method != NULL) { |
| 357 | return method; |
| 358 | } |
| 359 | |
| 360 | int32_t iftable_count = GetIfTableCount(); |
| 361 | IfTable* iftable = GetIfTable(); |
| 362 | for (int32_t i = 0; i < iftable_count; i++) { |
| 363 | method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(dex_cache, dex_method_idx); |
| 364 | if (method != NULL) { |
| 365 | return method; |
| 366 | } |
| 367 | } |
| 368 | return NULL; |
| 369 | } |
| 370 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 371 | ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 372 | MethodHelper mh; |
| 373 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 374 | ArtMethod* method = GetDirectMethod(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 375 | mh.ChangeMethod(method); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 376 | if (name == mh.GetName() && mh.GetSignature() == signature) { |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 377 | return method; |
| 378 | } |
| 379 | } |
| 380 | return NULL; |
| 381 | } |
| 382 | |
| 383 | ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature) const { |
| 384 | MethodHelper mh; |
| 385 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
| 386 | ArtMethod* method = GetDirectMethod(i); |
| 387 | mh.ChangeMethod(method); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 388 | if (name == mh.GetName() && signature == mh.GetSignature()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 389 | return method; |
| 390 | } |
| 391 | } |
| 392 | return NULL; |
| 393 | } |
| 394 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 395 | 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] | 396 | if (GetDexCache() == dex_cache) { |
| 397 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 398 | ArtMethod* method = GetDirectMethod(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 399 | if (method->GetDexMethodIndex() == dex_method_idx) { |
| 400 | return method; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | return NULL; |
| 405 | } |
| 406 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 407 | ArtMethod* Class::FindDirectMethod(const StringPiece& name, const StringPiece& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 408 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 409 | ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 410 | if (method != NULL) { |
| 411 | return method; |
| 412 | } |
| 413 | } |
| 414 | return NULL; |
| 415 | } |
| 416 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 417 | ArtMethod* Class::FindDirectMethod(const StringPiece& name, const Signature& signature) const { |
| 418 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
| 419 | ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature); |
| 420 | if (method != NULL) { |
| 421 | return method; |
| 422 | } |
| 423 | } |
| 424 | return NULL; |
| 425 | } |
| 426 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 427 | 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] | 428 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 429 | ArtMethod* method = klass->FindDeclaredDirectMethod(dex_cache, dex_method_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 430 | if (method != NULL) { |
| 431 | return method; |
| 432 | } |
| 433 | } |
| 434 | return NULL; |
| 435 | } |
| 436 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 437 | ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature) const { |
| 438 | MethodHelper mh; |
| 439 | for (size_t i = 0; i < NumVirtualMethods(); ++i) { |
| 440 | ArtMethod* method = GetVirtualMethod(i); |
| 441 | mh.ChangeMethod(method); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 442 | if (name == mh.GetName() && mh.GetSignature() == signature) { |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 443 | return method; |
| 444 | } |
| 445 | } |
| 446 | return NULL; |
| 447 | } |
| 448 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 449 | ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 450 | const Signature& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 451 | MethodHelper mh; |
| 452 | for (size_t i = 0; i < NumVirtualMethods(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 453 | ArtMethod* method = GetVirtualMethod(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 454 | mh.ChangeMethod(method); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 455 | if (name == mh.GetName() && signature == mh.GetSignature()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 456 | return method; |
| 457 | } |
| 458 | } |
| 459 | return NULL; |
| 460 | } |
| 461 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 462 | 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] | 463 | if (GetDexCache() == dex_cache) { |
| 464 | for (size_t i = 0; i < NumVirtualMethods(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 465 | ArtMethod* method = GetVirtualMethod(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 466 | if (method->GetDexMethodIndex() == dex_method_idx) { |
| 467 | return method; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | return NULL; |
| 472 | } |
| 473 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 474 | ArtMethod* Class::FindVirtualMethod(const StringPiece& name, const StringPiece& signature) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 475 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 476 | ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 477 | if (method != NULL) { |
| 478 | return method; |
| 479 | } |
| 480 | } |
| 481 | return NULL; |
| 482 | } |
| 483 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 484 | ArtMethod* Class::FindVirtualMethod(const StringPiece& name, const Signature& signature) const { |
| 485 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
| 486 | ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature); |
| 487 | if (method != NULL) { |
| 488 | return method; |
| 489 | } |
| 490 | } |
| 491 | return NULL; |
| 492 | } |
| 493 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 494 | 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] | 495 | for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 496 | ArtMethod* method = klass->FindDeclaredVirtualMethod(dex_cache, dex_method_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 497 | if (method != NULL) { |
| 498 | return method; |
| 499 | } |
| 500 | } |
| 501 | return NULL; |
| 502 | } |
| 503 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 504 | ArtMethod* Class::FindClassInitializer() const { |
| 505 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
| 506 | ArtMethod* method = GetDirectMethod(i); |
| 507 | if (method->IsConstructor() && method->IsStatic()) { |
| 508 | if (kIsDebugBuild) { |
| 509 | MethodHelper mh(method); |
Ian Rogers | 241b5de | 2013-10-09 17:58:57 -0700 | [diff] [blame] | 510 | CHECK(mh.IsClassInitializer()); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 511 | CHECK_STREQ(mh.GetName(), "<clinit>"); |
| 512 | CHECK_STREQ(mh.GetSignature().ToString().c_str(), "()V"); |
| 513 | } |
| 514 | return method; |
| 515 | } |
| 516 | } |
| 517 | return NULL; |
| 518 | } |
| 519 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 520 | ArtField* Class::FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 521 | // Is the field in this class? |
| 522 | // Interfaces are not relevant because they can't contain instance fields. |
| 523 | FieldHelper fh; |
| 524 | for (size_t i = 0; i < NumInstanceFields(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 525 | ArtField* f = GetInstanceField(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 526 | fh.ChangeField(f); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 527 | if (name == fh.GetName() && type == fh.GetTypeDescriptor()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 528 | return f; |
| 529 | } |
| 530 | } |
| 531 | return NULL; |
| 532 | } |
| 533 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 534 | ArtField* Class::FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 535 | if (GetDexCache() == dex_cache) { |
| 536 | for (size_t i = 0; i < NumInstanceFields(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 537 | ArtField* f = GetInstanceField(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 538 | if (f->GetDexFieldIndex() == dex_field_idx) { |
| 539 | return f; |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | return NULL; |
| 544 | } |
| 545 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 546 | ArtField* Class::FindInstanceField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 547 | // Is the field in this class, or any of its superclasses? |
| 548 | // Interfaces are not relevant because they can't contain instance fields. |
| 549 | for (Class* c = this; c != NULL; c = c->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 550 | ArtField* f = c->FindDeclaredInstanceField(name, type); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 551 | if (f != NULL) { |
| 552 | return f; |
| 553 | } |
| 554 | } |
| 555 | return NULL; |
| 556 | } |
| 557 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 558 | ArtField* Class::FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 559 | // Is the field in this class, or any of its superclasses? |
| 560 | // Interfaces are not relevant because they can't contain instance fields. |
| 561 | for (Class* c = this; c != NULL; c = c->GetSuperClass()) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 562 | ArtField* f = c->FindDeclaredInstanceField(dex_cache, dex_field_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 563 | if (f != NULL) { |
| 564 | return f; |
| 565 | } |
| 566 | } |
| 567 | return NULL; |
| 568 | } |
| 569 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 570 | ArtField* Class::FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 571 | DCHECK(type != NULL); |
| 572 | FieldHelper fh; |
| 573 | for (size_t i = 0; i < NumStaticFields(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 574 | ArtField* f = GetStaticField(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 575 | fh.ChangeField(f); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 576 | if (name == fh.GetName() && type == fh.GetTypeDescriptor()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 577 | return f; |
| 578 | } |
| 579 | } |
| 580 | return NULL; |
| 581 | } |
| 582 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 583 | ArtField* Class::FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 584 | if (dex_cache == GetDexCache()) { |
| 585 | for (size_t i = 0; i < NumStaticFields(); ++i) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 586 | ArtField* f = GetStaticField(i); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 587 | if (f->GetDexFieldIndex() == dex_field_idx) { |
| 588 | return f; |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | return NULL; |
| 593 | } |
| 594 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 595 | ArtField* Class::FindStaticField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 596 | // Is the field in this class (or its interfaces), or any of its |
| 597 | // superclasses (or their interfaces)? |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 598 | for (Class* k = this; k != NULL; k = k->GetSuperClass()) { |
| 599 | // Is the field in this class? |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 600 | ArtField* f = k->FindDeclaredStaticField(name, type); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 601 | if (f != NULL) { |
| 602 | return f; |
| 603 | } |
| 604 | // Is this field in any of this class' interfaces? |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 605 | ClassHelper kh(k); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 606 | for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) { |
| 607 | Class* interface = kh.GetDirectInterface(i); |
| 608 | f = interface->FindStaticField(name, type); |
| 609 | if (f != NULL) { |
| 610 | return f; |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | return NULL; |
| 615 | } |
| 616 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 617 | ArtField* Class::FindStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 618 | for (Class* k = this; k != NULL; k = k->GetSuperClass()) { |
| 619 | // Is the field in this class? |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 620 | ArtField* f = k->FindDeclaredStaticField(dex_cache, dex_field_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 621 | if (f != NULL) { |
| 622 | return f; |
| 623 | } |
| 624 | // Is this field in any of this class' interfaces? |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 625 | ClassHelper kh(k); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 626 | for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) { |
| 627 | Class* interface = kh.GetDirectInterface(i); |
| 628 | f = interface->FindStaticField(dex_cache, dex_field_idx); |
| 629 | if (f != NULL) { |
| 630 | return f; |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | return NULL; |
| 635 | } |
| 636 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 637 | ArtField* Class::FindField(const StringPiece& name, const StringPiece& type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 638 | // Find a field using the JLS field resolution order |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 639 | for (Class* k = this; k != NULL; k = k->GetSuperClass()) { |
| 640 | // Is the field in this class? |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 641 | ArtField* f = k->FindDeclaredInstanceField(name, type); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 642 | if (f != NULL) { |
| 643 | return f; |
| 644 | } |
| 645 | f = k->FindDeclaredStaticField(name, type); |
| 646 | if (f != NULL) { |
| 647 | return f; |
| 648 | } |
| 649 | // Is this field in any of this class' interfaces? |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 650 | ClassHelper kh(k); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 651 | for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) { |
| 652 | Class* interface = kh.GetDirectInterface(i); |
| 653 | f = interface->FindStaticField(name, type); |
| 654 | if (f != NULL) { |
| 655 | return f; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | return NULL; |
| 660 | } |
| 661 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 662 | static void SetPreverifiedFlagOnMethods(mirror::ObjectArray<mirror::ArtMethod>* methods) |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 663 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 664 | if (methods != NULL) { |
| 665 | for (int32_t index = 0, end = methods->GetLength(); index < end; ++index) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 666 | mirror::ArtMethod* method = methods->GetWithoutChecks(index); |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 667 | DCHECK(method != NULL); |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 668 | if (!method->IsNative() && !method->IsAbstract()) { |
| 669 | method->SetPreverified(); |
| 670 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | void Class::SetPreverifiedFlagOnAllMethods() { |
| 676 | DCHECK(IsVerified()); |
| 677 | SetPreverifiedFlagOnMethods(GetDirectMethods()); |
| 678 | SetPreverifiedFlagOnMethods(GetVirtualMethods()); |
| 679 | } |
| 680 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 681 | } // namespace mirror |
| 682 | } // namespace art |