Java object ID in jvm

后端 未结 1 1550
深忆病人
深忆病人 2020-11-29 09:47

There is an object ID displayed near the object value in Eclipse While debugging.

For example: 28332 is an ID of session object. Another example: waiting for:

1条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 10:43

    I presume they have internally an IdentityHashMap, assigning a unique (but meaningless otherwise) integer per object. This should be internal to the Eclipse debugger (not a special id that objects have). Are you asking how to get at that?

    Edit: I would set up breakpoint like this (note I'm not well versed in Eclipse):

    • I would have an initial breakpoint (like the one you used to take the screenshot), and print the System.identityHashCode(object) of the object I'm interested into.
    • Then I would create a breakpoint using the condition System.identityHashCode(object) == . It would be very rare for this to stop at the wrong object.

    Or if the object you are interested in has an appropriate toString() representation you could use, you could also try that instead of System.identityHashCode(object). In all cases, you don't have to rely to Eclipse' internal object id, but capture such an id (or almost) that you can derive from the object itself.

    0 讨论(0)
提交回复
热议问题