Proposal: Post debug Java code to target JVM and exec it

Yi Yang qingfeng.yy at alibaba-inc.com
Thu Jul 13 10:57:08 UTC 2023


Proposal: Post debug Java code to target JVM and exec it
Hello, I have an early idea to post a piece of Java code to a local JVM process via jcmd or jexec, like this:
jcmd VM.exec Debug.java
jexec Debug.java
class Debug {
public static void main(){
 ApplicationProperties c = loadClass("ApplicationProperties");
 // print static field of running Java program
 System.out.println(ApplicationProperties.field1);
 // call static method of running Java program
 ApplicationProperties.printAll();
 // ....
}
}
With this approach, we can do some useful things, such as:
- Get some runtime data of the program
- Troubleshoot Java problems
- In rare cases, it can also assist in JVM problem diagnosis
To protect the attach listener, we may need to create a new ExecThread at JVM startup and execute Debug::main in this thread. Do you have any comments on this idea?
Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20230713/610df7cb/attachment-0002.htm>


More information about the jdk-dev mailing list