Memory management----Garbage collector for Java virtual machines

Source: Internet
Author: User

1.Serial Collector

The advantage is simple and efficient, single threaded to avoid the overhead of thread interaction.

Disadvantage, stop the world is required for garbage collection (all user threads are paused).

2.ParNew Collector

It is a multi-threaded version of the serial collector and is a multi-threaded parallel collection of the new generation. Is the default Cenozoic collector for the CMS collector (described below).

Parnew is less efficient than the serial collector in the case of single CPUs because of the overhead of multithreaded interactions.

However, today's computers are generally multi-CPU multicore, and the parnew default number of threads is the number of CPUs. So it adapts more to the current.

3.Parallel Scavenge Collector

It is a collector that pursues throughput.

throughput = Run user code time/(run user code time + garbage Collection Time)

You can set the throughput you want to achieve with the-xx:gctimeratio parameter.

According to the actual operation, the Parallel scavenge collector adjusts the proportion of the Cenozoic eden:survivor in order to achieve the target throughput.

4.Serial Old Collector

It is the old version of the serial collector, using the tag grooming algorithm. The main meaning is to use the virtual machine in client mode.

In server mode, the JDK1.5 and previous versions are paired with the parallel scavenge collector.

In addition, the Serial old collector is also a preparation method for the CMS collector, which is used when concurrent Mode failure appears.

5.Parallel Old Collector

It is the old-age collector of the parallel scavenge collector, which uses multi-threaded tagging to organize the algorithm.

6.CMS (Concurrent Mark Sweep)

It pursues a low pause time, suitable for attention to service response speed scenarios, such as the Internet site B/s system on the server side.

CMS is based on the tag cleanup algorithm, divided into 4 steps:

1. Initial mark (CMS Initial Mark)

It takes a short time to pause the user thread and mark the objects that root can directly relate to.

2. Concurrent tagging (CMS Concurrent mark)

The process of root tracing without pausing the user thread

3. Re-tagging (CMS Remark)

The user thread needs to be paused in order to fix the tag record of the part of the object that generated the tag changes during the concurrent tag because the user thread continues to run.

The pause time in this phase is generally slightly longer than the initial marker phase, but is much shorter than the concurrent marker time.

4. Concurrent Purge (CMS Concurrent Sweep)

The disadvantages of the CMS collector are:

1) swallowing measures decreased;

2) Unable to clear floating garbage (due to garbage collection phase, user thread execution of garbage generated);

3) The tag cleanup algorithm generates memory fragmentation.

7.G1 Collector

The G1 collector is the most advanced and cutting-edge garbage collector, features:

1. Parallel and concurrency, similar to the CMS collector;

2. Collection of generations. G1 can independently manage the garbage collection of the entire Java heap;

3. Space integration, does not produce memory fragmentation. From the whole, G1 is based on the labeling algorithm, from the local (two region) is based on the replication algorithm;

4. Predictable pauses.

The G1 collector divides the entire Java heap into separate regions of equal size (region). G1 tracks the value of the garbage accumulation in each region (reclaim the acquired space and reclaim time-consuming experience values).

Maintain a prioritized list in the background, giving priority to recovering the most valuable region (the name of the Garbage-first) each time it is allowed to collect.

G1 Collector Execution Steps:

1. Initial mark (Initial marking)

2. Concurrent tagging (Concurrent marking)

3. Final mark (final marking)

4. Filter collection (Live Data counting and evacuation)

The previous 3 steps are similar to the CMS collector. In the final step of the filter collection, the G1 collector first sorts the recovery value and cost of each region, making a recovery plan based on the user's expected pause time.

From the information disclosed by Sun, the filter recovery phase can actually be done concurrently with the user program, but because only a portion of the region, the time is user-controllable.

And the pause user thread will greatly improve the collection efficiency, so the scheme of filtering and recycling is performed in parallel by suspending the user program.

Memory management----Garbage collector for Java virtual machines

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.