Getting GC settings for running JVM [duplicate]

2019-09-05 07:43发布

问题:

This question already has an answer here:

  • What GC parameters is a JVM running with? 5 answers

Is there a way to get the GC settings for a running JVM?

I'm trying to see what GC algorithm is running SerialGC, ParallelGC, ParallelOldGC, ConcurrentMarkSweepGC, ect.

回答1:

JVM has a nice MBean for that:

for(GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
   System.out.println(gc.getObjectName());
}

You should see MBeans names like "PS Scavenge" or "PS Mark Sweep". Use the following reference to match names with algorithms:

Copy (Young) - Copying collector

ParNew (Young) - Parallel young generation collector

PS Scavenge (Young) - Parallel object scavenger

MarkSweepCompact (Old) - Mark and sweep compactor

ConcurrentMarkSweep (Old) - Concurrent mark and sweep compactor

PS MarkSweep (Old) - Parallel mark and sweep collector

The same information can also be collected with any tool capanle of viewing MBeans: JConsole, JVisualVM, Jprofiler, etc.



回答2:

You can use jconsole and access some JMX beans of your JVM in its GUI. There you can see details of GC for Tenured or Young parts of JVM Memory. It's just in your jdk/bin folder (HotSpot)

Here is some useful resources:

Using JConsole