Deep JVM Reading Notes (iv)--java garbage collector

Source: Internet
Author: User

Garbage collector:

The main implementation of Java's garbage collection mechanism is the "garbage collector", but the garbage collector provided by each vendor's virtual machine is very different, and even the same virtual machine provides several separate garbage collectors for users to combine according to their different characteristics. Is the collector that the hot spot virtual machine contains, and then describes the characteristics of each collector.

    

Before introducing the various collectors, confirm the concept of parallelism and Concurrency: (below is the context of the garbage collector)

L Parallel (Parallel): Multiple garbage collection threads work in parallel, but the user thread is still waiting.

L Concurrency (Concurrent): The user thread executes concurrently with the garbage collection thread (not necessarily parallel, possibly alternately), the user program continues to run, and the garbage collector runs on the other CPU.

1.Serial Collector (New Generation – serial GC)

The most basic and oldest collector, he is a single-threaded collector, and single-threaded means that when he is in the garbage collection, must suspend all other work threads, called "Stop the World".

Advantage: Simple and efficient (compared to the single thread of other collectors), in a single CPU-bound environment, without the overhead of additional thread interaction, the maximum efficiency can be achieved.

Applicable: A virtual machine running in client mode.

2.ParNew Collector (New generation – parallel GC)

The Parnew collector is actually a multithreaded version of the serial collector, except for garbage collection using multiple threads, and the rest is the same as serial all control parameters. The default Cenozoic collector, which is configured as a CMS GC, can be specified with-XX:+USEPARNEWGC.

Pros: In a multi-CPU environment, it can be more efficient and the only new generation of parallel GC that can work with CMS collectors.

Applicable: A new generation collector is preferred for virtual machines running in server mode.

3.Parallel Scavenge collector (New generation – Parallel recovery GC)

It doesn't look like parnew, but parallel scavenge's biggest feature is that his focus is on CPU throughput, throughput = running code time/(Running code time + garbage collection time). Higher throughput can best take advantage of the efficiency of the CPU. -xx:maxgcpausemillis Configure the maximum garbage collection pause time,-xx:gctimeratio Configure the throughput size.

Advantage: Known as the "throughput first" collector, there is an adaptive tuning parameter (-xx:+useadaptivesizepolicy) that, when opened, eliminates the need to manually specify the Cenozoic size (-xmn), Eden, and survivor ratios (-XX: Survivorratio), the age limit (-xx:pretenuresizethreshold), and other details, the virtual opportunity dynamically adjusts these parameters to provide the most suitable pause time or maximum throughput.

Applicable: The default GC mode on a server-level multi-CPU machine, can also be specified by-XX:+USEPARALLELGC, and can be-xx:parallelgcthread to specify the number of threads.

4.Serial Old collector (older generation – serial GC)

Serial old is an older version of the Serial collector, also a single-threaded collector, using the "mark-and-organize" algorithm.

Applicable: Virtual machine used in client mode, two major uses in server mode: used in conjunction with parallel scavenge collector, as backup plan for CMS collector.

5.Parallel Old collector (older – parallel GC)

Parallel old is an older version of the Parallel scavenge collector, developed for matching the throughput-oriented nature of Parallel scavenge.

Application: Used in situations where throughput and CPU resource sensitivity are a priority.

6.CMS collector (old age – concurrent GC)

The CMS (Concurrent Mark Sweep) collector is a collector that targets the shortest recovery pause time. Based on the "tag-purge" algorithm, the entire process is divided into 4 steps: the initial tag (CMS initial mark), the Concurrency token (CMS concurrent mark), the re-tagging (CMS remark), and the Concurrent Purge (CMS concurrent sweep).

Where the initial tag, the re-tag is still "Stop the World", the initial tag is simply to mark the GC Roots can be directly associated with the object, the concurrent tagging of GC Roots tracing process, Re-tagging in order to fix the part of the object that caused the markup to change as the user program continues to run during the concurrency token, the stage pauses slightly longer than the initial marker phase, but is shorter than the concurrent tag time.

Advantages: Concurrent collection, low pause.

Application: Pay attention to the service response speed, system downtime and user experience of the Internet site or b/s system.

7.G1 Collector

The G1 (garbage first) collector is the forefront of current collector technology, with two significant improvements over previous CMS: collector and precise control pauses based on the "mark-and-organize" algorithm. The ability to perform low-pause memory recoveries without sacrificing throughput.

Report:

Default GC combination:

    

Optional GC combinations:

    

Resources:

http://blog.csdn.net/zhangren07/article/details/6270895

Http://www.blogjava.net/chhbjh/archive/2012/01/28/368936.html

Deep JVM Reading Notes (iv)--java garbage collector

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.