Skip to content

Latest commit

 

History

History
210 lines (146 loc) · 7.66 KB

File metadata and controls

210 lines (146 loc) · 7.66 KB

🔥 Ultimate Java Heap Dump Analysis Toolkit

Java CI

View on GitHub Pages

Heap Dump Banner

GitHub Stars GitHub Forks License: MIT Java JProfiler Heap Analysis

🚀 A complete developer-friendly guide and hands-on toolkit to analyze, troubleshoot, and optimize Java memory usage using heap dumps and modern profilers like JProfiler, jmap, and Eclipse MAT.


📚 Table of Contents


🔍 Introduction

This repository is your go-to guide for understanding Java heap dumps, analyzing them using JProfiler, and diagnosing memory leaks or performance bottlenecks. Whether you're debugging a production crash or fine-tuning memory usage—this toolkit has you covered.


🛠️ Tools You’ll Need

Tool Purpose Link
🧰 JProfiler Professional-grade heap dump analysis JProfiler
🧪 jmap JVM CLI tool to generate heap dumps jmap Docs
🔬 Eclipse MAT Free memory analyzer for .hprof MAT Download
🛠️ VisualVM Lightweight profiling/debugging tool VisualVM

📤 Generating a Heap Dump

jmap -dump:format=b,file=heapdump.hprof <PID>
  • <PID> is the Java process ID.
  • heapdump.hprof is the name of the output file.

🧪 Sample Java Code to Generate Heap Dump

import com.sun.management.HotSpotDiagnosticMXBean;
import java.lang.management.ManagementFactory;

public class HeapDumpExample {
    public static void main(String[] args) throws Exception {
        HotSpotDiagnosticMXBean mxBean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
        mxBean.dumpHeap("heapdump.hprof", true);
        System.out.println("Heap dump created!");
    }
}

📥 Analyzing Heap Dump with JProfiler

🔢 Step-by-Step

  1. Open JProfiler

  2. Go to File → Open Snapshot

  3. Select your .hprof file

  4. Start analyzing with:

    • Heap Walker
    • Reference Graph
    • Dominator Tree
    • GC Roots
    • Allocation Call Tree

🧭 Key Views to Explore

View Purpose
Classes View Identify classes with max memory footprint
Instances View Inspect each object instance and size
Reference Graph Understand object relationships
GC Roots Discover objects keeping others alive
Dominator Tree Visualize memory retention hierarchy
Allocation Tree Analyze object allocation paths

🔎 Understanding Key Concepts

Term Meaning
Heap The memory area where Java objects live
Shallow Size Memory directly consumed by the object
Retained Size Total memory retained if this object and its exclusives were GC’d
GC Root Root reference point in JVM memory graph
Dominator Object whose deletion would make child objects unreachable
Reference Chain Path from GC root to the object, useful for memory leak analysis

📊 Jargon Explained with Examples

Object A retains B and C
├── B
└── C

If B and C are only accessible through A,
then A's retained size = shallow size of A + B + C
  • Shallow Size: Just A
  • Retained Size: A + all exclusively retained objects

🧠 Retained Size vs Shallow Size

Metric What it Tells You Example
Shallow Size Object's own memory 40 bytes
Retained Size Memory freed if object + dependents removed 40 + B (30) + C (20)

🚨 Identifying Memory Leaks

  • High retained sizes
  • Excessive number of instances of a class
  • Objects held by static fields, thread locals, or long reference chains
  • Large collections (Map, List) with old or unnecessary data

Use JProfiler features like:

  • Leak Suspect Reports
  • Dominator Tree
  • Reference Graph

🌐 References & Official Docs


🏷️ Tags & Topics

#Java #HeapDump #JProfiler #MemoryLeak #GC #MAT #MemoryOptimization #JVM #ReferenceGraph #PerformanceTuning

🙌 Contributing

Pull requests welcome! Feel free to add:

  • Additional tools
  • More case studies
  • Tips for JVM tuning
  • Alternative profiling tools (YourKit, VisualVM)

📢 Spread the Word

If this helped you:

  • ⭐ Star the repo
  • 🔁 Share with your team
  • 📦 Fork and enhance

💻 Author

Crafted with 💙 by @Sharique55