In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
1. Minor GC and Full GCMinor GC: recycle the new generation, because the survival time of the new generation object is very short, so the Minor GC will be executed frequently and the execution speed is generally fast. Full GC: recycle the old age and the new generation, and the old age objects have a long survival time, so Full GC is rarely executed, and the execution speed is much slower than Minor GC. Memory allocation strategy
1. Objects are assigned first in Eden
In most cases, objects are allocated on the new generation Eden, and when there is not enough space in the Eden, the Minor GC is initiated.
two。 The big object went straight into the old age.
Large objects are objects that require contiguous memory space. The most typical large objects are very long strings and arrays.
It is common for large objects to trigger garbage collection in advance to get enough contiguous space to allocate to large objects.
-XX:PretenureSizeThreshold. Objects larger than this value are allocated directly in the old age to avoid a large amount of memory replication between Eden and Survivor.
3. Long-term surviving objects enter the old age.
Define an age counter for an object, which is born in Eden and still alive through Minor GC, will be moved to Survivor, the age will increase by 1 year, and when it reaches a certain age, it will move into the old age.
-XX:MaxTenuringThreshold is used to define the threshold of age. The default value is 15.
4. Dynamic object age determination
The virtual machine does not always require that the age of the object must reach MaxTenuringThreshold in order to promote the old age. If the sum of all object sizes of the same age in Survivor is more than half of the Survivor space, then the object whose age is greater than or equal to that age can directly enter the old age without waiting for the required age in MaxTenuringThreshold.
5. Space allocation guarantee
Before the occurrence of Minor GC, the virtual machine first checks whether the maximum contiguous space available in the old era is greater than the total space of all objects in the new generation, and if the condition is true, then Minor GC can confirm that it is secure.
If not, the virtual machine will check whether the value of HandlePromotionFailure allows the guarantee to fail, and if so, it will continue to check whether the maximum available contiguous space in the old age is larger than the average size of the object promoted to the old age. If it is larger, it will try to conduct a Minor GC; if the value of HandlePromotionFailure is less than, or if the value of HandlePromotionFailure does not allow risk, then a Full GC will be carried out.
Third, the trigger conditions of Full GC
For Minor GC, the trigger condition is very simple, when the Eden space is full, a Minor GC will be triggered. On the other hand, Full GC is relatively complex with the following conditions:
1. Call System.gc ()
It is only recommended that the virtual machine perform Full GC, but the virtual machine does not necessarily do so. This approach is not recommended, but instead allows the virtual machine to manage memory.
two。 Lack of space in the old days
The common scene of lack of space in the old age is that the large objects mentioned earlier directly enter the old age, and the long-term living objects enter the old age, and so on.
In order to avoid the Full GC caused by the above reasons, you should try not to create large objects and arrays. In addition, you can adjust the size of the new generation through the-Xmn virtual machine parameters, so that the object can be recycled in the new generation as far as possible, so that it will not enter the old age. You can also adjust the age of the object to the old age through-XX:MaxTenuringThreshold, so that the object can survive in the new generation for a longer period of time.
3. Space allocation guarantee failed
Minor GC that uses the replication algorithm requires old memory space as a guarantee, and a Full GC will be performed if the guarantee fails. Please refer to section 5 above for details.
4. JDK 1.7 and previous permanent generation space is insufficient.
Before JDK 1.7, the method area of HotSpot virtual machine was implemented with permanent generation, which stored some Class information, constants, static variables and other data.
When there are a large number of classes to load, reflected classes, and methods called in the system, the permanent generation may be full and Full GC will be executed if it is not configured to adopt CMS GC. If it still fails to recycle after Full GC, the virtual machine throws a java.lang.OutOfMemoryError.
In order to avoid the Full GC caused by the above reasons, the method can be adopted to increase the permanent space or switch to the use of CMS GC.
5. Concurrent Mode Failure
During the execution of CMS GC, there are also objects to be put into the old age, and when the old age is out of space (perhaps due to the temporary shortage of space caused by too much floating garbage in the GC process), a Concurrent Mode Failure error will be reported and Full GC will be triggered.
IV. Common tuning parameters
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.