Unsafe vs MemorySegments / Bounds checking...

Brian S O'Neill bronee at gmail.com
Wed Oct 30 14:06:21 UTC 2024


I was able to force inlining on a few key methods, and this appears to 
have improved performance a bit more, but inlining isn't always 
complete. Sometimes it gives up with messages like, "inlining too deep", 
"callee uses too much stack", and "don't inline Throwable constructors".

When inlining does work, the chain of method calls is 73, but the 
equivalent Unsafe chain is only 5. This might explain why Unsafe 
inlining usually works -- it's much shorter.

The inlining output will get screwed up in an email, so I pasted it here:

https://gist.github.com/broneill/f1cd899ea7385acc26f23ef98070bb16

One thing I find shocking is that when the method is inlined, the entire 
chain is processed again, every single time. There's no smaller 
intermediate representation being generated.

When inlining is partial, one of the methods it skips is 
"java.lang.Object::<init> (1 bytes)   failed to inline: inlining too 
deep".  Will this subsequently prevent escape analysis from eliminating 
an unnecessary allocation?

Inlining also fails sometimes with this message: "failed to inline: size 
 > DesiredMethodLimit". The long method chain should ideally collapse 
into a single machine instruction, but if the intermediate 
representation is too large, is HotSpot just giving up?


On 2024-10-29 05:43 PM, Jorn Vernee wrote:
> On 29-10-2024 20:22, Brian S O'Neill wrote:
>>
>>>
>>> If you have a better benchmark, or you can pin point the exact place 
>>> where the inlining failure occurs that would help immensely. You can 
>>> play around with CompileCommand and force inline for specific methods 
>>> of your application. (perhaps after verifying that such methods are 
>>> not inlined, which you can verify with -XX:+PrintInlining).
>>>
>>
>> How do I force inlining? I thought this was only possible the internal 
>> HotSpot annotation.
> 
> 
> See the output of 'java -XX:CompileCommand=help' (look at the output 
> before the standard help message). To force inlining of a method into 
> other compilation units you would use something like `- 
> XX:CompileCommand=inline,xyz.MyClass::myMethod`.
> 
> Jorn
> 



More information about the panama-dev mailing list