ObjPtr<>-ify ClassLinker::FindClass(), fix 1 stale reference use.
Thread::CreateAnnotatedStackTrace() was using a stale
reference `aste_array_class`.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 31113334
Change-Id: I191907c0053456bb57de425aa6ccd9668df818a2
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 16f2d0f..653e9ed 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -391,7 +391,7 @@
DCHECK(driver.GetCompilerOptions().IsQuickeningCompilationEnabled());
const char* descriptor = dex_file.GetClassDescriptor(class_def);
ClassLinker* class_linker = runtime->GetClassLinker();
- mirror::Class* klass = class_linker->FindClass(self, descriptor, class_loader);
+ ObjPtr<mirror::Class> klass = class_linker->FindClass(self, descriptor, class_loader);
if (klass == nullptr) {
CHECK(self->IsExceptionPending());
self->ClearException();
diff --git a/compiler/driver/compiler_driver_test.cc b/compiler/driver/compiler_driver_test.cc
index 856cb36..491e61f 100644
--- a/compiler/driver/compiler_driver_test.cc
+++ b/compiler/driver/compiler_driver_test.cc
@@ -88,7 +88,7 @@
StackHandleScope<1> hs(soa.Self());
Handle<mirror::ClassLoader> loader(
hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
- mirror::Class* c = class_linker->FindClass(soa.Self(), descriptor, loader);
+ ObjPtr<mirror::Class> c = class_linker->FindClass(soa.Self(), descriptor, loader);
CHECK(c != nullptr);
const auto pointer_size = class_linker->GetImagePointerSize();
for (auto& m : c->GetMethods(pointer_size)) {
@@ -115,14 +115,14 @@
ObjPtr<mirror::DexCache> dex_cache = class_linker_->FindDexCache(soa.Self(), dex);
EXPECT_EQ(dex.NumStringIds(), dex_cache->NumStrings());
for (size_t i = 0; i < dex_cache->NumStrings(); i++) {
- const mirror::String* string = dex_cache->GetResolvedString(dex::StringIndex(i));
+ const ObjPtr<mirror::String> string = dex_cache->GetResolvedString(dex::StringIndex(i));
EXPECT_TRUE(string != nullptr) << "string_idx=" << i;
}
EXPECT_EQ(dex.NumTypeIds(), dex_cache->NumResolvedTypes());
for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) {
- mirror::Class* type = dex_cache->GetResolvedType(dex::TypeIndex(i));
- EXPECT_TRUE(type != nullptr) << "type_idx=" << i
- << " " << dex.GetTypeDescriptor(dex.GetTypeId(dex::TypeIndex(i)));
+ const ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(dex::TypeIndex(i));
+ EXPECT_TRUE(type != nullptr)
+ << "type_idx=" << i << " " << dex.GetTypeDescriptor(dex.GetTypeId(dex::TypeIndex(i)));
}
EXPECT_TRUE(dex_cache->StaticMethodSize() == dex_cache->NumResolvedMethods()
|| dex.NumMethodIds() == dex_cache->NumResolvedMethods());
@@ -228,7 +228,7 @@
StackHandleScope<1> hs(self);
Handle<mirror::ClassLoader> h_loader(
hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
- mirror::Class* klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
+ ObjPtr<mirror::Class> klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
ASSERT_NE(klass, nullptr);
const auto pointer_size = class_linker->GetImagePointerSize();
@@ -289,7 +289,7 @@
StackHandleScope<1> hs(self);
Handle<mirror::ClassLoader> h_loader(
hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
- mirror::Class* klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
+ ObjPtr<mirror::Class> klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
ASSERT_NE(klass, nullptr);
EXPECT_TRUE(klass->IsVerified());
diff --git a/compiler/exception_test.cc b/compiler/exception_test.cc
index da1db45..15c0787 100644
--- a/compiler/exception_test.cc
+++ b/compiler/exception_test.cc
@@ -34,6 +34,7 @@
#include "mirror/object_array-inl.h"
#include "mirror/stack_trace_element.h"
#include "oat_quick_method_header.h"
+#include "obj_ptr-inl.h"
#include "optimizing/stack_map_stream.h"
#include "runtime-inl.h"
#include "scoped_thread_state_change-inl.h"
@@ -122,7 +123,7 @@
ArtMethod* method_g_;
private:
- mirror::Class* my_klass_;
+ ObjPtr<mirror::Class> my_klass_;
};
TEST_F(ExceptionTest, FindCatchHandler) {
diff --git a/compiler/optimizing/intrinsics.cc b/compiler/optimizing/intrinsics.cc
index dfe6d79..056f533 100644
--- a/compiler/optimizing/intrinsics.cc
+++ b/compiler/optimizing/intrinsics.cc
@@ -272,7 +272,8 @@
ClassLinker* class_linker = runtime->GetClassLinker();
gc::Heap* heap = runtime->GetHeap();
IntegerValueOfInfo info;
- info.integer_cache = class_linker->FindSystemClass(self, "Ljava/lang/Integer$IntegerCache;");
+ info.integer_cache =
+ class_linker->FindSystemClass(self, "Ljava/lang/Integer$IntegerCache;").Ptr();
if (info.integer_cache == nullptr) {
self->ClearException();
return info;
@@ -281,7 +282,7 @@
// Optimization only works if the class is initialized and in the boot image.
return info;
}
- info.integer = class_linker->FindSystemClass(self, "Ljava/lang/Integer;");
+ info.integer = class_linker->FindSystemClass(self, "Ljava/lang/Integer;").Ptr();
if (info.integer == nullptr) {
self->ClearException();
return info;
diff --git a/compiler/verifier_deps_test.cc b/compiler/verifier_deps_test.cc
index c0892ff..3fe2ec0 100644
--- a/compiler/verifier_deps_test.cc
+++ b/compiler/verifier_deps_test.cc
@@ -65,17 +65,16 @@
callbacks_.reset(new VerifierDepsCompilerCallbacks());
}
- mirror::Class* FindClassByName(const std::string& name, ScopedObjectAccess* soa)
+ ObjPtr<mirror::Class> FindClassByName(ScopedObjectAccess& soa, const std::string& name)
REQUIRES_SHARED(Locks::mutator_lock_) {
- StackHandleScope<1> hs(Thread::Current());
+ StackHandleScope<1> hs(soa.Self());
Handle<mirror::ClassLoader> class_loader_handle(
- hs.NewHandle(soa->Decode<mirror::ClassLoader>(class_loader_)));
- mirror::Class* klass = class_linker_->FindClass(Thread::Current(),
- name.c_str(),
- class_loader_handle);
+ hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_)));
+ ObjPtr<mirror::Class> klass =
+ class_linker_->FindClass(soa.Self(), name.c_str(), class_loader_handle);
if (klass == nullptr) {
- DCHECK(Thread::Current()->IsExceptionPending());
- Thread::Current()->ClearException();
+ DCHECK(soa.Self()->IsExceptionPending());
+ soa.Self()->ClearException();
}
return klass;
}
@@ -114,16 +113,16 @@
callbacks->SetVerifierDeps(verifier_deps_.get());
}
- void LoadDexFile(ScopedObjectAccess* soa, const char* name1, const char* name2 = nullptr)
+ void LoadDexFile(ScopedObjectAccess& soa, const char* name1, const char* name2 = nullptr)
REQUIRES_SHARED(Locks::mutator_lock_) {
class_loader_ = (name2 == nullptr) ? LoadDex(name1) : LoadMultiDex(name1, name2);
dex_files_ = GetDexFiles(class_loader_);
primary_dex_file_ = dex_files_.front();
SetVerifierDeps(dex_files_);
- StackHandleScope<1> hs(soa->Self());
+ StackHandleScope<1> hs(soa.Self());
Handle<mirror::ClassLoader> loader =
- hs.NewHandle(soa->Decode<mirror::ClassLoader>(class_loader_));
+ hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_));
for (const DexFile* dex_file : dex_files_) {
class_linker_->RegisterDexFile(*dex_file, loader.Get());
}
@@ -133,16 +132,16 @@
compiler_driver_->SetDexFilesForOatFile(dex_files_);
}
- void LoadDexFile(ScopedObjectAccess* soa) REQUIRES_SHARED(Locks::mutator_lock_) {
+ void LoadDexFile(ScopedObjectAccess& soa) REQUIRES_SHARED(Locks::mutator_lock_) {
LoadDexFile(soa, "VerifierDeps");
CHECK_EQ(dex_files_.size(), 1u);
- klass_Main_ = FindClassByName("LMain;", soa);
+ klass_Main_ = FindClassByName(soa, "LMain;");
CHECK(klass_Main_ != nullptr);
}
bool VerifyMethod(const std::string& method_name) {
ScopedObjectAccess soa(Thread::Current());
- LoadDexFile(&soa);
+ LoadDexFile(soa);
StackHandleScope<2> hs(soa.Self());
Handle<mirror::ClassLoader> class_loader_handle(
@@ -193,7 +192,7 @@
void VerifyDexFile(const char* multidex = nullptr) {
{
ScopedObjectAccess soa(Thread::Current());
- LoadDexFile(&soa, "VerifierDeps", multidex);
+ LoadDexFile(soa, "VerifierDeps", multidex);
}
SetupCompilerDriver();
VerifyWithCompilerDriver(/* verifier_deps */ nullptr);
@@ -204,13 +203,14 @@
bool is_strict,
bool is_assignable) {
ScopedObjectAccess soa(Thread::Current());
- LoadDexFile(&soa);
- mirror::Class* klass_dst = FindClassByName(dst, &soa);
+ LoadDexFile(soa);
+ StackHandleScope<1> hs(soa.Self());
+ Handle<mirror::Class> klass_dst = hs.NewHandle(FindClassByName(soa, dst));
DCHECK(klass_dst != nullptr) << dst;
- mirror::Class* klass_src = FindClassByName(src, &soa);
+ ObjPtr<mirror::Class> klass_src = FindClassByName(soa, src);
DCHECK(klass_src != nullptr) << src;
verifier_deps_->AddAssignability(*primary_dex_file_,
- klass_dst,
+ klass_dst.Get(),
klass_src,
is_strict,
is_assignable);
@@ -453,12 +453,12 @@
std::vector<const DexFile*> dex_files_;
const DexFile* primary_dex_file_;
jobject class_loader_;
- mirror::Class* klass_Main_;
+ ObjPtr<mirror::Class> klass_Main_;
};
TEST_F(VerifierDepsTest, StringToId) {
ScopedObjectAccess soa(Thread::Current());
- LoadDexFile(&soa);
+ LoadDexFile(soa);
dex::StringIndex id_Main1 = verifier_deps_->GetIdFromString(*primary_dex_file_, "LMain;");
ASSERT_LT(id_Main1.index_, primary_dex_file_->NumStringIds());
@@ -1441,7 +1441,7 @@
for (bool verify_failure : { false, true }) {
{
ScopedObjectAccess soa(Thread::Current());
- LoadDexFile(&soa, "VerifierDeps", multi);
+ LoadDexFile(soa, "VerifierDeps", multi);
}
VerifyWithCompilerDriver(/* verifier_deps */ nullptr);
@@ -1450,7 +1450,7 @@
{
ScopedObjectAccess soa(Thread::Current());
- LoadDexFile(&soa, "VerifierDeps", multi);
+ LoadDexFile(soa, "VerifierDeps", multi);
}
verifier::VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer));
if (verify_failure) {