<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hi, some comments inline below:<br>
</p>
<div class="moz-cite-prefix">On 09/05/2023 18:28, Cheng Jin wrote:<br>
</div>
<blockquote type="cite" cite="mid:BN8PR15MB2577279E587B485E51BA2E45F5769@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.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}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 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);<o:p></o:p></i></b></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?
</p>
</div>
</blockquote>
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>
<blockquote type="cite" cite="mid:BN8PR15MB2577279E587B485E51BA2E45F5769@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"><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
<o:p></o:p></i></b></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()) {<o:p></o:p></b></p>
<p class="MsoNormal"> ...<o:p></o:p></p>
<p class="MsoNormal"> <b>} else if
(FallbackLinker.isSupported()) {<o:p></o:p></b></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>
</div>
</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].</p>
<p>I hope this helps.</p>
<p>Maurizio<br>
</p>
<p>[1] -
<a class="moz-txt-link-freetext" 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 class="moz-txt-link-freetext" href="https://openjdk.org/projects/zero/">https://openjdk.org/projects/zero/</a><br>
[3] -
<a class="moz-txt-link-freetext" href="https://mail.openjdk.org/pipermail/porters-dev/2023-March/000753.html">https://mail.openjdk.org/pipermail/porters-dev/2023-March/000753.html</a><br>
</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:BN8PR15MB2577279E587B485E51BA2E45F5769@BN8PR15MB2577.namprd15.prod.outlook.com">
<div class="WordSection1">
<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>
</div>
</blockquote>
</body>
</html>