views:

111

answers:

1

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

Sample screenshot:

screenshot

For example: 28332 is an ID of session object. This id is neither a hash code nor a System.identityHashCode.

Does anybody knows - how to get THIS id of object?

+3  A: 

I presume they have internally an IdentityHashMap<Object, Integer>, 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 a 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) == <whatever number you saw at the previous step>. It would be very rare for this to stop at the wrong object.

Or if the object you are interested into 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.

Dimitris Andreou
Generally - i'm debugging application and would like to gather some info about objects some times during the process run - to stop at break point and get info about what object's path through the functions call...
Gorbush
+1 I think this is correct, the numbers seem to be allocated and tracked internally by the Eclipse debugger, being easier to read and recognise than actual JVM object identifiers.
skaffman
I too think they come from http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/jdk/api/jpda/jdi/com/sun/jdi/ObjectReference.html#uniqueID%28%29 implementation by Eclipse debugger indeed.
Redlab
Indeed, it's no coincidence that those two objects have ids 28332 and 28335, it's simply an incrementing counter assigning these numbers.
Dimitris Andreou