Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could an object be created in old generation?

As a newly created object is allocated to new generation. Is it possible a newly created object is allocated directly to an old or tenured generation ? if it is, then on which bases ?

like image 754
Muneeb Nasir Avatar asked Jul 30 '12 17:07

Muneeb Nasir


People also ask

When object is created then it will be placed in which generation?

Generation 0: Newly created objects are in Generation 0.

Which generation contains objects that have reached the minor GC age threshold?

Tenured Space: The objects which reach to max tenured threshold during the minor GC or young GC, will be moved to “Tenured Space” or “Old Generation Space“.

What is stop the world scenario in garbage collection?

Stop the World Event - All minor garbage collections are "Stop the World" events. This means that all application threads are stopped until the operation completes. Minor garbage collections are always Stop the World events. The Old Generation is used to store long surviving objects.


1 Answers

See "Frequently Asked Questions about Garbage Collection in the HotspotTM JavaTM Virtual Machine":

Do objects ever get allocated directly into the old generation?

In 1.4.1 there two situations where allocation may occur directly into the old generation.

If an allocation fails in the young generation and the object is a large array that does not contain any references to objects, it can be allocated directly into the old generation. In some select instances, this strategy was intended to avoid a collection of the young generation by allocating from the old generation.

There is a flag (available in 1.4.2 and later) l-XX:PretenureSizeThreshold= that can be set to limit the size of allocations in the young generation. Any allocation larger than this will not be attempted in the young generation and so will be allocated out of the old generation.

The threshold size for 1) is 64k words. The default size for PretenureSizeThreshold is 0 which says that any size can be allocated in the young generation.

In 1.4.2 case 1) the 64k word threshold continues to be true for the incremental collector (-Xincgc). For the default collector and the concurrent collector (-XX:+UseConcMarkSweepGC) the threshold value has been changed so that an attempt to allocate into the old generation only occurs if the size of the allocation is larger than the entire young generation (available space when it is empty). It was observed that there were cases where the 1.4.1 strategy for the default collector and concurrent collector were leading to full collections only (no young generation collections were being done). We deemed that bad enough to raise the threshold.

like image 76
munyengm Avatar answered Sep 28 '22 07:09

munyengm