<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:11.0pt;
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle21
{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">Hi Maurizio,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">>> … 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?
<o:p></o:p></p>
<p>Yes. That’s exactly something I’d like to know: e.g. what happens if a JNI upcall is triggered in a trivial FFM downcall? Crashing the VM to prevent the JNI upcall?<o:p></o:p></p>
<p>>> 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>The only way (I can image) to achieve a JNI upcall from a FFI downcall is to 1) do a JNI downcall at first to store a JNIEnv as a global variable in native and then 2) do a FFM downcall to trigger the JNI upcall with the stored global JNIEnv.<o:p></o:p></p>
<p>Suppose it works in this way, my question is whether such a JNI upcall should also be prevented/disallowed in a trivial FFM downcall based on 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> as follows:<o:p></o:p></p>
<p>A trivial function is a function that has an extremely short running time in all cases (similar to calling an empty function),
<o:p></o:p></p>
<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>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Best Regards<o:p></o:p></p>
<p class="MsoNormal">Cheng Jin<o:p></o:p></p>
<p class="MsoNormal"><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="mso-ligatures:none">From:</span></b><span lang="EN-US" style="mso-ligatures:none"> Maurizio Cimadamore <maurizio.cimadamore@oracle.com>
<br>
<b>Sent:</b> Wednesday, July 26, 2023 7:44 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">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:1.0pt;color:white;mso-ligatures:none"><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-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>
<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<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">On 26/07/2023 22:23, Cheng Jin wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Hi there,<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">I’ve got a couple of questions about the behavior of a trivial downcall (with
<b>isTrivial</b> specified).<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Is a FFI downcall able to trigger a JNI upcall ?<o:p></o:p></p>
<p class="MsoNormal">If so, should a JNI upcall should be captured in this trivial downcall?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Best Regards<o:p></o:p></p>
<p class="MsoNormal">Cheng Jin<o:p></o:p></p>
</blockquote>
</div>
</body>
</html>