<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hi Mat. It sounds like you could use multiple entry points based
on MethodKind to accomplish this. Add new entries to the
MethodKind enum for the upcall versions. Generate both the upcall
and non-upcall entry points, and map to appropriate MethodKind
values. Then use your runtime pattern match to decide with
MethodKind to use for each method in <a href="https://java.se.oracle.com/source/s?defs=AbstractInterpreter&project=jdk-cpu-git" class="intelliWindow-symbol" data-definition-place="undefined-in-file">AbstractInterpreter</a>::<a href="https://java.se.oracle.com/source/s?defs=method_kind&project=jdk-cpu-git" class="intelliWindow-symbol" data-definition-place="undefined-in-file">method_kind</a>(<b>const</b>
<a href="https://java.se.oracle.com/source/s?defs=methodHandle&project=jdk-cpu-git" class="intelliWindow-symbol" data-definition-place="undefined-in-file">methodHandle</a>&
<a href="https://java.se.oracle.com/source/s?defs=m&project=jdk-cpu-git" class="intelliWindow-symbol" data-definition-place="undefined-in-file">m</a>).<br>
</p>
<p>dl</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 10/9/24 6:42 PM, Mat Carter wrote:<br>
</div>
<blockquote type="cite" cite="mid:BL4PR21MB4128961B0C70498D8E4B8C9B8A782@BL4PR21MB4128.namprd21.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:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}div.WordSection1
{page:WordSection1;}</style>
<div class="WordSection1">
<p class="MsoNormal">Is there a place to encode calls to the VM
in the interpreted methods other than the method prologs? </p>
<p class="MsoNormal">I've recently discovered the interpreted
method adaptors which seems like a candidate, but there's
</p>
<p class="MsoNormal">no examples of the adaptors calling into
the VM.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Follows is the rational as to why I'm
looking for an alternative to the method prologs</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The AOTEndTrainingOnMethodEntry feature [1]
introduces calls from java methods into the
</p>
<p class="MsoNormal">VM (upcalls) when specific methods are
entered. The methods are identified via a pattern in a
</p>
<p class="MsoNormal">similar manner to the CompileOnly option.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Following the initial PR review we’re
looking at removing the knowledge of this AOT feature from
</p>
<p class="MsoNormal">the compilers/interpreter and introducing a
more generic system (RuntimeUpcalls) that can be
</p>
<p class="MsoNormal">used by other parts of the VM [2]. In
building out the RuntimeUpcalls system we've come across
</p>
<p class="MsoNormal">an inefficiency that isn't an immediate
problem for this feature, but should another feature use this
</p>
<p class="MsoNormal">new system then it's less than optimal.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Interpreted code uses a shared method
prolog (there are 8 variants for 'regular' methods [more
</p>
<p class="MsoNormal">for some special math/zip methods]), the
AOTEndTrainingOnMethodEntry feature introduces a
</p>
<p class="MsoNormal">further 5 prolog types. When there is a
single upcall (eg. AOTEndTrainingOnMethodEntry) to the VM
</p>
<p class="MsoNormal">everything is efficient.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The inefficiency issue arises as soon as
there are two or more upcalls; which upcalls relate to
</p>
<p class="MsoNormal">which methods is contained within the
RuntimeUpcalls system. When the interpreter examines
</p>
<p class="MsoNormal">the method flags they only indicate whether
there are any upcalls (but not how many or which ones).
</p>
<p class="MsoNormal">As the interpreter can't encode which
upcalls should be called in the prolog (without an explosion
</p>
<p class="MsoNormal">of new runtime generated prologs), it needs
to call the RuntimeUpcalls system which in turn iterates</p>
<p class="MsoNormal">over the upcalls and calls the appropriate
ones; the problem is that during that iteration the methods
</p>
<p class="MsoNormal">need to be compared against the pattern.
So we either pay a memory cost to cache the method to
</p>
<p class="MsoNormal">upcall relationships or we pay a
performance cost to repeatedly test the method against the
pattern.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This is not a problem for C1 and C2 as we
pay this cost only when the methods are compiled and
</p>
<p class="MsoNormal">create the multiple upcalls in those
methods, eliminating the need for pattern matching by the
</p>
<p class="MsoNormal">RuntimeUpcalls system during method
execution</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks in advance </p>
<p class="MsoNormal">Mat</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[1] <a href="https://github.com/openjdk/leyden/pull/21" moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/openjdk/leyden/pull/21</a></p>
<p class="MsoNormal">[2] <a href="https://github.com/macarte/leyden/pull/2" moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/macarte/leyden/pull/2</a></p>
</div>
</blockquote>
</body>
</html>