Java Heap Dumps

As name suggest, Heap dumps are only for java processes.

Commands to take heap dumps:

  • jmap -dump:live,format=b,file=heap.process_name.prof <PID>
  • jmap -dump:live,format=b,file=/home/Dumps/heap.process_name.prof <PID> 

Thread Analysis:

For analysis, we can use Java VisualVM and Eclipse Memory Analyzer

Heap Dump Parameter:

-Xms          set initial Java heap size in m,g or M,G (and not MB or GB)
-Xmx          set maximum Java heap size in m,g or M,G (and not MB or GB)

Garbage Collection:
In Java, there is object life cycle as below:

  • Object creation
  • Object in use
  • Object destruction

We need to clean object to release memory else we will have heap memory reaching 100%. Garbage collection is a way in Java which happens automatically and below are the available algorithm:


  • Mark and sweep:


  • Concurrent mark sweep (CMS) garbage collection:

To use CMS GC, use below JVM argument:
-XX:+UseConcMarkSweepGC


  • Serial garbage collection:

To use Serial GC, use below JVM argument:
-XX:+UseSerialGC


  • Parallel garbage collection:

To use parallel GC, use below JVM argument:
-XX:+UseParallelGC


  • G1 garbage collection:

If you want to use in Java 7 or Java 8 machines, use JVM argument as below:
-XX:+UseG1GC

No comments:

Post a Comment