Michael P
Michael P

Reputation: 2087

Java GC is high, how to find out which objects are GCed

I have a Java application built with Tomcat Webserver. Using Java mission control I know that under stress, the GC is very dominant. Every GC cycle, the CPU goes very high. What I would like to figure out is, what exactly each GC cycle is doing, in particular, I'd like to know which object it is promoting, and which objects it is freeing. For the objects that get freed, I'd like to know, not only what type they are, but where they have been created. Just knowing that I have a lot of byte[] or Strings is obviously not helping since there are a lot of places where those can be created, but only a few are in my control and are dominant.

Does anyone know a tool or method to do so.

Thanks in advance.

Upvotes: 3

Views: 852

Answers (2)

Alexey Ragozin
Alexey Ragozin

Reputation: 8409

Option 1 - Use Java Flight Recorder allocation profiling option. I understand that you are interested in dead object, but the trick is that majority of new object would become dead shortly.

Option 2 - SJK dead object histogram. SJK takes few class histograms of heap (same as jmap -histo) and reports difference. It has options to calculate dead and young dead populations.

Upvotes: 2

the8472
the8472

Reputation: 43160

You need to record object allocations, not what gets collected. Asymptotically collections and allocations are the same, but the latter can provide far more information when it occurs.

Various java profiling solutions offer such capability.

Upvotes: 2

Related Questions