user3668129
user3668129

Reputation: 4820

Why gc on old generation takes longer than gc on young generation

While performing GC, the JVM go over the live objects, and sweep unmarked objects.

According to: How to Tune Java Garbage Collection

"The execution time of Full GC is relatively longer than that of Minor GC"

Will this always be the case ?

If we have ~100 objects in the Old Generation space, and the average number of live objects (created and sweep objected) in the eden space is more than 100, it that still true ?

In addition , suppose we perform compact phase , then a rule of thumb says for better performance copy a small number of large size objects than copy large number of small size objects.

So what am I missing here ?

Upvotes: 3

Views: 1921

Answers (1)

Somnath Musib
Somnath Musib

Reputation: 3724

"The execution time of Full GC is relatively longer than that of Minor GC"

Yes.

When garbage collection happens memory is divided into generations, i.e. separate pools holding objects of different ages. Almost all most used configurations uses two generations, one for young objects (Young Generation) and one for old objects (Old Generation)

Different algorithms can be used to perform garbage collection in the different generations, each algorithm optimized based on commonly observed characteristics for that particular generation.

Generational garbage collection exploits the following observations, known as the weak generational hypothesis, regarding applications written in several programming languages, including the Java programming language:

  • Most allocated objects are not referenced (considered live) for long, that is, they die young.

  • Few references from older to younger objects exist.

Young generation collections occur relatively frequently and are efficient and fast because the young generation space is usually small and likely to contain a lot of objects that are no longer referenced.

Objects that survive some number of young generation collections are eventually promoted, or tenured, to the old generation.

Generational garbage collection

This generation is typically larger than the young generation and its occupancy grows more slowly. As a result, old generation collections are infrequent, but take significantly longer to complete.

The garbage collection algorithm chosen for a young generation typically puts a premium on speed, since young generation collections are frequent.

On the other hand, the old generation is typically managed by an algorithm that is more space efficient, because the old generation takes up most of the heap and old generation algorithms have to work well with low garbage densities.

Read this white paper for a better understanding. The above content is referenced from there.

Upvotes: 4

Related Questions