[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-serviceability-dev
Subject:    Re: Slow class loading when running JVM in debug mode
From:       Chris Plummer <chris.plummer () oracle ! com>
Date:       2019-06-21 18:50:40
Message-ID: ed380e5a-e00e-639b-0ec7-2230016a44e1 () oracle ! com
[Download RAW message or body]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">You might also want to have a look at:<br>
      <br>
      JDK:8214892: Delayed starting of debugging via jcmd<br>
      <br>
      This should allow you to defer initialization of the debug agent
      (and the creation of the loaded classes cache) until you turn on
      debugging using the jcmd (and the presumably follow that with an
      attach from a debugger).<br>
      <br>
      Note there is also an after-the-fact CSR in progress for this
      which might result in an eventual name change for debug agent
      option and jcmd command.<br>
      <br>
      Chris<br>
      <br>
      <br>
      On 6/21/19 3:06 AM, Egor Ushakov wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:074598ed-c337-a0cd-7c78-10e587de8431@jetbrains.com">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      Will have a look, thanks for advices!<br>
      <br>
      <div class="moz-cite-prefix">On 21-Jun-19 00:42, Chris Plummer
        wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:f0c4cc00-f277-46ee-1fe9-538b723c3504@oracle.com">
        <meta http-equiv="Content-Type" content="text/html;
          charset=utf-8">
        <div class="moz-cite-prefix">With respect to the specific issue
          brought up in <a
            href="https://youtrack.jetbrains.com/issue/JBR-1611"
            rel="noreferrer" target="_blank" \
moz-do-not-send="true">https://youtrack.jetbrains.com/issue/JBR-1611</a>:<br>  <br>
          "If we look into the code, we'll see that whenever a new class
          is loaded and an event about it is delivered, when a garbage
          collection has occurred, classTrack_processUnloads iterates
          over all loaded classes to see if any of them have been
          unloaded. This leads to O(classCount * gcCount) performance,
          which in case of frequent GCs (and they are frequent,
          especially the minor ones) is close to O(classCount^2). In
          IDEA, we have quite a lot of classes, especially counting all
          lambdas, so this results in quite significant overhead."<br>
          <br>
          The debug agent calls JVMTI GetLoadedClasses() during
          initialization to get a cache of all prepared classes. It
          keeps that cache up-to-date by getting JVMTI CLASS_PREPARE
          events. When there is a gc, the debug agent basically throws
          away the cache and creates a new one by calling
          GetLoadedClasses() again. It also compares the old and new
          caches to determine which classes where unloaded, and
          generates JDWP CLASS_UNLOAD events for them (if there is a
          debugger attached that wants them).<br>
          <br>
          It might be possible to defer initialization of the loaded
          classes cache (and any maintenance of it) until there is a
          debugger attached. I'm not sure if the only reason for the
          cache is for delivery of CLASS_UNLOAD events, but at first
          glance that appears to be the case.<br>
          <br>
          Chris<br>
          <br>
          On 6/20/19 1:31 PM, Volker Simonis wrote:<br>
        </div>
        <blockquote type="cite"
cite="mid:CA+3eh108bX-diLxb9nYuczWYJsXLrMUKgyzxqrqzQF-jhDv3iQ@mail.gmail.com">
          <meta http-equiv="content-type" content="text/html;
            charset=utf-8">
          <div>
            <div dir="auto">Hi Egor,</div>
          </div>
          <div dir="auto"><br>
          </div>
          <div dir="auto">yes, I‘d say this is something well known. The
            reason for this is that a debugging agent will request some
            JVMTI capabilities like  <span
              style="color:rgb(23,43,77);font-family:&quot;DejaVu
              Sans&quot;,sans-serif;font-size:19px">"can_access_local_variables"</span> \
which  can only be requested at JVM startup. However, once these
            capabilities have been taken, certain kinds of optimizations
            like for example Escape Analysis, can't be done anymore
            which results in a performance degradation even if you don't
            ever attach a debugger.</div>
          <div dir="auto"><br>
          </div>
          <div dir="auto">We‘ve always enabled debugging in our
            commercial SAP JVM and called it „Debugging on Demand" but
            usually didn't observed any performance slowdown of more
            than 3-5% at most. We've started contributing some of the
            improvements we've done to make this possible to the
            OpenJDK.</div>
          <div dir="auto"><br>
          </div>
          <div dir="auto">I've not looked into your concrete class
            loading use case. Maybe it's possible to improve that. First
            you have to check by which JVMTI capability it is triggered
            and if that capability is really necessary for debugging and
            can only be requested at startup. If the answer is yes, you
            can still check if it's not possible to improve the
            implementation of that capability in order to get a better
            runtime behavior.</div>
          <div dir="auto"><br>
          </div>
          <div dir="auto">Regards,</div>
          <div dir="auto">Volker</div>
          <div dir="auto"><br>
          </div>
          <div><br>
            <div class="gmail_quote">
              <div dir="ltr" class="gmail_attr">Egor Ushakov &lt;<a
                  href="mailto:egor.ushakov@jetbrains.com"
                  moz-do-not-send="true">egor.ushakov@jetbrains.com</a>&gt;
                schrieb am Do. 20. Juni 2019 um 11:36:<br>
              </div>
              <blockquote class="gmail_quote" style="margin:0 0 0
                .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi
                everyone!<br>
                <br>
                we have detected that a process started with the debug
                agent (even when <br>
                debugger is not actually attached) may run significantly
                slower than <br>
                without the agent, see:<br>
                <a href="https://youtrack.jetbrains.com/issue/JBR-1611"
                  rel="noreferrer" target="_blank"
                  moz-do-not-send="true">https://youtrack.jetbrains.com/issue/JBR-1611</a><br>
  We all thought that without the debugger attached there
                should not be a <br>
                difference.<br>
                Is that something well known? Should we file a bug?<br>
                <br>
                Thanks,<br>
                Egor<br>
                <br>
                -- <br>
                Egor Ushakov<br>
                Software Developer<br>
                JetBrains<br>
                <a href="http://www.jetbrains.com" rel="noreferrer"
                  target="_blank" \
moz-do-not-send="true">http://www.jetbrains.com</a><br>  The Drive to Develop<br>
                <br>
              </blockquote>
            </div>
          </div>
        </blockquote>
        <p><br>
        </p>
      </blockquote>
      <br>
      <pre class="moz-signature" cols="72">-- 
Egor Ushakov
Software Developer
JetBrains
<a class="moz-txt-link-freetext" href="http://www.jetbrains.com" \
moz-do-not-send="true">http://www.jetbrains.com</a> The Drive to Develop</pre>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic