"-XX:ParallelGCThreads=6" - Young GC Parallel Threads

This section demonstrates that the '-XX:ParallelGCThreads=6' option can be used to control the number of threads used in Young GC parallel phases.

In the previous tutorial, we learned that multiple threads are used by the CMS collector for the Young GC process.

For example, we saw 8 threads was used in the GC #1 (Young GC) in the previous tutorial. If you want to change the number of threads used in Young GC, you can specify a new number in the "-XX:ParallelGCThreads=n" option.

The example below shows all log messages of a single Young GC performed by the CMS collector with 6 threads specified.

herong> java -XX:+UseConcMarkSweepGC \
   -Xms90m -Xmx90m -XX:NewRatio=2 -XX:SurvivorRatio=1 \
   -XX:CMSInitiatingOccupancyFraction=20 \
   -XX:+UseCMSInitiatingOccupancyOnly \
   -XX:ParallelGCThreads=6 \
   -Xlog:gc*=trace \
   GarbageCollection2 > output.txt

herong> more output.txt

GC(1) Heap before GC invocations=1 (full 0): par new generation  ...
GC(1)   eden space 10240K,  91% used ...
GC(1)   from space 10240K,  87% used ...
GC(1)   to   space 10240K,   0% used ...
GC(1)  concurrent mark-sweep generation total 61440K, used 0K [...]
GC(1)  Metaspace       used 491K, capacity 4544K, committed 4864K, ...
GC(1)   class space    used 42K, capacity 408K, committed 512K, ...
GC(1) Pause Young (Allocation Failure)
GC(1) TLAB: gc thread: 0x013363577800 [id: 32696] desired_size: 200KB ...
...
GC(1) TLAB totals: thrds: 1  refills: 1 max: 1 slow allocs: 9 max 9 ...

GC(1) Collect gen: ParNew
GC(1) Young invoke=2 size=1048592
GC(1) WorkerManager::add_workers() : created_workers: 6
GC(1) GC Thread: using 6 out of 6 workers
GC(1) Using 6 workers of 6 for evacuation
   -- 8 threads used as specified by -XX:ParallelGCThreads=6

GC(1) ParNew (Allocation Failure)
GC(1) oops_do_marking_prologue
GC(1) WorkerManager::add_workers() : created_workers: 6
GC(1) GC Thread: using 6 out of 6 workers
GC(1)  204  3  java.util.Arrays::copyOf (40 bytes)   scavenge root
GC(1)  204  3  java.util.Arrays::copyOf (40 bytes)   oops_do, mark
...
GC(1) WorkerManager::add_workers() : created_workers: 6
GC(1) GC Thread: using 6 out of 6 workers
GC(1)   17  3  java.util.Set::of (4 bytes)   oops_do, unmark
GC(1)   20  3  java.util.Set::of (66 bytes)   oops_do, unmark
...
GC(1) oops_do_marking_epilogue
GC(1) 0[3]: 0/1184/16
GC(1) 0[4]: 13/1216/16
...
GC(1) Reference Processing: 0.0ms

GC(1) Desired survivor size 5242880 bytes, new threshold 1 ...
GC(1) Age table with threshold 1 (max threshold 15)
GC(1) - age   1:    6291552 bytes,    6291552 total

GC(1) Young PLAB allocation: allocated: 0B, wasted: 0B, unused: 0B, ...
GC(1) Young sizing: calculated: 8B, actual: 161320B

GC(1) ParNew (Allocation Failure) 10.168ms
GC(1) Collect gen: ParNew 10.227ms
GC(1) ParNew: 18358K->6144K(20480K)
GC(1) CMS: 0K->8005K(61440K)
GC(1) Metaspace: 491K->491K(1056768K)

GC(1) TLAB new size: thread: 0x013363577800 [id: 32696] refills 50 ...
...

GC(1) Pause Young (Allocation Failure) 17M->13M(80M) 10.636ms
GC(1) User=0.00s Sys=0.00s Real=0.00s

GC(1) Heap after GC invocations=2 (full 0): par new generation  ...
GC(1)   eden space 10240K,   0% used ...
GC(1)   from space 10240K,  60% used ...
GC(1)   to   space 10240K,   0% used ...
GC(1)  concurrent mark-sweep generation total 61440K, used 8005K ...
GC(1)  Metaspace       used 491K, capacity 4544K, committed 4864K, ...
GC(1)   class space    used 42K, capacity 408K, committed 512K, ...

As you can see, the "-XX:ParallelGCThreads=6" option works as expected. GC #1 (Young GC) used 6 threads.

Table of Contents

 About This Book

 Heap Memory Area and Size Control

 JVM Garbage Collection Logging

 Introduction of Garbage Collectors

 Serial Collector - "+XX:+UseSerialGC"

 Parallel Collector - "+XX:+UseParallelGC"

Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"

 What Is Concurrent Mark-Sweep (CMS) Collector

 Concurrent Mark-Sweep Collector GC Log Message Format

 Reduce Stop-The-World with Concurrent Mark and Sweep

 Parallel New (ParNew) Collector for Minor GC

 ParNew Collector - Tenuring Age Distribution

 Maximum Logging of All Phases on Young GC

"-XX:ParallelGCThreads=6" - Young GC Parallel Threads

 "-XX:MaxTenuringThreshold=0" - Tenuring Objects Immediately

 "-XX:CMSInitiatingOccupancyFraction=20" - Initiate CMS

 Maximum Logging of All Phases on Old GC

 Maximum Logging of All Phases on Full GC

 "-XX:ParallelGCThreads=6" - Old GC Parallel Threads

 "-XX:ConcGCThreads=3" - Old GC Concurrent Threads

 Garbage First (G1) Collector - "+XX:+UseG1GC"

 The Z Garbage Collector (ZGC) - "+XX:+UseZGC"

 Object References and Garbage Collection

 Garbage Collection Performance Test Program

 Performance Tests on Serial Collector

 Performance Tests on Parallel collector

 Performance Tests on Concurrent collector

 Performance Tests on G1 collector

 Garbage Collection Performance Test Summary

 References

 Full Version in PDF/EPUB