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

David Holmes david.holmes at oracle.com
Thu Jul 13 12:34:20 UTC 2023


On 13/07/2023 8:57 pm, Yi Yang wrote:
> 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?

So basically you want the ability to ask a running JVM to execute an 
arbitrary piece of java code. That may have some uses but in general 
seems incredibly dangerous - how would you safeguard such a facility?

Cheers,
David

> Thank you.


More information about the jdk-dev mailing list