java - How to get Object ID as used in Heap Dump -
i able same id being used in java heap dumps (created via jmap or jmx, etc). able identify live object @ still running application versus older memory snapshot (the heap dump) of same app.
i have tested little , obvioulsy not hashcode, neither jdi unique id (which can see in debuggers).
from checking code in sun.jvm.hotspot.utilities assume objects address in memory. tests sun.misc.unsafe didn't lead same id value used in heap dumps. (see here unsafe explanation: http://zeroturnaround.com/rebellabs/dangerous-code-how-to-be-unsafe-with-java-classes-objects-in-memory/)
any ideas? :) !
there 2 different ways create heap dump:
- from inside jvm process using dynamic attach mechanism (
jmapso), or - from external process using serviceability agent (
jmap -f)
in both cases object id in heap dump memory address of object @ moment of creating dump. here relevant hotspot source code: [1] , [2].
however, object id meaningless outside dump file, because objects can move in memory during garbage collection.
the other problem it's difficult (or impossible) reliable address of java object within java application - again, because objects may move along heap , because representation of object references can vary between different architectures, environments , jvm options, e.g. depending on heap size, usecompressedoops etc. here an example of getting object address within java application, not guaranteed work on jvm versions.
Comments
Post a Comment