In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Xiaobian to share with you what JVM garbage collector algorithm is, I believe most people still do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
1. Garbage collector algorithm
Garbage collector used to clean up garbage algorithms are: mark-clean algorithm, copy algorithm, mark-clean algorithm.
The algorithms used to divide generations according to different life cycles of objects include: Generation collection algorithm. This algorithm divides the Java heap into new generations and old generations.
1.1 Mark-Sweep algorithm
The mark-removal algorithm should be the algorithm that best meets our people's idea of dealing with garbage at the beginning. For example, if we want to clean up the garbage in the room, we must first locate (corresponding mark) which garbage is garbage, and then throw it away (corresponding removal). It is simple and rude. I don't care about the rest of the garbage. Hahaha.
Of course, some people say that when I clean my room, I will tidy up the things that are not garbage first and then throw away the garbage... You're on the wrong set. Please mark-clean the set.
This algorithm has two drawbacks.
1. Marking and cleaning efficiency is not high, according to this idea is a mark past, and scan which marks have passed before cleaning
2. Space debris problem, see the picture after finishing a lot of empty middle, this will make larger objects to apply for more continuous space when you can not apply, obviously you have enough space. And that leads to another GC.
1.2 replication algorithm
The copy algorithm is equivalent to saying that it has been improved on the shortcomings of the mark-and-clear algorithm. Basically it cuts the space in half, I use half at a time, when half is full I put the living objects in the other half in order, and then brainlessly clean up the half of the space that was just used, and then replace the memory space that retains the living objects. This eliminates the space debris problem of marker-cleanup algorithms.
Virtual machines basically use this algorithm to recycle new generations, but cutting in half is too inefficient, only half at a time. So HotSpot divides this space into three pieces, one Eden and two Survivor.
Because most of the objects of the Cenozoic generation are short-lived ghosts under normal circumstances, not many can survive, so the default spatial division ratio is 8:1:1. The usage is to use Eden and one Survivor at a time, and then throw the surviving objects to another Survivor. Then clean Eden and the previous Survivor.
Eden and the piece of Survivor that holds the surviving object are then used to welcome the new object. It is equivalent to swapping two Survivors every time after recycling.
However, there are always accidents. In case there are fewer short-lived ghosts in this wave and many survivors, there is still a guarantee mechanism, just like the guarantor in our real life. You can't afford the guarantor! This guarantor is the old age, that is, if Survivor can't let go, let go of the old age.
So why do virtual machines basically recycle new generations with this algorithm? Because most of the objects of the new generation do not survive for a long time, there are relatively few copies each time GC, and the efficiency is high. A little object is copied to Survivor each time.
If it is some old objects in the old age, the replication efficiency will be low. First of all, 8:1:1 is not appropriate, because there will be many objects surviving each time, and 1 cannot be put down. You may have to divide them by "50 - 50." Then the "50 - 50" division will be considered, because each object is basically alive, so each replication is equivalent to copying half of the objects in space. Inefficient.
Also, the new generation has the old generation as a guarantee, ah, too many objects can be placed in the old age, but the old age can not ah, there is no reliance. So there is the following algorithm.
1.3 Mark-Compact algorithm
The idea of the mark-clean algorithm is the same as that of the mark-clean algorithm. It marks the objects that need to be cleaned up first, but the subsequent steps are different. It is cleaning up. Yes, it is as diligent as those who clean up the room garbage every time.
Each time all the surviving objects are moved, and arranged in order of memory address, that is, all the living objects are moved like one end, and then all the memory after the end memory address is reclaimed. So there's no space debris problem with it.
1.4 generational collection algorithm
This algorithm divides Java heap into new generation and old generation, so that different collection algorithms can be used according to the object survival time characteristics of each generation.
Therefore, the new and old generations generally use replication algorithms. The old age is marked with a mark-clean or mark-clean algorithm.
The above is "JVM garbage collector algorithm is what" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
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.