Project Url: aragozin/heapunit
Introduction: Heap introspection for test puposes
More: Author   ReportBugs   

Test library to introspecting your Java heap via heap dumps.

HeapUnit can

  • capture heap dump of own JVM
  • scan content of dump
  • reconstruct Java objects from heap dump


Code snippet below dumps TCP Socket instances found in heap

HeapImage hi = HeapUnit.captureHeap();

for(HeapInstance i: hi.instances(SocketImpl.class)) {
    // fd field in SocketImpl class is nullified when socket gets closed
    boolean open = i.value("fd") != null;
    System.out.println(i.rehydrate() + (open ? " - open" : " - closed"));

Full source is here

Maven artifact

HeapUnit and dependencies is available in Maven Central Repo

Support Me
About Me
Google+: Trinea trinea
GitHub: Trinea