Home » Software Development » What is Garbage collection log, Thread dump, Heap dump?

About Ram Lakshmanan

Ram Lakshmanan
Ram Lakshmanan developed world's finest DevOps tools: GCeasy.io, fastThread.io, HeapHero.io. Every single day, millions & millions of people in North America—bank, travel, and commerce—use the applications that Ram Lakshmanan has architected. Ram is an acclaimed speaker in major conferences on scalability, availability, and performance topics. Recently, he has founded a startup, which specializes in troubleshooting performance problems.

What is Garbage collection log, Thread dump, Heap dump?

Java Virtual Machine (JVM) generates 3 critical artifacts that are useful for optimizing the performance and troubleshooting production problems. Those artifacts are:

  1. Garbage collection (GC) log
  2. Thread Dump
  3. Heap Dump

In this article let us try to understand these 3 critical artifacts, where to use them, how does it look, how to capture them, how to analyze them and their differences.

1. Garbage Collection Log

a) What is GC Log? 

GC Log contains garbage collection events related information. It will indicate how many GC events ran, what type of GC events they are (i.e. Young GC or Full GC), how long did each GC event pause the application, how much objects did each GC event reclaim. 

b) How does GC Log look?

Sample garbage collection log file can be found here. 

c) Where is GC Log used?

 Garbage collection logs are used to study the application’s GC and memory performance. It’s used to optimize the GC pause times, it’s used to identify optimal memory size for your application, it’s also used to troubleshoot memory related problems.

d) How to generate GC Log?

You can generate garbage collection log, by passing following JVM arguments:

For Java versions until 8:

1
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:<file-path>

For Java version starting from 9:

1
-Xlog:gc*:file=<file-path>

file-path: is the location where Garbage Collection log file will be written

e) How to understand GC Log?

Garbage collection log format varies depending on who is your JVM vendor (Oracle, HP, IBM, Azul, ..), Java version (1.5, 5, 6, 7, 8, 9, 10, 11, 12,…), garbage collection algorithm (Serial, Parallel, CMS, G1, Shenandoah, Z GC) and JVM arguments you pass. Thus there is not one standardized format available. However here is a video tutorial, which attempts to help you to understand the GC log file format.

f) What Tools are used to analyze GC Log?

 There are multiple Garbage collection log analysis tools. Some of the popular ones are given here: GCeasy, IBM GC & Memory visualizer, HP JMeter, Google Garbage Cat

2. Thread dump

a) What is Thread dump? 

 Thread dump is snapshot of all threads running in the application at point in time. It contains all the information about each thread in the application such as: thread state, thread Id, native Id, thread name, stack trace, priority.

b) How does Thread dump look?

Sample thread dump can be found here.

c) Where is Thread dump used?

 Thread dumps are primarily used for troubleshooting production problems such as CPU spikes, unresponsiveness in the application, poor response time, hung threads, high memory consumption.

d) How to generate Thread dump?

 Thread dumps can be captured from the running application using 8 different options. Most common option to take thread dump is to use the ‘jstack’ tool. jstack tool is shipped in JDK_HOME\bin folder. Here is the command that you need to issue to capture thread dump:

1
jstack -l  <pid> > <file-path>

where

pid: is the Process Id of the application, whose thread dump should be captured

file-path: is the file path where thread dump will be written in to. 

e) How to understand Thread dump?

Here is a video talk, that gives good detailed overview on how to understand the thread dumps. 

f) What Tools are used to analyze Thread dump?

 Here are the most widely used thread dump analysis tools: fastThread, Samurai, IBM Thread & Monitor analyzer, Visual VM

3. Heap dump

a) What is Heap dump? 

 Heap dump is a snapshot of your application’s memory in a point in time. It contains information such as what are the objects in memory, what values do they carry, what is their size, what other objects do they reference. 

b) How does Heap dump look?

 Sample heap dump can be found here. (Note: It is going to be in binary format. So you actually can’t read it).

c) Where is Heap dump used?

 Heap dumps are primarily used for troubleshooting memory related, OutOfMemoryError problems.

d) How to generate Heap dump?

 Heap dump can be captured from the running application using 7 different options. Most common option to take heap dump is to use the ‘jmap’ tool. jmap tool is shipped in JDK_HOME\bin folder. Here is the command that you need to issue to capture:

1
jmap -dump:format=b, file=<file-path> <pid> 

where

pid: is the Java Process Id, whose heap dump should be captured

file-path: is the file path where heap dump will be written in to.

e) How to understand Heap dump?

 Heap dump files are in binary format and tend to be large in size. Besides that, their format heavily lacks documentation. Thus, you have to use the heap dump analysis tools (given in next question) to analyze and understand them.

f) What Tools are used to analyze Heap dump?

 Here are the most widely used heap dump analysis tools: Eclipse MAT, HeapHero, JVisualVM.

Published on Java Code Geeks with permission by Ram Lakshmanan, partner at our JCG program. See the original article here: What is Garbage collection log, Thread dump, Heap dump?

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments