Move mirror::Class to use ObjPtr
Leave the return types as non ObjPtr for now. Fixed moving GC bugs
in tests.
Test: test-art-host
Bug: 31113334
Change-Id: I5da1b5ac55dfbc5cc97a64be2c870ba9f512d9b0
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 48d31a4..14cbf24 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -2218,7 +2218,7 @@
const DexFile& dex_file) {
StackHandleScope<1> hs(self);
DCHECK(out_location != nullptr);
- auto dex_cache(hs.NewHandle(down_cast<mirror::DexCache*>(
+ auto dex_cache(hs.NewHandle(ObjPtr<mirror::DexCache>::DownCast(
GetClassRoot(kJavaLangDexCache)->AllocObject(self))));
if (dex_cache.Get() == nullptr) {
self->AssertPendingOOMException();
@@ -4749,7 +4749,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++) {
- mirror::Class* super_iface = mirror::Class::GetDirectInterface(self, iface, i);
+ ObjPtr<mirror::Class> super_iface = mirror::Class::GetDirectInterface(self, iface, i);
if (!super_iface->HasBeenRecursivelyInitialized()) {
// Recursive step
handle_super_iface.Assign(super_iface);
@@ -6493,7 +6493,7 @@
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++) {
- mirror::Class* interface = have_interfaces
+ ObjPtr<mirror::Class> interface = have_interfaces
? interfaces->GetWithoutChecks(i)
: mirror::Class::GetDirectInterface(self, klass, i);
DCHECK(interface != nullptr);
@@ -6532,9 +6532,9 @@
ScopedAssertNoThreadSuspension nts("Copying mirror::Class*'s for FillIfTable");
std::vector<mirror::Class*> to_add;
for (size_t i = 0; i < num_interfaces; i++) {
- mirror::Class* interface = have_interfaces ? interfaces->Get(i) :
+ ObjPtr<mirror::Class> interface = have_interfaces ? interfaces->Get(i) :
mirror::Class::GetDirectInterface(self, klass, i);
- to_add.push_back(interface);
+ to_add.push_back(interface.Ptr());
}
new_ifcount = FillIfTable(iftable.Get(), super_ifcount, std::move(to_add));
@@ -8298,7 +8298,7 @@
mirror::Class::FindField(self, hs.NewHandle(h_path_class_loader->GetClass()), "parent",
"Ljava/lang/ClassLoader;");
DCHECK(parent_field != nullptr);
- mirror::Object* boot_cl =
+ ObjPtr<mirror::Object> boot_cl =
soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader)->AllocObject(self);
parent_field->SetObject<false>(h_path_class_loader.Get(), boot_cl);