Types of HotSpot VM GC

Source: Internet
Author: User

Collector species

There are four types of GC in HotSpot VM 5.0:

incremental (sometimes called train) low pause collector has been deprecated, not introduced.

Category Serial collector Parallel collector
( throughput collector )
Concurrent Collector
(Concurrent low Pause collector)
Introduced

Single Thread Collector
Using a single thread to do all the GC work, without the communication between the threads, this method is relatively efficient

Parallel collector
Use multiple cups to improve GC efficiency using multi-threaded approach
Mainly to reach a certain throughput as the goal

Concurrent Collectors
Use multiple cups to improve GC efficiency using multi-threaded approach
Perform most of the work concurrently, making the GC pause short

trial scene single processor machine with no pause time requirements

for science and technology and background processing
applications with medium-size/large-scale data set size and running on multiprocessor, focusing on throughput (throughput)

Suitable for medium-scale/large-scale data set size applications, Application server, telecom field
Focus on response time, not throughput

use client mode default
can use
Use-XX:+USESERIALGC to enforce
Benefits: No advantages to server apps
Disadvantage: slow, not fully use hardware resources

Server mode default

--ygc:ps fgc:parallel MSC

Use-XX:+USEPARALLELGC or-XX:+USEPARALLELOLDGC to enforce the designation

-- PARALLELGC represents FGC for parallel MSC

--PARALLELOLDGC represents FGC for parallel compacting

Benefits : Efficient

Disadvantage : When the heap becomes larger, the pause time will become longer

available-xx:+ USECONCMARKSWEEPGC enforce
Advantage :
When you recycle old, the pause time for the application is very high, and it is suitable for applications that require higher latency
Disadvantages :
1. Memory fragmentation and floating garbage
2.old away memory allocation inefficient
3. The overall time spent on recycling
4. And application Scramble CPU
Memory Recovery Trigger Ygc
Eden Space is low
FGC
Old space is low
Perm Lack of space
Display call System.GC (), including the timing trigger for RMI, etc.
A pessimistic strategy when YGC
Dump Live Memory information (jmap–dump:live)
Ygc
Eden Space is low
FGC
Old space is low
Perm Lack of space
Display call System.GC (), including the timing trigger for RMI, etc.
YGC when the pessimistic strategy--YGC before &YGC
Dump Live Memory information (jmap–dump:live)
Ygc
Eden Space is low
CMS GC
1.old Gen's usage rate is a certain ratio of 92% by default
2. Cmsclassunloadingenabled is configured, and Perm Gen usage reaches a certain ratio by default of 92%
3.Hotspot decide whether to touch the law by its own estimation
4. System.GC is called when Explictgcinvokesconcurrent is configured.
Full GC (Serial MSC)
Promotion failed or concurrent Mode failure;
What happens when a memory recovery is triggered Ygc
Empties the memory occupied by all no ref objects in Eden+from
Copy all the surviving objects in the Eden+from to the To
In this process, some objects will be promoted to old:
--to not fit.
--The number of survivors exceeds tenuring threshold
Recalculate tenuring Threshold;
Single-threaded to do the above actions
Full Suspension Application
FGC
If Collectgen0first is configured, the YGC is triggered first
Clears the object of no ref in the heap, and the class information loaded in the ClassLoader that has been unloaded in the PermGen
Single-threaded to do the above actions
Full Suspension Application
Ygc
Same as serial action, different points:
1. Multithreaded processing
At the end of the 2.YGC, the tenuring Threshold is recalculated, and the Eden and from are re-resized
FGC
1. If SCAVENGEBEFOREFULLGC (default) is configured, the YGC (??) is triggered first.
2.MSC: Empties the no ref object in the heap, PermGen the class information loaded in the ClassLoader that has been unloaded, and compresses
3.Compacting: Empty Some of the no ref objects in the heap, PermGen the class information loaded in the ClassLoader that have been unloaded, and partially compress
Multithreading to do the above actions.


Ygc
Same as serial action, different points:
1. Multithreaded processing
CMSGC:
1.old Gen arrival ratio clears only the space occupied by objects of no ref in old Gen
2.perm Gen arrival ratio clears only the ClassLoader loaded class information that has been cleared
FGC
With serial
Detail parameters Available-XX:+USESERIALGC forced use
-xx:survivorratio=x, controlling the size of the EDEN/S0/S1
-xx:maxtenuringthreshold to control the maximum number of times an object survives in the Cenozoic
-xx:pretenuresizethreshold=x, objects that control more than a large number of bytes are allocated in the old.
-xx:survivorratio=x, controlling the size of the EDEN/S0/S1
-xx:maxtenuringthreshold to control the maximum number of times an object survives in the Cenozoic

-xx:useadaptivesizepolicy remove YGC to dynamically adjust Eden from already tenuringthreshold action

-xx:parallelgcthreads setting the number of threads in parallel

-xx:cmsinitiatingoccupancyfraction set when Old Gen is used to reach how much ratio is triggered
-xx:cmsinitiatingpermoccupancyfraction, setting perm gen usage to reach how much ratio is triggered
-xx:+usecmsinitiatingoccupancyonly prohibit hostspot self-triggering CMS GC

Note:

    • The difference between throughput collector and concurrent low pause collector is that throughput collector uses multi-threading only in young area, while concurrent low pause Collector also uses multithreading in tenured generation.
    • According to the official documentation, both of them need to be in a multi-CPU situation to work. In the case of a CPU, it would be inferior to the default serial collector, because thread management consumes CPU resources. And in the case of two CPUs, it also raises little. It only increases in the case of more CPUs. Of course concurrent low Pause collector has a pattern that can be used on less CPU machines, providing as few pauses as possible, see CMS GC Incrementalmode.
    • When you want to use throughput collector, add-XX:+USEPARALLELGC to Java opt and start throughput collector collection. You can also add-xx:parallelgcthreads=<desired number> to change the number of threads. There are also two parameters-xx:maxgcpausemillis=<nnn> and-xx:gctimeratio=<nnn>,maxgcpausemillis=<nnn> to control the maximum pause time, while the-XX : Gctimeratio can increase the ratio of the GC to the CPU, reducing the heap by the largest number of words.

Note Sun's official note :

1. The throughput Collector:this Collector uses a parallel version of the young generation collector. It is used if THE-XX:+USEPARALLELGC option was passed on the command line. The tenured generation collector is the same as the serial collector.

2. The concurrent low Pause collector:this collector is used if THE-XINCGC™OR-XX:+USECONCMARKSWEEPGC are passed on the Command line. The concurrent collector is used to collect the tenured generation and does most of the collection concurrently with the E Xecution of the application. The application is paused for short periods during the collection. A parallel version of the young generation copying collector are used with the concurrent collector. The concurrent low Pause collector is used if the OPTION-XX:+USECONCMARKSWEEPGC are passed on the command line.

3. The incremental (sometimes called train) low pause collector:this collector are used only IF-XX:+USETRAINGC are passed On the command line. This collector have not changed since the J2SE Platform version 1.4.2 and are currently not under active development. It is not being supported in the future releases. Please see the 1.4.2 GC Tuning Document For information in this collector.

CMS GC Incremental Mode

When you want to use concurrent low pause collector, add-XX:+USECONCMARKSWEEPGC to the Java opt. Concurrent low Pause collector also has a model for a machine with less CPU, called incremental mode. This mode uses a CPU to run the program during the GC, with little time to pause the program and check that the object survives.

In incremental mode, each collection process is suspended two times and the second is slightly longer. For the first time, simply query the surviving object from root. A second time is used to examine the surviving object in detail. The whole process is as follows:

* Stop all application threads; Do the initial mark; Resume all application threads (first pause, initial session mark)
* Do the concurrent mark (uses one procesor for the concurrent work) (Run as tag)
* Do the concurrent Pre-clean (uses one processor for the concurrent work) (ready to clean up)
* Stop all application threads; Do the remark; Resume all application threads (second pause, mark, check)
* Do the concurrent sweep (uses one processor for the concurrent work) (clean up during operation)
* Do the concurrent Reset (uses one processor for the concurrent work) (recovery)

When you want to use incremental mode, you need to use the following variables:

-xx:+cmsincrementalmode default:disabled start I-cms mode (must WITH-XX:+USECONCMARKSWEEPGC)
-xx:+cmsincrementalpacing default:disabled provides auto-correction function
-xx:cmsincrementaldutycycle=<n> default:50 start CMS on-line
-xx:cmsincrementaldutycyclemin=<n> default:10 Start the downline of the CMS
-xx:cmsincrementalsafetyfactor=<n> Default:10 used to calculate the number of cycles
-xx:cmsincrementaloffset=<n> default:0 Minimum cycle times (This is the percentage (0-100) by which the incremental mode duty CYC Le is shifted to the right within the period between minor collections.)
-xx:cmsexpavgfactor=<n> Default:25 provides a guide to the collection of
Sun's recommended usage parameters are:
-XX:+USECONCMARKSWEEPGC \
-xx:+cmsincrementalmode \
-xx:+cmsincrementalpacing \
-xx:cmsincrementaldutycyclemin=0 \
-XX:CMSINCREMENTALDUTYCYCLE=10 \
-XX:+PRINTGC Details \
-xx:+printgctimestamps \
-xx:-traceclassunloading
Note: If you use throughput collector and concurrent low pause collector, both of these garbage collectors need to be appropriately high in memory size to prepare for multithreading.

How to choose Collector:

    • The app runs on a single-processor machine without pause time requirements, allowing the VM to select or UseSerialGC .
    • Focus on peak application performance (high performance), no pause time is too stringent, let VMs choose or useparallelgc+UseParallelOldGC(optionally).
    • 重点考虑response time,pause time要小,UseConcMarkSweepGC.

Garbage collctor–future

    • Garbage First (G1)
      jdk1.6 Update or JDK7
    • Few flags need to set
      -xx:maxgcpausemillis=100
      -xx:gcpauseintervalmillis=6000

Have not tried to use ...

Summary

Import java.util.ArrayList;
Import java.util.List;
public class Summarycase {
public static void Main (string[] args) throws Interruptedexception {
list<object> caches = new arraylist<object> ();
for (int i = 0; i < 7; i++) {
Caches.add (New byte[1024 * 1024 * 3]);
Thread.Sleep (1000);
}
Caches.clear ();
for (int i = 0; i < 2; i++) {
Caches.add (New byte[1024 * 1024 * 3]);
Thread.Sleep (1000);
}
}
}
Executed with the following two parameters, how many YGC will be executed several times FGC?
  • -xms30m-xmx30m-xmn10m -XLOGGC:GC.LOG-XX:+PRINTTENURINGDISTRIBUTION-XX:+USEPARALLELGC
     2.062: [  GC 
    Desired survivor size 1310720 bytes, new threshold 7 (max)
    6467k->6312k (29440K), 0.0038214 secs]
    4.066: [GC
    Desired survivor size 1310720 bytes, new threshold 7 (max)
    12536k->12440k (29440K), 0.0036804 secs]
    6. 070: [GC
    Desired survivor size 1310720 bytes, new threshold 7 (max)
    18637k->18584k (29440K), 0.0040175 secs]6.074: [Full GC 18584k->18570k (29440K), 0.0031329 secs]
    8.078: [Full GC 24749k->3210k (29440K), 0.0045590 secs ]
    (see http://rdc.taobao.com/team/jm/archives/440 for specific analysis)
  • -xms30m-xmx30m-xmn10m-xloggc:gc.log-xx:+printtenuringdistribution-xx:+useserialgc
    2.047: [GC
    Desired survivor size 524288 bytes, new threshold (Max 15)
    -Age 1: 142024 bytes, 142024 Total
    6472K->6282K (29696K), 0.0048686 secs]
    4.053: [GC
    Desired survivor size 524288 bytes, new threshold (Max 15)
    -Age 2: 141880 bytes, 141880 Total
    12512k->12426k (29696K), 0.0047334 secs]
    6.058: [GC
    Desired survivor size 524288 bytes, new threshold (Max 15)
    -Age 3: 141880 bytes, 141880 Total
    18627k->18570k (29696K), 0.0049135 secs]
    8.063: [Full GC 24752k->3210k (29696K), 0.0077895 secs]
    (See http://rdc.taobao.com/team/jm/archives/458 for specific analysis)

Reference:

    1. http://jiangyongyuan.iteye.com/blog/356502
    2. http://www.helloying.com/blog/archives/164
    3. Http://hi.baidu.com/sdausea/blog/item/c599ef13fcd3a7dbf6039e12.html
    4. Tuning garbage Collection with the 1.4.2 JAVATM Virtual machine.
    5. http://blog.bluedavy.com/?p=200
    6. Http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

Types of HotSpot VM GC

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.