<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<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;">
<p></p>
<span id="ms-rterangepaste-start"></span>
<div style=""></div>
<div style="">
<div>
<div></div>
</div>
</div>
<div style=""></div>
<div style=""></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">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">
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">
here</a>. Could anyone please tell us why a warning is not shown when jstack is dynamically attaching itself?</span></p>
<p><span><br>
</span></p>
<p><span><u>Details for reproduction</u></span></p>
<p><span><br>
</span></p>
<p><span>Source code for reproduction is attached. If you use IntelliJ, you can directy load this project and execute the provided run configurations. First executed 'LongRunning' which will simply suspend the thread for a few minutes and then the 'AgentLoader'
 will try to attach itself dynamically.</span></p>
<p><span><br>
</span></p>
<p><span>If you don't use IntelliJ, please add '<span>--add-exports jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED --add-modules jdk.jcmd --add-exports jdk.jcmd/sun.tools.jps=ALL-UNNAMED</span>' to your Java compiler and JVM to run the above classes.<br>
</span></p>
<p><br>
</p>
<font size="2" color="#808080"><span style="font-family:Arial,"Helvetica Neue",helvetica,sans-serif,serif,"EmojiFont"; background-color:rgb(255,255,255)"><span id="x_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,serif,"EmojiFont"">Regards,</span></div>
<span style="font-family:Garamond,Georgia,serif,serif,"EmojiFont""></span><span style="font-family:Garamond,Georgia,serif,serif,"EmojiFont""></span><span style="color:rgb(0,0,0)"></span><span style="font-family:Garamond,Georgia,serif,serif,"EmojiFont""></span><span style="font-family:Garamond,Georgia,serif,serif,"EmojiFont""></span>
<div style="margin-top:0; margin-bottom:0"><span style="color:rgb(0,0,0); font-family:Garamond,Georgia,serif,serif,"EmojiFont"">Aman Sharma</span></div>
</span></span></font><span id="ms-rterangepaste-end"></span>
<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"></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>
</body>
</html>