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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
  1. DZone
  2. Coding
  3. Java
  4. Which GC Algorithm Is Being Used by a Specific JVM Instance?

Which GC Algorithm Is Being Used by a Specific JVM Instance?

Want more insight into your JVMs? Of course you do. Fortunately, there are easy ways to see which GC algorithm is in use as well as more general heap information.

Ali Dehghani user avatar by
Ali Dehghani
·
Apr. 06, 17 · Tutorial
Like (11)
Save
Tweet
Share
13.72K Views

Join the DZone community and get the full member experience.

Join For Free

Using the monitoring tools provided by the JDK, we can gain insights into the JVM itself. One such insight that may come useful in some situations is the GC algorithm used by a specific JVM instance. First off, we should somehow identify that JVM instance. In order to do that, we can use the jps utility to find all the running JVMs in the current machine or a machine specified with a host-id. 

For example, running the following command in my local machine:

jps -l


Would produce the following result:

2912 org.jetbrains.jps.cmdline.Launcher
1985
2913 me.alidg.Application
2915 sun.tools.jps.Jps
2175 org.jetbrains.idea.maven.server.RemoteMavenServer


As you can spot from the output, the Process Id for my trivial Spring Boot app running with the me.alidg.Application main entry is 2913. You also can find this process id using the typical ps (or whatever OS-specific tool you have at your disposal) but it needs more filtering to find your desired JVM instance.

After finding the process id of the JVM instance, you can use the jmap utility. Basically, jmapwill provide heap dumps and other information about JVM memory usage:

jmap [option] <pid>


So knowing that our pid is 2913, we can use the following command to print a Java heap summary:

jmap -heap 2913


The output of this command would be:

Attaching to process ID 2913, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC
// truncated


As you can spot from the output, this JVM instance is using the Concurrent Mark-Sweep GC or CMS GC algorithm. If I run my Spring Boot app with the -XX:+UseG1GC flag, the output for the same command would be:

Attaching to process ID 2961, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13

using thread-local object allocation.
Garbage-First (G1) GC with 8 thread(s)
// truncated


jmap -heap also will provide information about the JIT compiler, heap configuration, Interned strings statistics and Heap usage.

Java (programming language) Java virtual machine Algorithm

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 5 Tips for Optimizing Your React App’s Performance
  • Internal Components of Apache ZooKeeper and Their Importance
  • Application Assessment Questions for Migration Projects
  • A ChatGPT Job Interview for a Scrum Master Position

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: