I have an application with about 80 instances of 80 different classes. The amount of garbage generated by some subset of these classes is unacceptable and stop the world pauses are too long, since my application is real time.
What I want to find is which classes are responsible for creating the largest number of objects on heap (not aggregate size, but raw number of objects), since this is what causes stop the world pauses to take so long.
How do I find this out?
If JVisualVM is required, I have this.
Try JProfiler, there's at least a free trial. One of the memory views tells you which classes have the most instances created (and how many). You can also use memory recording; start recording, set a "mark", run an operation you think creates garbage, stop recording, see which classes have the most instances created since the "mark" was set. Basically, you need a good profiler, doesn't matter much which one. Typically the commercial ones are better, in my experience.
UPDATE: a good profiler will tell you exactly how many instances of a class exist. This sounds like what you are asking for.
A very lightweight approach to look at the number of objects per class is Class Histogram.
Just generate class histogram by
jmap -histo <PID>
.Use
-XX:+PrintClassHistogramBeforeFullGC
,-XX:+PrintClassHistogramAfterFullGC
to see class histograms when your stop-the-world pause occurs. You can compare the snapshot before/after to see which class instances get collected during the stop-the-world pause.See more details in Profiling number of garbage-collected object instances per class.