<div dir="ltr"><div>Sorry if this is a silly question. I wanted to check my understanding of method handles in downcalls.  The example below is from jextract, though I have similar handwritten sections in my own non-jextract examples. For best performance, the MethodHandle is declared in static field:</div><div><br></div><div><div style="background-color:rgb(255,255,255);padding:0px 0px 0px 2px"><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:"Consolas";font-size:10pt;white-space:pre"><p style="margin:0px"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(127,0,85);font-weight:bold">public</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(127,0,85);font-weight:bold">static</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(127,0,85);font-weight:bold">final</span><span style="color:rgb(0,0,0)"> FunctionDescriptor </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">DESC</span><span style="color:rgb(0,0,0)"> = FunctionDescriptor.</span><span style="color:rgb(0,0,0);font-style:italic">ofVoid</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">ADDRESS</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">JAVA_LONG</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">JAVA_LONG</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">ADDRESS</span><span style="color:rgb(0,0,0)">);</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(127,0,85);font-weight:bold">public</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(127,0,85);font-weight:bold">static</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(127,0,85);font-weight:bold">final</span><span style="color:rgb(0,0,0)"> MemorySegment </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">ADDR</span><span style="color:rgb(0,0,0)"> = </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">LOOKUP</span><span style="color:rgb(0,0,0)">.findOrThrow(</span><span style="color:rgb(42,0,255)">"qsort"</span><span style="color:rgb(0,0,0)">);</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(127,0,85);font-weight:bold">public</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(127,0,85);font-weight:bold">static</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(127,0,85);font-weight:bold">final</span><span style="color:rgb(0,0,0)"> MethodHandle </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">MH</span><span style="color:rgb(0,0,0)"> = </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">LINKER</span><span style="color:rgb(0,0,0)">.downcallHandle(</span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">ADDR</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">DESC</span><span style="color:rgb(0,0,0)">);</span></p><p style="margin:0px"><br></p></div></div>Would I get similar performance benefit for qsort MH.invokeExact if I changed above to use a record for Download fields instead? <br></div><div><br></div><div><div style="background-color:rgb(255,255,255);padding:0px 0px 0px 2px"><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:"Consolas";font-size:10pt;white-space:pre"><p style="margin:0px"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(127,0,85);font-weight:bold">record</span><span style="color:rgb(0,0,0)"> Downcall(MemorySegment </span><span style="color:rgb(106,62,62)">address</span><span style="color:rgb(0,0,0)">, FunctionDescriptor </span><span style="color:rgb(106,62,62)">descriptor</span><span style="color:rgb(0,0,0)">, MethodHandle </span><span style="color:rgb(106,62,62)">handle</span><span style="color:rgb(0,0,0)">) {</span></p><p style="margin:0px"></p><p style="margin:0px"><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(127,0,85);font-weight:bold">public</span><span style="color:rgb(0,0,0)"> Downcall(MemorySegment </span><span style="color:rgb(106,62,62)">addr</span><span style="color:rgb(0,0,0)">, FunctionDescriptor </span><span style="color:rgb(106,62,62)">desc</span><span style="color:rgb(0,0,0)">) {</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">            </span><span style="color:rgb(127,0,85);font-weight:bold">this</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(106,62,62)">addr</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(106,62,62)">desc</span><span style="color:rgb(0,0,0)">, Linker.</span><span style="color:rgb(0,0,0);font-style:italic">nativeLinker</span><span style="color:rgb(0,0,0)">().downcallHandle(</span><span style="color:rgb(106,62,62)">addr</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(106,62,62)">desc</span><span style="color:rgb(0,0,0)">));</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">        }</span></p>    }</div><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:"Consolas";font-size:10pt;white-space:pre"><br></div></div>This means the definition is now a one liner:</div><div><br></div><div><div style="background-color:rgb(255,255,255);padding:0px 0px 0px 2px"><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:"Consolas";font-size:10pt;white-space:pre"><div style="background-color:rgb(255,255,255);padding:0px 0px 0px 2px"><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:"Consolas";font-size:10pt;white-space:pre"><p style="margin:0px"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(127,0,85);font-weight:bold">private</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(127,0,85);font-weight:bold">static</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(127,0,85);font-weight:bold">final</span><span style="color:rgb(0,0,0)"> </span><span style="text-decoration:underline rgb(0,102,204);color:rgb(0,102,204)">Downcall</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">CALL = </span><span style="color:rgb(127,0,85);font-weight:bold">new</span><span style="color:rgb(0,0,0)"> Downcall(</span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">LOOKUP</span><span style="color:rgb(0,0,0)">.findOrThrow(</span><span style="color:rgb(42,0,255)">"qsort"</span><span style="color:rgb(0,0,0)">), FunctionDescriptor.</span><span style="color:rgb(0,0,0);font-style:italic">ofVoid</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">ADDRESS</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">JAVA_LONG</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">JAVA_LONG</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(0,0,192);font-style:italic;font-weight:bold">ADDRESS</span><span style="color:rgb(0,0,0)">));</span></p><p style="margin:0px">    // invoke with <span style="color:rgb(0,0,0)">CALL.</span><span style="background-color:rgb(255,255,255);padding:0px 0px 0px 2px"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:"Consolas";font-size:10pt;white-space:pre"><span style="color:rgb(0,0,0)"></span><span style="color:rgb(0,0,192)">handle</span></span></span><span style="background-color:rgb(255,255,255);padding:0px 0px 0px 2px"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:"Consolas";font-size:10pt;white-space:pre"><span style="color:rgb(0,0,192)"></span><span style="color:rgb(0,0,0)">.invokeExact(</span><span style="color:rgb(106,62,62)">base</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(106,62,62)">nitems</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(106,62,62)">size</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(106,62,62)">compar</span><span style="color:rgb(0,0,0)">)</span></span></span>
<br></p><p style="margin:0px">Kind regards</p><p style="margin:0px"><br></p><p style="margin:0px">Duncan Gittins</p>
<div><br></div>

<p style="margin:0px"><br></p><p style="margin:0px"><br></p><p style="margin:0px"><br></p></div></div><p style="margin:0px"><br></p></div></div><br></div></div>