src/java.base/share/classes/java/lang/ref/Finalizer.java

Print this page

        

*** 28,37 **** --- 28,40 ---- import java.security.PrivilegedAction; import java.security.AccessController; import sun.misc.JavaLangAccess; import sun.misc.SharedSecrets; import sun.misc.VM; + import java.util.TreeMap; + import java.util.Set; + import java.util.Map; final class Finalizer extends FinalReference<Object> { /* Package-private; must be in same package as the Reference class */
*** 85,94 **** --- 88,127 ---- /* Invoked by VM */ static void register(Object finalizee) { new Finalizer(finalizee); } + static String printFinalizationQueue() { + Finalizer tmp = unfinalized; + Map <String, Integer> countMap = new TreeMap<String, Integer>(); + synchronized (lock) { + while(tmp != null) { + Object referent = tmp.get(); + if (referent != null) { + Class<?> objClass = referent.getClass(); + String className = objClass.getName(); + Integer cnt = countMap.get(className); + if (cnt == null) { + countMap.put(className,1); + } + else { + countMap.put(className,cnt + 1); + } + } + tmp = tmp.next; + } + } + + StringBuilder sb = new StringBuilder(); + Set<String> keys = countMap.keySet(); + for (String key : keys) { + sb.append("Class: " + key + " count: " + countMap.get(key) + "\n"); + } + + return sb.toString(); + } + private void runFinalizer(JavaLangAccess jla) { synchronized (this) { if (hasBeenFinalized()) return; remove(); }