简体   繁体   English

如何在正在运行的JVM中查找类实例

[英]How to find a class instance in a running JVM

I am trying to figure out a way to find a class instance inside a working JVM. 我试图找到一种在工作JVM中查找类实例的方法。 The JVM is embedded into another process and an object is created by this process. JVM嵌入到另一个进程中,并且该进程创建了一个对象。 The same process executes my Java code. 相同的进程执行我的Java代码。 I do not have a direct access to the Java object reference in my Java code, but I know the class of that object. 我没有直接访问Java代码中的Java对象引用,但我知道该对象的类。 I want to find out if there are objects of this class already instantiated in JVM, and if they are, I want to find them (get say an Object array with references to all the instances of this class). 我想知道是否已经在JVM中实例化了这个类的对象,如果它们是,我想找到它们(比如说一个Object数组,引用了这个类的所有实例)。 This mechanism can be either a Java API or an JNI API. 此机制可以是Java API或JNI API。

I know it is possible since debuggers let me inspect all instances. 我知道这是可能的,因为调试器让我检查所有实例。 I just cannot seem to find the way. 我似乎无法找到方法。

Thanks 谢谢

Nikita 尼基塔

In case anybody is curious, It is possible and I am doing it now using JVMTI. 如果有人好奇,有可能,我现在正在使用JVMTI。 Not straightforward, but very doable. 不是直截了当的,但非常可行。 You can look at my other post about jvmti and you will find the answer. 你可以查看我关于jvmti的其他帖子,你会找到答案。

Perplexed by jvmti object allocation callback behavior 困惑的是jvmti对象分配回调行为

Thanks 谢谢

This should be possible from another process using the debug interface 这应该可以通过使用调试接口的另一个进程实现

http://docs.oracle.com/javase/6/docs/jdk/api/jpda/jdi/ http://docs.oracle.com/javase/6/docs/jdk/api/jpda/jdi/

However, if I understand your requirement correctly, you would need your process to debug itself which is probably not going to work. 但是,如果我正确理解您的要求,您将需要您的过程来调试自己,这可能不会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM