<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    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>
  </body>
</html>