Types of hotspot VM GC

Source: Internet
Author: User

Collector type

GC has four types in hotspot VM 5.0:

Incremental (sometimes called Train) Low pause collector It has been deprecated and is not introduced.

Category Serial collector Parallel collector
(Throughput collector)
Concurrent collector
(Concurrent low pause collector)
Introduction

Single-thread collector
It is relatively efficient to use a single thread to complete all GC tasks without inter-thread communication.

Parallel collector
Improve GC efficiency by using multiple CPUs in multi-thread mode
It is mainly aimed at reaching a certain throughput.

Concurrent collector
Improve GC efficiency by using multiple CPUs in multi-thread mode
Concurrency completes most of the work, making GC pause short

Trial Use Case Single-processor machine without pause time requirements

applicable to science and technology and background processing
Applications with medium/large data sets and running on multiple processors, throughput

suitable for applications with medium-scale/large-scale data sets, application servers, and telecommunications
focus on response time, instead of throughput

use default value in client mode
available-XX: + useserialgc force use
advantages: no advantages for server applications
disadvantages: low speed, insufficient hardware resources

default in server mode

-- ygc: ps fgc: parallel MSC

available-XX: + useparallelgc or-XX: + useparalleloldgc forcibly specified

-- parallelgc indicates that FGC is parallel MSC

-- paralleloldgc indicates that FGC is parallel compacting

advantages : high Efficiency

disadvantage : When the heap increases, the pause time becomes longer.

available-XX: + useconcmarksweepgc forcibly specified
advantages :
when you recycle old objects, the pause time caused by the application is very short. It is suitable for applications with high latency requirements.
disadvantages :
1. memory fragmentation and floating garbage
2. old memory allocation efficiency is low
3. the entire recycling time is relatively long
4. compete for CPU with applications
Memory recycle trigger Ygc
Insufficient Eden Space
FGC
Insufficient old space
Insufficient perm Space
Displays scheduled calls to system. GC (), including RMI.
Pessimistic strategy in ygc
Dump live memory information (jmap-dump: Live)
Ygc
Insufficient Eden Space
FGC
Insufficient old space
Insufficient perm Space
Displays scheduled calls to system. GC (), including RMI.
Pessimistic strategy for ygc-before and after ygc
Dump live memory information (jmap-dump: Live)
Ygc
Insufficient Eden Space
CMS GC
1. The default usage rate of Old Gen is 92%.
2. cmsclassunloadingenabled is configured, and the use of perm Gen reaches a certain ratio. The default value is 92%.
3. hotspot determines whether to touch the method based on estimation.
4. When explictgcinvokesconcurrent is configured, The system. GC is called.
Full GC (Serial MSC)
Promotion failed or concurrent mode failure;
What happens when memory reclaim is triggered? Ygc
Clear memory occupied by all No ref objects in Eden + from
Copy all surviving objects in Eden + from
In this process, some objects will be promoted to the old:
-- To cannot be placed
-- The number of surviving times exceeds tenuring threshold
Recalculate tenuring threshold;
The preceding actions are performed by a single thread.
Suspend the application
FGC
If collectgen0first is configured, ygc is triggered first.
Clears the No ref object in heap and the class information loaded in the uninstalled classloader in permgen.
The preceding actions are performed by a single thread.
Suspend the application
Ygc
Similar to serial actions, the differences are as follows:
1. Multithreading
2. At the end of ygc, not only will tenuring threshold be re-calculated, but the Eden and from sizes be re-adjusted.
FGC
1. If scavengebeforefullgc is configured (default), ygc (?) is triggered first (??)
2. MSC: Clear the No ref object in heap, and compress the class information loaded in the uninstalled classloader in permgen.
3. compacting: clears some No ref objects in the heap, class information loaded in the uninstalled classloader in the permgen, and partially compresses
Multiple Threads perform the preceding operations.

Ygc
Similar to serial actions, the differences are as follows:
1. Multithreading
Cmsgc:
1. When Old Gen reaches the ratio, only the space occupied by no ref objects in Old Gen is cleared.
2. When perm Gen reaches the ratio, only the class information loaded by the cleared classloader is cleared.
FGC
Same as serial
Detailed Parameters -XX: + useserialgc mandatory
-XX: Required vorratio = X, which controls the size of Eden/S0/S1
-XX: maxtenuringthreshold, used to control the maximum number of times objects survive the new generation.
-XX: pretenuresizethreshold = x. Objects whose size exceeds the size of bytes are allocated in the old format.
-XX: Required vorratio = X, which controls the size of Eden/S0/S1
-XX: maxtenuringthreshold, used to control the maximum number of times objects survive the new generation.

-XX: useadaptivesizepolicy: After ygc is removed, the Eden From tenuringthreshold action is dynamically adjusted.

-XX: parallelgcthreads sets the number of parallel threads.

-XX: cmsinitiatingoccupancyfraction is triggered when the ratio of Old Gen usage is set
-XX: cmsinitiatingpermoccupancyfraction, which is triggered when the ratio of perm Gen usage is set.
-XX: + usecmsinitiatingoccupancyonly prohibits hostspot from triggering cms gc by itself

Note:

    • The difference between throughput collector and concurrent low pause collector is that throughput collector only uses multithreading in the young area, while concurrent low pause collector uses multithreading in tenured generation.
    • According to the official documentation, the two of them need to play a role in the case of multiple CPUs. In the case of a CPU, It is inferior to the default serial collector because thread management consumes CPU resources. In the case of two CPUs, the increase is not significant. It can be improved only when more CPUs are available. Of course, concurrent low pause collector has a mode that provides as few pause modes as possible on machines with fewer CPUs. For details, seeCms gc incremental Mode.
    • To use throughput collector, add-XX: + useparallelgc to Java opt to start throughput collector collection. You can also add-XX: parallelgcthreads = <desired number> to change the number of threads. Two other parameters-XX: maxgcpausemillis = <NNN> and-XX: gctimeratio = <NNN>, maxgcpausemillis = <NNN> are used to control the maximum pause time, while-XX: gctimeratio can increase the CPU proportion of GC, and minimize heap.

Official notes to Sun:

1. the throughput COLLECTOR: This collector uses a parallel version of the young generation collector. it is used if the-XX: + useparallelgc option is 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 is passed on the command line. the concurrent collector is used to collect the tenured generation and does most of the collection concurrently with the execution of the application. the application is paused for short periods during the collection. A parallel version of the young generation copying collector is used with the concurrent collector. the concurrent low pause collector is used if the option-XX: + useconcmarksweepgc is passed on the command line.

3. the incremental (sometimes called Train) Low pause COLLECTOR: This collector is used only if-XX: + usetraingc is passed on the command line. this collector has not changed since the j2se platform version 1.4.2 and is currently not under active development. it will not be supported in future releases. please see the 1.4.2 GC tuning document for information on 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 mode for preparing machines with fewer CPUs, called incremental mode. In this mode, a CPU is usedProgramDuring the running process, GC only takes a short time to pause the program and check whether the object is alive.

In incremental mode, each collection process is paused twice, and the second time is slightly longer. Used for the first time to simply query the surviving objects from the root. The second time is used to check the surviving objects in detail. The process is as follows:

* Stop all application threads; Do The initial mark; resume all application threads (first pause, initial call Mark)
* Do The concurrent mark (uses one procesor For The concurrent Work) (running is a tag)
* Do The concurrent pre-clean (uses one processor For The concurrent Work) (prepare for cleanup)
* 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) (cleanup during running)
* Do The concurrent reset (uses one processor For The concurrent Work (recovery)

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 the automatic correction function.
-XX: cmsincrementaldutycycle = < N > Default: 50 launch CMS
-XX: cmsincrementaldutycyclemin = < N > Default: 10 start CMS offline
-XX: cmsincrementalsafetyfactor = < N > Default: 10 is used to calculate the number of cycles.
-XX: cmsincrementaloffset = < N > Default: 0 minimum number of cycles (this is the percentage (0-100) by which the incremental mode duty cycle is shifted to Right Within the period between minor collections .)
-XX: cmsexpavgfactor = < N > Default: 25 provides a number of guided collections

Sun recommends the following parameters:

-XX: + useconcmarksweepgc \
-XX: + cmsincrementalmode \
-XX: + cmsincrementalpacing \
-XX: cmsincrementaldutycyclemin = 0 \
-XX: cmsincrementaldutycycle = 10 \
-XX: + printgc details \
-XX: + printgctimestamps \
-XX:-traceclassunloading

NOTE: If throughput collector and concurrent low pause collector are used, these two garbage collectors must have a high memory size to prepare for multithreading.

How to Select COLLECTOR:

    • The app runs on a single processor without the pause time requirement.Useserialgc.
    • Peak application performance (High Performance) with no strict pause time requirements. Let the VM select or useparallelgc +Useparalleloldgc(Optionally ).
    • Focus on response time, pause time should be small,Useconcmarksweepgc.

Garbage collctor-Future

    • Garbage first (G1)
      Jdk1.6 update 14 or jdk7
    • Few flags need to set
      -XX: maxgcpausemillis = 100
      -XX: gcpauseintervalmillis = 6000

I have not tried to use it...

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 );
}
}
}

How many times does ygc run with the following two parameters?

  • -Xms30m-xmx30m-xmn10m-xloggc: GC. Log-XX: + printtenuringdistribution-XX: + useparallelgc
    2.062: [GC
    Desired encrypted vor size 1310720 bytes, New Threshold 7 (max 15)
    6467 K-> 6312 K (29440 K), 0.0038214 secs]
    4.066: [GC
    Desired encrypted vor size 1310720 bytes, New Threshold 7 (max 15)
    12536 K-> 12440 K (29440 K), 0.0036804 secs]
    6.070: [GC
    Desired encrypted vor size 1310720 bytes, New Threshold 7 (max 15)
    18637 K-> 18584 K (29440 K), 0.0040175 secs]
    6.074: [full GC 18584 K-> 18570 K (29440 K), 0.0031329 secs]
    8.078: [full GC 24749 K-> 3210 K (29440 K), 0.0045590 secs]

    (For detailed analysis, see http://rdc.taobao.com/team/jm/archives/440)

  • -Xms30m-xmx30m-xmn10m-xloggc: GC. Log-XX: + printtenuringdistribution-XX: + useserialgc
    2.047: [GC
    Desired encrypted vor size 524288 bytes, New Threshold 15 (max 15)
    -Age 1: 142024 bytes, 142024 total
    6472 K-> 6282 K (29696 K), 0.0048686 secs]
    4.053: [GC
    Desired encrypted vor size 524288 bytes, New Threshold 15 (max 15)
    -Age 2: 141880 bytes, 141880 total
    12512 K-> 12426 K (29696 K), 0.0047334 secs]
    6.058: [GC
    Desired encrypted vor size 524288 bytes, New Threshold 15 (max 15)
    -Age 3: 141880 bytes, 141880 total
    18627 K-> 18570 K (29696 K), 0.0049135 secs]
    8.063: [full GC 24752 K-> 3210 K (29696 K), 0.0077895 secs]

    (For detailed analysis, see http://rdc.taobao.com/team/jm/archives/458)

Refer:

    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

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.