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

本小妞迷上赌 提交于 2020-01-12 05:35:08

问题


Please let me know what is the best way to determine composition of young generation memory promoted to old generation, after each 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.


回答1:


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



来源:https://stackoverflow.com/questions/2335833/java-gc-top-object-classes-promoted-by-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!