<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 09/05/2023 22:07, Cheng Jin wrote:<br>
</div>
<blockquote type="cite" cite="mid:BN8PR15MB2577A53CEC4BAC3876E508AFF5769@BN8PR15MB2577.namprd15.prod.outlook.com">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@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: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;}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">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()" moz-do-not-send="true" class="moz-txt-link-freetext">https://cr.openjdk.org/~pminborg/panama/21/v1/javadoc/java.base/java/lang/foreign/Linker.Option.html#isTrivial()</a>
to enable the optimization?</p>
</div>
</blockquote>
<p>Yes, you need to pass this "trivial" linker option when creating
a downcall method handle (note that the downcall method handle
factory method accepts a varargs of linker options).</p>
<p>Maurizio<br>
</p>
<blockquote type="cite" cite="mid:BN8PR15MB2577A53CEC4BAC3876E508AFF5769@BN8PR15MB2577.namprd15.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><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
<a class="moz-txt-link-rfc2396E" href="mailto:maurizio.cimadamore@oracle.com"><maurizio.cimadamore@oracle.com></a>
<br>
<b>Sent:</b> May 9, 2023 4:41 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 JEP442 at
<a class="moz-txt-link-freetext" href="https://openjdk.org/jeps/442">https://openjdk.org/jeps/442</a><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" 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>
</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" moz-do-not-send="true" class="moz-txt-link-freetext">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://urldefense.com/v3/__https://shipilev.net/jvm/anatomy-quarks/9-jni-critical-gclocker/__;!!ACWV5N9M2RV99hQ!KzszxNKci3FnbYarVj8AXwe_Mzua_DqjXqby51t6ctmIMyqLC9Xas2myACu7hYxx3-BRAWS0lHfs7RgJepChNxGD$" moz-do-not-send="true">https://shipilev.net/jvm/anatomy-quarks/9-jni-critical-gclocker/</a><br>
[2] - <a href="https://openjdk.org/projects/zero/" moz-do-not-send="true" class="moz-txt-link-freetext">https://openjdk.org/projects/zero/</a><br>
[3] - <a href="https://mail.openjdk.org/pipermail/porters-dev/2023-March/000753.html" moz-do-not-send="true" class="moz-txt-link-freetext">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>
</blockquote>
</body>
</html>