Most Popular Posts

16/04/2013

Garbage Collectors - HotSpot


TL;DR



Types of Garbage Collectors in HotSpot:
  • Serial
  • Parallel
  • Concurrent (CMS)


Young Generation Collectors:
  1. -XX:+UseSerialGC
  2. -XX:+UseParallelGC (Use parallel for Young, Serial for Old)
  3. -XX:+UseParNewGC

Old Generation Collectors:

  1. -XX:+UseParallelOldGC (Parallel Young and Old)
  2. -XX:+UseConcMarkSweepGC –XX:-UseParNewGC (Concurrent Mark Sweep with Serial Young)
  3. -XX:+UseConcMarkSweepGC –XX:+UseParNewG (Concurrent Mark Sweep + Parallel Young)
Additional note:


-XX:+DisableExplicitGC - prevent calls to System.gc()



Details:

Serial collector:


-XX:+UseSerialGC

Serial Collector - runs in single thread. No communication overhead between the threads. Used for mini data sets (<100MB). This collector is quick but suited for single CPU machines.


Parallel collector:

-XX:+UseParallelGC
and (optionally) enable parallel compaction with
-XX:+UseParallelOldGC 
-XX:+UseParNewGC
This type of collector is similar to the serial collector, but runs with multiple threads and does the minor collection in these threads. Be default:

N garbage collector threads = N CPUs on the host.

We can take the control over the number of threads by using the following option:

-XX:ParallelGCThreads=[number of threads]

Concurrent collector:

-XX:+UseConcMarkSweepGC 

One thread is used during initial mark and remark phase. For the concurrent marking and sweeping, CMS thread runs along the application threads. Used when the short pauses and response time are crucial.


In this collector parallel version of the young generation collector is used. For the Old/ Tenured generation, serial collector is used.


Concurrent low pause collector:


-Xincgc ™ or -XX:+UseConcMarkSweepGC

This collector is used to collect Old Generation and is done concurrently with the running application, however application is still paused for short amounts of time during the collection.. A parallel version of the young generation copying collector is used with the concurrent collector. 

Incremental low pause collector:



-XX:+UseTrainGC


This is currently not under the development, and has not changed since the J2SE Platform version 1.4.2


Note:


ParallelGC partially implies the -XX:+UseConcMarkSweepGC and should not (this doesn't mean you can't use it ;) ) be used in the same cmd line.



No comments:

Post a Comment