Profile Image
PiPi

Why do objects in the Eden area directly promote to the Old area ?

In the G1 garbage collection process, why do objects in the Eden area directly promote to the Old area without passing through the Survivors area during young generation collection? 

 

In the diagram below, the last young generation collection:

[Eden: 372.0M(372.0M) -> 0.0B(488.0M) Survivors: 36.0M -> 44.0M Heap: 4574.7M(8192.0M) -> 4232.7M(8192.0M)]
Old generation memory used = 4232.7M - 44.0M = 4188.7M

 

In the following young generation collection:

[Eden: 388.0M(364.0M) -> 0.0B(356.0M) Survivors: 44.0M -> 52.0M Heap: 4620.7M(8192.0M) -> 4388.7M(8192.0M)]

Old generation memory used = 4388.7M - 52.0M = 4336.7M

 

At this point, the old generation has increased by 148M, which is much larger than the size of the last Survivors area (44M). This indicates that at least 148M - 44M = 104M was directly promoted to the old generation. Why?

 

 

 

 

  • g1gc

Please Sign In or to post your comment or answer

Profile Image

Kousika M

Hello PiPi,

Greetings!

In general, objects in the Eden area may directly promote to the Old generation due to memory pressure, insufficient space in Survivor spaces, large object allocations, or JVM garbage collection tuning.

 

Insufficient Space in Survivor Spaces:

In a normal scenario, when a young generation garbage collection (Minor GC) occurs, objects in the Eden space that are still alive are moved to one of the two Survivor spaces (S0 or S1). However, if both Survivor spaces are full or lack sufficient space, objects will be promoted directly to the Old generation, even if they haven't lived long enough.

 

Large object allocations:

Some objects are too large to fit in the Eden space or the Survivor spaces. These large objects are directly allocated in the Old generation to avoid fragmentation or inefficient memory usage. 

 

Full GC Pressure:

If the Old generation is fragmented or nearly full, the JVM might trigger more aggressive promotions from the Eden space to avoid frequent Full GCs, which are expensive. In this scenario, objects that are still relatively young can be moved to the Old generation to free up space in the Young generation.

 

Thanks.

Profile Image

PiPi

Hello Kousika M,
Thank you for your help and answers!

 

Before this phenomenon occurred, the GC logs showed a situation of G1 Humongous Allocation.

 

I would like to ask how to analyze Humongous Objects, such as the total size of the regions they occupy, the fragmentation they cause, etc.

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • g1gc