jvm中的Java对象ID [英] Java object ID in jvm
问题描述
例如:28332是会话对象的ID。
这个id既不是哈希码也不是 System.identityHashCode
。
有人知道 - 得到这个对象的id?
我假定他们内部有一个 IdentityHashMap< Object,Integer&
,为每个对象分配唯一(但无意义的)整数。这应该是eclipse调试器的内部(不是一个特殊的id对象有),你问如何得到?
编辑:我将设置一个这样的断点(注意我不太熟悉eclipse):
- 我会有一个初始断点(像你以前用来截图的那个),并打印出
System.identityHashCode(object)
我感兴趣的对象。 - 然后,我将使用条件
System.identityHashCode(object)==<在上一步看到的数字>
。对于这个错误的对象来说,这是非常罕见的。
或者如果您感兴趣的对象具有适当的<$您可以使用c $ c> toString()表示,也可以尝试代替 System.identityHashCode(object)
。在所有情况下,您不必依赖eclipse的内部对象id,而是捕获从对象本身导出的id(或几乎)。
There is an object ID is displayed near the object value in eclipse While debugging.
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?
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.
这篇关于jvm中的Java对象ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!