JAVA Common garbage collector __java

Source: Internet
Author: User

Serial collector: (Serial collector)

This collector is a single-threaded collector, but its single-threaded meaning does not just mean that it uses only one CPU or a collection thread to do the garbage collection, but more importantly, when it does garbage collection, All of the other worker threads must be paused (Stop-the-world: Pause the user's normal working thread) until it is collected. The collector runs as shown in the following illustration:

In the figure above:
The new generation adopts the replication algorithm, Stop-the-world
The old age uses the mark-sorting algorithm, Stop-the-world
While it is working on GC, it can cause stop-the-world, but it exists because it is simple and efficient (one-line turndown with other collectors), without the overhead of threading interaction for a single CPU environment, concentrating on GC, Natural can achieve the highest single path mobile phone efficiency. So the serial collector is a good choice for running in client mode (it is still the default Cenozoic collector that the virtual machine runs in client mode).

parnew Collector: Multi-threaded version of the serial collector (GC with multiple threads)

The Parnew Collector is a multithreaded version of the serial collector.
It is the preferred Cenozoic collector running in server mode, except for the serial collector, which currently works only with the CMS collector. The CMS collector is considered a landmark concurrent collector, so if there is a garbage collector that can be used with it to make it more perfect, then this collector must also be an integral part of the device. The collector runs as shown in the following illustration:

In the figure above:
The new generation adopts the replication algorithm, Stop-the-world
The old age uses the mark-sorting algorithm, Stop-the-world

parnew scanvenge Collector

Similar to Parnew, but more focused on throughput. The goal is to achieve a collector that can control throughput.
The pause time and throughput cannot be tuned at the same time. One side of the purchase hope that less time to pause, on the other hand, the high throughput, in fact, this is contradictory. Because: In the GC, the total amount of garbage collection is unchanged, if the pause time is reduced, the frequency will increase; Since the frequency increases, the description will be frequent GC, the throughput will be reduced, performance will be reduced.
Throughput: The ratio of time/cpu total elapsed time for the CPU to user code, that is, when the user code is run/(run user code time + garbage collection time). For example, the virtual machine runs for 100 minutes, where the garbage collection takes 1 minutes, and the throughput is 99%.

G1 Collector:

is one of the most foreword results of today's collector development, knowing that the Jdk1.7,sun company has reached a sufficiently mature commercial level.
Advantages:
Its greatest advantage is that it combines spatial integration without producing a lot of debris and reducing the frequency of GC. The second is to allow users to explicitly specify the time of pause. (You can specify a minimum time, which will not be recycled at this time). One of the reasons it has been so efficient is that it prioritizes garbage collection, which ensures its efficiency by prioritizing a zone-recovery approach.
If your application pursues a standstill, that G1 can now be an option to try and if your application pursues throughput, then G1 will not bring you any special benefits.
Note: All of the above collectors will stop the world when the GC is executed, but the following CMS collector does not.

cms collector: (old age collector)

The CMS collector (Concurrent Mark Sweep: Concurrent mark Cleanup) is a collector that targets the shortest recovery pause time. Suitable for use in the Internet station or b/S system server, this kind of application attaches particular importance to the server response speed, I hope the system pauses the shortest time.
CMS collector Run Process: (emphasis is on the process of implementing markup)
(1) Initial mark
The object to which the root can be directly associated
Fast speed
(2) Concurrent tags (together with user threads)
Main tag process, marking all objects
(3) Re-marking
The user thread is still running because of concurrent markup, so before the formal cleanup
(4) Concurrent purge (together with user threads)
Direct cleanup of objects based on tag results
The entire process is shown in the following illustration:

In the figure above, the initial marking and re-marking is needed to stop the world. The longest time in the process is concurrent markup and concurrency cleanup, both of which can work with user threads.
Advantages:
Concurrent collection, Low pause
Disadvantages:
(1) Causes the user's execution speed to be reduced.
(2) Unable to handle floating garbage. Because it uses the tag-purge algorithm. It is possible that some of the garbage is behind the mark and the next GC will not be recycled. If the CMS does not meet the needs of the program during the run, it will temporarily enable the serial old collector to recreate the collection of older years.
(3) Because of the tag-purge algorithm, a large number of fragments are produced. There is often a large amount of space left in the old age, but it is not possible to find enough contiguous space to allocate the current object and have to trigger a full GC in advance.
Question: Since the tag-purge algorithm causes the fragmentation of memory space, why does the CMS collector use the tag cleanup algorithm instead of using the tagging algorithm:
Answer:
The CMS collector is more concerned with pauses, it works with the user thread (concurrent execution) when it does GC, and if the tagging algorithm is used, then the memory space of the available objects will be moved while the application threads are not able to find the Application object.

Reference Blog: http://www.knowsky.com/889010.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.