36

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: (id=101) is displayed in the Debug panel. These IDs are neither a hash code nor a System.identityHashCode.

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

Nathan
  • 8,093
  • 8
  • 50
  • 76
Gorbush
  • 463
  • 1
  • 4
  • 5

1 Answers1

29

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 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 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.

Nathan
  • 8,093
  • 8
  • 50
  • 76
Dimitris Andreou
  • 8,806
  • 2
  • 33
  • 36
  • 2
    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 Jul 20 '10 at 11:53
  • 4
    +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 Jul 20 '10 at 11:54
  • 1
    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 Jul 20 '10 at 12:03
  • 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 Jul 20 '10 at 12:08
  • 1
    In my opinion, as the question is how to get the ID of eclipse, I think you should stand out the answer part of "It's internal, you can't", and then you could add the extra information about the usual case that is to identify the object to have a breakpoint for it. – PhoneixS Nov 21 '16 at 17:56