2

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.

richs
  • 4,699
  • 10
  • 43
  • 56

2 Answers2

5

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.

Jk1
  • 11,233
  • 9
  • 54
  • 64
  • Problem is that I don't have access to the source and I can't recompile. – richs Sep 18 '13 at 19:58
  • 1
    You can also view the same MBean information with external tools like JConsole, JVisualVM or JProfiler – Jk1 Sep 18 '13 at 19:59
  • I looked at the MBeans tab under that java.lang.GarbageCollector package but i don't see anything that tells me what is the GC algorithm? – richs Sep 18 '13 at 20:13
  • Pay attention to the MBean names under that tab. For my platform, for example, they are "PS Scavenge" and "PS MarkSweep". See updated answer with name-to-alrorithm reference – Jk1 Sep 18 '13 at 20:43
3

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

zaerymoghaddam
  • 3,037
  • 1
  • 27
  • 33