<div class="__aliyun_email_body_block"><div  style="line-height:1.7;font-family:tahoma;font-size:14.0px;color:#000000;"><div  style="clear:both;">Proposal: Post debug Java code to target JVM and exec it<br ></div><div  style="clear:both;"><br ><div  style="clear:both;">Hello, I have an early idea to post a piece of Java code to a local JVM process via jcmd or jexec, like this:</div><div  style="clear:both;"><br ></div><div  style="clear:both;">jcmd VM.exec Debug.java</div><div  style="clear:both;">jexec Debug.java</div><div  style="clear:both;"><br ></div><div  style="clear:both;">class Debug {</div><div  style="clear:both;">public static void main(){</div><div  style="clear:both;"> ApplicationProperties c = loadClass("ApplicationProperties");</div><div  style="clear:both;"> // print static field of running Java program</div><div  style="clear:both;"> System.out.println(ApplicationProperties.field1);</div><div  style="clear:both;"> // call static method of running Java program</div><div  style="clear:both;"> ApplicationProperties.printAll();</div><div  style="clear:both;"> // ....</div><div  style="clear:both;">}</div><div  style="clear:both;">}</div><div  style="clear:both;"><br ></div><div  style="clear:both;">With this approach, we can do some useful things, such as:</div><div  style="clear:both;">- Get some runtime data of the program</div><div  style="clear:both;">- Troubleshoot Java problems</div><div  style="clear:both;">- In rare cases, it can also assist in JVM problem diagnosis</div><div  style="clear:both;"><br ></div><div  style="clear:both;">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?</div><span ><div  style="clear:both;"><span ><br ></span></div>Thank you.</span></div></div></div>