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
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
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Inspect the Contents of the Java Metaspace Region
  • JVM Memory Architecture and GC Algorithm Basics
  • All You Need To Know About Garbage Collection in Java
  • 7 JVM Arguments of Highly Effective Applications [Videos]

Trending

  • Memory Management in Java: An Introduction
  • Apache Flink
  • Five Free AI Tools for Programmers to 10X Their Productivity
  • DevSecOps: Integrating Security Into Your DevOps Workflow
  1. DZone
  2. Coding
  3. Java
  4. Java GC Causes Distilled

Java GC Causes Distilled

This comprehensive cheatsheet will help you figure out when garbage collection in Java is triggered and what it should affect.

Artem Dmitriev user avatar by
Artem Dmitriev
·
Jan. 22, 17 · Tutorial
Like (38)
Save
Tweet
Share
29.23K Views

Join the DZone community and get the full member experience.

Join For Free

As it's quite obvious, every GC collection in Hotspot JVM has a good reason to start. They might vary with respect to the current situation in the system and memory state. They all are known as GC Causes. Here, we will try to highlight and explain all the possible reasons for GC to start in Java 7/8.

GC Causes

The most common source of knowledge about GC events and causes are GC Logs files, which can be enabled with the -Xloggc:/path/to/file JVM flag. Such files consist of verbose trace data, which is very hard to read. In order to see the whole picture about your GC work, you should use GC Log Analyze tools; the good one for such purpose is GCPlot.

Following is a table which describes each possible GC Cause. It is ordered by an occurrence frequency in an average application.

GC Cause

Description

Allocation Failure

Application tried to make a new allocation and failed due to lack of available space in Young generation; hence Minor GC is required. On Linux, the JVM can trigger a GC if the kernel notifies there isn't much memory left via mem_notify.

GC Locker

GC is started after all threads leave the JNI Critical region. For more information on JNI, refer to the Java Native Interface documentation website. GC is blocked when any thread is in the JNI Critical region and can start only when all of them outside of it.

G1 Evacuation Pause

This is actual only for the G1 collector. It indicates that it is copying live objects from one set of regions (Young and sometimes Young + Tenured, which is called Mixed) to another set of regions.

G1 Humongous Allocation

This is actual only for the G1 collector. Humongous is an allocation when its size is greater than 50% of one region size; the object then allocated in special space. Nevertheless, it also causes normal GC collection to get more (possibly continuous also) space for such objects.

CMS Initial Mark

Initial mark phase of CMS, for more details, see Phases of CMS. It also triggers Young Space collection.

System.gc()

There was a System.gc() call in the application code. You can start JVM with the -XX:+DisableExplicitGC flag to disable such behavior.

Adaptive Size Ergonomics

Indicates you are using the adaptive heap size policy (ability to change Young and Tenured spaces size at runtime), enabled via the -XX:+UseAdaptiveSizePolicy flag. By default, it is enabled in the recent versions of JVM.

Allocation Profiler

This is actual only for versions of Java before 8 and only when  -Xaprof  is set. It triggers just before JVM exits.

Heap Inspection

GC was triggered by an inspection operation on the heap, most probably by the jmap tool with the -histo:live  flag set.

Heap Dump

GC was initiated before heap dump is made by some profiling instrument.

No GC

Normally, you shouldn't see this reason. It was occurring in older Java versions, in case jstat command was started before any collection occurred. Other case is when jstat checks GC without any GC activity.

Last Ditch Collection

When Metaspace (Java 8+) or PermGen (Java 7-) is full and you can't allocate a new object here, JVM first tries to clean it, triggering appropriate collector. If that's not possible, it then tries to expand it. If that doesn't work as well, it triggers Full GC with this cause name. Soft references are being cleaned during it as well.

Perm Generation Full

Triggered as a result of an allocation failure in PermGen. Actual for Java versions prior to 8.

Metadata GC Threshold

Triggered as a result of an allocation failure in Metaspace. Metaspace is a replacement for PermGen in Java 8+.

JvmtiEnv ForceGarbageCollection

Something called the JVM tool interface function ForceGarbageCollection.


garbage collection Java (programming language) Java Native Interface Java virtual machine

Published at DZone with permission of Artem Dmitriev. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Inspect the Contents of the Java Metaspace Region
  • JVM Memory Architecture and GC Algorithm Basics
  • All You Need To Know About Garbage Collection in Java
  • 7 JVM Arguments of Highly Effective Applications [Videos]

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

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: