<div dir="ltr">I learned more by watching the devoxx video: <a href="https://www.youtube.com/watch?v=xFb_LcapbXw&ab_channel=Devoxx">https://www.youtube.com/watch?v=xFb_LcapbXw&ab_channel=Devoxx</a>. I got it now, it's not the safepoints that are causing the problem, it's the nested loop issue.

Thanks for your explanation!<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.com</a>> 于2024年10月10日周四 00:56写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
I'm not aware of anything specifically related to safepoints and long <br>
loops, but I'm cc'ing Roland just in case.<br>
<br>
My understanding of the problem is that, when we have a loop with a long <br>
induction variable, C2 really emits two nested loops, as it wants to go <br>
back to a place where the inner loop works with an int induction variable.<br>
<br>
This double-loop can sometimes cause performance regressions, especially <br>
for short-loops. I believe Roland is working on a fix to specialize code <br>
when the limit can be speculated to be "small" enough.<br>
<br>
On the general topic of safepoints, my udnerstanding is that we'd like <br>
long loops to have safepoints every now and then. Even intrinsics such <br>
as System::arrayCopy have, over time, changed to insert some safepoint, <br>
not to stall GC completely when running a long bulk operation.<br>
<br>
But if you have evidence and/or benchmark where you think long loops are <br>
generating too many safepoints, and that developers are falling back to <br>
use ints as a result, please let us know. I'm not aware of such issues <br>
but somebody else might.<br>
<br>
Maurizio<br>
<br>
<br>
On 09/10/2024 17:18, xichen liu wrote:<br>
> I would like to raise a question regarding the use <br>
> of `MemorySegment` for pointer traversal in memory. I have noticed <br>
> that when using `long` as a loop condition variable for traversal, the <br>
> JVM inserts safepoint checks, which leads to an overall performance <br>
> decrease. As a result, it seems that developers are advised to <br>
> manually convert the `long` variable to an `int` type to avoid this issue.<br>
><br>
> While I am not an expert in this area, my own testing in GraalVM shows <br>
> that it is capable of achieving similar performance when <br>
> using `long` in loops with fewer iterations, comparable to <br>
> using `int`, whereas C2 does not seem to handle this as efficiently.<br>
><br>
> I recall that there has been some previous discussion on this issue, <br>
> and I would like to inquire about the current status of this matter. <br>
> Could you please provide any updates or insights on how this has been <br>
> addressed?<br>
><br>
> Best regards.<br>
</blockquote></div>