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