Talk about the JVM (ii) Some common concepts of GC

Source: Internet
Author: User

The previous article summarizes the basic algorithm of GC, the basic principle of various GC collectors, or the concept of coarse granularity. This article will collate some of the common concepts of GC, understand these concepts, and believe in a more in-depth understanding of GC


1. When will the minor GC be triggered?

    • The Eden area is full, or the newly created object size > Eden's remaining space
    • The CMS sets the Cmsscavengebeforeremark parameter so that the minor GC is first remark before the CMS to clean up the next generation and speed up the remark. This whole stop-the world time is broken
    • Minor GC is triggered first when full GC

2. When will the full GC be triggered?

    • Minor after GC the surviving objects are promoted to the old age due to pessimistic strategies, there are two scenarios that trigger the full GC, 1 of the average size of the objects that were previously promoted > The remaining space in the old age
    • 1 kinds of minor GC after the survival of the object beyond the old generation of the remaining space. Both of these situations are due to the fact that older generations guarantee the promotion of new-generation objects, and the size of each promotion is unpredictable, so it can only be based on statistics, one based on the historical average, and one based on the next highest possible level of promotion. Both of these cases belong to the promotion failure
    • CMS failed, the occurrence of concurrent mode failure will cause the full GC, in which case the serial old collector is used, which is single-threaded and has a significant impact on the GC. Concurrent mode failure is due to the fact that the remaining space in the old age is insufficient, resulting in large objects created by user threads that are concurrently executing with the GC thread (the object of the new generation directly promoted by Pretenuresizethreshold to the old age size threshold ) cannot enter the old age , as long as stop the world to suspend the user thread, perform GC cleanup. You can set Cmsinitiatingoccupancyfraction to reserve the space remaining when the appropriate CMS executes
    • The new generation of direct promotion to the old age of large objects over the old age of the remaining space, triggering full GC. Note the difference between promotion failure, promotion failure refers to a warranty failure that occurred after the minor GC
    • Perm The full GC is triggered by insufficient space on the permanent generation, allowing the CMS to clean up the permanent space. Set Cmsclassunloadingenabled to
    • Full GC caused by System.GC (), can be set DISABLEEXPLICITGC to prohibit call System.GC throw full GC

3. CMS is not equal to full GC, many people will think that CMS will definitely trigger minor GC. CMS is the GC strategy for the old age, in principle it will not go to clean up the Cenozoic, only set Cmsscavengebeforeremark optimization, or concurrent mode failure when the minor GC


4. Under what circumstances will the new generation of objects be promoted to the old age?

    • When the object size exceeds the object size threshold set by the Pretenuresizethreshold, the object allocates space directly in the old age
    • When the age of an object starting from 1 has accumulated more than 1/2 of the survivor region, a thenuring Threshold is calculated, and the new generation of objects beyond that ages will enter the old age, even though there is plenty of space for the new generation. Note that Maxtenuringthreshold only set the maximum thenuring Threshold, not that only greater than Max Tenuring Threshold will enter the old age, but as long as more than the calculated tenuring Threshold will enter the old age, Maxtenuringthreshold set the maximum value of tenuring threshold.

5. Once the object has entered the old age, it can only be cleared when the CMS is triggered (for CMS only) or full GC


6. When does the heap occur in Oom?

    • When the time spent in GC exceeds GCTIMELIMIT, this value defaults to 98%
    • When the size of the GC is less than Gcheapfreelimit, the value defaults to 2%

7. What is the remaining space is not enough?

The amount of space left is not enough to say that the overall space is not enough to allocate an object, but that continuous space is not enough to be allocated to an object . Therefore, once the memory fragmentation is likely to occur in the remaining space is not enough, so the CMS collector, it needs to be marked-clear a few times after compression, to optimize. Cmsfullgcsbeforecompaction can be set to be compressed after several cleanup


8. The number of full GC is said to be the number of stop the world, so a CMS at least will give the full GC number of times +2, because CMS Initial Mark and remark will stop the world, remember to do 2 times. And the CMS may fail to raise a full GC again


9. JMI System.GC () clears the cache by default for one hours, so you can DISABLEEXPLICITGC, You can also set the Sun.rmi.dgc.client.gcInterval and Sun.rmi.dgc.server.gcInterval parameters to specify the time for JMI cleanup


10. For performance tuning, it should be understood that for a given piece of hardware, a given algorithm (garbage collector), the amount of space a single/multiple thread can reclaim per unit of time is close to a constant. If you want to shorten the GC, you need to consider whether you want to adjust the small space


One. The CMS collector will reduce the time of the Stop the world, allowing GC threads and business threads to concurrency, which will also lengthen the time of a single GC for the CMS collector


as far as possible to keep the object in the new generation, because the new generation uses the replication algorithm, relatively faster recovery, and the number of minor GC is certainly more than the full GC, then the object in the new generation is more capable of being cleared. Once the object is in the old age, it will only be recycled when the full GC, the object will stay in the whole system for a long time, it is likely to create its thread long dead, and it is still alive


in order to keep objects in the new generation as much as possible, it is important to set the size of the survivor area because it is directly related to whether the object enters the old age. Before this situation, obviously there is a lot of new generation of space, but every time after minor GC there are always objects into the old age. Later found that because the survivor is too small, resulting in tenuring threshold is 1, meaning that the age of 1 of the object size over the SURVIVOR/2, age as long as more than 1 of the object will be directly into the old age. When entering the old age, objects are only cleared when the full GC is in. If you jump the survivor space, so that object objects as close as possible to Max Tenuring threshold to enter the old age, this time will greatly reduce the age of the object size, and let the object in the Cenozoic stay longer, improve the probability that they are quickly cleared out of the system



Talk about the JVM (ii) Some common concepts of GC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.