heapunit

项目地址:aragozin/heapunit
简介:Heap introspection for test puposes
更多:作者   提 Bug   
标签:

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

Example

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

<dependency>
    <groupId>org.gridkit.heapunit</groupId>
    <artifactId>heapunit</artifactId>
    <version>0.2</version>
</dependency>
随手点击下面广告,支持我维护本站吧
随手点击下面广告支持我免费维护吧
Android 开发经验分享
随手点击下面广告支持本站吧
 
Android 开发经验分享