class.cc revision 28bd2e4f151267b34b8e1eb19c489d8d547bbf5c
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 19#include "art_field-inl.h" 20#include "art_method-inl.h" 21#include "class_linker-inl.h" 22#include "class_loader.h" 23#include "class-inl.h" 24#include "dex_cache.h" 25#include "dex_file-inl.h" 26#include "dex_file_annotations.h" 27#include "gc/accounting/card_table-inl.h" 28#include "handle_scope-inl.h" 29#include "method.h" 30#include "object_array-inl.h" 31#include "object-inl.h" 32#include "runtime.h" 33#include "thread.h" 34#include "throwable.h" 35#include "utils.h" 36#include "well_known_classes.h" 37 38namespace art { 39namespace mirror { 40 41GcRoot<Class> Class::java_lang_Class_; 42 43void Class::SetClassClass(ObjPtr<Class> java_lang_Class) { 44 CHECK(java_lang_Class_.IsNull()) 45 << java_lang_Class_.Read() 46 << " " << java_lang_Class; 47 CHECK(java_lang_Class != nullptr); 48 java_lang_Class->SetClassFlags(kClassFlagClass); 49 java_lang_Class_ = GcRoot<Class>(java_lang_Class); 50} 51 52void Class::ResetClass() { 53 CHECK(!java_lang_Class_.IsNull()); 54 java_lang_Class_ = GcRoot<Class>(nullptr); 55} 56 57void Class::VisitRoots(RootVisitor* visitor) { 58 java_lang_Class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); 59} 60 61inline void Class::SetVerifyError(ObjPtr<Object> error) { 62 CHECK(error != nullptr) << PrettyClass(this); 63 if (Runtime::Current()->IsActiveTransaction()) { 64 SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_), error); 65 } else { 66 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_), error); 67 } 68} 69 70void Class::SetStatus(Handle<Class> h_this, Status new_status, Thread* self) { 71 Status old_status = h_this->GetStatus(); 72 ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); 73 bool class_linker_initialized = class_linker != nullptr && class_linker->IsInitialized(); 74 if (LIKELY(class_linker_initialized)) { 75 if (UNLIKELY(new_status <= old_status && new_status != kStatusError && 76 new_status != kStatusRetired)) { 77 LOG(FATAL) << "Unexpected change back of class status for " << PrettyClass(h_this.Get()) 78 << " " << old_status << " -> " << new_status; 79 } 80 if (new_status >= kStatusResolved || old_status >= kStatusResolved) { 81 // When classes are being resolved the resolution code should hold the lock. 82 CHECK_EQ(h_this->GetLockOwnerThreadId(), self->GetThreadId()) 83 << "Attempt to change status of class while not holding its lock: " 84 << PrettyClass(h_this.Get()) << " " << old_status << " -> " << new_status; 85 } 86 } 87 if (UNLIKELY(new_status == kStatusError)) { 88 CHECK_NE(h_this->GetStatus(), kStatusError) 89 << "Attempt to set as erroneous an already erroneous class " 90 << PrettyClass(h_this.Get()); 91 if (VLOG_IS_ON(class_linker)) { 92 LOG(ERROR) << "Setting " << PrettyDescriptor(h_this.Get()) << " to erroneous."; 93 if (self->IsExceptionPending()) { 94 LOG(ERROR) << "Exception: " << self->GetException()->Dump(); 95 } 96 } 97 98 // Remember the current exception. 99 CHECK(self->GetException() != nullptr); 100 h_this->SetVerifyError(self->GetException()); 101 } 102 static_assert(sizeof(Status) == sizeof(uint32_t), "Size of status not equal to uint32"); 103 if (Runtime::Current()->IsActiveTransaction()) { 104 h_this->SetField32Volatile<true>(StatusOffset(), new_status); 105 } else { 106 h_this->SetField32Volatile<false>(StatusOffset(), new_status); 107 } 108 109 // Setting the object size alloc fast path needs to be after the status write so that if the 110 // alloc path sees a valid object size, we would know that it's initialized as long as it has a 111 // load-acquire/fake dependency. 112 if (new_status == kStatusInitialized && !h_this->IsVariableSize()) { 113 DCHECK_EQ(h_this->GetObjectSizeAllocFastPath(), std::numeric_limits<uint32_t>::max()); 114 // Finalizable objects must always go slow path. 115 if (!h_this->IsFinalizable()) { 116 h_this->SetObjectSizeAllocFastPath(RoundUp(h_this->GetObjectSize(), kObjectAlignment)); 117 } 118 } 119 120 if (!class_linker_initialized) { 121 // When the class linker is being initialized its single threaded and by definition there can be 122 // no waiters. During initialization classes may appear temporary but won't be retired as their 123 // size was statically computed. 124 } else { 125 // Classes that are being resolved or initialized need to notify waiters that the class status 126 // changed. See ClassLinker::EnsureResolved and ClassLinker::WaitForInitializeClass. 127 if (h_this->IsTemp()) { 128 // Class is a temporary one, ensure that waiters for resolution get notified of retirement 129 // so that they can grab the new version of the class from the class linker's table. 130 CHECK_LT(new_status, kStatusResolved) << PrettyDescriptor(h_this.Get()); 131 if (new_status == kStatusRetired || new_status == kStatusError) { 132 h_this->NotifyAll(self); 133 } 134 } else { 135 CHECK_NE(new_status, kStatusRetired); 136 if (old_status >= kStatusResolved || new_status >= kStatusResolved) { 137 h_this->NotifyAll(self); 138 } 139 } 140 } 141} 142 143void Class::SetDexCache(ObjPtr<DexCache> new_dex_cache) { 144 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), new_dex_cache); 145 SetDexCacheStrings(new_dex_cache != nullptr ? new_dex_cache->GetStrings() : nullptr); 146} 147 148void Class::SetClassSize(uint32_t new_class_size) { 149 if (kIsDebugBuild && new_class_size < GetClassSize()) { 150 DumpClass(LOG_STREAM(FATAL_WITHOUT_ABORT), kDumpClassFullDetail); 151 LOG(FATAL_WITHOUT_ABORT) << new_class_size << " vs " << GetClassSize(); 152 LOG(FATAL) << "class=" << PrettyTypeOf(this); 153 } 154 // Not called within a transaction. 155 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size); 156} 157 158// Return the class' name. The exact format is bizarre, but it's the specified behavior for 159// Class.getName: keywords for primitive types, regular "[I" form for primitive arrays (so "int" 160// but "[I"), and arrays of reference types written between "L" and ";" but with dots rather than 161// slashes (so "java.lang.String" but "[Ljava.lang.String;"). Madness. 162String* Class::ComputeName(Handle<Class> h_this) { 163 String* name = h_this->GetName(); 164 if (name != nullptr) { 165 return name; 166 } 167 std::string temp; 168 const char* descriptor = h_this->GetDescriptor(&temp); 169 Thread* self = Thread::Current(); 170 if ((descriptor[0] != 'L') && (descriptor[0] != '[')) { 171 // The descriptor indicates that this is the class for 172 // a primitive type; special-case the return value. 173 const char* c_name = nullptr; 174 switch (descriptor[0]) { 175 case 'Z': c_name = "boolean"; break; 176 case 'B': c_name = "byte"; break; 177 case 'C': c_name = "char"; break; 178 case 'S': c_name = "short"; break; 179 case 'I': c_name = "int"; break; 180 case 'J': c_name = "long"; break; 181 case 'F': c_name = "float"; break; 182 case 'D': c_name = "double"; break; 183 case 'V': c_name = "void"; break; 184 default: 185 LOG(FATAL) << "Unknown primitive type: " << PrintableChar(descriptor[0]); 186 } 187 name = String::AllocFromModifiedUtf8(self, c_name); 188 } else { 189 // Convert the UTF-8 name to a java.lang.String. The name must use '.' to separate package 190 // components. 191 name = String::AllocFromModifiedUtf8(self, DescriptorToDot(descriptor).c_str()); 192 } 193 h_this->SetName(name); 194 return name; 195} 196 197void Class::DumpClass(std::ostream& os, int flags) { 198 if ((flags & kDumpClassFullDetail) == 0) { 199 os << PrettyClass(this); 200 if ((flags & kDumpClassClassLoader) != 0) { 201 os << ' ' << GetClassLoader(); 202 } 203 if ((flags & kDumpClassInitialized) != 0) { 204 os << ' ' << GetStatus(); 205 } 206 os << "\n"; 207 return; 208 } 209 210 Thread* const self = Thread::Current(); 211 StackHandleScope<2> hs(self); 212 Handle<Class> h_this(hs.NewHandle(this)); 213 Handle<Class> h_super(hs.NewHandle(GetSuperClass())); 214 auto image_pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); 215 216 std::string temp; 217 os << "----- " << (IsInterface() ? "interface" : "class") << " " 218 << "'" << GetDescriptor(&temp) << "' cl=" << GetClassLoader() << " -----\n", 219 os << " objectSize=" << SizeOf() << " " 220 << "(" << (h_super.Get() != nullptr ? h_super->SizeOf() : -1) << " from super)\n", 221 os << StringPrintf(" access=0x%04x.%04x\n", 222 GetAccessFlags() >> 16, GetAccessFlags() & kAccJavaFlagsMask); 223 if (h_super.Get() != nullptr) { 224 os << " super='" << PrettyClass(h_super.Get()) << "' (cl=" << h_super->GetClassLoader() 225 << ")\n"; 226 } 227 if (IsArrayClass()) { 228 os << " componentType=" << PrettyClass(GetComponentType()) << "\n"; 229 } 230 const size_t num_direct_interfaces = NumDirectInterfaces(); 231 if (num_direct_interfaces > 0) { 232 os << " interfaces (" << num_direct_interfaces << "):\n"; 233 for (size_t i = 0; i < num_direct_interfaces; ++i) { 234 ObjPtr<Class> interface = GetDirectInterface(self, h_this, i); 235 if (interface == nullptr) { 236 os << StringPrintf(" %2zd: nullptr!\n", i); 237 } else { 238 ObjPtr<ClassLoader> cl = interface->GetClassLoader(); 239 os << StringPrintf(" %2zd: %s (cl=%p)\n", i, PrettyClass(interface).c_str(), cl.Ptr()); 240 } 241 } 242 } 243 if (!IsLoaded()) { 244 os << " class not yet loaded"; 245 } else { 246 // After this point, this may have moved due to GetDirectInterface. 247 os << " vtable (" << h_this->NumVirtualMethods() << " entries, " 248 << (h_super.Get() != nullptr ? h_super->NumVirtualMethods() : 0) << " in super):\n"; 249 for (size_t i = 0; i < NumVirtualMethods(); ++i) { 250 os << StringPrintf(" %2zd: %s\n", i, PrettyMethod( 251 h_this->GetVirtualMethodDuringLinking(i, image_pointer_size)).c_str()); 252 } 253 os << " direct methods (" << h_this->NumDirectMethods() << " entries):\n"; 254 for (size_t i = 0; i < h_this->NumDirectMethods(); ++i) { 255 os << StringPrintf(" %2zd: %s\n", i, PrettyMethod( 256 h_this->GetDirectMethod(i, image_pointer_size)).c_str()); 257 } 258 if (h_this->NumStaticFields() > 0) { 259 os << " static fields (" << h_this->NumStaticFields() << " entries):\n"; 260 if (h_this->IsResolved() || h_this->IsErroneous()) { 261 for (size_t i = 0; i < h_this->NumStaticFields(); ++i) { 262 os << StringPrintf(" %2zd: %s\n", i, PrettyField(h_this->GetStaticField(i)).c_str()); 263 } 264 } else { 265 os << " <not yet available>"; 266 } 267 } 268 if (h_this->NumInstanceFields() > 0) { 269 os << " instance fields (" << h_this->NumInstanceFields() << " entries):\n"; 270 if (h_this->IsResolved() || h_this->IsErroneous()) { 271 for (size_t i = 0; i < h_this->NumInstanceFields(); ++i) { 272 os << StringPrintf(" %2zd: %s\n", i, PrettyField(h_this->GetInstanceField(i)).c_str()); 273 } 274 } else { 275 os << " <not yet available>"; 276 } 277 } 278 } 279} 280 281void Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) { 282 if (kIsDebugBuild && new_reference_offsets != kClassWalkSuper) { 283 // Sanity check that the number of bits set in the reference offset bitmap 284 // agrees with the number of references 285 uint32_t count = 0; 286 for (ObjPtr<Class> c = this; c != nullptr; c = c->GetSuperClass()) { 287 count += c->NumReferenceInstanceFieldsDuringLinking(); 288 } 289 // +1 for the Class in Object. 290 CHECK_EQ(static_cast<uint32_t>(POPCOUNT(new_reference_offsets)) + 1, count); 291 } 292 // Not called within a transaction. 293 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), 294 new_reference_offsets); 295} 296 297bool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) { 298 size_t i = 0; 299 size_t min_length = std::min(descriptor1.size(), descriptor2.size()); 300 while (i < min_length && descriptor1[i] == descriptor2[i]) { 301 ++i; 302 } 303 if (descriptor1.find('/', i) != StringPiece::npos || 304 descriptor2.find('/', i) != StringPiece::npos) { 305 return false; 306 } else { 307 return true; 308 } 309} 310 311bool Class::IsInSamePackage(ObjPtr<Class> that) { 312 ObjPtr<Class> klass1 = this; 313 ObjPtr<Class> klass2 = that; 314 if (klass1 == klass2) { 315 return true; 316 } 317 // Class loaders must match. 318 if (klass1->GetClassLoader() != klass2->GetClassLoader()) { 319 return false; 320 } 321 // Arrays are in the same package when their element classes are. 322 while (klass1->IsArrayClass()) { 323 klass1 = klass1->GetComponentType(); 324 } 325 while (klass2->IsArrayClass()) { 326 klass2 = klass2->GetComponentType(); 327 } 328 // trivial check again for array types 329 if (klass1 == klass2) { 330 return true; 331 } 332 // Compare the package part of the descriptor string. 333 std::string temp1, temp2; 334 return IsInSamePackage(klass1->GetDescriptor(&temp1), klass2->GetDescriptor(&temp2)); 335} 336 337bool Class::IsThrowableClass() { 338 return WellKnownClasses::ToClass(WellKnownClasses::java_lang_Throwable)->IsAssignableFrom(this); 339} 340 341void Class::SetClassLoader(ObjPtr<ClassLoader> new_class_loader) { 342 if (Runtime::Current()->IsActiveTransaction()) { 343 SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader); 344 } else { 345 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader); 346 } 347} 348 349ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, 350 const StringPiece& signature, 351 PointerSize pointer_size) { 352 // Check the current class before checking the interfaces. 353 ArtMethod* method = FindDeclaredVirtualMethod(name, signature, pointer_size); 354 if (method != nullptr) { 355 return method; 356 } 357 358 int32_t iftable_count = GetIfTableCount(); 359 ObjPtr<IfTable> iftable = GetIfTable(); 360 for (int32_t i = 0; i < iftable_count; ++i) { 361 method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature, pointer_size); 362 if (method != nullptr) { 363 return method; 364 } 365 } 366 return nullptr; 367} 368 369ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, 370 const Signature& signature, 371 PointerSize pointer_size) { 372 // Check the current class before checking the interfaces. 373 ArtMethod* method = FindDeclaredVirtualMethod(name, signature, pointer_size); 374 if (method != nullptr) { 375 return method; 376 } 377 378 int32_t iftable_count = GetIfTableCount(); 379 ObjPtr<IfTable> iftable = GetIfTable(); 380 for (int32_t i = 0; i < iftable_count; ++i) { 381 method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature, pointer_size); 382 if (method != nullptr) { 383 return method; 384 } 385 } 386 return nullptr; 387} 388 389ArtMethod* Class::FindInterfaceMethod(ObjPtr<DexCache> dex_cache, 390 uint32_t dex_method_idx, 391 PointerSize pointer_size) { 392 // Check the current class before checking the interfaces. 393 ArtMethod* method = FindDeclaredVirtualMethod(dex_cache, dex_method_idx, pointer_size); 394 if (method != nullptr) { 395 return method; 396 } 397 398 int32_t iftable_count = GetIfTableCount(); 399 ObjPtr<IfTable> iftable = GetIfTable(); 400 for (int32_t i = 0; i < iftable_count; ++i) { 401 method = iftable->GetInterface(i)->FindDeclaredVirtualMethod( 402 dex_cache, dex_method_idx, pointer_size); 403 if (method != nullptr) { 404 return method; 405 } 406 } 407 return nullptr; 408} 409 410ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, 411 const StringPiece& signature, 412 PointerSize pointer_size) { 413 for (auto& method : GetDirectMethods(pointer_size)) { 414 if (name == method.GetName() && method.GetSignature() == signature) { 415 return &method; 416 } 417 } 418 return nullptr; 419} 420 421ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, 422 const Signature& signature, 423 PointerSize pointer_size) { 424 for (auto& method : GetDirectMethods(pointer_size)) { 425 if (name == method.GetName() && signature == method.GetSignature()) { 426 return &method; 427 } 428 } 429 return nullptr; 430} 431 432ArtMethod* Class::FindDeclaredDirectMethod(ObjPtr<DexCache> dex_cache, 433 uint32_t dex_method_idx, 434 PointerSize pointer_size) { 435 if (GetDexCache() == dex_cache) { 436 for (auto& method : GetDirectMethods(pointer_size)) { 437 if (method.GetDexMethodIndex() == dex_method_idx) { 438 return &method; 439 } 440 } 441 } 442 return nullptr; 443} 444 445ArtMethod* Class::FindDirectMethod(const StringPiece& name, 446 const StringPiece& signature, 447 PointerSize pointer_size) { 448 for (ObjPtr<Class> klass = this; klass != nullptr; klass = klass->GetSuperClass()) { 449 ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature, pointer_size); 450 if (method != nullptr) { 451 return method; 452 } 453 } 454 return nullptr; 455} 456 457ArtMethod* Class::FindDirectMethod(const StringPiece& name, 458 const Signature& signature, 459 PointerSize pointer_size) { 460 for (ObjPtr<Class> klass = this; klass != nullptr; klass = klass->GetSuperClass()) { 461 ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature, pointer_size); 462 if (method != nullptr) { 463 return method; 464 } 465 } 466 return nullptr; 467} 468 469ArtMethod* Class::FindDirectMethod(ObjPtr<DexCache> dex_cache, 470 uint32_t dex_method_idx, 471 PointerSize pointer_size) { 472 for (ObjPtr<Class> klass = this; klass != nullptr; klass = klass->GetSuperClass()) { 473 ArtMethod* method = klass->FindDeclaredDirectMethod(dex_cache, dex_method_idx, pointer_size); 474 if (method != nullptr) { 475 return method; 476 } 477 } 478 return nullptr; 479} 480 481ArtMethod* Class::FindDeclaredDirectMethodByName(const StringPiece& name, 482 PointerSize pointer_size) { 483 for (auto& method : GetDirectMethods(pointer_size)) { 484 ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size); 485 if (name == np_method->GetName()) { 486 return &method; 487 } 488 } 489 return nullptr; 490} 491 492// TODO These should maybe be changed to be named FindOwnedVirtualMethod or something similar 493// because they do not only find 'declared' methods and will return copied methods. This behavior is 494// desired and correct but the naming can lead to confusion because in the java language declared 495// excludes interface methods which might be found by this. 496ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, 497 const StringPiece& signature, 498 PointerSize pointer_size) { 499 for (auto& method : GetVirtualMethods(pointer_size)) { 500 ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size); 501 if (name == np_method->GetName() && np_method->GetSignature() == signature) { 502 return &method; 503 } 504 } 505 return nullptr; 506} 507 508ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, 509 const Signature& signature, 510 PointerSize pointer_size) { 511 for (auto& method : GetVirtualMethods(pointer_size)) { 512 ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size); 513 if (name == np_method->GetName() && signature == np_method->GetSignature()) { 514 return &method; 515 } 516 } 517 return nullptr; 518} 519 520ArtMethod* Class::FindDeclaredVirtualMethod(ObjPtr<DexCache> dex_cache, 521 uint32_t dex_method_idx, 522 PointerSize pointer_size) { 523 if (GetDexCache() == dex_cache) { 524 for (auto& method : GetDeclaredVirtualMethods(pointer_size)) { 525 if (method.GetDexMethodIndex() == dex_method_idx) { 526 return &method; 527 } 528 } 529 } 530 return nullptr; 531} 532 533ArtMethod* Class::FindDeclaredVirtualMethodByName(const StringPiece& name, 534 PointerSize pointer_size) { 535 for (auto& method : GetVirtualMethods(pointer_size)) { 536 ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size); 537 if (name == np_method->GetName()) { 538 return &method; 539 } 540 } 541 return nullptr; 542} 543 544ArtMethod* Class::FindVirtualMethod(const StringPiece& name, 545 const StringPiece& signature, 546 PointerSize pointer_size) { 547 for (ObjPtr<Class> klass = this; klass != nullptr; klass = klass->GetSuperClass()) { 548 ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature, pointer_size); 549 if (method != nullptr) { 550 return method; 551 } 552 } 553 return nullptr; 554} 555 556ArtMethod* Class::FindVirtualMethod(const StringPiece& name, 557 const Signature& signature, 558 PointerSize pointer_size) { 559 for (ObjPtr<Class> klass = this; klass != nullptr; klass = klass->GetSuperClass()) { 560 ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature, pointer_size); 561 if (method != nullptr) { 562 return method; 563 } 564 } 565 return nullptr; 566} 567 568ArtMethod* Class::FindVirtualMethod(ObjPtr<DexCache> dex_cache, 569 uint32_t dex_method_idx, 570 PointerSize pointer_size) { 571 for (ObjPtr<Class> klass = this; klass != nullptr; klass = klass->GetSuperClass()) { 572 ArtMethod* method = klass->FindDeclaredVirtualMethod(dex_cache, dex_method_idx, pointer_size); 573 if (method != nullptr) { 574 return method; 575 } 576 } 577 return nullptr; 578} 579 580ArtMethod* Class::FindVirtualMethodForInterfaceSuper(ArtMethod* method, PointerSize pointer_size) { 581 DCHECK(method->GetDeclaringClass()->IsInterface()); 582 DCHECK(IsInterface()) << "Should only be called on a interface class"; 583 // Check if we have one defined on this interface first. This includes searching copied ones to 584 // get any conflict methods. Conflict methods are copied into each subtype from the supertype. We 585 // don't do any indirect method checks here. 586 for (ArtMethod& iface_method : GetVirtualMethods(pointer_size)) { 587 if (method->HasSameNameAndSignature(&iface_method)) { 588 return &iface_method; 589 } 590 } 591 592 std::vector<ArtMethod*> abstract_methods; 593 // Search through the IFTable for a working version. We don't need to check for conflicts 594 // because if there was one it would appear in this classes virtual_methods_ above. 595 596 Thread* self = Thread::Current(); 597 StackHandleScope<2> hs(self); 598 MutableHandle<IfTable> iftable(hs.NewHandle(GetIfTable())); 599 MutableHandle<Class> iface(hs.NewHandle<Class>(nullptr)); 600 size_t iftable_count = GetIfTableCount(); 601 // Find the method. We don't need to check for conflicts because they would have been in the 602 // copied virtuals of this interface. Order matters, traverse in reverse topological order; most 603 // subtypiest interfaces get visited first. 604 for (size_t k = iftable_count; k != 0;) { 605 k--; 606 DCHECK_LT(k, iftable->Count()); 607 iface.Assign(iftable->GetInterface(k)); 608 // Iterate through every declared method on this interface. Each direct method's name/signature 609 // is unique so the order of the inner loop doesn't matter. 610 for (auto& method_iter : iface->GetDeclaredVirtualMethods(pointer_size)) { 611 ArtMethod* current_method = &method_iter; 612 if (current_method->HasSameNameAndSignature(method)) { 613 if (current_method->IsDefault()) { 614 // Handle JLS soft errors, a default method from another superinterface tree can 615 // "override" an abstract method(s) from another superinterface tree(s). To do this, 616 // ignore any [default] method which are dominated by the abstract methods we've seen so 617 // far. Check if overridden by any in abstract_methods. We do not need to check for 618 // default_conflicts because we would hit those before we get to this loop. 619 bool overridden = false; 620 for (ArtMethod* possible_override : abstract_methods) { 621 DCHECK(possible_override->HasSameNameAndSignature(current_method)); 622 if (iface->IsAssignableFrom(possible_override->GetDeclaringClass())) { 623 overridden = true; 624 break; 625 } 626 } 627 if (!overridden) { 628 return current_method; 629 } 630 } else { 631 // Is not default. 632 // This might override another default method. Just stash it for now. 633 abstract_methods.push_back(current_method); 634 } 635 } 636 } 637 } 638 // If we reach here we either never found any declaration of the method (in which case 639 // 'abstract_methods' is empty or we found no non-overriden default methods in which case 640 // 'abstract_methods' contains a number of abstract implementations of the methods. We choose one 641 // of these arbitrarily. 642 return abstract_methods.empty() ? nullptr : abstract_methods[0]; 643} 644 645ArtMethod* Class::FindClassInitializer(PointerSize pointer_size) { 646 for (ArtMethod& method : GetDirectMethods(pointer_size)) { 647 if (method.IsClassInitializer()) { 648 DCHECK_STREQ(method.GetName(), "<clinit>"); 649 DCHECK_STREQ(method.GetSignature().ToString().c_str(), "()V"); 650 return &method; 651 } 652 } 653 return nullptr; 654} 655 656// Custom binary search to avoid double comparisons from std::binary_search. 657static ArtField* FindFieldByNameAndType(LengthPrefixedArray<ArtField>* fields, 658 const StringPiece& name, 659 const StringPiece& type) 660 REQUIRES_SHARED(Locks::mutator_lock_) { 661 if (fields == nullptr) { 662 return nullptr; 663 } 664 size_t low = 0; 665 size_t high = fields->size(); 666 ArtField* ret = nullptr; 667 while (low < high) { 668 size_t mid = (low + high) / 2; 669 ArtField& field = fields->At(mid); 670 // Fields are sorted by class, then name, then type descriptor. This is verified in dex file 671 // verifier. There can be multiple fields with the same in the same class name due to proguard. 672 int result = StringPiece(field.GetName()).Compare(name); 673 if (result == 0) { 674 result = StringPiece(field.GetTypeDescriptor()).Compare(type); 675 } 676 if (result < 0) { 677 low = mid + 1; 678 } else if (result > 0) { 679 high = mid; 680 } else { 681 ret = &field; 682 break; 683 } 684 } 685 if (kIsDebugBuild) { 686 ArtField* found = nullptr; 687 for (ArtField& field : MakeIterationRangeFromLengthPrefixedArray(fields)) { 688 if (name == field.GetName() && type == field.GetTypeDescriptor()) { 689 found = &field; 690 break; 691 } 692 } 693 CHECK_EQ(found, ret) << "Found " << PrettyField(found) << " vs " << PrettyField(ret); 694 } 695 return ret; 696} 697 698ArtField* Class::FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) { 699 // Binary search by name. Interfaces are not relevant because they can't contain instance fields. 700 return FindFieldByNameAndType(GetIFieldsPtr(), name, type); 701} 702 703ArtField* Class::FindDeclaredInstanceField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx) { 704 if (GetDexCache() == dex_cache) { 705 for (ArtField& field : GetIFields()) { 706 if (field.GetDexFieldIndex() == dex_field_idx) { 707 return &field; 708 } 709 } 710 } 711 return nullptr; 712} 713 714ArtField* Class::FindInstanceField(const StringPiece& name, const StringPiece& type) { 715 // Is the field in this class, or any of its superclasses? 716 // Interfaces are not relevant because they can't contain instance fields. 717 for (ObjPtr<Class> c = this; c != nullptr; c = c->GetSuperClass()) { 718 ArtField* f = c->FindDeclaredInstanceField(name, type); 719 if (f != nullptr) { 720 return f; 721 } 722 } 723 return nullptr; 724} 725 726ArtField* Class::FindInstanceField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx) { 727 // Is the field in this class, or any of its superclasses? 728 // Interfaces are not relevant because they can't contain instance fields. 729 for (ObjPtr<Class> c = this; c != nullptr; c = c->GetSuperClass()) { 730 ArtField* f = c->FindDeclaredInstanceField(dex_cache, dex_field_idx); 731 if (f != nullptr) { 732 return f; 733 } 734 } 735 return nullptr; 736} 737 738ArtField* Class::FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) { 739 DCHECK(type != nullptr); 740 return FindFieldByNameAndType(GetSFieldsPtr(), name, type); 741} 742 743ArtField* Class::FindDeclaredStaticField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx) { 744 if (dex_cache == GetDexCache()) { 745 for (ArtField& field : GetSFields()) { 746 if (field.GetDexFieldIndex() == dex_field_idx) { 747 return &field; 748 } 749 } 750 } 751 return nullptr; 752} 753 754ArtField* Class::FindStaticField(Thread* self, 755 Handle<Class> klass, 756 const StringPiece& name, 757 const StringPiece& type) { 758 // Is the field in this class (or its interfaces), or any of its 759 // superclasses (or their interfaces)? 760 for (ObjPtr<Class> k = klass.Get(); k != nullptr; k = k->GetSuperClass()) { 761 // Is the field in this class? 762 ArtField* f = k->FindDeclaredStaticField(name, type); 763 if (f != nullptr) { 764 return f; 765 } 766 // Wrap k incase it moves during GetDirectInterface. 767 StackHandleScope<1> hs(self); 768 HandleWrapperObjPtr<Class> h_k(hs.NewHandleWrapper(&k)); 769 // Is this field in any of this class' interfaces? 770 for (uint32_t i = 0; i < h_k->NumDirectInterfaces(); ++i) { 771 StackHandleScope<1> hs2(self); 772 Handle<Class> interface(hs2.NewHandle(GetDirectInterface(self, h_k, i))); 773 f = FindStaticField(self, interface, name, type); 774 if (f != nullptr) { 775 return f; 776 } 777 } 778 } 779 return nullptr; 780} 781 782ArtField* Class::FindStaticField(Thread* self, 783 ObjPtr<Class> klass, 784 ObjPtr<DexCache> dex_cache, 785 uint32_t dex_field_idx) { 786 for (ObjPtr<Class> k = klass; k != nullptr; k = k->GetSuperClass()) { 787 // Is the field in this class? 788 ArtField* f = k->FindDeclaredStaticField(dex_cache, dex_field_idx); 789 if (f != nullptr) { 790 return f; 791 } 792 // Though GetDirectInterface() should not cause thread suspension when called 793 // from here, it takes a Handle as an argument, so we need to wrap `k`. 794 ScopedAssertNoThreadSuspension ants(__FUNCTION__); 795 StackHandleScope<1> hs(self); 796 Handle<Class> h_k(hs.NewHandle(k)); 797 // Is this field in any of this class' interfaces? 798 for (uint32_t i = 0; i < h_k->NumDirectInterfaces(); ++i) { 799 ObjPtr<Class> interface = GetDirectInterface(self, h_k, i); 800 f = FindStaticField(self, interface, dex_cache, dex_field_idx); 801 if (f != nullptr) { 802 return f; 803 } 804 } 805 } 806 return nullptr; 807} 808 809ArtField* Class::FindField(Thread* self, 810 Handle<Class> klass, 811 const StringPiece& name, 812 const StringPiece& type) { 813 // Find a field using the JLS field resolution order 814 for (ObjPtr<Class> k = klass.Get(); k != nullptr; k = k->GetSuperClass()) { 815 // Is the field in this class? 816 ArtField* f = k->FindDeclaredInstanceField(name, type); 817 if (f != nullptr) { 818 return f; 819 } 820 f = k->FindDeclaredStaticField(name, type); 821 if (f != nullptr) { 822 return f; 823 } 824 // Is this field in any of this class' interfaces? 825 StackHandleScope<1> hs(self); 826 HandleWrapperObjPtr<Class> h_k(hs.NewHandleWrapper(&k)); 827 for (uint32_t i = 0; i < h_k->NumDirectInterfaces(); ++i) { 828 StackHandleScope<1> hs2(self); 829 Handle<Class> interface(hs2.NewHandle(GetDirectInterface(self, h_k, i))); 830 f = interface->FindStaticField(self, interface, name, type); 831 if (f != nullptr) { 832 return f; 833 } 834 } 835 } 836 return nullptr; 837} 838 839void Class::SetSkipAccessChecksFlagOnAllMethods(PointerSize pointer_size) { 840 DCHECK(IsVerified()); 841 for (auto& m : GetMethods(pointer_size)) { 842 if (!m.IsNative() && m.IsInvokable()) { 843 m.SetSkipAccessChecks(); 844 } 845 } 846} 847 848const char* Class::GetDescriptor(std::string* storage) { 849 if (IsPrimitive()) { 850 return Primitive::Descriptor(GetPrimitiveType()); 851 } else if (IsArrayClass()) { 852 return GetArrayDescriptor(storage); 853 } else if (IsProxyClass()) { 854 *storage = Runtime::Current()->GetClassLinker()->GetDescriptorForProxy(this); 855 return storage->c_str(); 856 } else { 857 const DexFile& dex_file = GetDexFile(); 858 const DexFile::TypeId& type_id = dex_file.GetTypeId(GetClassDef()->class_idx_); 859 return dex_file.GetTypeDescriptor(type_id); 860 } 861} 862 863const char* Class::GetArrayDescriptor(std::string* storage) { 864 std::string temp; 865 const char* elem_desc = GetComponentType()->GetDescriptor(&temp); 866 *storage = "["; 867 *storage += elem_desc; 868 return storage->c_str(); 869} 870 871const DexFile::ClassDef* Class::GetClassDef() { 872 uint16_t class_def_idx = GetDexClassDefIndex(); 873 if (class_def_idx == DexFile::kDexNoIndex16) { 874 return nullptr; 875 } 876 return &GetDexFile().GetClassDef(class_def_idx); 877} 878 879uint16_t Class::GetDirectInterfaceTypeIdx(uint32_t idx) { 880 DCHECK(!IsPrimitive()); 881 DCHECK(!IsArrayClass()); 882 return GetInterfaceTypeList()->GetTypeItem(idx).type_idx_; 883} 884 885ObjPtr<Class> Class::GetDirectInterface(Thread* self, 886 Handle<Class> klass, 887 uint32_t idx) { 888 DCHECK(klass.Get() != nullptr); 889 DCHECK(!klass->IsPrimitive()); 890 if (klass->IsArrayClass()) { 891 ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); 892 if (idx == 0) { 893 return class_linker->FindSystemClass(self, "Ljava/lang/Cloneable;"); 894 } else { 895 DCHECK_EQ(1U, idx); 896 return class_linker->FindSystemClass(self, "Ljava/io/Serializable;"); 897 } 898 } else if (klass->IsProxyClass()) { 899 ObjPtr<ObjectArray<Class>> interfaces = klass.Get()->GetInterfaces(); 900 DCHECK(interfaces != nullptr); 901 return interfaces->Get(idx); 902 } else { 903 uint16_t type_idx = klass->GetDirectInterfaceTypeIdx(idx); 904 ObjPtr<Class> interface = klass->GetDexCache()->GetResolvedType(type_idx); 905 if (interface == nullptr) { 906 interface = Runtime::Current()->GetClassLinker()->ResolveType(klass->GetDexFile(), type_idx, 907 klass.Get()); 908 CHECK(interface != nullptr || self->IsExceptionPending()); 909 } 910 return interface; 911 } 912} 913 914ObjPtr<Class> Class::GetCommonSuperClass(Handle<Class> klass) { 915 DCHECK(klass.Get() != nullptr); 916 DCHECK(!klass->IsInterface()); 917 DCHECK(!IsInterface()); 918 ObjPtr<Class> common_super_class = this; 919 while (!common_super_class->IsAssignableFrom(klass.Get())) { 920 ObjPtr<Class> old_common = common_super_class; 921 common_super_class = old_common->GetSuperClass(); 922 DCHECK(common_super_class != nullptr) << PrettyClass(old_common); 923 } 924 return common_super_class; 925} 926 927const char* Class::GetSourceFile() { 928 const DexFile& dex_file = GetDexFile(); 929 const DexFile::ClassDef* dex_class_def = GetClassDef(); 930 if (dex_class_def == nullptr) { 931 // Generated classes have no class def. 932 return nullptr; 933 } 934 return dex_file.GetSourceFile(*dex_class_def); 935} 936 937std::string Class::GetLocation() { 938 ObjPtr<DexCache> dex_cache = GetDexCache(); 939 if (dex_cache != nullptr && !IsProxyClass()) { 940 return dex_cache->GetLocation()->ToModifiedUtf8(); 941 } 942 // Arrays and proxies are generated and have no corresponding dex file location. 943 return "generated class"; 944} 945 946const DexFile::TypeList* Class::GetInterfaceTypeList() { 947 const DexFile::ClassDef* class_def = GetClassDef(); 948 if (class_def == nullptr) { 949 return nullptr; 950 } 951 return GetDexFile().GetInterfacesList(*class_def); 952} 953 954void Class::PopulateEmbeddedVTable(PointerSize pointer_size) { 955 PointerArray* table = GetVTableDuringLinking(); 956 CHECK(table != nullptr) << PrettyClass(this); 957 const size_t table_length = table->GetLength(); 958 SetEmbeddedVTableLength(table_length); 959 for (size_t i = 0; i < table_length; i++) { 960 SetEmbeddedVTableEntry(i, table->GetElementPtrSize<ArtMethod*>(i, pointer_size), pointer_size); 961 } 962 // Keep java.lang.Object class's vtable around for since it's easier 963 // to be reused by array classes during their linking. 964 if (!IsObjectClass()) { 965 SetVTable(nullptr); 966 } 967} 968 969class ReadBarrierOnNativeRootsVisitor { 970 public: 971 void operator()(ObjPtr<Object> obj ATTRIBUTE_UNUSED, 972 MemberOffset offset ATTRIBUTE_UNUSED, 973 bool is_static ATTRIBUTE_UNUSED) const {} 974 975 void VisitRootIfNonNull(CompressedReference<Object>* root) const 976 REQUIRES_SHARED(Locks::mutator_lock_) { 977 if (!root->IsNull()) { 978 VisitRoot(root); 979 } 980 } 981 982 void VisitRoot(CompressedReference<Object>* root) const 983 REQUIRES_SHARED(Locks::mutator_lock_) { 984 ObjPtr<Object> old_ref = root->AsMirrorPtr(); 985 ObjPtr<Object> new_ref = ReadBarrier::BarrierForRoot(root); 986 if (old_ref != new_ref) { 987 // Update the field atomically. This may fail if mutator updates before us, but it's ok. 988 auto* atomic_root = 989 reinterpret_cast<Atomic<CompressedReference<Object>>*>(root); 990 atomic_root->CompareExchangeStrongSequentiallyConsistent( 991 CompressedReference<Object>::FromMirrorPtr(old_ref.Ptr()), 992 CompressedReference<Object>::FromMirrorPtr(new_ref.Ptr())); 993 } 994 } 995}; 996 997// The pre-fence visitor for Class::CopyOf(). 998class CopyClassVisitor { 999 public: 1000 CopyClassVisitor(Thread* self, 1001 Handle<Class>* orig, 1002 size_t new_length, 1003 size_t copy_bytes, 1004 ImTable* imt, 1005 PointerSize pointer_size) 1006 : self_(self), orig_(orig), new_length_(new_length), 1007 copy_bytes_(copy_bytes), imt_(imt), pointer_size_(pointer_size) { 1008 } 1009 1010 void operator()(ObjPtr<Object> obj, size_t usable_size ATTRIBUTE_UNUSED) const 1011 REQUIRES_SHARED(Locks::mutator_lock_) { 1012 StackHandleScope<1> hs(self_); 1013 Handle<mirror::Class> h_new_class_obj(hs.NewHandle(obj->AsClass())); 1014 Object::CopyObject(h_new_class_obj.Get(), orig_->Get(), copy_bytes_); 1015 Class::SetStatus(h_new_class_obj, Class::kStatusResolving, self_); 1016 h_new_class_obj->PopulateEmbeddedVTable(pointer_size_); 1017 h_new_class_obj->SetImt(imt_, pointer_size_); 1018 h_new_class_obj->SetClassSize(new_length_); 1019 // Visit all of the references to make sure there is no from space references in the native 1020 // roots. 1021 ObjPtr<Object>(h_new_class_obj.Get())->VisitReferences( 1022 ReadBarrierOnNativeRootsVisitor(), VoidFunctor()); 1023 } 1024 1025 private: 1026 Thread* const self_; 1027 Handle<Class>* const orig_; 1028 const size_t new_length_; 1029 const size_t copy_bytes_; 1030 ImTable* imt_; 1031 const PointerSize pointer_size_; 1032 DISALLOW_COPY_AND_ASSIGN(CopyClassVisitor); 1033}; 1034 1035Class* Class::CopyOf(Thread* self, int32_t new_length, ImTable* imt, PointerSize pointer_size) { 1036 DCHECK_GE(new_length, static_cast<int32_t>(sizeof(Class))); 1037 // We may get copied by a compacting GC. 1038 StackHandleScope<1> hs(self); 1039 Handle<Class> h_this(hs.NewHandle(this)); 1040 gc::Heap* heap = Runtime::Current()->GetHeap(); 1041 // The num_bytes (3rd param) is sizeof(Class) as opposed to SizeOf() 1042 // to skip copying the tail part that we will overwrite here. 1043 CopyClassVisitor visitor(self, &h_this, new_length, sizeof(Class), imt, pointer_size); 1044 ObjPtr<Object> new_class = kMovingClasses ? 1045 heap->AllocObject<true>(self, java_lang_Class_.Read(), new_length, visitor) : 1046 heap->AllocNonMovableObject<true>(self, java_lang_Class_.Read(), new_length, visitor); 1047 if (UNLIKELY(new_class == nullptr)) { 1048 self->AssertPendingOOMException(); 1049 return nullptr; 1050 } 1051 return new_class->AsClass(); 1052} 1053 1054bool Class::ProxyDescriptorEquals(const char* match) { 1055 DCHECK(IsProxyClass()); 1056 return Runtime::Current()->GetClassLinker()->GetDescriptorForProxy(this) == match; 1057} 1058 1059// TODO: Move this to java_lang_Class.cc? 1060ArtMethod* Class::GetDeclaredConstructor( 1061 Thread* self, Handle<ObjectArray<Class>> args, PointerSize pointer_size) { 1062 for (auto& m : GetDirectMethods(pointer_size)) { 1063 // Skip <clinit> which is a static constructor, as well as non constructors. 1064 if (m.IsStatic() || !m.IsConstructor()) { 1065 continue; 1066 } 1067 // May cause thread suspension and exceptions. 1068 if (m.GetInterfaceMethodIfProxy(kRuntimePointerSize)->EqualParameters(args)) { 1069 return &m; 1070 } 1071 if (UNLIKELY(self->IsExceptionPending())) { 1072 return nullptr; 1073 } 1074 } 1075 return nullptr; 1076} 1077 1078uint32_t Class::Depth() { 1079 uint32_t depth = 0; 1080 for (ObjPtr<Class> klass = this; klass->GetSuperClass() != nullptr; klass = klass->GetSuperClass()) { 1081 depth++; 1082 } 1083 return depth; 1084} 1085 1086uint32_t Class::FindTypeIndexInOtherDexFile(const DexFile& dex_file) { 1087 std::string temp; 1088 const DexFile::TypeId* type_id = dex_file.FindTypeId(GetDescriptor(&temp)); 1089 return (type_id == nullptr) ? DexFile::kDexNoIndex : dex_file.GetIndexForTypeId(*type_id); 1090} 1091 1092template <PointerSize kPointerSize, bool kTransactionActive> 1093ObjPtr<Method> Class::GetDeclaredMethodInternal( 1094 Thread* self, 1095 ObjPtr<Class> klass, 1096 ObjPtr<String> name, 1097 ObjPtr<ObjectArray<Class>> args) { 1098 // Covariant return types permit the class to define multiple 1099 // methods with the same name and parameter types. Prefer to 1100 // return a non-synthetic method in such situations. We may 1101 // still return a synthetic method to handle situations like 1102 // escalated visibility. We never return miranda methods that 1103 // were synthesized by the runtime. 1104 constexpr uint32_t kSkipModifiers = kAccMiranda | kAccSynthetic; 1105 StackHandleScope<3> hs(self); 1106 auto h_method_name = hs.NewHandle(name); 1107 if (UNLIKELY(h_method_name.Get() == nullptr)) { 1108 ThrowNullPointerException("name == null"); 1109 return nullptr; 1110 } 1111 auto h_args = hs.NewHandle(args); 1112 Handle<Class> h_klass = hs.NewHandle(klass); 1113 ArtMethod* result = nullptr; 1114 for (auto& m : h_klass->GetDeclaredVirtualMethods(kPointerSize)) { 1115 auto* np_method = m.GetInterfaceMethodIfProxy(kPointerSize); 1116 // May cause thread suspension. 1117 ObjPtr<String> np_name = np_method->GetNameAsString(self); 1118 if (!np_name->Equals(h_method_name.Get()) || !np_method->EqualParameters(h_args)) { 1119 if (UNLIKELY(self->IsExceptionPending())) { 1120 return nullptr; 1121 } 1122 continue; 1123 } 1124 auto modifiers = m.GetAccessFlags(); 1125 if ((modifiers & kSkipModifiers) == 0) { 1126 return Method::CreateFromArtMethod<kPointerSize, kTransactionActive>(self, &m); 1127 } 1128 if ((modifiers & kAccMiranda) == 0) { 1129 result = &m; // Remember as potential result if it's not a miranda method. 1130 } 1131 } 1132 if (result == nullptr) { 1133 for (auto& m : h_klass->GetDirectMethods(kPointerSize)) { 1134 auto modifiers = m.GetAccessFlags(); 1135 if ((modifiers & kAccConstructor) != 0) { 1136 continue; 1137 } 1138 auto* np_method = m.GetInterfaceMethodIfProxy(kPointerSize); 1139 // May cause thread suspension. 1140 ObjPtr<String> np_name = np_method->GetNameAsString(self); 1141 if (np_name == nullptr) { 1142 self->AssertPendingException(); 1143 return nullptr; 1144 } 1145 if (!np_name->Equals(h_method_name.Get()) || !np_method->EqualParameters(h_args)) { 1146 if (UNLIKELY(self->IsExceptionPending())) { 1147 return nullptr; 1148 } 1149 continue; 1150 } 1151 if ((modifiers & kSkipModifiers) == 0) { 1152 return Method::CreateFromArtMethod<kPointerSize, kTransactionActive>(self, &m); 1153 } 1154 // Direct methods cannot be miranda methods, so this potential result must be synthetic. 1155 result = &m; 1156 } 1157 } 1158 return result != nullptr 1159 ? Method::CreateFromArtMethod<kPointerSize, kTransactionActive>(self, result) 1160 : nullptr; 1161} 1162 1163template 1164ObjPtr<Method> Class::GetDeclaredMethodInternal<PointerSize::k32, false>( 1165 Thread* self, 1166 ObjPtr<Class> klass, 1167 ObjPtr<String> name, 1168 ObjPtr<ObjectArray<Class>> args); 1169template 1170ObjPtr<Method> Class::GetDeclaredMethodInternal<PointerSize::k32, true>( 1171 Thread* self, 1172 ObjPtr<Class> klass, 1173 ObjPtr<String> name, 1174 ObjPtr<ObjectArray<Class>> args); 1175template 1176ObjPtr<Method> Class::GetDeclaredMethodInternal<PointerSize::k64, false>( 1177 Thread* self, 1178 ObjPtr<Class> klass, 1179 ObjPtr<String> name, 1180 ObjPtr<ObjectArray<Class>> args); 1181template 1182ObjPtr<Method> Class::GetDeclaredMethodInternal<PointerSize::k64, true>( 1183 Thread* self, 1184 ObjPtr<Class> klass, 1185 ObjPtr<String> name, 1186 ObjPtr<ObjectArray<Class>> args); 1187 1188template <PointerSize kPointerSize, bool kTransactionActive> 1189ObjPtr<Constructor> Class::GetDeclaredConstructorInternal( 1190 Thread* self, 1191 ObjPtr<Class> klass, 1192 ObjPtr<ObjectArray<Class>> args) { 1193 StackHandleScope<1> hs(self); 1194 ArtMethod* result = klass->GetDeclaredConstructor(self, hs.NewHandle(args), kPointerSize); 1195 return result != nullptr 1196 ? Constructor::CreateFromArtMethod<kPointerSize, kTransactionActive>(self, result) 1197 : nullptr; 1198} 1199 1200// Constructor::CreateFromArtMethod<kTransactionActive>(self, result) 1201 1202template 1203ObjPtr<Constructor> Class::GetDeclaredConstructorInternal<PointerSize::k32, false>( 1204 Thread* self, 1205 ObjPtr<Class> klass, 1206 ObjPtr<ObjectArray<Class>> args); 1207template 1208ObjPtr<Constructor> Class::GetDeclaredConstructorInternal<PointerSize::k32, true>( 1209 Thread* self, 1210 ObjPtr<Class> klass, 1211 ObjPtr<ObjectArray<Class>> args); 1212template 1213ObjPtr<Constructor> Class::GetDeclaredConstructorInternal<PointerSize::k64, false>( 1214 Thread* self, 1215 ObjPtr<Class> klass, 1216 ObjPtr<ObjectArray<Class>> args); 1217template 1218ObjPtr<Constructor> Class::GetDeclaredConstructorInternal<PointerSize::k64, true>( 1219 Thread* self, 1220 ObjPtr<Class> klass, 1221 ObjPtr<ObjectArray<Class>> args); 1222 1223int32_t Class::GetInnerClassFlags(Handle<Class> h_this, int32_t default_value) { 1224 if (h_this->IsProxyClass() || h_this->GetDexCache() == nullptr) { 1225 return default_value; 1226 } 1227 uint32_t flags; 1228 if (!annotations::GetInnerClassFlags(h_this, &flags)) { 1229 return default_value; 1230 } 1231 return flags; 1232} 1233 1234void Class::SetObjectSizeAllocFastPath(uint32_t new_object_size) { 1235 if (Runtime::Current()->IsActiveTransaction()) { 1236 SetField32Volatile<true>(ObjectSizeAllocFastPathOffset(), new_object_size); 1237 } else { 1238 SetField32Volatile<false>(ObjectSizeAllocFastPathOffset(), new_object_size); 1239 } 1240} 1241 1242} // namespace mirror 1243} // namespace art 1244