“This is the 22nd day of my participation in the August Gwen Challenge.

🔉 introduction

Next, clean up the rest of the garbage collector.

⭐️ Classic garbage collector

🌟 SerialOld collector

The SerialOld collector is an older, single-threaded version of Serial that uses a mark-up algorithm and, in server mode, serves two purposes: figure below.

  • withParallel ScavengeCollector used in conjunction with (JDK5Before)
  • As aCMSCollect failed plans

🌟 ParallelOld collector

The ParallelOld collector is an older version of the Parallel insane, multithreaded, application of the tag collation algorithm, which was only released in JDK6. The ParallelOld collector would be insane to use the Parallel insane, why? You can’t find SerialOld to match up with, but the Parallel Insane can’t be insane due to SerialOld’s insane performance on a server. On the other hand, the SerialOld insane can’t take advantage of the Parallel processing power of a server. As a result, the combination of ParNew and CMS is not necessarily better.

Now that ParallelOld collector is available, the awkwardness is gone, and cowherd still has to match weaver girl, ahem. In cases where throughput is first or processor resources are scarce, we can give it priority, as shown below.

🌟 CMS collector

The CMS collector, named Concurrent Mark Sweep, aims at the shortest pause time and is suitable for some applications with low latency requirements. The system pause time of such applications is as short as possible to bring users a good interactive experience.

Mark Sweep is based on a mark-sweep algorithm, and the process is a four-step process:

  • Initial flag (CMS inital mark)
  • Concurrent token (CMS inital mark)
  • Relabel (CMS remark)
  • Concurrent cleanup (Concurrent sweep)

Initial mark and concurrent mark need to Stop the world, the speed of initial mark is very good, only need to mark the object associated with GCRoots, concurrent mark that takes a long time, what? Just iterate through all the objects associated with GCRoots without suspending the user thread. Since it is a concurrent operation, incremental updates will inevitably occur. For incremental updates, you can click (portal) to see.

The last step is cleanup, and since there is no need to suspend the user thread and move live objects, the operation is also concurrent, as shown below.

Disadvantages of the CMS collector

  • Sensitive to processor resources
  • Prone to floating garbage
  • Prone to space debris

Programs designed for concurrency are sensitive to processor resources, because some resources have to be removed to do extra things, which will not cause user threads to stop, but will occupy part of the processing power of the processor, which will make the program slow down and reduce the total throughput. If your processor core number, of course no problem, but if the core number is low, even less than 4, the impact will be big, may result in the user program suddenly become very slow, that in order to solve this kind of situation, the virtual machine provides a concurrent collector, incremental in concurrent collection and tag, alternating dynamic operation, minimize waste thread holding time. This lengthened the garbage collection time, but had little impact on the program. The theory was good, but the practice was not good, so JDK9 was scrapped.

The second point is that because the operation is parallel, the user thread will continue to generate garbage, but some garbage appears after the marking process is finished, so it cannot be collected at this stage, which is the part of the catch. Also, in order to guarantee user thread continues to run, can’t wait for old age to full garbage collection, but to set aside part of memory for the use of the concurrent collection procedures, if the reserved program memory can’t meet the needs of object allocation, would be a concurrent failure as a result, the virtual machine will freeze user threads, Use Serial Old, which makes the pause time longer.

The last one has been introduced. If you want to know more about it, you can click on “Portal”.

📝 digression

The people who are most loved are those who have contributed the most to the betterment of mankind and human life. That should be right in principle. However, if you further ask who this person is, you run into no small trouble. It has always been hard to say whether political leaders, or even religious leaders, do much good or much evil.

And so I sincerely believe that the man who best serves the community is the man who provides it with work for its self-improvement, and thus indirectly for its perfection. This applies first to great artists and second to scientists. Undoubtedly, it is not the results of research that elevate the mind and enrich its inner nature, but the drive to understand, the creative and perceptive mental work.

Day 22, come on!