ayvango
ayvango

Reputation: 5977

Is it possible to monitor gc compactification with jmx?

I could retrieve GarbageCollectionMXBean from jmx. But how could I distinguish major gc from full gc? That are unofficial terms. I denote gc as major if old generation was cleaned. And by full I mean gc that compacts (defragment) heap. From practical perspective full gc occurs when concurrent mode fails or programmer explicitly calls System.gs

Is it possible to distinguish such events with jmx?

Upvotes: 1

Views: 992

Answers (1)

Galo Navarro
Galo Navarro

Reputation: 460

Two words of warning:

  • Note that "major" gc, as you define it, doesn't necessarily exclude compaction (e.g. G1GC performs incremental compaction on major cycles). Hence, your question for distinguising "major" from "full" events is different than "compacting" vs. "non compacting" events. I understand that you have more interest in the latter, but let me know otherwise.
  • Details about collectors are JVM specific. I will answer for HotSpot, but this may not be valid for other implementations.

AFAIK, there is no data offered in JMX beans about compacting and non compacting events. JMX does offer (inside java.lang:type=GarbageCollector) stats about each collector so knowing some details about each collector's phases you can make a reasonable inference of compaction events.

For example, the ConcurrentMarkSweep collector (-XX:+UseConcMarkSweepGC) does not compact (hence, you can't use these events). However, when CMS is unable to free up enough space (typically due to fragmentation) it will schedule a MarkSweepCompact for the next event. These events would be a compacting event, I believe they should appear under java.lang:name=MarkSweepCompact,type=GarbageCollector).

G1GC (the default for Java 8), performs incremental compaction in each event so I'm not sure GC events will be particularly useful.

The Parallel collector compacts the old generation, the right MBean should be java.lang:type=GarbageCollector,name=PS MarkSweep.

Useful docs: - HotSpot GC docs (java8): https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html - A quick ref. of most collectors (but old) https://blogs.oracle.com/jonthecollector/our-collectors - Zing's continuously compacting collector as an example of different JVM implementations: http://www.azulsystems.com/sites/default/files/images/c4_paper_acm.pdf

Upvotes: 1

Related Questions