All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gridkit.jvmtool.heapdump.SingletonDetector Maven / Gradle / Ivy

There is a newer version: 0.16
Show newest version
package org.gridkit.jvmtool.heapdump;

import org.netbeans.lib.profiler.heap.FieldValue;
import org.netbeans.lib.profiler.heap.Heap;
import org.netbeans.lib.profiler.heap.JavaClass;
import org.netbeans.lib.profiler.heap.ObjectFieldValue;

public class SingletonDetector {

    private RefSet singletons = new RefSet();
    
    public void findSingletons(Heap heap) {
        
        for(JavaClass jc: heap.getAllClasses()) {
            for(FieldValue field: jc.getStaticFieldValues()) {
                if (field instanceof ObjectFieldValue) {
                    long ref = ((ObjectFieldValue)field).getInstanceId();
                    if (ref != 0) {
                        singletons.set(ref, true);
                    }
                }
            }
        }        
    }
    
    public RefSet getSingletons() {
        return singletons;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy