You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:33:41 UTC

[sling-org-apache-sling-extensions-classloader-leak-detector] 02/06: SLING-3359 - Classloader Leak Detector Console Tab

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.extensions.classloader-leak-detector-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-extensions-classloader-leak-detector.git

commit b9b4828e408d2d42edb5b3b953c04dcb483f4b21
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Feb 10 12:42:45 2014 +0000

    SLING-3359 - Classloader Leak Detector Console Tab
    
    adding some comments and also ensuring that PhantomReference are properly cleared
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/leak-detector@1566596 13f79535-47bb-0310-9956-ffa450edef68
---
 .../extensions/leakdetector/internal/LeakDetector.java  | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/extensions/leakdetector/internal/LeakDetector.java b/src/main/java/org/apache/sling/extensions/leakdetector/internal/LeakDetector.java
index 38e4446..1cca04c 100644
--- a/src/main/java/org/apache/sling/extensions/leakdetector/internal/LeakDetector.java
+++ b/src/main/java/org/apache/sling/extensions/leakdetector/internal/LeakDetector.java
@@ -29,7 +29,10 @@ import org.slf4j.LoggerFactory;
 
 public class LeakDetector implements Runnable, BundleActivator {
     /**
-     * Set of PhantomReferences such that PhantomReference itself is not GC
+     * Set of PhantomReferences such that PhantomReference itself is not GC.
+     * While analyzing the Heap Dump it might appear that GC roots of such classloaders (suspected)
+     * points to LeakDetector. This happens because they are held here through PhantomReference
+     * and there normal GC has not been done. So consider that as false positive
      */
     private final Set<Reference<?>> refs = Collections.synchronizedSet(new HashSet<Reference<?>>());
 
@@ -124,7 +127,10 @@ public class LeakDetector implements Runnable, BundleActivator {
 
         log.info("Shutting down reference collector for Classloader LeakDetector");
         //Drain out the queue
-        while (queue.poll() != null);
+        BundleReference ref = null;
+        while ((ref = (BundleReference)queue.poll()) != null){
+            removeBundle(ref);
+        }
     }
 
     private void removeBundle(BundleReference ref) {
@@ -134,6 +140,7 @@ public class LeakDetector implements Runnable, BundleActivator {
             //bi cannot be null
             bi.decrementUsageCount(ref);
             refs.remove(ref);
+            ref.clear();
         }
 
         log.info("Detected garbage collection of bundle [{}] - Classloader [{}]", bi, ref.classloaderInfo);
@@ -240,6 +247,12 @@ public class LeakDetector implements Runnable, BundleActivator {
 
     private static class ClassloaderInfo implements Comparable<ClassloaderInfo> {
         final Long creationTime = System.currentTimeMillis();
+        /**
+         * The hashCode might collide for two different classloaders but then
+         * we cannot keep a hard reference to Classloader reference. So at best
+         * we keep the systemHashCode and *assume* it is unqiue at least wrt
+         * classloader instances
+         */
         final long systemHashCode;
 
         private ClassloaderInfo(ClassLoader cl) {

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.