First, trigger the full GC to execute the situation
In addition to calling System.GC directly, there are four things that trigger full GC execution.
1. Insufficient space for old generation
The old generation space is only insufficient when the new generation objects are transferred and created as large objects and large arrays, and when there is still insufficient space after executing full GC, the following error is thrown:
Java.lang.OutOfMemoryError:Java Heap Space
In order to avoid the above two conditions caused by the FULLGC, tuning should try to make the object in the minor GC phase is recycled, so that the object in the Cenozoic to survive for a period of time and do not create too large objects and arrays.
2. Permanet Generation Space Full
The permanetgeneration is stored in some class information, such as, when the system to load classes, reflected classes and the number of methods to call, Permanet generation may be full, in the case is not configured to adopt a CMS GC will be executed in the context of a fully GC. If the full GC is still not recycled, the JVM throws the following error message:
Java.lang.OutOfMemoryError:PermGen Space
To avoid the full GC phenomenon caused by Perm Gen, the method is to increase the perm gen space or to use a CMS GC.
3. CMS GC appears promotion failed and concurrent mode failure
For programs that use the CMS for legacy GC, pay particular attention to whether there are two promotion failed and concurrent mode failure in the GC log, which can trigger full GC when both conditions occur.
Promotionfailed is in the minor GC, Survivor space, objects can only be placed in the old generation, and at this time the old generation also can not be caused; Concurrent mode failure is in the execution of CMS In the process of GC, there are objects to be put into the old generation, while the old generation space is insufficient.
The response is to increase the survivorspace, the old generation space, or to reduce the rate of triggering concurrent GC, but in the JDK 5.0+, 6.0+ version It is possible that the bug29 of the JDK will cause the CMS to trigger remark action long after the sweeping is complete. For this condition, you can avoid this by setting the-xx:cmsmaxabortableprecleantime=5 (in MS).
4. The average size of the minor GC promoted to the old generation is greater than the remaining space of the old generation
This is a more complex trigger situation, the hotspot in order to avoid the new generation of objects promoted to the old generation of space shortage of old generation, in the minor GC, made a judgment, if the previous statistics obtained minor GC promoted to the old generation of the average size greater than the old generation of the remaining space, Then the full GC is triggered directly.
For example, after the first time the program triggers MINORGC, 6MB objects are promoted to the old generation, then the next time the minor GC occurs, first check whether the old generation of the remaining space is greater than 6MB, if less than 6MB, then execute full GC.
When the new generation adopts PSGC, the way is slightly different, PS GC is also checked after the minor GC, for example, the first time in the above example minor GC, the PS GC will check that the old generation of the remaining space is greater than 6MB, if less than, trigger the recovery of the old generation.
In addition to the 4 scenarios above, the full GC is executed one hour by default for sun JDK applications that use RMI for RPC or management. You can set the time interval for full GC execution by using-java-dsun.rmi.dgc.client.gcinterval=3600000 at startup or by-xx:+ DISABLEEXPLICITGC to disallow RMI calls to System.GC.
Original address: http://book.51cto.com/art/201011/235592.htm
* Object Assignment rules
1. The object is prioritized in the Eden area, and the virtual machine executes the minor GC once if there is not enough space in the Eden area.
2. Large objects go directly into the old age (large objects are objects that require a large amount of contiguous memory space). This is done to avoid a large amount of memory copying between the Eden Zone and the two survivor zones (the Cenozoic uses a replication algorithm to collect memory).
3. Long-term survival of the object into the old age. The virtual machine defines an age counter for each object, and if the object passes through 1 minor GC then the object will enter the Survivor area, then each time after the minor GC so the object's age plus 1, know to reach the threshold object into the old age area.
4. Dynamically determine the age of the object. If the sum of all objects of the same age in the survivor area is greater than half the size of survivor space, objects older than or equal to that age can enter the old age directly.
5. Space allocation guarantees. Each time the minor GC is performed, the JVM calculates the average size of the objects moved to the old age area of the survivor area, and if the value is greater than the remaining value of the old age area, a full GC is performed, and if it is less than the check handlepromotionfailure setting, If true, only the monitor GC is performed, and if False the full GC is performed.
GC Triggers full GC execution