[jboss-cvs] JBossAS SVN: r71983 - trunk/testsuite/src/main/org/jboss/test/classloader/leak/clstore.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 10 18:51:38 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-04-10 18:51:38 -0400 (Thu, 10 Apr 2008)
New Revision: 71983

Modified:
   trunk/testsuite/src/main/org/jboss/test/classloader/leak/clstore/LeakAnalyzer.java
Log:
Improve Reference type handling and report node descriptions

Modified: trunk/testsuite/src/main/org/jboss/test/classloader/leak/clstore/LeakAnalyzer.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/classloader/leak/clstore/LeakAnalyzer.java	2008-04-10 22:43:40 UTC (rev 71982)
+++ trunk/testsuite/src/main/org/jboss/test/classloader/leak/clstore/LeakAnalyzer.java	2008-04-10 22:51:38 UTC (rev 71983)
@@ -24,8 +24,7 @@
 
 import java.io.CharArrayWriter;
 import java.io.PrintWriter;
-import java.lang.ref.SoftReference;
-import java.lang.ref.WeakReference;
+import java.lang.ref.Reference;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -33,6 +32,7 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.Map.Entry;
 
 import org.jboss.logging.Logger;
 import org.jboss.profiler.jvmti.JVMTICallBack;
@@ -112,6 +112,13 @@
 
       return charArray.toString();
    }
+   
+   
+   public void notifyOnReferences(String temporaryFile, JVMTICallBack callback)
+   {
+      // We override the superclass version to pass 'true' for notifyOnClasses
+      notifyInventory(true,temporaryFile,null,callback);
+   }
 
    /** Explore references recursively */
    private void exploreObject(ReferenceReportNode node, Object source, int currentLevel, final int maxLevel,
@@ -119,25 +126,17 @@
    {
       if (maxLevel >= 0 && currentLevel >= maxLevel)
       {
-         node.setMessage("<i>MaxLevel</i>)");
+         String msg = node.getMessage() == null ? "" : node.getMessage() + " -- ";
+         node.setMessage(msg + "<i>MaxLevel</i>");
          return;
       }
 
-      Integer index = new Integer(System.identityHashCode(source));
+      String index = source.getClass().getName() + "@" + System.identityHashCode(source);
 
       if (alreadyExplored.contains(index))
       {
-         String message = null;
-         if (source instanceof Class)
-         {
-            message = " object instanceOf " + source + "@" + index
-                  + " was already described before on this report";
-         }
-         else
-         {
-            message = " object instanceOf " + source.getClass() + "@" + index
-                  + " was already described before on this report";
-         }
+         String message = node.getMessage() == null ? "" : node.getMessage() + " -- ";
+         message += " object " + index + " was already described before on this report";
 
          node.setMessage(message);
          prunableLeaves.add(node);
@@ -167,7 +166,7 @@
 
          if (nextReference != null && !weakAndSoft)
          {
-            if (nextReference instanceof WeakReference || nextReference instanceof SoftReference)
+            if (nextReference instanceof Reference)
             {
                // WeakHashMap$Entry and ThreadLocal$ThreadLocalMap$Entry are
                // special cases, where the Entry key is a weak ref, but the 
@@ -176,12 +175,31 @@
                // java.lang.ref.Referent.referent -- all others are potential
                // strong references
                String msg = child.getMessage();
-               if (msg.indexOf("java.lang.ref.Reference.referent=") >= 0)
+               if (msg.indexOf("FieldReference private java.lang.Object java.lang.ref.Reference.referent=") >= 0)
+               {                  
+                  if (nextReference instanceof Map.Entry)
+                  {
+                     // WeakHashMap$Entry is suspicious. 
+                     // Put in some more info about the entry
+                     Map.Entry entry = (Entry) nextReference;
+                     Object key = entry.getKey();
+                     msg += " KEY=" + (key == null ? " null" : key.getClass().getName() + "@" + System.identityHashCode(key));
+                     Object val= entry.getValue();
+                     msg += " VALUE=" + (val == null ? " null" : val.getClass().getName() + "@" + System.identityHashCode(val));
+                     child.setMessage(msg);
+                  }
+                  
+                  prunableLeaves.add(child);                  
+                  nextReference = null;
+               }
+               else if (msg.indexOf("java.lang.ThreadLocal$ThreadLocalMap$Entry") >= 0)
                {
-                  prunableLeaves.add(child);
+                  // Get the key and follow that to see why it isn't released
+                  nextReference = ((Reference) nextReference).get();
                }
+               // else just keep going
                
-               nextReference = null;
+               
             }
          }
 
@@ -229,7 +247,6 @@
 
    private String callToString(Object obj, boolean callToString)
    {
-
       try
       {
          if (obj == null)
@@ -238,21 +255,13 @@
          }
          else
          {
-            if (callToString)
+            String base = obj.getClass().getName() + "@" + System.identityHashCode(obj);
+            if (callToString || obj instanceof Class)
             {
-               return obj.toString();
+               base += "(" + obj.toString() + ")";
             }
-            else
-            {
-               if (obj instanceof Class)
-               {
-                  return obj.toString();
-               }
-               else
-               {
-                  return obj.getClass().getName() + "@" + System.identityHashCode(obj);
-               }
-            }
+            
+            return base;
          }
 
       }




More information about the jboss-cvs-commits mailing list