changeset 3614:ec98e58952b2

7197350: NPG: jvmtiHeapReferenceCallback receives incorrect reference_kind for system class roots Summary: Fix the iteration over the system classes and report the correct reference kind. Reviewed-by: coleenp, rbackman
author stefank
date Tue, 11 Sep 2012 14:59:23 +0200
parents 4bfe8b33cf66
children 8a02ca5e5576
files src/share/vm/memory/iterator.cpp src/share/vm/memory/iterator.hpp src/share/vm/prims/jvmtiTagMap.cpp
diffstat 3 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/memory/iterator.cpp	Mon Sep 10 16:37:22 2012 -0700
+++ b/src/share/vm/memory/iterator.cpp	Tue Sep 11 14:59:23 2012 +0200
@@ -26,6 +26,10 @@
 #include "memory/iterator.hpp"
 #include "oops/oop.inline.hpp"
 
+void KlassToOopClosure::do_klass(Klass* k) {
+  k->oops_do(_oop_closure);
+}
+
 void ObjectToOopClosure::do_object(oop obj) {
   obj->oop_iterate(_cl);
 }
--- a/src/share/vm/memory/iterator.hpp	Mon Sep 10 16:37:22 2012 -0700
+++ b/src/share/vm/memory/iterator.hpp	Tue Sep 11 14:59:23 2012 +0200
@@ -128,6 +128,13 @@
   virtual void do_klass(Klass* k) = 0;
 };
 
+class KlassToOopClosure : public KlassClosure {
+  OopClosure* _oop_closure;
+ public:
+  KlassToOopClosure(OopClosure* oop_closure) : _oop_closure(oop_closure) {}
+  virtual void do_klass(Klass* k);
+};
+
 // ObjectClosure is used for iterating through an object space
 
 class ObjectClosure : public Closure {
--- a/src/share/vm/prims/jvmtiTagMap.cpp	Mon Sep 10 16:37:22 2012 -0700
+++ b/src/share/vm/prims/jvmtiTagMap.cpp	Tue Sep 11 14:59:23 2012 +0200
@@ -2552,15 +2552,17 @@
       return;
     }
 
+    assert(Universe::heap()->is_in_reserved(o), "should be impossible");
+
     jvmtiHeapReferenceKind kind = root_kind();
-
-    assert(Universe::heap()->is_in_reserved(o), "should be impossible");
+    if (kind == JVMTI_HEAP_REFERENCE_SYSTEM_CLASS) {
       // SystemDictionary::always_strong_oops_do reports the application
       // class loader as a root. We want this root to be reported as
       // a root kind of "OTHER" rather than "SYSTEM_CLASS".
-      if (o->is_instance() && root_kind() == JVMTI_HEAP_REFERENCE_SYSTEM_CLASS) {
+      if (!o->is_instanceMirror()) {
         kind = JVMTI_HEAP_REFERENCE_OTHER;
       }
+    }
 
     // some objects are ignored - in the case of simple
     // roots it's mostly Symbol*s that we are skipping
@@ -2991,7 +2993,8 @@
   // Preloaded classes and loader from the system dictionary
   blk.set_kind(JVMTI_HEAP_REFERENCE_SYSTEM_CLASS);
   SystemDictionary::always_strong_oops_do(&blk);
-  ClassLoaderDataGraph::always_strong_oops_do(&blk, NULL, false);
+  KlassToOopClosure klass_blk(&blk);
+  ClassLoaderDataGraph::always_strong_oops_do(&blk, &klass_blk, false);
   if (blk.stopped()) {
     return false;
   }