Introduction to several common garbage collectors for Java virtual machines

Source: Internet
Author: User

New Generation Collectors

Serial Collecting Device

It is the most basic and oldest collector, and before JDK1.3.1 is the only option for the generation of virtual machines to collect. It is a single-threaded collector, and until now it is still the default new generation collector that the virtual machine runs in client mode. Advantages: simple and efficient.

Feature: Only one CPU or one collection thread will be used to complete the garbage collection work, and all other worker threads must be paused until the collection is completed when garbage collection occurs. It does not have the overhead of thread interaction, so it can achieve the highest single-thread collection efficiency.

parnew Collecting Device

The multithreaded version of the serial collector, in addition to using multiple threads for garbage collection, behaves exactly like the serial collector. is the preferred Cenozoic collector in a virtual machine in server mode. Currently only it can work with the CMS collector. Is the default Cenozoic collector after the-XX:+USECONCMARKSWEEPGC option, or you can use the-XX:+USEPARNEWGC option to force it. The number of collection threads opened by default is the same as the number of CPUs. You can use the-xx:parallelgcthreads parameter to limit the number of threads that are garbage collected.

Parrallel Scavenge Collector

This collector's focus is on achieving a controllable throughput. High throughput makes the most efficient use of CPU time and completes the operation of the program as quickly as possible, primarily for tasks in the background that do not require much interaction.

Throughput = time to run user code/(run user code time + garbage Collection Time)

-xx:maxgcpausemillis Control maximum garbage collection pause time

-xx:gctimeratio directly set throughput size

-xx:useadaptivesizepolicy Open Adaptive Adjustment strategy

Old age Collector

Serial Old Collecting Device

Older versions of the serial collector, using the "mark-and-Organize" algorithm

parrallel Old Collecting Device

Parrallel scavenge old version, using multithreading and the "mark-and-organize" algorithm,

CMS (Concurrent Mark Sweep) Collecting Device

Based on the "mark-clear" algorithm implementation, to obtain the shortest payback time for the target collector, mainly used to pay attention to the service response speed of applications such as the b\s system service side.

Process:

Initial tag: Stop the world is required, just mark the object that GC roots can relate to, fast.

Concurrency token: The process of GC Root tacing.

Re-tagging: Requires stop the world, fixed the tag record of the part of the object that caused the tag to change during the concurrency tag, and the pause time is slightly longer than the initial mark phase, but is much shorter than the concurrent tagging phase.

Concurrent purge: for concurrent cleanup.

Disadvantages:

1, CPU resource-sensitive, will occupy a portion of the thread resources, the default number of boot threads is (number of CPUs +3)/4

2, unable to handle floating garbage, may appear "Concurrent Mode Failure" failure resulting in another full GC generation.

The CMS is activated by default for 68% of space in the old age, and can be adjusted to increase the trigger percentage by appropriately adjusting the value of the parameter-xx:cmsinitiatingoccupancyfraction, in order to reduce the number of memory recoveries for better performance. But can not be set too high, to reserve the appropriate memory for the program to use, otherwise the "Concurrent Mode Failure" will cause the virtual machine to start the backup plan temporarily enable the serial old collector to re-age garbage collection, so that the pause time is very long.

3. A large amount of space debris may be generated, leading to a full GC starting early.

Parameter-xx:usecmscpactatfullcollection, sets whether the CMS will perform a memory defragmentation once the garbage collection is complete. Effective only when using the CMS collector

Parameter-xx:fullgcsbeforecompaction, set the CMS collector to start a memory defragmentation after a number of garbage collection times. Effective only when using the CMS collector

G1 Collecting Device

Based on the "mark-and-organize" algorithm, the pause can be controlled very precisely. (//to do)

Introduction to several common garbage collectors for Java virtual machines

Related Article

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.