<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    Hi Iñigo,<br>
    <br>
    The problem is that we can unmount a virtual thread, then mount it
    again, thaw a few frames, execute code that acquires a JNI monitor,
    and then call thaw again without releasing that monitor. Thaw code
    assumes all monitors must be released at that point but doesn't
    consider JNI acquired ones. In this test this will happen if the
    vthread is unmounted in System.out.println("Thread doing JNI call: "
    ...) because of contention with the main thread
    doing System.out.println("Main waiting for event."). You can
    reproduce this issue by adding Thread.yield() before
    jniMonitorEnterAndLetObjectDie().<br>
    <br>
    Thanks,<br>
    Patricio<br>
    <br>
    <div class="moz-cite-prefix">On 7/22/24 7:30 AM, Iñigo Mediavilla
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CA+wBRWDM0F1KgdcW=3oDDBLoU7Ff6e2AEk092jZNCRoVNU-TdA@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">
          <div>Hello Serguei,<br>
            <br>
          </div>
          Thanks a lot for sharing the update and for solving the issue.
          Do you think that you could help me understand exactly what's
          happening ?<br>
          <br>
        </div>
        <div>Based on the DBG output shared in JBS, my understanding is
          that what happens in the test is the following:<br>
        </div>
        <div dir="ltr"><br>
          Main                         Thread<br>
          -------------------------   ----------------------------<br>
          1. acquire java lock<br>
          2. starting thread<br>
                                           3. jni call<br>
                                           4. MonitorContendedEnter<br>
          5. release java lock<br>
                                           6. acquire java lock<br>
                                           7. MonitorContendedEntered<br>
                                           8. Thread in sync section<br>
                                           9. release java lock<br>
                                         10. why freeze doesn't pin ?<br>
          <br>
        </div>
        <div>What I'm struggling to understand is why after the thread
          releases the java lock, the virtual thread is still frozen,
          and specially why does it freeze while holding a jni monitor ?
          I've run tests locally trying to freeze a virtual thread
          holding a JNI lock and my virtual threads are always being
          pinned to the carrier with reason ("holding a lock"). <br>
          <br>
        </div>
        <div>Thanks in advance</div>
        <div><br>
        </div>
        <div>Íñigo<br>
        </div>
        <div dir="ltr"><br>
        </div>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Fri, Jul 19, 2024 at
            10:41 PM Serguei Spitsyn <<a href="mailto:serguei.spitsyn@oracle.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">serguei.spitsyn@oracle.com</a>>
            wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
            0.8ex;border-left:1px solid
            rgb(204,204,204);padding-left:1ex">
            <div>
              <div lang="EN-US">
                <div>
                  <p class="MsoNormal" style="margin-bottom:12pt"><span style="font-size:14pt;font-family:"Aptos",sans-serif">Hi
                    </span><span style="font-size:14pt">Iñigo,</span><span style="font-size:11pt"></span></p>
                  <p class="MsoNormal"><span style="font-size:14pt;font-family:"Aptos",sans-serif">Patricio
                      helped to reproduce this issue and also identified
                      the problem (please, see in the bug report).<br>
                      The fix is a one-liner. I’ll post a PR after some
                      mach5 testing.<br>
                      <br>
                      Thank you for involvement into this issue!<br>
                      <br>
                      Thanks,</span></p>
                  <p class="MsoNormal"><span style="font-size:14pt;font-family:"Aptos",sans-serif">Serguei</span></p>
                  <p class="MsoNormal"><span style="font-size:14pt;font-family:"Aptos",sans-serif"> </span></p>
                  <div id="m_-4987297925683164692m_-316009806055635242mail-editor-reference-message-container">
                    <div>
                      <div style="border-width:1pt medium
                        medium;border-style:solid none
                        none;border-color:rgb(181,196,223) currentcolor
                        currentcolor;padding:3pt 0in 0in">
                        <p class="MsoNormal" style="margin-bottom:12pt"><b><span style="font-size:12pt;font-family:"Aptos",sans-serif;color:black">From:
                            </span></b><span style="font-size:12pt;font-family:"Aptos",sans-serif;color:black">Iñigo
                            Mediavilla <<a href="mailto:imediava@gmail.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">imediava@gmail.com</a>><br>
                            <b>Date: </b>Saturday, July 13, 2024 at
                            12:08</span><span style="font-size:12pt;font-family:"Arial",sans-serif;color:black"> </span><span style="font-size:12pt;font-family:"Aptos",sans-serif;color:black">AM<br>
                            <b>To: </b>Chris Plummer <<a href="mailto:chris.plummer@oracle.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">chris.plummer@oracle.com</a>><br>
                            <b>Cc: </b><a href="mailto:dholmes@openjdk.org" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">dholmes@openjdk.org</a>
                            <<a href="mailto:dholmes@openjdk.org" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">dholmes@openjdk.org</a>>,
                            <a href="mailto:loom-dev@openjdk.org" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">loom-dev@openjdk.org</a>
                            <<a href="mailto:loom-dev@openjdk.org" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">loom-dev@openjdk.org</a>>,
                            <a href="mailto:sspitsyn@openjdk.org" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">sspitsyn@openjdk.org</a>
                            <<a href="mailto:sspitsyn@openjdk.org" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">sspitsyn@openjdk.org</a>><br>
                            <b>Subject: </b>Re: JDK-8334085: Cannot
                            reproduce failing test</span></p>
                      </div>
                      <div>
                        <div>
                          <p class="MsoNormal"><span style="font-size:11pt">I see, in that case
                              Serguei would you want to still own this
                              JBS or would you be OK if I try to have a
                              look at it ?</span></p>
                        </div>
                        <div>
                          <p class="MsoNormal"><span style="font-size:11pt"> </span></p>
                        </div>
                        <div>
                          <p class="MsoNormal" style="margin-bottom:12pt"><span style="font-size:11pt">Iñigo</span></p>
                          <div>
                            <div>
                              <p class="MsoNormal"><span style="font-size:11pt">El vie, 12 jul
                                  2024, 19:11, Chris Plummer <<a href="mailto:chris.plummer@oracle.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">chris.plummer@oracle.com</a>>
                                  escribió:</span></p>
                            </div>
                            <blockquote style="border-width:medium
                              medium medium 1pt;border-style:none none
                              none solid;border-color:currentcolor
                              currentcolor currentcolor
                              rgb(204,204,204);padding:0in 0in 0in
                              6pt;margin-left:4.8pt;margin-right:0in">
                              <p class="MsoNormal"><span style="font-size:11pt">Failures are
                                  very intermittent. We last saw a
                                  failure in our CI testing
                                  <br>
                                  on 2024-07-03. What command are you
                                  using to run the test?<br>
                                  <br>
                                  Chris<br>
                                  <br>
                                  On 7/12/24 2:34 AM, Iñigo Mediavilla
                                  wrote:<br>
                                  > Hello,<br>
                                  ><br>
                                  > While looking at possible JBS
                                  tickets to work on, I saw JDK-8334085
                                  <br>
                                  > where an assertion was reported
                                  to be failing for the <br>
                                  > GetOwnedMonitorInfoTest. Before I
                                  even asked around to wonder if this <br>
                                  > issue was already being looked
                                  at, I tried to reproduce the failure <br>
                                  > locally, but I don't manage to
                                  make the test fail. Is this still an <br>
                                  > issue in JDK-24 ? David can you
                                  still reproduce the failing test ?<br>
                                  ><br>
                                  > Best<br>
                                  ><br>
                                  > Íñigo Mediavilla Saiz<br>
                                  ><br>
                                  ></span></p>
                            </blockquote>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>