Reputation: 3924
My application has a lot of garbage collection and I would like to analyze that. What I want to see is which objects are being garbage collected. I think that will give me idea where to look for optimization (adding cache or whatever).
Is there an option to print detailed GC information, including how many objects from each class were garbage collected?
I'm using the G1GC, if that's important.
Thanks!
Upvotes: 4
Views: 2028
Reputation: 3924
Oracle's JFR (Java Flight Recorder, or Java Mission Control) is a great tool to help in this task - it shows the load on GC per object - meaning how many objects from each class are generated (this goes together with the objects that are collected). Very recommended.
Upvotes: 3
Reputation: 5090
I would approach this slightly differently - it isn't so much you want to know which objects are being collected, but which objects are taking up the heap (but have been collected after the next GC).
There are a number of tools that allow you inspect the objects and classes the come from in the heap, VisualVM as mentioned by Alex Suo above, JProfiler (which is nice but a paid for application), YourKit (the same) or jmap. Using any of these I would record heap state at regular intervals that you can cross-reference with your verbose garbage-collection logs.
Depending on your application, you can also make considerable progress using your verbose garbage-collection logs in conjunction with your application's activity logs (what activities cause noticeable jumps in the heap, particularly where there is some similar decrease when a GC occurs later). Even if you use the tools above, your activity logs may be crucial in identifying where the memory usage is coming from.
Upvotes: 0
Reputation: 1
To trace Garbage Collection activity use this command:
-verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails
Upvotes: 0
Reputation: 3119
I am not sure about G1GC but usually I found the VisualVM toolkit quite helpful. It's a decent combination of good feature, adequate in-depth object analysis as well as good speed (a lot of GC tools in the early age sucks on this). It's a free tool, too.
http://visualvm.java.net/download.html
Upvotes: 0
Reputation: 31
This has been answer there : Howto print java class garbage collection events?
You need to run your JVM using the arguments
-verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails
Upvotes: 0