In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the principle of jvm garbage collection mechanism". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the principle of jvm garbage collection mechanism".
Principles of garbage collection mechanism:
How does jvm tell if an object is junk?
Using the reachability analysis method to analyze a GC roots object, starting from a node GC ROOT, looking for the corresponding reference node, after finding this node, continue to look for the reference node of this node, when all the reference nodes are found, the remaining nodes are considered to be unreferenced nodes, that is, useless nodes are garbage.
The objects in java that can be used as GC Root are:
1. Objects referenced in the virtual machine stack (table of local variables)
two。 Objects referenced by static properties in the method area
3. Objects referenced by constants in the method area
4. Objects referenced in the local method stack (Native objects)
Garbage collection algorithm for garbage collection:
1.Mark-Sweep (Mark-clear) algorithm
This is the most basic garbage collection algorithm, the reason why it is the most basic because it is the easiest to implement, the idea is also the simplest. The mark-clear algorithm is divided into two phases: the marking phase and the clearing phase. The task of the marking phase is to mark all the objects that need to be recycled, and the cleanup phase is to reclaim the space occupied by the marked objects. The tag-cleanup algorithm is easy to implement, but a more serious problem is that it is easy to produce memory fragments. too much fragmentation may cause a new garbage collection action to be triggered in advance when there is not enough space to find when space for large objects needs to be allocated.
2.Copying (replication) algorithm Cenozoic GC algorithm
It divides available memory into two equal chunks according to capacity, using only one of them at a time. When this piece of memory is used up, copy the surviving objects to another piece, and then clean up the used memory space at once, so that the problem of memory fragmentation will not occur easily.
Although this algorithm is simple to implement, efficient and not easy to produce memory fragments, it makes a high price for the use of memory space, because the memory that can be used is reduced to half of the original memory.
Obviously, the efficiency of Copying algorithm has a lot to do with the number of living objects, if there are many living objects.
Then the efficiency of Copying algorithm will be greatly reduced.
In the replication algorithm, when the second step is repeated again, the age of the object in the jvm is increased by one. When the jvm round trip reaches 15 times and the age reaches 15:00, the new generation will turn to the old age.
3.Mark-Compact (marking-finishing) algorithm
The tag finishing algorithm is based on the tag removal method, that is, after the garbage is cleared, the surviving object is moved to the other side.
4.Generational Collection (Generation Collection) algorithm
Generation collection algorithm is the algorithm adopted by most JVM garbage collectors at present. Its core idea is to divide the memory into several different regions according to the life cycle of the object. Generally speaking, the heap area is divided into TenuredGeneration and Young Generation. The characteristic of the old era is that only a small number of objects need to be recycled during each garbage collection, while the characteristic of the new generation is that a large number of objects need to be recycled each time, so the most suitable collection algorithm can be adopted according to the characteristics of different generations.
The label replication algorithm is adopted for the new generation, because most of the objects are collected for each garbage collection in the new generation, that is to say, the number of operations that need to be copied is less, but in practice, the space of the new generation is not divided according to the proportion of 1:1. Generally speaking, the new generation is divided into a larger Eden space and two smaller Survivor spaces, using Eden space and a piece of Survivor space each time. When recycling, copy the objects that are still alive in Eden and Survivor to another piece of Survivor space, and then clean up the Eden and the Survivor space you just used.
The characteristic of the old days is that only a small number of objects are reclaimed each time, so the tagging algorithm is used.
Note that another generation outside the heap is Permanet Generation, which is used to store class classes, constants, method descriptions, and so on.
The recycling of the permanent generation mainly consists of two parts: abandoned constants and useless classes.
Thank you for your reading, the above is the content of "the principle of jvm garbage collection mechanism". After the study of this article, I believe you have a deeper understanding of the principle of jvm garbage collection mechanism, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.