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/runtime/proxy_test.h b/runtime/proxy_test.h
index fa5a449..860d96c 100644
--- a/runtime/proxy_test.h
+++ b/runtime/proxy_test.h
@@ -25,6 +25,7 @@
#include "class_root.h"
#include "mirror/class-inl.h"
#include "mirror/method.h"
+#include "obj_ptr-inl.h"
namespace art {
namespace proxy_test {
@@ -32,11 +33,11 @@
// Generate a proxy class with the given name and interfaces. This is a simplification from what
// libcore does to fit to our test needs. We do not check for duplicated interfaces or methods and
// we do not declare exceptions.
-mirror::Class* GenerateProxyClass(ScopedObjectAccess& soa,
- jobject jclass_loader,
- ClassLinker* class_linker,
- const char* className,
- const std::vector<mirror::Class*>& interfaces)
+ObjPtr<mirror::Class> GenerateProxyClass(ScopedObjectAccess& soa,
+ jobject jclass_loader,
+ ClassLinker* class_linker,
+ const char* className,
+ const std::vector<Handle<mirror::Class>>& interfaces)
REQUIRES_SHARED(Locks::mutator_lock_) {
StackHandleScope<1> hs(soa.Self());
Handle<mirror::Class> javaLangObject = hs.NewHandle(
@@ -46,21 +47,23 @@
jclass javaLangClass = soa.AddLocalReference<jclass>(mirror::Class::GetJavaLangClass());
// Builds the interfaces array.
- jobjectArray proxyClassInterfaces = soa.Env()->NewObjectArray(interfaces.size(), javaLangClass,
- nullptr);
+ jobjectArray proxyClassInterfaces =
+ soa.Env()->NewObjectArray(interfaces.size(), javaLangClass, /* initialElement */ nullptr);
soa.Self()->AssertNoPendingException();
for (size_t i = 0; i < interfaces.size(); ++i) {
soa.Env()->SetObjectArrayElement(proxyClassInterfaces, i,
- soa.AddLocalReference<jclass>(interfaces[i]));
+ soa.AddLocalReference<jclass>(interfaces[i].Get()));
}
// Builds the method array.
jsize methods_count = 3; // Object.equals, Object.hashCode and Object.toString.
- for (mirror::Class* interface : interfaces) {
+ for (Handle<mirror::Class> interface : interfaces) {
methods_count += interface->NumVirtualMethods();
}
jobjectArray proxyClassMethods = soa.Env()->NewObjectArray(
- methods_count, soa.AddLocalReference<jclass>(GetClassRoot<mirror::Method>()), nullptr);
+ methods_count,
+ soa.AddLocalReference<jclass>(GetClassRoot<mirror::Method>()),
+ /* initialElement */ nullptr);
soa.Self()->AssertNoPendingException();
jsize array_index = 0;
@@ -91,7 +94,7 @@
proxyClassMethods, array_index++, soa.AddLocalReference<jobject>(
mirror::Method::CreateFromArtMethod<kRuntimePointerSize, false>(soa.Self(), method)));
// Now adds all interfaces virtual methods.
- for (mirror::Class* interface : interfaces) {
+ for (Handle<mirror::Class> interface : interfaces) {
for (auto& m : interface->GetDeclaredVirtualMethods(kRuntimePointerSize)) {
soa.Env()->SetObjectArrayElement(
proxyClassMethods, array_index++, soa.AddLocalReference<jobject>(
@@ -104,9 +107,13 @@
jobjectArray proxyClassThrows = soa.Env()->NewObjectArray(0, javaLangClass, nullptr);
soa.Self()->AssertNoPendingException();
- mirror::Class* proxyClass = class_linker->CreateProxyClass(
- soa, soa.Env()->NewStringUTF(className), proxyClassInterfaces, jclass_loader,
- proxyClassMethods, proxyClassThrows);
+ ObjPtr<mirror::Class> proxyClass = class_linker->CreateProxyClass(
+ soa,
+ soa.Env()->NewStringUTF(className),
+ proxyClassInterfaces,
+ jclass_loader,
+ proxyClassMethods,
+ proxyClassThrows);
soa.Self()->AssertNoPendingException();
return proxyClass;
}