11

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.

4 Answers 4

7

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.

4
  • In fact I've read this post. Generally Full GC cleans entire Heap answers my question. Thanks!
    – Neo
    Feb 13, 2016 at 16:31
  • One more question: what algorithm will G1 use when performing full gc? Full GC is much slower just because it cleans all regions?
    – Neo
    Feb 13, 2016 at 16:34
  • Full GCs: Currently G1 full gc is single threaded and very slow, we should try to avoid full gcs as much as possible. Feb 13, 2016 at 17:01
  • does jvm print a log every time Humongous Allocation happens?
    – Erben Mo
    Oct 25, 2016 at 6:39
4

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.

2

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.

0

The difference between young and mixed GC is:

  • Mixed GC contains the old regions reclamation (1/8 of old regions by default.)
  • Mixed GC will be triggered when IHOP is reached. (By default when the old gen > 45%.)

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.