From a8bba7d0853b372aea3ed3ea154fb2b2a23c2c9d Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 30 May 2018 15:18:48 +0100 Subject: 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 --- runtime/native/java_lang_Class.cc | 41 ++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 24 deletions(-) (limited to 'runtime/native/java_lang_Class.cc') diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 261178b0ee..c6bdfa10c6 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -215,17 +215,9 @@ static jstring Class_getNameNative(JNIEnv* env, jobject javaThis) { return soa.AddLocalReference(mirror::Class::ComputeName(hs.NewHandle(c))); } -// TODO: Move this to mirror::Class ? Other mirror types that commonly appear -// as arrays have a GetArrayClass() method. -static ObjPtr GetClassArrayClass(Thread* self) - REQUIRES_SHARED(Locks::mutator_lock_) { - ObjPtr class_class = mirror::Class::GetJavaLangClass(); - return Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_class); -} - static jobjectArray Class_getInterfacesInternal(JNIEnv* env, jobject javaThis) { ScopedFastNativeObjectAccess soa(env); - StackHandleScope<4> hs(soa.Self()); + StackHandleScope<1> hs(soa.Self()); Handle klass = hs.NewHandle(DecodeClass(soa, javaThis)); if (klass->IsProxyClass()) { @@ -237,10 +229,12 @@ static jobjectArray Class_getInterfacesInternal(JNIEnv* env, jobject javaThis) { return nullptr; } + ClassLinker* linker = Runtime::Current()->GetClassLinker(); const uint32_t num_ifaces = iface_list->Size(); - Handle class_array_class = hs.NewHandle(GetClassArrayClass(soa.Self())); - Handle> ifaces = hs.NewHandle( - mirror::ObjectArray::Alloc(soa.Self(), class_array_class.Get(), num_ifaces)); + ObjPtr class_array_class = + GetClassRoot>(linker); + ObjPtr> ifaces = + mirror::ObjectArray::Alloc(soa.Self(), class_array_class, num_ifaces); if (ifaces.IsNull()) { DCHECK(soa.Self()->IsExceptionPending()); return nullptr; @@ -250,20 +244,21 @@ static jobjectArray Class_getInterfacesInternal(JNIEnv* env, jobject javaThis) { // with kActiveTransaction == false. DCHECK(!Runtime::Current()->IsActiveTransaction()); - ClassLinker* linker = Runtime::Current()->GetClassLinker(); - MutableHandle interface(hs.NewHandle(nullptr)); for (uint32_t i = 0; i < num_ifaces; ++i) { const dex::TypeIndex type_idx = iface_list->GetTypeItem(i).type_idx_; - interface.Assign(linker->LookupResolvedType(type_idx, klass.Get())); - ifaces->SetWithoutChecks(i, interface.Get()); + ObjPtr interface = linker->LookupResolvedType(type_idx, klass.Get()); + DCHECK(interface != nullptr); + ifaces->SetWithoutChecks(i, interface); } - return soa.AddLocalReference(ifaces.Get()); + return soa.AddLocalReference(ifaces); } -static mirror::ObjectArray* GetDeclaredFields( - Thread* self, ObjPtr klass, bool public_only, bool force_resolve) - REQUIRES_SHARED(Locks::mutator_lock_) { +static ObjPtr> GetDeclaredFields( + Thread* self, + ObjPtr klass, + bool public_only, + bool force_resolve) REQUIRES_SHARED(Locks::mutator_lock_) { StackHandleScope<1> hs(self); IterationRange> ifields = klass->GetIFields(); IterationRange> sfields = klass->GetSFields(); @@ -672,10 +667,8 @@ static jobjectArray Class_getDeclaredClasses(JNIEnv* env, jobject javaThis) { // Pending exception from GetDeclaredClasses. return nullptr; } - ObjPtr class_array_class = GetClassArrayClass(soa.Self()); - if (class_array_class == nullptr) { - return nullptr; - } + ObjPtr class_array_class = GetClassRoot>(); + DCHECK(class_array_class != nullptr); ObjPtr> empty_array = mirror::ObjectArray::Alloc(soa.Self(), class_array_class, 0); return soa.AddLocalReference(empty_array); -- cgit v1.2.3-59-g8ed1b