Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...