I have a long-running (multiple days) application with objects that I expect to stay around for varying lengths of time before they can be garbage collected. Let's say there's four categories:
To help with tuning, I'd like to find a way of checking what actual data is getting in to the tenured generation, using the Java 6 Hotspot VM. Using jmap to generate HPROF files doesn't seem to include generational information. Is there another way of getting this information?
No, there is no simple way to get generation information for individual object. In fact if you ask for "live" objects, this will trigger a Full GC and place all objects into the old generation (so now you know where all the objects are, but not where they were)
Objects which survive a full GC are likely to be in old generation so if your system does a full GC every 5 minutes, anything which lasts longer than that is much the same.
The best thing you can do is to minimise discarded objects (use a memory profiler to help) This will improve GC performance and descrease how often they occur. In extreme examples you can use off heap memory which is difficult to work with but uses next to no heap. esp useful if you have many GB of data.