Arkantos
Arkantos

Reputation: 6608

When is a Full GC triggered?

As per my understanding:

Minor GC

a GC that happens in the young gen is usually called Minor because it takes less time to complete as the live-set will be usually small (i'm talking about typical java application considering the weak generational hypothesis) and a copying collector with less number of objects to relocate and remap.

Major GC

a GC that occurs in the old gen is usually called Major GC because it takes more time to complete as live-set will be mostly big (compared to young gen) and it usually compacts the old gen and the time for compaction increases linearly with the old generation size.

Unfortunately the GC logs report the old generation collection as Full GC while it's only the Old generation that's being collected. But in java memory management white paper there's a notion of Full GC in which the entire heap is collected.

A Full GC will be triggered whenever the heap fills up. In such a case the 
young generation is collected first followed by the old generation. If the 
old generation is too full to accept the content of the young generation,
the young generation GC is omitted and the old generation GC is used to 
collect the full heap, either in parallel or serial. Either way the whole 
heap is collected with a stop-the-world event.

If there's always a Minor GC when the young gen fills up and if there's always a Major GC when the old gen fills up, when will this so called Full GC happen? How come the heap becomes full if both the young gen and old gen collectors are doing their part?

Upvotes: 14

Views: 31600

Answers (2)

Narasimman SP
Narasimman SP

Reputation: 216

Full GC - We know already, it collects both Young Gen Space and Old Gen Space

When it is triggered?

I will explain two scenarios

1. Faster Object Allocation/Promotion rate to Old Generation

Assume CMS is running in old gen space. At the same time more and more objects are promoted to old gen space due to MINOR GC running in young gen space at a much more pace than the CMS is operating. So,

The GC algorithm predicts that the concurrent collection will not end before the heap becomes full, so it decides to stop everything and run a FULL GC.

2. Promotional Failure

What is promotional failure? - This is related to a failure while promoting objects from the younger to older generation space in the heap.

Assume MINOR GC is running in young gen space and tries to promote an object to old gen space and if the old gen does not have enough contiguous space to hold the object, it leads to promotion failure.

Promotion Failure will call for a FULL GC to run. It does not call for CMS GC because the main reason promotional failure happens is fragmentation. As CMS will not solve fragmentation issues, FULL GC is the go-to-option.

If suppose CMS is running in old gen space during Promotion Failure, it will result in Concurrent Mode Failure and of-course a FULL GC will run.

Upvotes: 2

Arkantos
Arkantos

Reputation: 6608

A Full GC where in both the young and old generations are collected occurs when there's change in region size.

For example, if we mention

-Xms1024m -Xmx2048m -XX:PermSize=512m -XX:MaxPermSize=1024m

JVM initially starts with 1GB of heap but reserves space for 2GB from OS. So as the usage of these regions increases, based on VM ergonomics, Young and old generations are resized until they reach the max reserved size of 2GB.

Same thing applies for PermSize as well, every time PermGen resizes, a full GC will occur.

Upvotes: 11

Related Questions