I need to stop a process by invoking a particular method on an instance of a given class. The process has been running for a day, and if I shut it down hard, I lose a lot of work. Due to a bug in the API, the GUI is wrongly wired and doesn't call the correct stop function. I have an interactive Java (Scala) interpreter attached, so if I could get hold of the instance of the process, I could easily invoke the correct method.
I am not in a debugging session, there is no com.sun.jdi. I can see the instance in a stack trace dump, but StackTraceElement
doesn't contain actual instances, just classes and line numbers.
Is there any way in a running session, without specific instrumentation, to get hold of that instance -- through its class, through a thread dump?
It is possible to get all instances of the given class using JVMTI IterateOverInstancesOfClass
function. See an example in this answer.
Create a JNI library that will find the required instance using the above function and invoke a method on it from JNI_OnLoad
entry. Then invoke System.load
from the interpreter console to load this library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With