Minor and Full GC
**Minor GC: ** Refers to garbage collection that occurs in the new generation. Since Most Java objects are ephemeral, Minor GC is very frequent and generally fast.
**Full GC: ** Old GC, or Major GC. The Applicability of the Parallel Avenge Avenge a Major GC, often accompanied by at least one Minor GC. Major GC is typically 10 times slower than Minor GC.
Allocation policy
-
In most cases, objects are allocated in the Eden area of the new generation. When the Eden area does not have enough space to allocate, the virtual machine will initiate a Minor GC.
-
Large objects are Java objects that require a large amount of contiguous memory, typically long strings and arrays.
-
VMS use generational collection to manage memory. During memory reclamation, they must be able to identify which objects should be placed in the new generation and which objects should be placed in the old age. Therefore, the virtual machine defines an object age counter for each object. If the object is born in Eden and still alive after the first Minor GC and can be accommodated by Survivor, it is moved into Survivor space and the object age is set to 1. Each time an object “survives” a Minor GC in Survior, its age increases by one year, and when it reaches a certain age (15 by default), it is promoted to the old age. The threshold of the current age of an object can be set by using ** -xx :MaxTenutingThreshold**.
-
In order to better adapt to the memory conditions of different applications, virtual machines do not always require objects to reach the MaxTenutingThreshold to advance to the old age. If the sum of the size of all objects of the same age in a Survivor space is greater than half of the size in a Survivor space, objects older than or equal to that age can go straight to the old age.
-
Before a Minor GC occurs, the virtual machine checks to see if the maximum available contiguous space of the old generation is greater than the total space of all objects of the new generation. If this condition is true, then the Minor GC is guaranteed to be safe. If this condition is not true, the virtual machine looks at the HandlePromotionFailure setting to see if the guarantee failure is allowed. If so, it continues to check if the maximum available contiguous space of the old age is greater than the average size of the objects promoted to the old age, and if so, a Minor GC is attempted. If less than, or if the HandlePromotionFailure setting does not allow risk, then a Full GC is also done.