Deep understanding of Java Virtual Machines (v): Hotspot garbage Collection algorithm implementation

Source: Internet
Author: User
Tags garbage collection

This article is about the Sun hotspot virtual machine implementation, mainly explained Serial,parnew,parallel scavenge,serial old,cms (Concurrent Marsk Sweep), Parallel old, G1 (Garbage-i) garbage collector.

First look at the Java heap memory structure, which is suitable for garbage collectors outside the G1 collector:


First , according to the life cycle of Java objects, the Java heap memory is divided into old age and young generation, and the new age can be controlled by parameter-xmn10m .
Then the young generation is divided into 3, a Eden area, two survivor regions of equal size, the size of the Eden area and the survivor area can be controlled by the parameter-xx:survivorratio=8 .
In the garbage collection area there is an interesting statement "Stop the World" because when garbage collection is performed, all user threads need to be stopped.

1. Serial Collector

Young Generation collector.
The replication algorithm is used.
As the name suggests, it is a single-threaded collector. The new generation default collector for virtual machines in client mode . 2. Parnew collector

Young Generation collector.
The replication algorithm is used.
is actually a multi-threaded version of the serial collector.
The new generation default collector for virtual machines in server mode.
The Parnew Collector is also the default Cenozoic collector after using the-XX:+USECONCMARKSWEPGC option, or you can use the-XX:+USEPARNEWGC option to force it to be specified.
It has the same number of collection threads as the CPU by default, and can limit the number of garbage collection threads by-xx:parallelgcthreads parameters. 3. Parallel Scavenge collector

Young generation collector.
The replication algorithm is used.
Parallel collector.
The focus is on achieving a controllable throughput (throughput first), rather than the wait time for the user thread as much as the other collectors can shorten garbage collection.
Throughput is the ratio of the CPU's running user code to the total time elapsed, i.e. throughput = Run user code time/(run user code time + garbage collection time).
The parameter-xx:maxgcpausemillis parameter is used to control the maximum garbage collection pause time.
The parameter-xx:gctimeratio directly sets the throughput size (garbage collection time ratio, the countdown to throughput). 4. Serial Old collector

Old age collector.
Using tag-finishing algorithm.
Single threaded, similar to serial collectors.
The default old age collector for virtual machines in client mode. 5. Parallel Old collector

old age collector.
Using tag-finishing algorithm.
Multithreading, similar to the parallel scavenge collector.
Used with parallel scavenge collectors. 6. CMS Collector

old age collector.
Using the tag-purge algorithm.
Get the shortest recovery pause time for the purpose.
The whole process is divided into 4 steps:
Initial tag
Concurrent markup
Re-mark
Concurrency cleanup
The two steps of initial marking and re tagging still require "Stop the world".
The number of recycle threads that are enabled by default is (number of CPUs +3)/4.
The value of the parameter -xx:cmsinitiatingoccupancyfraction to trigger the garbage collection. 7. G1 (garbage) collector

Today, the development of collector technology is the most cutting-edge technology.
Released from jdk1.7.

Attached: JVM memory layout and garbage collection and management detailed http://blog.csdn.net/chaofanwei/article/details/12028831

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.