Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java object ID in jvm

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?

like image 868
Gorbush Avatar asked Jul 20 '10 11:07

Gorbush


People also ask

What is object ID in Java?

ObjectId(int timestamp, int machineIdentifier, short processIdentifier, int counter) Creates an ObjectId using the given time, machine identifier, process identifier, and counter. ObjectId(java.lang.String hexString) Constructs a new instance from a 24-byte hexadecimal string representation.

How do I find the ID of an object?

Find User (Object ID) Select Users. Browse to or search for the desired user, then select the account name to view the user account's profile information. The Object ID is located in the Identity section on the right. Find role assignments by selecting Access control (IAM) in the left menu, then Role assignments.

What is id in Eclipse?

Thats' the unique object-id eclipse assigns to objects it sees. It helps you in identifying objects while debugging. Follow this answer to receive notifications. answered Jun 16, 2012 at 4:50. Suraj Chandran.


1 Answers

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.

like image 122
Dimitris Andreou Avatar answered Oct 22 '22 18:10

Dimitris Andreou