<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;"><span >Actually, this is not a very new and strange idea. I often encounter similar needs in actual debugging and troubleshooting. In addition, this feature has also been implemented in some external tools (<a  href="https://arthas.aliyun.com/en/doc/ognl.html" target="_blank">https://arthas.aliyun.com/en/doc/ognl.html</a>). It would be very convenient for problem diagnosis if JDK natively had this capability</span></div><div  style="clear:both;"><br /></div><blockquote  style="margin-right:0;margin-top:0;margin-bottom:0;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><div  style="clear:both;">------------------------------------------------------------------</div><div  style="clear:both;">From:David Holmes <david.holmes@oracle.com></div><div  style="clear:both;">Send Time:2023 Jul. 13 (Thu.) 20:34</div><div  style="clear:both;">To:"YANG, Yi" <qingfeng.yy@alibaba-inc.com>; jdk-dev <jdk-dev@openjdk.org></div><div  style="clear:both;">Subject:Re: Proposal: Post debug Java code to target JVM and exec it</div><div  style="clear:both;"><br /></div>On 13/07/2023 8:57 pm, Yi Yang wrote:<br >> Proposal: Post debug Java code to target JVM and exec it<br >> <br >> Hello, I have an early idea to post a piece of Java code to a local JVM <br >> process via jcmd or jexec, like this:<br >> <br >> jcmd VM.exec Debug.java<br >> jexec Debug.java<br >> <br >> class Debug {<br >> public static void main(){<br >> ApplicationProperties c = loadClass("ApplicationProperties");<br >> // print static field of running Java program<br >> System.out.println(ApplicationProperties.field1);<br >> // call static method of running Java program<br >> ApplicationProperties.printAll();<br >> // ....<br >> }<br >> }<br >> <br >> With this approach, we can do some useful things, such as:<br >> - Get some runtime data of the program<br >> - Troubleshoot Java problems<br >> - In rare cases, it can also assist in JVM problem diagnosis<br >> <br >> To protect the attach listener, we may need to create a new ExecThread <br >> at JVM startup and execute Debug::main in this thread. Do you have any <br >> comments on this idea?<br ><br >So basically you want the ability to ask a running JVM to execute an <br >arbitrary piece of java code. That may have some uses but in general <br >seems incredibly dangerous - how would you safeguard such a facility?<br ><br >Cheers,<br >David<br ><br >> Thank you.</blockquote></div></div>