Reputation: 2226
For garbage first collector, young gc means performing gc in young generation only and mixed gc would clean both young and old generation.
So what is full gc? Why it lasts longer than mixed gc?
I've done some searching but I didn't find any post that explains full gc.
Upvotes: 11
Views: 8321
Reputation: 2215
The difference between young and mixed GC is:
From Oracle documentation: https://docs.oracle.com/en/java/javase/11/gctuning/garbage-first-g1-garbage-collector1.html
Adaptive IHOP tries to set the Initiating Heap Occupancy so that the first mixed garbage collection of the space-reclamation phase starts when the old generation occupancy is at a current maximum old generation size minus the value of -XX:G1HeapReservePercent as the extra buffer.
For full GC,
After space-reclamation, the collection cycle restarts with another young-only phase. As backup, if the application runs out of memory while gathering liveness information, G1 performs an in-place stop-the-world full heap compaction (Full GC) like other collectors.
The reason that a Full GC occurs is because the application allocates too many objects that can't be reclaimed quickly enough. Often concurrent marking has not been able to complete in time to start a space-reclamation phase.
Upvotes: 0
Reputation: 38910
From Oracle G1 GC blog and technetwork article
Young GC:
The collection set of the Young GC includes only young/survivor regions.
Mixed GC:
The collection set of the Mixed GC includes both young/survivor regions, but also old regions.
Humongous Objects and Humongous Allocations
For G1 GC, any object that is more than half a region size is considered a "Humongous object". Such an object is allocated directly in the old generation into "Humongous regions". These Humongous regions are a contiguous set of regions.
Dead Humongous objects are freed at the end of the marking cycle during the cleanup phase also during a full garbage collection cycle.
In-order to reduce copying overhead, the Humongous objects are not included in any evacuation pause. A full garbage collection cycle compacts Humongous objects in place.
Generally a Full GC cleans the entire Heap – both Young and Tenured spaces (old gen)
On a different note, you have to worry about how much time "application threads were stopped" irrespective of GC type : Young GC or Full GC etc.
Upvotes: 7
Reputation: 43052
Under normal conditions G1 should only run young and mixed collections to meet its pause time goals.
Full GCs are a fallback mechanism and likely to violate those goals. They occur when mixed GCs aren't able to keep up with allocations, when a humongous allocation could not be satisifed or when a GC is requested with System.gc()
and some other conditions.
Logging with -XX:+PrintGCDetails
should include a cause for full collections.
Upvotes: 2
Reputation: 1959
The g1 divides the heap into regions, where the young generation and the old generation consists of several regions each. A young GC collects some regions (not all), however, all of them are assigned to the young generation. A mixed GC collects some regions (not all), some belong the young generation, at least one to the old generation. A full GC collects all regions, and, in consequence, the young and the old generation.
Upvotes: 4