<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>We have a guarantee in UpcallLinker::on_entry to check that we
      are coming from the native thread state:
<a class="moz-txt-link-freetext" href="https://github.com/openjdk/jdk/blob/8650026ff16e5c5eff897f9fd39c0c35fd8b7367/src/hotspot/share/prims/upcallLinker.cpp#L78">https://github.com/openjdk/jdk/blob/8650026ff16e5c5eff897f9fd39c0c35fd8b7367/src/hotspot/share/prims/upcallLinker.cpp#L78</a>
      (I believe we have a test for that as well).<br>
      <br>
      I think for JNI there's just an assert when we call from native
      code into the JNI API and transition to the VM thread state from
      native:
<a class="moz-txt-link-freetext" href="https://github.com/openjdk/jdk/blob/8650026ff16e5c5eff897f9fd39c0c35fd8b7367/src/hotspot/share/runtime/interfaceSupport.inline.hpp#L98">https://github.com/openjdk/jdk/blob/8650026ff16e5c5eff897f9fd39c0c35fd8b7367/src/hotspot/share/runtime/interfaceSupport.inline.hpp#L98</a></p>
    <p>Jorn<br>
    </p>
    <div class="moz-cite-prefix">On 27/07/2023 15:44, Maurizio
      Cimadamore wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:7169c7e4-235a-51ba-6e14-9590645247e6@oracle.com">
      
      <p>The behavior is undefined. It might crash, or not.</p>
      <p>While the description says that the downcall should not upcall,
        please note that the Javadoc doesn't say anywhere that
        ill-behaved downcalls will produce new errors. Moreover, the
        javadoc says this:</p>
      <p> </p>
      <blockquote type="cite">
        <p> Using this linker option when linking non trivial functions
          is likely to have adverse effects, such as loss of
          performance, or JVM crashes.</p>
      </blockquote>
      Basically, you are in undefined behavior territory. It seems to me
      that you are inferring too much from the javadoc.
      <p>While I agree it might be desirable to detect this and log some
        kind of error (see email I sent yesterday), I don't think that,
        as thing stands, the javadoc is incorrect, and/or lacking
        information.</p>
      <p>Maurizio<br>
      </p>
      <p><br>
      </p>
      <div class="moz-cite-prefix">On 27/07/2023 14:40, Cheng Jin wrote:<br>
      </div>
      <blockquote type="cite" cite="mid:BN8PR15MB257733FE3CA75202C523ADD7F501A@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.EmailStyle19
        {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;}</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 class="MsoNormal"><span style="font-size:11.0pt">But I
              tried a simple example to indirectly trigger a JNI upcall
              within a trivial FFM downcall by saving a global JNIEnv
              within a JNI downcall at first which works good as
              follows. Does it mean that a FFM trivial downcall
              literally doesn’t stop a JNI upcall which seems
              inconsistent with the description of <a href="https://urldefense.com/v3/__https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/foreign/Linker.Option.html*isTrivial()__;Iw!!ACWV5N9M2RV99hQ!KpMq9yrQInVdYsiAcZWCDTeOZd_GLJwrDN4n06JvbKQ194M_eabqlUaxzgDuSjbnoxQLukS4Uu8wT7q__xolFW5e$" moz-do-not-send="true">
https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/foreign/Linker.Option.html#isTrivial()</a><o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">or OpenJDK
              doesn’t support such behavior mixed with JNI & FFM?<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"><o:p> </o:p></span></p>
          <p class="MsoNormal"><b><span style="font-size:11.0pt">[1]
                JniTest.java<o:p></o:p></span></b></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">public
              class JniTest {<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">       
              private static Linker linker = Linker.nativeLinker();<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">   static
              {<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">     
              System.loadLibrary("jnitest");<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">       
              private static final SymbolLookup nativeLibLookup =
              SymbolLookup.loaderLookup();<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">private
              native int addJNI2Ints(int arg1, int arg2);<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">    public
              int <b>addJNI2Ints_Upcall</b>(int arg1, int arg2) {<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">      int
              sum = arg1 + arg2;<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">     
              System.out.println("trivial: addJNI2Ints_Upcall: sum = " +
              sum);<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">     
              return sum;<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"><o:p> </o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">       
              public void test_add2Ints() throws Throwable {<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">               
              FunctionDescriptor fd = FunctionDescriptor.of(JAVA_INT,
              JAVA_INT, JAVA_INT);<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">               
              MemorySegment functionSymbol =
              nativeLibLookup.find("add2Ints").get();<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">               
              MethodHandle mh = linker.downcallHandle(functionSymbol,
              fd, <b>Linker.Option.isTrivial()</b>);<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">               
              int result = (int)mh.invokeExact(112, 123);<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">               
              System.out.println("test_add2Ints result = " + result);<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"><o:p> </o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">   public
              static void main(String[] args) throws Throwable {<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">     
              JniTest test = new JniTest();<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">      int
              sum = test.<b>addJNI2Ints</b>(112, 123); </span><span style="font-size:11.0pt;font-family:Wingdings">ß</span><span style="font-size:11.0pt">-- call the JNI native at first
              to save the global JNIEnv & jobject<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">     
              System.out.println("addJNI2Ints sum = " + sum);<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">     
              test.test_<b>add2Ints</b>(); </span><span style="font-size:11.0pt;font-family:Wingdings">ß</span><span style="font-size:11.0pt">-- use saved the global JNIEnv
              & jobject to trigger a JNI upcall in native.<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">}<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
          <p class="MsoNormal"><b><span style="font-size:11.0pt">[2]
                JniTest.c<o:p></o:p></span></b></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">#include
              <jni.h><o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">#include
              "JniTest.h"<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">JNIEnv
              *globalEnv;<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">jobject
              globalObj;<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">JNIEXPORT
              int JNICALL Java_JniTest_addJNI2Ints(JNIEnv *env, jobject
              thisObj, jint arg1, jint arg2) {<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">    jint
              intSum = arg1 + arg2;<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">   
              globalEnv = env;<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">   
              globalObj = thisObj;<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">   
              printf("\nJava_JniTest_addJNI2Ints: env = %p, globalObj =
              %p\n", globalEnv, globalObj);<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">    return
              intSum;<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"><o:p> </o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">int<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">add2Ints(int
              intArg1, int intArg2)<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">       
              printf("\nadd2Ints: globalEnv = %p, globalObj = %p\n",
              globalEnv, globalObj);<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">    jclass
              clazz = (*globalEnv)->GetObjectClass(globalEnv,
              globalObj);<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">   
              jmethodID method = (*globalEnv)->GetMethodID(globalEnv,
              clazz, "addJNI2Ints_Upcall", "(II)I");<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">    return
              (*globalEnv)->CallIntMethod(globalEnv, globalObj,
              method, intArg1, intArg2);<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"><o:p> </o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">[3]Commands:<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">./jdk21_hotspot_x86_64/bin/javac 
              --enable-preview --source 21  -h . JniTest.java<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">gcc -fPIC
              -I"./jdk21_hotspot_x86_64/include"
              -I"./jdk21_hotspot_x86_64/include/linux" -shared -g  -o
              libjnitest.so  JniTest.c<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">./jdk21_hotspot_x86_64/bin/java
              --enable-preview  -Djava.library.path=./jnitests 
              --enable-native-access=ALL-UNNAMED
              -Dforeign.restricted=permit   JniTest<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">[4]
              Output:<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">Java_JniTest_addJNI2Ints:
              env = 0x7f81f8028a08, globalObj = 0x7f81ff379998<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">addJNI2Ints
              sum = 235<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">add2Ints:
              intSum = 235<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">add2Ints:
              globalEnv = 0x7f81f8028a08, globalObj = 0x7f81ff379998<o:p></o:p></span></p>
          <p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
          <p class="MsoNormal"><b><span style="font-size:11.0pt">trivial:
                addJNI2Ints_Upcall: sum = 235 </span></b><b><span style="font-size:11.0pt;font-family:Wingdings">ß</span></b><b><span style="font-size:11.0pt"><o:p></o:p></span></b></p>
          <p class="MsoNormal"><span style="font-size:11.0pt">test_add2Ints
              result = 235<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"><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" moz-do-not-send="true"><maurizio.cimadamore@oracle.com></a>
                <br>
                <b>Sent:</b> Wednesday, July 26, 2023 8:45 PM<br>
                <b>To:</b> Cheng Jin <a class="moz-txt-link-rfc2396E" href="mailto:jincheng@ca.ibm.com" moz-do-not-send="true"><jincheng@ca.ibm.com></a>;
                <a class="moz-txt-link-abbreviated
                  moz-txt-link-freetext" href="mailto:panama-dev@openjdk.org" moz-do-not-send="true">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">On 27/07/2023
                01: 40, Cheng Jin wrote: >> Right, JNI has not
                much to do with this. There's different ways to upcall
                back into Java (JNI and FFM upcall stubs). If so, my
                understanding is that both JNI and FFM upcall should
                crash the VM <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-hYpT1IJMQ-iYRkuvEjWPesZVtAje5jWUBYoL2pAM1wRGP31iKedgOBvqFHgP6rIVsAh-wdcVItzgnQJ8qkuKPFDFOpo-3zg$" 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>
          <p><o:p> </o:p></p>
          <div>
            <p class="MsoNormal"><span style="font-size:11.0pt">On
                27/07/2023 01:40, Cheng Jin wrote:<o:p></o:p></span></p>
          </div>
          <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
            <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><o:p></o:p></p>
          </blockquote>
          <p>I believe so. Jorn will confirm.<o:p></o:p></p>
          <p>Maurizio<o:p></o:p></p>
          <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
            <p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span style="font-size:11.0pt">Best
                Regards</span><o:p></o:p></p>
            <p class="MsoNormal"><span style="font-size:11.0pt">Cheng
                Jin</span><o:p></o:p></p>
            <p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></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 </span><a href="mailto:maurizio.cimadamore@oracle.com" moz-do-not-send="true"><span style="font-size:11.0pt" lang="EN-US"><maurizio.cimadamore@oracle.com></span></a><span style="font-size:11.0pt" lang="EN-US"> <br>
                  <b>Sent:</b> Wednesday, July 26, 2023 8:29 PM<br>
                  <b>To:</b> Cheng Jin </span><a href="mailto:jincheng@ca.ibm.com" moz-do-not-send="true"><span style="font-size:11.0pt" lang="EN-US"><jincheng@ca.ibm.com></span></a><span style="font-size:11.0pt" lang="EN-US">; </span><a href="mailto:panama-dev@openjdk.org" moz-do-not-send="true"><span style="font-size:11.0pt" lang="EN-US">panama-dev@openjdk.org</span></a><span style="font-size:11.0pt" lang="EN-US"><br>
                  <b>Subject:</b> [EXTERNAL] Re: Questions about the
                  trivial downcall</span><o:p></o:p></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.  </span><o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal" style="mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerStart</span><o:p></o:p></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 </span></b><o:p></o:p></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. </span><o:p></o:p></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>  ‌
                                      <o:p></o:p></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</span><o:p></o:p></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"> </span><o:p></o:p></p>
                <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Best Regards</span><o:p></o:p></p>
                <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Cheng Jin</span><o:p></o:p></p>
                <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> </span><o:p></o:p></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 </span><a href="mailto:maurizio.cimadamore@oracle.com" moz-do-not-send="true"><span style="font-size:11.0pt" lang="EN-US"><maurizio.cimadamore@oracle.com></span></a><span style="font-size:11.0pt" lang="EN-US"> <br>
                      <b>Sent:</b> Wednesday, July 26, 2023 7:44 PM<br>
                      <b>To:</b> Cheng Jin </span><a href="mailto:jincheng@ca.ibm.com" moz-do-not-send="true"><span style="font-size:11.0pt" lang="EN-US"><jincheng@ca.ibm.com></span></a><span style="font-size:11.0pt" lang="EN-US">; </span><a href="mailto:panama-dev@openjdk.org" moz-do-not-send="true"><span style="font-size:11.0pt" lang="EN-US">panama-dev@openjdk.org</span></a><span style="font-size:11.0pt" lang="EN-US"><br>
                      <b>Subject:</b> [EXTERNAL] Re: Questions about the
                      trivial downcall</span><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"> </span><o:p></o:p></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><o:p></o:p></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><o:p></o:p></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><o:p></o:p></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><o:p></o:p></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">  </span><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><span style="font-size:11.0pt">  ‌
                                          </span><o:p></o:p></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><o:p></o:p></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:</span><o:p></o:p></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,</span><o:p></o:p></p>
                  <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> </span><o:p></o:p></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).</span><o:p></o:p></p>
                  <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> </span><o:p></o:p></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 ?</span><o:p></o:p></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?</span><o:p></o:p></p>
                  <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
                  <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Best Regards</span><o:p></o:p></p>
                  <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt">Cheng Jin</span><o:p></o:p></p>
                </blockquote>
              </div>
            </blockquote>
          </blockquote>
        </div>
      </blockquote>
    </blockquote>
  </body>
</html>