src/share/vm/oops/instanceMirrorKlass.cpp

Print this page

        

@@ -181,11 +181,17 @@
   InstanceKlass::oop_follow_contents(cm, obj);
 
   // Follow the klass field in the mirror.
   Klass* klass = java_lang_Class::as_Klass(obj);
   if (klass != NULL) {
+    // For anonymous classes we need to handle the class loader data,
+    // otherwise it won't be claimed and can be unloaded.
+    if (klass->oop_is_instance() && InstanceKlass::cast(klass)->is_anonymous()) {
+      PSParallelCompact::follow_class_loader(cm, klass->class_loader_data());
+    } else {
     PSParallelCompact::follow_klass(cm, klass);
+    }
   } else {
     // If klass is NULL then this a mirror for a primitive type.
     // We don't have to follow them, since they are handled as strong
     // roots in Universe::oops_do.
     assert(java_lang_Class::is_primitive(obj), "Sanity check");

@@ -330,21 +336,10 @@
 
 int InstanceMirrorKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
   int size = oop_size(obj);
   InstanceKlass::oop_update_pointers(cm, obj);
 
-  // Follow the klass field in the mirror.
-  Klass* klass = java_lang_Class::as_Klass(obj);
-  if (klass != NULL) {
-    PSParallelCompact::adjust_klass(cm, klass);
-  } else {
-    // If klass is NULL then this a mirror for a primitive type.
-    // We don't have to follow them, since they are handled as strong
-    // roots in Universe::oops_do.
-    assert(java_lang_Class::is_primitive(obj), "Sanity check");
-  }
-
   InstanceMirrorKlass_OOP_ITERATE(                                            \
     start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj),\
     PSParallelCompact::adjust_pointer(p),                                     \
     assert_nothing)
   return size;