JVM - get an instance of a class in a running (non-instrumental) session

I need to stop the process by calling a specific method on an instance of this class. The process works all day, and if I close it tightly, I will lose a lot of work. Due to an error in the API, the graphical interface is not connected correctly and does not call the correct stop function. I have an interactive Java interpreter (Scala), so if I could get an instance of the process, I could easily call the correct method.

I am not participating in a debugging session, no com.sun.jdi. I can see the instance in the stack trace dump, but the StackTraceElement does not contain actual instances, just classes and line numbers.

Is there any way in the current session without special tools to get this instance - through its class through a stream dump?

+6
source share
1 answer

You can get all instances of this class using the JVMTI IterateOverInstancesOfClass . See an example in this answer .

Create a JNI library that will find the required instance using the function above and call the method from it from JNI_OnLoad . Then call System.load from the interpreter console to load this library.

+2
source

All Articles