![]() |
|
Twitter: http://www.twitter.com/cguntur |
LinkedIn: http://www.linkedin.com/in/chandraguntur |
My blog: http://www.cguntur.me |
![]() |
![]() |
![]() |
1. Based on how collection runs | 2. Based on how objects are marked |
|
|
3. Based on run interval of collections | 4. Based on what collection does to objects |
|
|
The most rudimentary garbage collection is based on references:
|
![]() |
The mark/sweep collection pattern is based on tracing:
|
![]() |
The copying garbage collection is based on tracing:
|
![]() |
Mark/Sweep/Compact | Copying |
|
|
|
![]() |
G1GC is the new default collector since JDK 9.
-XX:G1HeapRegionSize
with a numeric value (that is a power of 2).
Explanation:
|
![]() |
Young Collection (Eden & SurvivorF → SurvivorT ):
|
![]() |
![]() |
![]() |
Young Collection (Survivor → Tenured):
|
![]() |
![]() |
![]() |
Young-Only - Initial Mark:
|
![]() |
![]() |
![]() |
-XX:InitiatingHeapOccupancyPercent
: -XX:-G1UseAdaptiveIHOP
.-XX:G1ReservePercent
: -XX:-G1EagerReclaimHumongousObjects
, may need to turn on Experimental options.
Young-Only - Concurrent Marking:
|
![]() |
![]() |
1. Snapshot-at-the-beginning (SATB) | 2. Objects added/dereferenced | 3. Root Scan |
![]() |
![]() |
![]() |
4. Root Painting | 5. Children Painting | 6. Completion |
![]() |
![]() |
![]() |
Young-Only - Remark:
|
![]() |
![]() |
![]() |
Young-Only - Cleanup:
|
![]() |
![]() |
Space Reclamation - Mixed Collection:
|
![]() |
![]() |
![]() |
OutOfMemoryError
s.-XX:MetaspaceSize
(replaces -XX:PermSize), default = 21.8M.-XX:MaxMetaspaceSize
(replaces -XX:MaxPermSize), default = unlimited.-XX:PermSize
and -XX:MaxPermSize
with the new options.-XX:MaxGCPauseMillis
(default = 200).-XX:GCPauseTimeInterval
(no default).-XX:InitiatingHeapOccupancyPercent
(default = 45).-XX:G1ReservePercent
(default = 10).-XX:G1HeapWastePercent
(default = 5).-XX:G1MixedGCCountTarget
(default = 8).
-XX:G1HeapWastePercent
.Type | Young GC | Tenured GC | JVM Option |
---|---|---|---|
Serial GC | Serial | Serial | -XX:+UseSerialGC |
Parallel GC | Parallel Scavenge | Parallel | -XX:+UseParallelGC -XX:+UseParallelOldGC |
CMS GC | Parallel New | CMS | -XX:+UseParNewGC -XX:+UseConcMarkSweepGC |
G1 GC | G1GC | -XX:+UseG1GC |
Type | Parallel | Concurrent | Young GC | Tenured GC | Feature |
---|---|---|---|---|---|
Serial GC |   - |   - | Serial | Serial | Batch processing |
Parallel GC | Yes |   - | Parallel | Parallel | High throughput |
CMS GC | Yes | Yes | Parallel | Parallel & Conc. | Low Pause |
G1 GC | Yes | Yes | Parallel | Parallel & Conc. | Low pause & High throughput |
java -XX:+PrintFlagsInitial -version
java -XX:+PrintFlagsInitial MyApplication
java -XX:+PrintFlagsFinal -version
java -XX:+PrintFlagsFinal MyApplication
java -XX:+PrintCommandLineFlags -version
java -XX:+PrintCommandLineFlags MyApplication
-version
is used as the executable above. As is shown, it can be replaced with any java class with a main(...)
as well.java -Xlog:help
GC Type | Option | Meaning |
---|---|---|
Pre-G1GC | -Xloggc:/path/to/gc.log | Destination path for the logs. |
Pre-G1GC | -XX:+PrintGCDetails | Increases the verbosity of logged content. |
Pre-G1GC | -XX:+PrintGCDateStamps | Log date and timestamp of the collection. |
G1GC | -Xlog:gc |
Log messages with gc tag using info level to stdout, with default decorations. |
G1GC | -Xlog:gc,safepoint |
Log messages with either gc or safepoint tags (exclusive), both using 'info' level, to stdout, with default decorations. |
G1GC | -Xlog:gc+ref=debug |
Log messages with both gc and ref tags, using debug level, to stdout, with default decorations. |
G1GC | -Xlog:gc=debug:file=gc.txt:none |
Log messages with gc tag using debug level to file gc.txt with no decorations. |
G1GC | -Xlog:gc=trace:file=gc.txt:uptimemillis, pids:filecount=5,filesize=1m |
Log messages with gc tag using trace level to a rotating logs of 5 files of size 1MB, using the base name gc.txt, with uptimemillis and pid decorations. |
G1GC | -Xlog:gc::uptime,tid |
Log messages with gc tag using info level to output stdout, using uptime and tid decorations. |
G1GC | -Xlog:gc*=info,safepoint*=off |
Log messages with at least gc using info level, but turn off logging of messages tagged with safepoint. |
Region | region |
Liveness | liveness |
Marking | marking |
Remembered Set | remset |
Ergonomics | ergo |
Class Histogram | classhisto |
Safepoint | safepoint |
Task | task |
Heap | heap |
JNI | jni |
Promotion(Parallel) Local Allocation Buffer | plab |
Promotion | promotion |
Reference | ref |
String Deduplication | stringdedup |
Statistics | stats |
Tenuring | age |
Thread Local Allocation Buffer | tlab |
Metaspace | metaspace |
Humongous Allocation | alloc |
Refinement | refine |
Humongous | humongous |
String Symbol Table | stringtable |
-XX:G1HeapRegionSize
).-XX:ConcGCThreads
).-XX:G1ReservePercent
-XX:G1UseAdaptiveIHOP
and manually set -XX:InitiatingHeapOccupancyPercent
.System.gc()
calls in some library.
-XX:ExplicitGCInvokesConcurrent
.gc()
calls with -XX:DisableExplicitGC
.-XX:G1NewSizePercent
reduces the young generation size.-XX:G1MaxNewSizePercent
.gc+ergo+cset=trace
in logging).-XX:G1MixedGCCountTarget
.-XX:G1MixedGCLiveThresholdPercent
.-XX:G1HeapWastePercent
.My contact information |
Twitter: http://www.twitter.com/cguntur |
LinkedIn: http://www.linkedin.com/in/chandraguntur |
My blog: http://www.cguntur.me |
![]() |
![]() |
![]() |