Several cases java trigger full gc Overview

Foreword

Recently asked this question, in this record tidy.

Call System.gc () method

Calling this method is to suggest the JVM Full GC, although only a recommendation and not necessarily, but in many cases it will trigger Full GC, thereby increasing the frequency of Full GC, but also an increase of the number of intermittent pauses. Department recommended strongly influenced can not use this method do not use, so that the virtual machine to manage its own memory, by by -XX: to prohibit the RMI call System.gc + DisableExplicitGC.

Old's lack of space

Old's only space for the large object, appear insufficient phenomenon in the new generation of large arrays into objects and create, if space is still insufficient after the implementation of Full GC, then throw the following error:
java.lang.OutOfMemoryError: the Java heap Space
to avoid the above two conditions caused by the Full GC, tune should as far as possible so that the object is recovered in the Minor GC stage, so that objects in the new generation of multi survive for some time and do not create too large objects and arrays.

Lack of space for the living area

JVM specification runtime methods zone data area in the HotSpot virtual machine has been used to call eternal life or eternal life on behalf of the district, Permanet Generation stored for a number of class information, constants, variables and other static data, when the system is to be loaded class, when many classes and method calls reflected, Permanet Generation may be filled in is not configured to use of Full GC will perform in the case of CMS GC. If you still can not recover after a Full GC, the JVM will throw the following error message:
java.lang.OutOfMemoryError: PermGen Space
To avoid Perm Gen Full GC fill the resulting phenomenon, the method can be used to increase the Perm Gen into space or use CMS GC.

promotion failed and concurrent mode failure CMS GC when

For the program using the CMS's old GC, with particular attention to whether the promotion failed and concurrent mode failure two conditions GC logs, when these two conditions might appear

Triggers Full GC.
promotion failed when undertaking Minor GC, survivor space does not fit, subject only into the old era, at a time when the old year also fit caused; concurrent mode failure in

CMS GC during the execution of the object to be placed in the same time there's the old, old years at a time due to lack of space (sometimes "lack of space" is the current CMS GC floating garbage too much cause temporary space is insufficient to trigger Full GC ).
Of measures: increase the survivor space, space years old or lower trigger rate concurrent GC, but 5.0 + 6.0 + version of the JDK is likely due to the JDK bug29 cause CMS completed in remark

After a long time to trigger sweeping action. For this situation, by setting -XX: CMSMaxAbortablePrecleanTime = 5 (in units of ms) to avoid.

Statistics obtained by Minor GC promoted to the average size of the remaining space is larger than the old generation of old age

This is a more complex triggering, Hotspot order to avoid the phenomenon of the new generation of objects promoted to the old generation old generation leads to lack of space, during Minor GC, made a judgment, if the

Statistics obtained before the Minor GC promoted to the average size of the old generation is greater than the remaining space of the old generation, then directly triggers Full GC.
After the first program, for example, trigger Minor GC, 6MB objects have promoted to the old generation, then the next time Minor GC occurred, first checks whether the old generation of the remaining space is larger than 6MB, if less than 6MB,

The implementation of Full GC.
When using the new generation PS GC, slightly different, PS GC is also checked after Minor GC, for example, in the above example after the first Minor GC, PS GC though the remaining space is checked whether old generation

Greater than 6MB, such as less than, trigger the recovery of the old generation.
In addition to the above four conditions for the use of RPC or RMI to manage the Sun JDK application, the default will be one hour to perform a Full GC in the case. By by startup - java -

Dsun.rmi.dgc.client.gcInterval = 3600000 Full GC to set the interval, or by performing -XX: RMI calls to prohibit System.gc + DisableExplicitGC.

Large object heap allocation

The so-called large object, refers to the need for a large amount of contiguous memory space of java object, such as a long array of such objects directly into the old era, and although there's a great old space left, but could not find a large enough contiguous space to assigned to the current object, in which case it will trigger the JVM Full GC.

To solve this problem, CMS garbage collector provides a configurable parameter, namely -XX: + UseCMSCompactAtFullCollection switch parameters for the process after "enjoy" Full GC finished serving a complimentary extra defragmentation process of memory consolidation not complicated by the problem of space debris is gone, but not the same Teton long time, JVM designers also provides another argument -XX: CMSFullGCsBeforeCompaction, this parameter is used to set how many times the uncompressed Full GC after execution , followed by a band compression.

Guess you like

Origin www.cnblogs.com/jichi/p/12588087.html