In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the characteristics and usage scenarios of JVM 7 kinds of garbage collectors. The content is very detailed. Interested friends can use it for reference. I hope it will help you.
The collector discussed here is based on the HotSpot virtual machine after JDK1.7Update 14, which contains all the collectors shown in figure 3-5 below:
The figure above shows seven collectors for different generations, and if there is a connection between the two collectors, they can be used together.
1.Serial collector
Serial collector is the most basic and oldest collector. Is a single-threaded collector. When it does garbage collection, it must pause all other worker threads until its collection is complete.
The Serial collector is still the default new generation collector for virtual machines running in Client mode, which is a good choice for virtual machines running in Client mode.
2.ParNew collector
The ParNew collector is actually a multithreaded version of the Serial collector. Except for using multithreading for garbage collection, the rest of the behavior, including all the control parameters available to the Serial collector, collection algorithm, Stop The Worl, object allocation rules, collection strategy, and so on, are exactly the same as the Serial collector.
The ParNew collector is the preferred new generation collector for many virtual machines running in Server mode. One of the performance-independent but important reasons is that, apart from the Serial collector, only ParNew currently works with the CMS collector.
3.Parallel Scavenge (parallel Recycling) collector
Parallel Scavenge collector is a new generation collector, which is not only a collector using replication algorithm, but also a parallel multithreaded collector.
The goal of the collector is to achieve a controllable throughput (Throughput). The so-called throughput is the ratio of the time spent by CPU running user code to the total time consumed by CPU, that is, throughput = running user code time / (running user code time + garbage collection time)
The shorter the pause time, the more suitable it is for programs that need to interact with users.
The response speed can improve the user experience, while high throughput can efficiently use CPU time to complete the program's computing tasks as soon as possible, which is mainly suitable for tasks that do not require too much interaction in the background.
The Parallel Scavenge collector provides two parameters for precise control of throughput, one of which controls the maximum garbage collection pause time
-XX:MaxGCPauseMillis parameter and-XX:GCTimeRatio parameter that directly sets the throughput size
The Parallel Scavenge collector has one more parameter:-XX:+UseAdaptiveSizePolicy. This is a switch parameter. When this parameter is turned on, there is no need to manually specify detailed parameters such as the size of the new generation (- Xmn), the ratio of Eden to Survivor (- XX:SurvivorRatio), and the age of the promoted old object (- XX:PretenureSizeThreshold). You just need to set up the basic memory data (such as-Xmx to set the maximum heap), and then use the MaxGVPauseMillis parameter or GCTimeRation parameter to set an optimization goal for the virtual machine.
Adaptive adjustment strategy is also an important difference between Parallel Scavenge collector and ParNew collector.
4.Serial Old collector
Serial Old, an older version of the Serial collector, is also a single-threaded collector that uses the tag collation algorithm. The main significance of this collector is also to be used by virtual machines in Client mode.
If you are in Server mode, there are two main uses:
(1) used with Parallel Scavenge collector in JDK1.5 and previous versions
(2) as a backup plan for CMS collector, it is used when Concurrent Mode Failure occurs in concurrent collection.
Work Engineering of Serial Old Collector
5.Parallel Old collector
Parallel Old is an old-fashioned version of the Parallel Scavenge collector, using multithreading and mark-up algorithms. This collector is only available in 1.6.
6.CMS collector
CMS (Concurrent Mark Sweep) collector is a kind of collector whose goal is to obtain the shortest recovery pause time. At present, a large part of Java applications are concentrated on the service side of the Internet website or BBG S system. This kind of applications pay special attention to the response speed of the server, hoping that the system will have the shortest pause time in order to bring a better experience to users. The CMS collector meets the needs of this kind of application very well.
The CMS collector is implemented based on the mark-clear algorithm. Its operation process is more complex than the previous collectors, and the whole process is divided into four steps:
(1) initial marking
(2) concurrent marking
(3) re-marking
(4) concurrent clearance
Among them, the initial marking and relabeling these two steps still need "Stop The World".
Main advantages of CMS collector: concurrent collection, low pause.
There are three obvious disadvantages of CMS:
(1) the CMS collector is very sensitive to CPU resources. When the number of CPU is less than 4, the impact of CMS on user programs may become great. To cope with this situation, the virtual machine provides a variety of CMS collectors called incremental concurrent collectors. What we have done and the idea that the PC operating system in the single CPU era uses preemption to simulate the multitasking mechanism
(2) the CMS collector cannot handle floating garbage, and a "Concurrent Mode Failure" failure may result in another Full GC generation. Under the default setting of JDK1.5, the CMS collector will be activated when 68% of the space is used in the old years. This is a conservative setting. If the blue age is not growing too fast in the application, you can appropriately increase the trigger percentage by increasing the parameter-XX:CMSInitiatingOccupancyFraction to reduce the number of memory reclaim to achieve better performance. In JDK1.6, the startup threshold of the CMS collector has been raised to 92%.
(3) CMS is a collector based on the "mark-clear" algorithm, and a large number of space debris will be generated at the end of the phone. With too much space debris, there may be a lot of space left in the old age, but we can't find enough contiguous space to allocate current objects, so we have to start FullGC ahead of time. To solve this problem, the CMS collector provides a-XX:+UseCMSCompactAtFullCollection switch parameter (on by default) to start the memory defragmentation process when the CMS collector cannot hold back the FullGC. The memory defragmentation process is not concurrent, the space debris problem is gone, but the pause time is longer. The virtual machine designer also provides another parameter-XX:CMSFullGCsBeforeCompaction, which is used to set how many times an uncompressed FullGC is executed, followed by one with compression (the default value is 0, indicating defragmentation every time you enter the FullGC).
7. G1 collector
Advantages of the G1 collector:
(1) parallelism and concurrency
(2) generational collection
(3) Spatial arrangement (tag finishing algorithm, replication algorithm)
(4) predictable pause (in addition to the pursuit of low pause at G1, a predictable pause time model can be established, which allows the user to specify that the time spent on garbage collection should not exceed N milliseconds within a time period of M milliseconds, which has almost realized the characteristics of Java (RTSJ) and the collector).
When using the G1 collector, the memory layout of the Java heap is planned as multiple equal-sized independent areas (Region). Although the concept of the new generation and the old age is still retained, the new generation and the old age are no longer physically isolated, they are all part of the collection of Region.
The G1 collector can build a predictable pause time model because it can systematically avoid area-wide garbage collection in a real Java heap. G1 tracks the value of garbage accumulation in each Region (the empirical value of the space obtained by recycling and the time required for recycling), and maintains a priority list in the background, giving priority to the most valuable Region (that is, another name of Garbage-First) according to the allowed collection time. This method of using Region to divide memory space and priority area recovery ensures that the G1 collector can obtain as high gray machine efficiency as possible in a limited time.
The idea of "breaking up into parts" of G1 memory
Adding Remembered Set to the enumeration range of the GC root node ensures that the whole heap is neither scanned nor omitted.
If the operation of maintaining the Remembered Set is not calculated, the operation of the G1 collector can be roughly divided into the following steps:
(1) initial marking
(2) concurrent marking
(3) final mark
(4) screening and recycling
About the characteristics of JVM 7 garbage collectors and what is the use of the scene to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.