Clean up Class::GetDirectInterface().
Fetch array interfaces from the `IfTable`. This removes the
only use of the `Thread* self` argument, so we can remove
that argument. We also make the function non-static to avoid
the explicit `klass` argument. Similarly clean up arguments
of `Class::FindClass()` and `Class::FindStaticClass()`.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 181943478
Change-Id: Id639b675b4eb331a777cf318eb61bd19e05de4f0
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 50b5357..0eeda74 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -897,15 +897,11 @@
object_array_class->GetIfTable()->SetInterface(0, java_lang_Cloneable.Get());
object_array_class->GetIfTable()->SetInterface(1, java_io_Serializable.Get());
- // Check Class[] and Object[]'s interfaces. GetDirectInterface may cause thread suspension.
- CHECK_EQ(java_lang_Cloneable.Get(),
- mirror::Class::GetDirectInterface(self, class_array_class.Get(), 0));
- CHECK_EQ(java_io_Serializable.Get(),
- mirror::Class::GetDirectInterface(self, class_array_class.Get(), 1));
- CHECK_EQ(java_lang_Cloneable.Get(),
- mirror::Class::GetDirectInterface(self, object_array_class.Get(), 0));
- CHECK_EQ(java_io_Serializable.Get(),
- mirror::Class::GetDirectInterface(self, object_array_class.Get(), 1));
+ // Check Class[] and Object[]'s interfaces.
+ CHECK_EQ(java_lang_Cloneable.Get(), class_array_class->GetDirectInterface(0));
+ CHECK_EQ(java_io_Serializable.Get(), class_array_class->GetDirectInterface(1));
+ CHECK_EQ(java_lang_Cloneable.Get(), object_array_class->GetDirectInterface(0));
+ CHECK_EQ(java_io_Serializable.Get(), object_array_class->GetDirectInterface(1));
CHECK_EQ(object_array_string.Get(),
FindSystemClass(self, GetClassRootDescriptor(ClassRoot::kJavaLangStringArrayClass)));
@@ -1859,10 +1855,9 @@
return true;
};
class_table->Visit(verify_direct_interfaces_in_table);
- Thread* self = Thread::Current();
for (ObjPtr<mirror::Class> klass : classes) {
for (uint32_t i = 0, num = klass->NumDirectInterfaces(); i != num; ++i) {
- CHECK(klass->GetDirectInterface(self, klass, i) != nullptr)
+ CHECK(klass->GetDirectInterface(i) != nullptr)
<< klass->PrettyDescriptor() << " iface #" << i;
}
}
@@ -5401,7 +5396,7 @@
StackHandleScope<1> hs_iface(self);
MutableHandle<mirror::Class> handle_scope_iface(hs_iface.NewHandle<mirror::Class>(nullptr));
for (size_t i = 0; i < num_direct_interfaces; i++) {
- handle_scope_iface.Assign(mirror::Class::GetDirectInterface(self, klass.Get(), i));
+ handle_scope_iface.Assign(klass->GetDirectInterface(i));
CHECK(handle_scope_iface != nullptr) << klass->PrettyDescriptor() << " iface #" << i;
CHECK(handle_scope_iface->IsInterface());
if (handle_scope_iface->HasBeenRecursivelyInitialized()) {
@@ -5554,7 +5549,7 @@
MutableHandle<mirror::Class> handle_super_iface(hs.NewHandle<mirror::Class>(nullptr));
// First we initialize all of iface's super-interfaces recursively.
for (size_t i = 0; i < num_direct_ifaces; i++) {
- ObjPtr<mirror::Class> super_iface = mirror::Class::GetDirectInterface(self, iface.Get(), i);
+ ObjPtr<mirror::Class> super_iface = iface->GetDirectInterface(i);
CHECK(super_iface != nullptr) << iface->PrettyDescriptor() << " iface #" << i;
if (!super_iface->HasBeenRecursivelyInitialized()) {
// Recursive step
@@ -7185,8 +7180,7 @@
// super_ifcount entries filled in with the transitive closure of the interfaces of the superclass.
// The other entries are uninitialized. We will fill in the remaining entries in this function. The
// iftable must be large enough to hold all interfaces without changing its size.
-static size_t FillIfTable(Thread* self,
- ObjPtr<mirror::Class> klass,
+static size_t FillIfTable(ObjPtr<mirror::Class> klass,
ObjPtr<mirror::ObjectArray<mirror::Class>> interfaces,
ObjPtr<mirror::IfTable> iftable,
size_t super_ifcount,
@@ -7207,9 +7201,8 @@
size_t filled_ifcount = super_ifcount;
const bool have_interfaces = interfaces != nullptr;
for (size_t i = 0; i != num_interfaces; ++i) {
- ObjPtr<mirror::Class> interface = have_interfaces
- ? interfaces->Get(i)
- : mirror::Class::GetDirectInterface(self, klass, i);
+ ObjPtr<mirror::Class> interface =
+ have_interfaces ? interfaces->Get(i) : klass->GetDirectInterface(i);
// Let us call the first filled_ifcount elements of iftable the current-iface-list.
// At this point in the loop current-iface-list has the invariant that:
@@ -7301,9 +7294,8 @@
size_t ifcount = super_ifcount + num_interfaces;
// Check that every class being implemented is an interface.
for (size_t i = 0; i < num_interfaces; i++) {
- ObjPtr<mirror::Class> interface = have_interfaces
- ? interfaces->GetWithoutChecks(i)
- : mirror::Class::GetDirectInterface(self, klass.Get(), i);
+ ObjPtr<mirror::Class> interface =
+ have_interfaces ? interfaces->GetWithoutChecks(i) : klass->GetDirectInterface(i);
DCHECK(interface != nullptr);
if (UNLIKELY(!interface->IsInterface())) {
std::string temp;
@@ -7335,8 +7327,8 @@
// doesn't really do anything.
self->AllowThreadSuspension();
- const size_t new_ifcount = FillIfTable(
- self, klass.Get(), interfaces.Get(), iftable.Get(), super_ifcount, num_interfaces);
+ const size_t new_ifcount =
+ FillIfTable(klass.Get(), interfaces.Get(), iftable.Get(), super_ifcount, num_interfaces);
self->AllowThreadSuspension();
@@ -9313,18 +9305,15 @@
ObjPtr<mirror::ClassLoader> class_loader,
uint32_t field_idx,
bool is_static) {
- ArtField* resolved = nullptr;
- Thread* self = is_static ? Thread::Current() : nullptr;
- const DexFile& dex_file = *dex_cache->GetDexFile();
-
- resolved = is_static ? mirror::Class::FindStaticField(self, klass, dex_cache, field_idx)
- : klass->FindInstanceField(dex_cache, field_idx);
+ ArtField* resolved = is_static ? klass->FindStaticField(dex_cache, field_idx)
+ : klass->FindInstanceField(dex_cache, field_idx);
if (resolved == nullptr) {
+ const DexFile& dex_file = *dex_cache->GetDexFile();
const dex::FieldId& field_id = dex_file.GetFieldId(field_idx);
const char* name = dex_file.GetFieldName(field_id);
const char* type = dex_file.GetFieldTypeDescriptor(field_id);
- resolved = is_static ? mirror::Class::FindStaticField(self, klass, name, type)
+ resolved = is_static ? klass->FindStaticField(name, type)
: klass->FindInstanceField(name, type);
}
@@ -9346,8 +9335,7 @@
ObjPtr<mirror::DexCache> dex_cache,
ObjPtr<mirror::ClassLoader> class_loader,
uint32_t field_idx) {
- Thread* self = Thread::Current();
- ArtField* resolved = mirror::Class::FindField(self, klass, dex_cache, field_idx);
+ ArtField* resolved = klass->FindField(dex_cache, field_idx);
if (resolved != nullptr &&
hiddenapi::ShouldDenyAccessToMember(resolved,