开发者

Java GC: top object classes promoted (by size)?

开发者 https://www.devze.com 2022-12-21 18:51 出处:网络
Please let me know what is the best way to determine composition of young generation memory promoted to old generation, after ea开发者_高级运维ch young GC event?

Please let me know what is the best way to determine composition of young generation memory promoted to old generation, after ea开发者_高级运维ch young GC event?

Ideally I would like to know class names which are responsible say, for 80% of heap in each "young gen -> old gen" promotion chunk;

Example: I have 600M young gen, each tenure promotes 6M; I want to know which objects compose this 6M.

Thank you.


There is no easy way to do this, however, I have recently been analyzing memory performance of large java apps, and can share some experience.

Here is how I found what objects are being promoted to old gen:

First you need to identify what objects are in "old/tenured" space. This is basically you standard java heap analysis. For this I recommend jmap. It is part of the sun jvm. run: jmap -dump:file=heap.hprof PID to get a heap dump. This will pause the jvm during the dump (~for 30 secs on a 2GB heap)

Now load the .prof file in Memory analyser (the best tool for this, hands down) I would spend a day playing with Memory analyzer to understand it, watch the screencam (needs a login, but worth it).

Now you will know what objects are in your heap.

Here is the trick: In the overview screen of Memory analyser, there is a link to: "Unreachable objects histogram". Now these objects are all to be collected during the next GC. But some are probably in eden, some in survivor and some in old.

Now, get some profiler with memory profiling capability, I prefer yourKit. Run your app with yourkit and record object allocation.

Run it and record object creation. Once you have a list of objects created use all three lists to get a picture of what is going on. Do what humans do best, see patterns.

  • What objects are created and are reachable. (Memory analyser)
  • Objects unreachable in heap (Memory analyser)
  • Objects created during a run (Profiler)

Another way to approach is YourKit generations view. You can take snapshots of your heap and compare what objects are still alive between snapshots. If you use this with visualgc you can determine how long an object must be alive to be promoted to old gen, and take snapshots at these intervals to see what objects are still alive.

Well, good luck. /JT

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号