<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:"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;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        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;}
@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="#0563C1" 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">Many thanks for the detailed clarifications.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">As for this linker option for downcall,  does it mean users need to specify Linker.Option.isTrivial() at
<a href="https://cr.openjdk.org/~pminborg/panama/21/v1/javadoc/java.base/java/lang/foreign/Linker.Option.html#isTrivial()">https://cr.openjdk.org/~pminborg/panama/21/v1/javadoc/java.base/java/lang/foreign/Linker.Option.html#isTrivial()</a> to enable the optimization?<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">From:</span></b><span lang="EN-US"> Maurizio Cimadamore <maurizio.cimadamore@oracle.com>
<br>
<b>Sent:</b> May 9, 2023 4:41 PM<br>
<b>To:</b> Cheng Jin <jincheng@ca.ibm.com>; panama-dev@openjdk.org<br>
<b>Subject:</b> [EXTERNAL] Re: Questions about JEP442 at https://openjdk.org/jeps/442<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, some comments inline below: On 09/05/2023 18: 28, Cheng Jin wrote: Hi there, I feel confused with the following descriptions in JEP442 at https: //openjdk. org/jeps/442:
 Provided a linker option to optimize calls to functions that are short-lived <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>
</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, some comments inline below:<o:p></o:p></p>
<div>
<p class="MsoNormal">On 09/05/2023 18:28, 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 feel confused with the following descriptions in JEP442 at
<a href="https://openjdk.org/jeps/442">https://openjdk.org/jeps/442</a>:<o:p></o:p></p>
<p class="MsoNormal"><b><i>Provided a linker option to optimize calls to functions that are short-lived and will not upcall to Java (e.g., clock_gettime);</i></b><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Can anybody explain what the linker option is intended for (assuming it is used in upcall?) and how it works in terms of the optimization in there?
<o:p></o:p></p>
</blockquote>
<p class="MsoNormal">This option only affects calls from Java to native. When you go from Java to native there is some bookkeeping required in order to change the thread state from Java-state to native-state (and back when you leave). While these transitions
 are quick (typically < 5ns), there are some edge cases where clients working in low-latency environments really need to shave off every last nanosecond out of a native call - especially native calls such as e.g. gettime which can return very quickly. Of course,
 removing thread transitions comes with big caveats too: a native function called in this way would have to terminate quickly (as GC would be disabled for the duration of the call), and it can never upcall back to Java. As such, this is a mechanism that should
 only really be used in very specific cases, by a very specific set of developers. (You might have heard of the term "critical JNI" [1] in the past - this option in some way is a replacement for that functionality).<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Another question is about the fallback linker: <b><i>Provided a fallback native linker implementation, based on libffi
</i></b><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">It seems to me t that it is never used unless the current platform has no support on the foreign linker as indicated in code at java.base/share/classes/jdk/internal/foreign/CABI.java:<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">       <b>if (ForeignLinkerSupport.isSupported()) {</b><o:p></o:p></p>
<p class="MsoNormal">       ...<o:p></o:p></p>
<p class="MsoNormal">       <b>} else if (FallbackLinker.isSupported()) {</b><o:p></o:p></p>
<p class="MsoNormal">            return FALLBACK; // fallback linker<o:p></o:p></p>
<p class="MsoNormal">       }<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">If so, what is the background of introducing this kind of linker? and where can it be used?<o:p></o:p></p>
</blockquote>
<p>This linker can be used on all platforms which do not provide any low level support for the linker API. For instance in the case of the zero assempler port [1] which, by definition, doesn't provide any way to generate assembly on the fly. This has more to
 do with allowing the linker API to be supported in extreme situations, but not something the user really has to care about. The big benefit, however, is that the user can expect the Linker API to be supported in more platforms [3].<o:p></o:p></p>
<p>I hope this helps.<o:p></o:p></p>
<p>Maurizio<o:p></o:p></p>
<p>[1] - <a href="https://shipilev.net/jvm/anatomy-quarks/9-jni-critical-gclocker/">https://shipilev.net/jvm/anatomy-quarks/9-jni-critical-gclocker/</a><br>
[2] - <a href="https://openjdk.org/projects/zero/">https://openjdk.org/projects/zero/</a><br>
[3] - <a href="https://mail.openjdk.org/pipermail/porters-dev/2023-March/000753.html">https://mail.openjdk.org/pipermail/porters-dev/2023-March/000753.html</a><o:p></o:p></p>
<p><o:p> </o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<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>