Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 783
Arkantos Avatar asked Jul 15 '14 19:07

Arkantos


People also ask

How is full GC triggered?

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.

What triggers major GC?

JVM will trigger full GC(both minor+major GC) when the heap is full.

Is full GC major GC?

Major GC is cleaning the Old space. Full GC is cleaning the entire Heap – both Young and Old spaces.

What is full GC ergonomics?

Ergonomics is the process by which the Java Virtual Machine (JVM) and garbage collection tuning, such as behavior-based tuning, improve application performance. The JVM provides platform-dependent default selections for the garbage collector, heap size, and runtime compiler.


1 Answers

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.

like image 101
Arkantos Avatar answered Oct 11 '22 02:10

Arkantos