<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 27/07/2023 01:40, Cheng Jin wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:BN8PR15MB2577022FC6170AF3C6DF750FF501A@BN8PR15MB2577.namprd15.prod.outlook.com">
      
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}div.WordSection1
        {page:WordSection1;}ol
        {margin-bottom:0cm;}ul
        {margin-bottom:0cm;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p>>> Right, JNI has not much to do with this. There's
          different ways to upcall back into Java (JNI and FFM upcall
          stubs).<o:p></o:p></p>
        <p class="MsoNormal"><span style="font-size:11.0pt">If so, my
            understanding is that both JNI and FFM upcall should crash
            the VM in a trivial FFM downcall, correct?</span></p>
      </div>
    </blockquote>
    <p>I believe so. Jorn will confirm.</p>
    <p>Maurizio<br>
    </p>
    <blockquote type="cite" cite="mid:BN8PR15MB2577022FC6170AF3C6DF750FF501A@BN8PR15MB2577.namprd15.prod.outlook.com">
      <div class="WordSection1">
        <p class="MsoNormal"><span style="font-size:11.0pt"><o:p></o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt">Best Regards<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt">Cheng Jin<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
        <div style="border:none;border-top:solid #E1E1E1
          1.0pt;padding:3.0pt 0cm 0cm 0cm">
          <p class="MsoNormal"><b><span style="font-size:11.0pt" lang="EN-US">From:</span></b><span style="font-size:11.0pt" lang="EN-US"> Maurizio Cimadamore
              <a class="moz-txt-link-rfc2396E" href="mailto:maurizio.cimadamore@oracle.com"><maurizio.cimadamore@oracle.com></a>
              <br>
              <b>Sent:</b> Wednesday, July 26, 2023 8:29 PM<br>
              <b>To:</b> Cheng Jin <a class="moz-txt-link-rfc2396E" href="mailto:jincheng@ca.ibm.com"><jincheng@ca.ibm.com></a>;
              <a class="moz-txt-link-abbreviated" href="mailto:panama-dev@openjdk.org">panama-dev@openjdk.org</a><br>
              <b>Subject:</b> [EXTERNAL] Re: Questions about the trivial
              downcall<o:p></o:p></span></p>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <div>
          <p class="MsoNormal" style="mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">and does not call back
              into Java (e. g. using an upcall stub).
              ß------------------------- it occurs to me that any kind
              of upcall should be disallowed in such case whether it is
              JNI or FFM, am I correct? Right, JNI has not much to do
              with this. 
              <o:p></o:p></span></p>
        </div>
        <div>
          <p class="MsoNormal" style="mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerStart<o:p></o:p></span></p>
        </div>
        <table class="MsoNormalTable" style="width:100.0%;border-radius:4px" width="100%" cellspacing="0" cellpadding="0" border="0">
          <tbody>
            <tr>
              <td style="padding:12.0pt 0cm 12.0pt 0cm">
                <table class="MsoNormalTable" style="width:100.0%;background:#D0D8DC;border:none;border-top:solid
                  #90A4AE 3.0pt" width="100%" cellspacing="0" cellpadding="0" border="1">
                  <tbody>
                    <tr>
                      <td style="border:none;padding:0cm 7.5pt 3.75pt
                        4.5pt" valign="top">
                        <table class="MsoNormalTable" cellspacing="0" cellpadding="0" border="0" align="left">
                          <tbody>
                            <tr>
                              <td style="padding:3.0pt 6.0pt 3.0pt
                                6.0pt">
                                <p class="MsoNormal"><b><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:black">This
                                      Message Is From an External Sender
                                      <o:p></o:p></span></b></p>
                              </td>
                            </tr>
                            <tr>
                              <td style="padding:3.0pt 6.0pt 3.0pt
                                6.0pt">
                                <p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black">This
                                    message came from outside your
                                    organization.
                                    <o:p></o:p></span></p>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                        <table class="MsoNormalTable" cellspacing="0" cellpadding="0" border="0" align="right">
                          <tbody>
                            <tr>
                              <td style="padding:3.0pt 0cm 3.0pt 0cm">
                                <p class="MsoNormal">  <a href="https://us-phishalarm-ewt.proofpoint.com/EWT/v1/PjiDSg!2c-gyJS_6lP6sKYb2IHEjb2TaeBqM7xJQ9RStijLaImfla_LrFEK8T2PB5_umxDwUuL8X7BGAHosOeXRLCglJfzdYnJaiHF6gQ$" target="_blank" moz-do-not-send="true"><strong><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:black;border:solid
                                        #666666
                                        1.0pt;padding:6.0pt;font-weight:normal;text-decoration:none">  Report Suspicious  </span></strong></a>  ‌
                                  <span style="font-size:11.0pt"><o:p></o:p></span></p>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </td>
            </tr>
          </tbody>
        </table>
        <div>
          <p class="MsoNormal" style="mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerEnd<o:p></o:p></span></p>
        </div>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <div>
            <p>and does not call back into Java (e.g. using an upcall
              stub). <span style="font-family:Wingdings">
                ß</span>------------------------- it occurs to me that
              any kind of upcall should be disallowed in such case
              whether it is JNI or FFM, am I correct?
              <o:p></o:p></p>
          </div>
        </blockquote>
        <p>Right, JNI has not much to do with this. There's different
          ways to upcall back into Java (JNI and FFM upcall stubs).<o:p></o:p></p>
        <p>Your question is: what happens if we do call back when we are
          in trivial mode.<o:p></o:p></p>
        <p>I believe the answer is "we crash" (but not in a "nice way"),
          and I'm not too sure we can do much to prevent that. I believe
          Jorn knows more on that topic.<o:p></o:p></p>
        <p>Maurizio<o:p></o:p></p>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <div>
            <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
            <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Best Regards<o:p></o:p></span></p>
            <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Cheng Jin<o:p></o:p></span></p>
            <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
            <div style="border:none;border-top:solid #E1E1E1
              1.0pt;padding:3.0pt 0cm 0cm 0cm">
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-size:11.0pt" lang="EN-US">From:</span></b><span style="font-size:11.0pt" lang="EN-US"> Maurizio
                  Cimadamore
                  <a href="mailto:maurizio.cimadamore@oracle.com" moz-do-not-send="true"><maurizio.cimadamore@oracle.com></a>
                  <br>
                  <b>Sent:</b> Wednesday, July 26, 2023 7:44 PM<br>
                  <b>To:</b> Cheng Jin <a href="mailto:jincheng@ca.ibm.com" moz-do-not-send="true"><jincheng@ca.ibm.com></a>;
                  <a href="mailto:panama-dev@openjdk.org" moz-do-not-send="true" class="moz-txt-link-freetext">panama-dev@openjdk.org</a><br>
                  <b>Subject:</b> [EXTERNAL] Re: Questions about the
                  trivial downcall</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
            </div>
            <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
            <div>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">Hi, a trivial
                  downcall is supposed to target a native function that
                  (a) terminates quickly (so as not to block the GC for
                  too long) and (b) does not upcall into Java. So, no, a
                  trivial downcall cannot trigger upcalls (I don't think
                  we detect </span><span style="font-size:11.0pt"><o:p></o:p></span></p>
            </div>
            <div>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerStart</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
            </div>
            <table class="MsoNormalTable" style="width:100.0%;border-radius:4px" width="100%" cellspacing="0" cellpadding="0" border="0">
              <tbody>
                <tr>
                  <td style="padding:12.0pt 0cm 12.0pt 0cm">
                    <table class="MsoNormalTable" style="width:100.0%;background:#D0D8DC;border:none;border-top:solid
                      #90A4AE 3.0pt" width="100%" cellspacing="0" cellpadding="0" border="1">
                      <tbody>
                        <tr>
                          <td style="border:none;padding:0cm 7.5pt
                            3.75pt 4.5pt" valign="top">
                            <table class="MsoNormalTable" cellspacing="0" cellpadding="0" border="0" align="left">
                              <tbody>
                                <tr>
                                  <td style="padding:3.0pt 6.0pt 3.0pt
                                    6.0pt">
                                    <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:black">This
                                          Message Is From an External
                                          Sender
                                        </span></b><span style="font-size:11.0pt"><o:p></o:p></span></p>
                                  </td>
                                </tr>
                                <tr>
                                  <td style="padding:3.0pt 6.0pt 3.0pt
                                    6.0pt">
                                    <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black">This
                                        message came from outside your
                                        organization.
                                      </span><span style="font-size:11.0pt"><o:p></o:p></span></p>
                                  </td>
                                </tr>
                              </tbody>
                            </table>
                            <table class="MsoNormalTable" cellspacing="0" cellpadding="0" border="0" align="right">
                              <tbody>
                                <tr>
                                  <td style="padding:3.0pt 0cm 3.0pt
                                    0cm">
                                    <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">  <a href="https://us-phishalarm-ewt.proofpoint.com/EWT/v1/PjiDSg!2c-r455VanMQ2qYReaGl7Z4QRx46ATMxAjK9nbXsj13QlLeimn0PtcIAb-U80cJ-A34Q8dYfoQ6JN5nMYOpBz-Hn3cuAGTZLJQ$" target="_blank" moz-do-not-send="true"><strong><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:black;border:solid
                                              #666666
                                              1.0pt;padding:6.0pt;font-weight:normal;text-decoration:none">  Report Suspicious  </span></strong></a>  ‌
                                        <o:p></o:p></span></p>
                                  </td>
                                </tr>
                              </tbody>
                            </table>
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </td>
                </tr>
              </tbody>
            </table>
            <div>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerEnd</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
            </div>
            <p>Hi,<br>
              a trivial downcall is supposed to target a native function
              that (a) terminates quickly (so as not to block the GC for
              too long) and (b) does not upcall into Java.<o:p></o:p></p>
            <p>So, no, a trivial downcall cannot trigger upcalls (I
              don't think we detect this, I believe the JVM just crashes
              if you do).<o:p></o:p></p>
            <p>Also I notice that you speak of "JNI" upcall. Is that
              what you really mean - e.g. a trivial FFM downcall making
              an upcall using JNI? In general, I think it's a bit hard
              for downcalls to do anything that has to do with JNI
              because the invoked native function is not passed a JNIEnv
              - FFM really just bridges the Java code with the native
              library function you want to call, nothing more. (I
              suppose that function could get its hands on the VM using
              the JNI attach API, but I feel that's a different question
              from what you were asking?).<o:p></o:p></p>
            <p>Maurizio<o:p></o:p></p>
            <div>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">On 26/07/2023 22:23, Cheng
                  Jin wrote:<o:p></o:p></span></p>
            </div>
            <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Hi there,<o:p></o:p></span></p>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">I’ve got a couple of
                  questions about the behavior of a trivial downcall
                  (with
                  <b>isTrivial</b> specified).<o:p></o:p></span></p>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Is a FFI downcall able to
                  trigger a JNI upcall ?<o:p></o:p></span></p>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">If so, should a JNI upcall
                  should be captured in this trivial downcall?<o:p></o:p></span></p>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Best Regards<o:p></o:p></span></p>
              <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Cheng Jin<o:p></o:p></span></p>
            </blockquote>
          </div>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>