Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

eclipse - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...