The JVM has a good MBean for this:
for(GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { System.out.println(gc.getObjectName()); }
You should see MBeans names such as "PS Scavenge" or "PS Mark Sweep". Use the following link to map names to algorithms:
Copy (Young) - Copy Collector
ParNew (Young) - Parallel collector of the young generation
PS Scavenge (Young) - Parallel garbage object
MarkSweepCompact (Old) - Mark and roll the seal
ConcurrentMarkSweep (Old) - Parallel Marking and Swing Seal
PS MarkSweep (old) - Parallel Tag and Arrow Collector
The same information can also be collected using any MBeans viewing toolkit: JConsole, JVisualVM, Jprofiler, etc.
Jk1
source share