<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Garamond,Georgia,serif;" dir="ltr">
<p>Dear Bernd,</p>
<p><br>
</p>
<p>> <span>You sure you do the same thing?</span></p>
<p><br>
</p>
<p>Was a bit confused, but Alan clarified it. Thanks!<br>
</p>
<p><br>
</p>
<p>Dear Alan,</p>
<p><br>
</p>
<p>> <span>The warning is limited to cases where code (in the form of a JVMTI agent in a shared library, or a Java agent in an agent JAR file) is loaded into a running VM without opt-in on the command line</span></p>
<p><br>
</p>
<p>I was of the opinion that usage of any API in <a href="https://docs.oracle.com/en/java/javase/21/docs/api/jdk.attach/com/sun/tools/attach/package-summary.html" class="OWAAutoLink">
`<span>com.sun.tools.attach</span>`</a> package would trigger this warning, but it is clear to me now when the warning will be triggered. Thank you for your answer!<br>
</p>
<p><br>
</p>
<p>> <span>, there are a number of commands implemented in Java that may be closer to what you are looking for.</span></p>
<p><br>
</p>
<p>We will take a look, thanks!<br>
</p>
<p><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<div id="m_4935352394101912768Signature">
<div name="divtagdefaultwrapper"><font size="2" color="#808080"><span style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif; background-color:rgb(255,255,255)"><span id="divtagdefaultwrapper" style="font-size:12pt">
<div style="margin-top:0; margin-bottom:0"><span style="color:rgb(0,0,0); font-family:Garamond,Georgia,serif">Regards,</span></div>
<span style="font-family:Garamond,Georgia,serif"></span><span style="font-family:Garamond,Georgia,serif"></span><span style="color:rgb(0,0,0)"></span><span style="font-family:Garamond,Georgia,serif"></span><span style="font-family:Garamond,Georgia,serif"></span>
<div style="margin-top:0; margin-bottom:0"><span style="color:rgb(0,0,0); font-family:Garamond,Georgia,serif">Aman Sharma</span></div>
</span><br>
</span></font></div>
<div name="divtagdefaultwrapper"><font size="2" color="#808080"><span style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif; background-color:rgb(255,255,255)"></span><span class="im">PhD Student<br style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif">
<span style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif; background-color:rgb(255,255,255)">KTH Royal Institute of Technology</span><br style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif">
</span><span style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif; background-color:rgb(255,255,255)">School of Electrical Engineering and Computer Science (EECS)</span><br style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif">
<span style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif; background-color:rgb(255,255,255)">Department of Theoretical Computer Science (TCS)</span><br style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif">
<span style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif; background-color:rgb(255,255,255)"><a href="http://www.kth.se" target="_blank" id="LPNoLP"></a><a href="https://www.kth.se/profile/amansha" class="OWAAutoLink" id="LPNoLP"></a><a href="https://www.kth.se/profile/amansha" class="OWAAutoLink" id="LPNoLP"></a></span></font></div>
</div>
<a href="https://www.kth.se/profile/amansha" class="OWAAutoLink" id="LPNoLP"><span style="font-size:10pt"></span></a><a href="https://algomaster99.github.io/" class="OWAAutoLink" id="LPNoLP">https://algomaster99.github.io/</a><br>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Alan Bateman <alan.bateman@oracle.com><br>
<b>Sent:</b> Tuesday, December 31, 2024 8:00:57 AM<br>
<b>To:</b> Aman Sharma; serviceability-dev@openjdk.org<br>
<b>Cc:</b> Serena Cofano<br>
<b>Subject:</b> Re: Why does jstack not trigger a warning in target JVM >= 21?</font>
<div> </div>
</div>
<div>On 30/12/2024 14:42, Aman Sharma wrote:<br>
<blockquote type="cite" cite="mid:4171b12b29df447d882513ff51a13cd7@kth.se"><style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Garamond, Georgia, serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<span id="ms-rterangepaste-start"></span>
<div style="">
<div></div>
</div>
<p>Hi all,</p>
<p><br>
</p>
<p>I hope this is the correct email thread to ask a question related to <span><a href="https://openjdk.org/jeps/451" target="_blank" rel="noopener noreferrer" class="x_OWAAutoLink" moz-do-not-send="true">JEP 451: Prepare to Disallow the Dynamic Loading of Agents</a>.</span></p>
<p><span><br>
</span></p>
<p><span>For some context, we at KTH are trying to build a serviceability tool that would monitor dependencies that are running in the target JVM. We looked at jstack for inspiration as it is able to return the stack trace of the target JVM, but we want classes
 instead and then we can get dependencies as we have annotated each class with dependency information.</span></p>
<p><span><br>
</span></p>
<p><span>While looking at jstack, we noticed that it does not trigger the warning "<span>WARNING: A {Java,JVM TI} agent has been loaded dynamically</span>" when the target JVM is 21. However, when we try to build our own agent using the attach API, we get the
 warning exactly how it says in the JEP. I initially thought that an exception was made for jstack in the open JDK code but I could find it either
<a href="https://github.com/openjdk/jdk/blob/24c5ff7ba58cb7cf93df07f81484cd8fae60e31e/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java#L107" target="_blank" rel="noopener noreferrer" class="x_OWAAutoLink" moz-do-not-send="true">
here</a> or <a href="https://github.com/openjdk/jdk/blob/24c5ff7ba58cb7cf93df07f81484cd8fae60e31e/src/hotspot/share/prims/jvmtiAgent.cpp#L521" target="_blank" rel="noopener noreferrer" class="x_OWAAutoLink" moz-do-not-send="true">
here</a>. Could anyone please tell us why a warning is not shown when jstack is dynamically attaching itself?</span></p>
<br>
</div>
</blockquote>
Attaching to a running VM to run diagnostic commands doesn't trigger a warning. The warning is limited to cases where code (in the form of a JVMTI agent in a shared library, or a Java agent in an agent JAR file) is loaded into a running VM without opt-in on
 the command line.<br>
<br>
It might be that some of of the existing jcmd commands might give you inspiration. While most of the diagnostic commands in written in C++, there are a number of commands implemented in Java that may be closer to what you are looking for.<br>
<br>
-Alan<br>
</div>
</body>
</html>