I was curious about how different JVM garbage collector command line options mapped to actual selections in the virtual machine at runtime. Note: all of my testing was using Oracle JDK 1.8.0_60, but the update number (60 in this case) shouldn't matter.
According to Oracle's GC Tuning Guide, these are the available GC selection command line options:
-XX:+UseConcMarkSweepGC-XX:+UseG1GC-XX:+UseParallelGC-XX:+UseParallelOldGC-XX:+UseParNewGCand-XX:-UseParNewGC-XX:+UseSerialGC
For example, you'd use the following options with the java executable for selecting the CMS collector:
java -XX:+UseConcMarkSweepGC -XX:+UseParNewGC
And the JVM would select the ParNew young and ConcurrentMarkSweep old generation collectors,
as named by the GarbageCollectorMXBean:
ParNew, ConcurrentMarkSweep
GraphCollectors is a short program that outputs a directed graph using the DOT graph language.
It creates combinations of GC options, and uses them to construct a command line for starting an external JVM
process that prints actual collector settings to stdout.
Use the following Maven Wrapper command line to run the program, which outputs a graph to stdout:
$ mvnw compile exec:exec
You'll need to download and install Graphviz here.
Render the graph using the following command line:
$ dot -Tpng collectors.gv > collectors.png
There are 7 combinations of GC command line options, mapping to 6 young and old collectors
at runtime. This means, for example, that it's not strictly necessary to pass
-XX:+UseConcMarkSweepGC -XX:+UseParNewGC to select the ParNew collector: the JVM will do
that by default!
