OSDN Git Service

Avoid visiting find array class cache as roots
authorMathieu Chartier <mathieuc@google.com>
Mon, 12 Oct 2015 22:06:16 +0000 (15:06 -0700)
committerMathieu Chartier <mathieuc@google.com>
Mon, 12 Oct 2015 22:16:05 +0000 (15:16 -0700)
If we visit the find array class cache as roots it will prevent
unloading for any array classes in the cache. This is not ideal
since it may take a long time for the entries to get replaced.

Also added a missed exception check in getDeclaredClasses.

Bug: 22720414

Change-Id: Id34557fd034b3e3967ef629301ee251931937849

runtime/class_linker.cc
runtime/native/java_lang_Class.cc

index 5ff4bc1..370ea5c 100644 (file)
@@ -1023,9 +1023,9 @@ void ClassLinker::VisitRoots(RootVisitor* visitor, VisitRootFlags flags) {
   class_roots_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
   VisitClassRoots(visitor, flags);
   array_iftable_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
-  for (GcRoot<mirror::Class>& root : find_array_class_cache_) {
-    root.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
-  }
+  // Instead of visiting the find_array_class_cache_ drop it so that it doesn't prevent class
+  // unloading if we are marking roots.
+  DropFindArrayClassCache();
 }
 
 class VisitClassLoaderClassesVisitor : public ClassLoaderVisitor {
index 5da15df..3a73900 100644 (file)
@@ -522,6 +522,10 @@ static jobjectArray Class_getDeclaredClasses(JNIEnv* env, jobject javaThis) {
   }
   if (classes == nullptr) {
     // Return an empty array instead of a null pointer.
+    if (soa.Self()->IsExceptionPending()) {
+      // Pending exception from GetDeclaredClasses.
+      return nullptr;
+    }
     mirror::Class* class_class = mirror::Class::GetJavaLangClass();
     mirror::Class* class_array_class =
         Runtime::Current()->GetClassLinker()->FindArrayClass(soa.Self(), &class_class);