Move ArtField to ObjPtr
Added EXPECT_OBJ_PTR_EQ and variants to gtests.
Fixed moving GC bugs in:
ClassLinker::CreatePathClassLoader
ClassLinkerTest: StaticFields
ObjPtr Decode call sites: 186 -> 181.
Some tests fail due to ResolvedFieldAccessTest, will fix in follow
up CL.
Bug: 31113334
Test: test-art-host CC baker
Change-Id: I8b266ad00f3c20c8cbe7cfdf280d175083df0b88
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index 87b6dc3..50466ed 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -4563,9 +4563,11 @@
return nullptr;
} else {
std::string temp;
- mirror::Class* klass = field->GetDeclaringClass();
+ ObjPtr<mirror::Class> klass = field->GetDeclaringClass();
const RegType& field_klass =
- FromClass(klass->GetDescriptor(&temp), klass, klass->CannotBeAssignedFromOtherTypes());
+ FromClass(klass->GetDescriptor(&temp),
+ klass.Decode(),
+ klass->CannotBeAssignedFromOtherTypes());
if (obj_type.IsUninitializedTypes()) {
// Field accesses through uninitialized references are only allowable for constructors where
// the field is declared in this class.
@@ -4662,10 +4664,11 @@
}
}
- mirror::Class* field_type_class =
+ ObjPtr<mirror::Class> field_type_class =
can_load_classes_ ? field->GetType<true>() : field->GetType<false>();
if (field_type_class != nullptr) {
- field_type = &FromClass(field->GetTypeDescriptor(), field_type_class,
+ field_type = &FromClass(field->GetTypeDescriptor(),
+ field_type_class.Decode(),
field_type_class->CannotBeAssignedFromOtherTypes());
} else {
DCHECK(!can_load_classes_ || self_->IsExceptionPending());
@@ -4785,12 +4788,12 @@
// Get the field type.
const RegType* field_type;
{
- mirror::Class* field_type_class = can_load_classes_ ? field->GetType<true>() :
+ ObjPtr<mirror::Class> field_type_class = can_load_classes_ ? field->GetType<true>() :
field->GetType<false>();
if (field_type_class != nullptr) {
field_type = &FromClass(field->GetTypeDescriptor(),
- field_type_class,
+ field_type_class.Decode(),
field_type_class->CannotBeAssignedFromOtherTypes());
} else {
Thread* self = Thread::Current();
diff --git a/runtime/verifier/reg_type-inl.h b/runtime/verifier/reg_type-inl.h
index d93aaa1..10f1be5 100644
--- a/runtime/verifier/reg_type-inl.h
+++ b/runtime/verifier/reg_type-inl.h
@@ -44,7 +44,7 @@
}
}
-inline bool RegType::CanAccessMember(mirror::Class* klass, uint32_t access_flags) const {
+inline bool RegType::CanAccessMember(ObjPtr<mirror::Class> klass, uint32_t access_flags) const {
if ((access_flags & kAccPublic) != 0) {
return true;
}
diff --git a/runtime/verifier/reg_type.h b/runtime/verifier/reg_type.h
index 9170bb1..472381d 100644
--- a/runtime/verifier/reg_type.h
+++ b/runtime/verifier/reg_type.h
@@ -29,6 +29,7 @@
#include "base/stringpiece.h"
#include "gc_root.h"
#include "handle_scope.h"
+#include "obj_ptr.h"
#include "object_callbacks.h"
#include "primitive.h"
@@ -205,7 +206,7 @@
REQUIRES_SHARED(Locks::mutator_lock_);
// Can this type access a member with the given properties?
- bool CanAccessMember(mirror::Class* klass, uint32_t access_flags) const
+ bool CanAccessMember(ObjPtr<mirror::Class> klass, uint32_t access_flags) const
REQUIRES_SHARED(Locks::mutator_lock_);
// Can this type be assigned by src?
diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc
index 350c838..3e1958f 100644
--- a/runtime/verifier/verifier_deps.cc
+++ b/runtime/verifier/verifier_deps.cc
@@ -19,6 +19,7 @@
#include "compiler_callbacks.h"
#include "leb128.h"
#include "mirror/class-inl.h"
+#include "obj_ptr-inl.h"
#include "runtime.h"
namespace art {
@@ -107,10 +108,10 @@
}
}
-bool VerifierDeps::IsInClassPath(mirror::Class* klass) {
+bool VerifierDeps::IsInClassPath(ObjPtr<mirror::Class> klass) {
DCHECK(klass != nullptr);
- mirror::DexCache* dex_cache = klass->GetDexCache();
+ ObjPtr<mirror::DexCache> dex_cache = klass->GetDexCache();
if (dex_cache == nullptr) {
// This is a synthesized class, in this case always an array. They are not
// defined in the compiled DEX files and therefore are part of the classpath.
diff --git a/runtime/verifier/verifier_deps.h b/runtime/verifier/verifier_deps.h
index dc8dfaf..3223f6f 100644
--- a/runtime/verifier/verifier_deps.h
+++ b/runtime/verifier/verifier_deps.h
@@ -26,6 +26,7 @@
#include "base/array_ref.h"
#include "base/mutex.h"
#include "method_resolution_kind.h"
+#include "obj_ptr.h"
#include "os.h"
namespace art {
@@ -176,7 +177,7 @@
// Returns true if `klass` is null or not defined in any of dex files which
// were reported as being compiled.
- bool IsInClassPath(mirror::Class* klass)
+ bool IsInClassPath(ObjPtr<mirror::Class> klass)
REQUIRES_SHARED(Locks::mutator_lock_);
// Returns the index of `str`. If it is defined in `dex_file_`, this is the dex