DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Memory Leak Due to Uncleared ThreadLocal Variables
  • Using Heap Dumps to Find Memory Leaks
  • Charge Vertical Scaling With the Latest Java GCs

Trending

  • The Rise of the Intelligent AI Agent: Revolutionizing Database Management With Agentic DBA
  • How to Reduce Technical Debt With Artificial Intelligence (AI)
  • Testing the MongoDB MCP Server Using SingleStore Kai
  • Advanced Insight Generation: Revolutionizing Data Ingestion for AI-Powered Search
  1. DZone
  2. Coding
  3. Java
  4. Essential JVM Tools for Garbage Collection Debugging

Essential JVM Tools for Garbage Collection Debugging

This article explores several tools for analyzing Java GC performance, including built-in utilities like jstat, jcmd, and jvisualvm.

By 
Jill Thornhill user avatar
Jill Thornhill
·
Jun. 25, 25 · Review
Likes (6)
Comment
Save
Tweet
Share
2.0K Views

Join the DZone community and get the full member experience.

Join For Free

Java garbage collection is a boon to programmers, but it can cause headaches in production. Poorly-tuned GC is extremely resource-hungry.

Tuning and troubleshooting GC is therefore an important skill. How do you obtain information on how GC is performing? What tools can you use to identify bottlenecks and inefficiencies? 

This article takes a brief look at several different applications that analyze GC performance.

Understanding Java Garbage Collection

Before you begin monitoring and tuning GC, you’ll need a good understanding of the tasks it performs, the terminology, and the various GC algorithms. If you’re new to this topic, I’d recommend reading this comprehensive article on Java Garbage Collection.

GC Logging

The best source of information about GC is the logs, which record details of all garbage collection events. These include:

  • What triggered the event;
  • What type of event;
  • Duration;
  • Memory reclaimed in each memory pool.

To activate GC logging, use command line switches when invoking the JVM: 

  • For Java 8 and earlier: -XX:+PrintGCDetails -Xloggc:<gc-log-file-path>
  • For Java 9 and later: -Xlog:gc*:file=<gc-log-file-path>where <gc-log-file-path> is the path to the file that will contain the log.

The logs are in text format, and may look like this:

Sample GC Log File

Fig 1: Sample GC Log File

The format may differ depending on the version of JVM and the algorithm selected. For information about the log file format, see: Analyzing GC Logs Guide.

We wouldn’t normally analyze the logs manually, since they may be thousands of lines long. They can be useful for a quick check, or for inputting into analysis tools.

JDK Utilities for Troubleshooting and Monitoring

The JDK includes several useful tools for collecting troubleshooting information.

jvisualvm

This is a GUI-based tool useful for monitoring various aspects of JVM performance. It captures information about running programs, useful for on-the-fly analysis.

To invoke the tool, type jvisualvm on the command line.

It displays a GUI screen, listing all running Java applications on the left. After choosing the application, you can find information about the process, and open a monitor screen as shown below.

Monitoring Screen: jvisualvm

Fig 2: Monitoring Screen: jvisualvm


jvisualvm doesn’t specifically show GC statistics, but you can see from the heap graph whether GC is successfully clearing unused memory. The CPU usage graph is also useful. You can request the application to perform GC, letting you monitor resource usage during the event.

jstat

This is a multi-purpose tool, gathering runtime statistics about various aspects of Java applications. It has many options, some of which are useful for GC monitoring:

  • -gc: Detailed GC statistics;

  • -gcutil : Percentage used in each memory pool, and a summary of GC activity;

  • -gccapacity : The minimum, maximum and current sizes of each memory pool.

A sample jstat command is:

jstat -gcutil 15540 250 10 > jstatout.txt
  • -gcutil: The option;

  • 15540: The PID of the Java process;

  • 250: The sampling interval in milliseconds;

  • 10: The number of samples;

  • jstatout.txt: The output file.

The output, imported into a spreadsheet, looks like this:

GC Statistics Produced by jstat

Fig 3: GC Statistics Produced by jstat


The output columns are defined in the jstat official documentation.

jcmd

This is a versatile troubleshooting utility, giving insights into JVM  performance. It has many options. Particularly useful in monitoring GC is:

jcmd 6504 VM.events > events.txt


  • 6504: The PID of the Java application;
  • VM.events: An option requesting JVM events;
  • events.txt: The output file.

This includes details of all types of JVM events, so the output is quite long. Scrolling through the output, you’ll find GC information that looks like this:

GC Events Section in jcmd Output

Fig 4: GC Events Section in jcmd Output


External Tools

Although all these tools provide useful information, getting a full picture of how well GC is working can still be tedious. Let’s look at two tools outside of the JDK that can streamline GC analysis.

IBM GC and Memory Visualizer (GCMV)

This is a comprehensive GC log analyzer. It’s good for advanced users, but difficult for beginners. You need to know exactly what you’re looking for. GCMV is a GUI-based tool, allowing you to select the metrics you want to see. It then displays them in graph form, as shown below.

IBM GCMV

Fig 5: IBM GCMV


Since you have to manually select each set of metrics, it can be time-consuming to obtain a full picture of GC performance.

GCeasy

GCeasy is also a log analyzer. It provides users at any level with access to detailed GC analysis in a short amount of time.

GCeasy performs a detailed analysis of the log, and presents the results in a series of graphs and charts. It uses AI to create a report of any potential issues, as well as giving tailored performance tuning suggestions. The information includes key performance indicators, detailed memory analysis, and a graph of memory before and after each GC event. It’s ideal for regular GC monitoring, since it can be automated.

The image below shows a montage of a few of the charts produced by GCeasy.

Selection of Charts Produced by GCeasy

Fig 6: Selection of Charts Produced by GCeasy


Conclusion

In this article, we’ve looked at a few tools you can use to monitor Java garbage collection performance.

Each of these has its place, but for fast and comprehensive GC analysis, GCeasy is the tool of choice for many systems engineers. Its ease of use and quality information make garbage collection tuning simple.

Java virtual machine Tool garbage collection

Opinions expressed by DZone contributors are their own.

Related

  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Memory Leak Due to Uncleared ThreadLocal Variables
  • Using Heap Dumps to Find Memory Leaks
  • Charge Vertical Scaling With the Latest Java GCs

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: