<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@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;}
/* Style Definitions */
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;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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]-->
</head>
<body lang="EN-CA" link="blue" vlink="purple" style="word-wrap:break-word">
<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://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/foreign/Linker.Option.html#isTrivial()">
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 lang="EN-US" style="font-size:11.0pt">From:</span></b><span lang="EN-US" style="font-size:11.0pt"> Maurizio Cimadamore <maurizio.cimadamore@oracle.com>
<br>
<b>Sent:</b> Wednesday, July 26, 2023 8:45 PM<br>
<b>To:</b> Cheng Jin <jincheng@ca.ibm.com>; panama-dev@openjdk.org<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" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;border-radius:4px">
<tbody>
<tr>
<td style="padding:12.0pt 0cm 12.0pt 0cm">
<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;background:#D0D8DC;border:none;border-top:solid #90A4AE 3.0pt">
<tbody>
<tr>
<td valign="top" style="border:none;padding:0cm 7.5pt 3.75pt 4.5pt">
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="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" border="0" cellspacing="0" cellpadding="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"><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 lang="EN-US" style="font-size:11.0pt">From:</span></b><span lang="EN-US" style="font-size:11.0pt"> Maurizio Cimadamore
</span><a href="mailto:maurizio.cimadamore@oracle.com"><span lang="EN-US" style="font-size:11.0pt"><maurizio.cimadamore@oracle.com></span></a><span lang="EN-US" style="font-size:11.0pt">
<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"><span lang="EN-US" style="font-size:11.0pt"><jincheng@ca.ibm.com></span></a><span lang="EN-US" style="font-size:11.0pt">;
</span><a href="mailto:panama-dev@openjdk.org"><span lang="EN-US" style="font-size:11.0pt">panama-dev@openjdk.org</span></a><span lang="EN-US" style="font-size:11.0pt"><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" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;border-radius:4px">
<tbody>
<tr>
<td style="padding:12.0pt 0cm 12.0pt 0cm">
<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;background:#D0D8DC;border:none;border-top:solid #90A4AE 3.0pt">
<tbody>
<tr>
<td valign="top" style="border:none;padding:0cm 7.5pt 3.75pt 4.5pt">
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="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" border="0" cellspacing="0" cellpadding="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"><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 lang="EN-US" style="font-size:11.0pt">From:</span></b><span lang="EN-US" style="font-size:11.0pt"> Maurizio Cimadamore
</span><a href="mailto:maurizio.cimadamore@oracle.com"><span lang="EN-US" style="font-size:11.0pt"><maurizio.cimadamore@oracle.com></span></a><span lang="EN-US" style="font-size:11.0pt">
<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"><span lang="EN-US" style="font-size:11.0pt"><jincheng@ca.ibm.com></span></a><span lang="EN-US" style="font-size:11.0pt">;
</span><a href="mailto:panama-dev@openjdk.org"><span lang="EN-US" style="font-size:11.0pt">panama-dev@openjdk.org</span></a><span lang="EN-US" style="font-size:11.0pt"><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" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;border-radius:4px">
<tbody>
<tr>
<td style="padding:12.0pt 0cm 12.0pt 0cm">
<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;background:#D0D8DC;border:none;border-top:solid #90A4AE 3.0pt">
<tbody>
<tr>
<td valign="top" style="border:none;padding:0cm 7.5pt 3.75pt 4.5pt">
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="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" border="0" cellspacing="0" cellpadding="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"><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>
</body>
</html>