Exploring Java 7's new Garbage Collector G1 feature

Source: Internet
Author: User

G1 garbage collector (G1 GC) is a new Garbage Collector introduced by Java HotSpot VM in JDK 7, java SE 6 Update 14 already contains a G1 version (according to BKJIA's previous report, when Java SE 6 u14 debuted in early June, Sun's original statement was: the G1 Garbage Collector must be charged for use. Shortly afterwards, Sun said that this was a misunderstanding, modified the original statement, and said that the current and future use of G1 is completely free ), g1 is designed to replace the HotSpot low-latency parallel mark/clear garbage collector (also called CMS.
Java 7 G1 attributes

G1 is a server-side garbage collector with the following attributes:

◆ Concurrency and concurrency: G1 utilizes the concurrency in today's hardware. When the Java application thread is stopped, it uses all available CPU (core, hardware thread, etc) accelerate Its stop and run Java threads to minimize the entire stack during the stop process.

◆ Generation: Like other HotSpot GC, G1 is a generation, which means that it is processing newly allocated objects (young generation) and objects that have survived for a period of time (old generation) different, it is mainly concentrated on the garbage collection activities on new objects, because they are the most likely to be recycled, the old objects are only occasionally accessed, for most Java applications, replacement of garbage collection has important advantages for alternative solutions.

◆ Compression: Unlike CMS, G1 compresses the stack over time. Compression eliminates potential fragmentation issues and ensures smooth and consistent operations during long running.

◆ Predictability: G1 has better predictability than CMS, because it eliminates the benefits of fragment issues and has no negative impact during CMS stop. In addition, G1 has a pause prediction model, allow it to meet (or rarely exceed) the pause time target.

Java 7 G1 description

Compared with other HotSpot GC, G1 adopts a very different STACK layout method. in G1, there is no physical isolation between the young generation and the old generation. On the contrary, there is a continuous stack between them, which is divided into regions of the same size (region). The young generation may be a set of discontinuous regions, and the old generation may be the same, this allows G1 to flexibly move resources between the young and old generations.

Recycling in G1 occurs by eliminating the pause. During this period, survivors refer to the transfer of the collection back to another region so that the recovery area can be regenerated and the elimination of the pause is parallel, all available CPUs will participate, most of which eliminate the available young areas for paused collection, which is the same as the young recycling in other HotSpot GC. During the paused period, the old area will also be selected occasionally for recycling, g1.

Similar to CMS, G1 periodically executes a concurrent mark pause. The primary responsibility of this phase is to identify which old area of junk objects are the most complete, because these are the most effective and worthy of recovery, unlike CMS, G1 does not execute concurrent cleanup pause. On the contrary, the most useful old area is the mark of the pause through the concurrent mark, it is recycled during the subsequent elimination pause.

Use G1

G1 is still regarded as a test item. You can use the following two parameters to enable it:

-XX: + UnlockExperimentalVMOptions-XX: + UseG1GC to set a GC pause time target, use the following parameters:

-XX: MaxGCPauseMillis = 50 (pause time target 50 ms) When G1 is used, you can also specify the time interval. This can be used when the GC pause duration is not longer than the preceding time range:

-XX: GCPauseIntervalMillis = 200 (pause interval objective: 200 ms) Pay attention to the goals described in the preceding two options. There is no commitment or guarantee, and in some cases they may work, GC is not always able to execute them.

In addition, the size of the young generation can clearly specify the impact elimination Pause Time:

-XX: + G1YoungGenSize = 512 m (young generation size: 512 M) G1 also uses the surviving space (possibly non-contiguous regions). Their size can be specified using a common parameter, for example:

-XX: Unknown vorratio = 6 finally, in order to run G1 to make full use of its potential, try to set the following two default disabled parameters, because they may expose a rare competition status:

-XX: + G1ParallelRSetUpdatingEnabled-XX: + G1ParallelRSetScanningEnabled. Note that after-XX: + PrintGCDetails is set, G1 is much wordy than other HotSpot GC methods, because it prints the timing of each GC thread and other information that helps with troubleshooting, if you want to make GC logs simpler, use the-verbosegc parameter.

Latest Developments in Java 7 G1

G1 development now focuses on the legacy reliability issues and performance improvement, while also gradually removing the following restrictions:

◆ G1 does not fully support JVM tool interfaces (jvm ti) or Java Management Extensions (JMX). Therefore, G1 monitoring and management tools may not work properly;

◆ G1 does not support incremental permanent replacement recovery. If an application generates many types of dump, permanent replacement recovery is required, which can be implemented during full GC;

◆ For GC pause time, G1 sometimes performs better than CMS and sometimes worse than CMS.

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.