Overview of Java triggering full GC

preface

I've been asked this question recently. I'd like to make a record here.

System. Call of GC () method

This method is called to advise the JVM to perform full GC. Although it is only a suggestion rather than a certain one, it will trigger full GC in many cases, thus increasing the frequency of full GC, that is, increasing the number of intermittent pauses. It is strongly recommended that you do not use this method and let the virtual machine manage its memory by itself. You can prohibit RMI from calling system through - XX: + disableexplicitgc gc。

Insufficient space in old age

The old age space is insufficient only when the new generation objects are transferred into and created as large objects and large arrays. When the space is still insufficient after full GC is executed, the following error is thrown: Java Lang. outofmemoryerror: in order to avoid full GC caused by the above two conditions, Java heap space should try to make the object recycled in the minor GC stage, make the object survive for a long time in the new generation, and do not create too large objects and arrays.

Insufficient space in immortality area

The method area in the runtime data area in the JVM specification is also commonly referred to as the immortal generation or immortal area in the hotspot virtual machine. The permanet generation stores some class information, constants, static variables and other data. When there are many classes to be loaded, reflected classes and called methods in the system, the permanet generation may be filled, Full GC is also executed when CMS GC is not configured. If the full GC still fails to recycle, the JVM will throw the following error message: Java Lang. outofmemoryerror: permgen spaceto avoid the phenomenon of full GC caused by perm Gen full, you can increase the perm Gen space or switch to CMS GC.

Promotion failed and concurrent mode failure occur during CMS GC

For the procedure of using CMS for GC of the elderly generation, pay special attention to whether there are promotion failed and concurrent mode failure in the GC log. When these two conditions occur, they may

Full GC is triggered. Promotion failed is caused by the fact that during minor GC, the survivor space cannot be placed, and the object can only be placed in the elderly generation, and the elderly generation cannot be placed at this time; Concurrent mode failure is

During the execution of CMS GC, there are objects to be put into the elderly generation at the same time, At this time, the elderly generation is short of space (sometimes the "space shortage" is caused by too much floating garbage during CMS GC, resulting in a temporary space shortage to trigger full GC). The measures are: increase the survivor space, old age space or reduce the ratio of triggering concurrent GC. However, in JDK 5.0 + and 6.0 +, the CMS may complete the remark due to JDK bug 29

The sweeping action is triggered after a long time. This situation can be avoided by setting - XX: cmsmaxaabortableprecleantime = 5 (unit: ms).

The average size of minor GC promoted to the old generation is greater than the remaining space in the old generation

This is a complex triggering situation. In order to avoid the lack of space in the old generation due to the promotion of the new generation object to the old generation, hotspot made a judgment during minor GC. If

If the average size of minor GC promoted to the old generation from the previous statistics is greater than the remaining space of the old generation, the full GC will be triggered directly. For example, after the program triggers minor GC for the first time, 6MB objects are promoted to the old generation. When the next minor GC occurs, first check whether the remaining space of the old generation is greater than 6MB. If it is less than 6MB,

Full GC is executed. When the Cenozoic adopts PS GC, the method is slightly different. PS GC will also check after minor GC. For example, after the first minor GC in the above example, PS GC will check whether the remaining space of the old generation is empty at this time

Greater than 6MB, if less than, it will trigger the recycling of the old generation. In addition to the above four conditions, sun JDK applications that use RMI for RPC or management will execute full GC once an hour by default. You can use - Java at startup-

Dsun. rmi. dgc. client. Gcinterval = 3600000 to set the execution interval of full GC or - XX: + disableexplicitgc to prohibit RMI from calling system gc。

Allocating large objects in the heap

The so-called large object refers to a Java object that requires a large amount of continuous memory space, such as a long array. This object will directly enter the older generation. Although the older generation has a large remaining space, it cannot find a large enough continuous space to allocate to the current object, which will trigger the JVM to perform full GC.

In order to solve this problem, CMS garbage collector provides a configurable parameter, namely - XX: + usecmcomportatfullcollection switch parameter, which is used to give an additional free defragmentation process after "enjoying" the full GC service. The memory defragmentation process cannot occur simultaneously. The space fragmentation problem is gone, but the Teton time has to be longer, The JVM designers also provide another parameter - XX: cmsfullgcsbeforecompaction, which is used to set the number of uncompressed full GCS followed by a compressed GC.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>