Question about memorySegment with safepoint checks?
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Oct 9 16:56:12 UTC 2024
Hello,
I'm not aware of anything specifically related to safepoints and long
loops, but I'm cc'ing Roland just in case.
My understanding of the problem is that, when we have a loop with a long
induction variable, C2 really emits two nested loops, as it wants to go
back to a place where the inner loop works with an int induction variable.
This double-loop can sometimes cause performance regressions, especially
for short-loops. I believe Roland is working on a fix to specialize code
when the limit can be speculated to be "small" enough.
On the general topic of safepoints, my udnerstanding is that we'd like
long loops to have safepoints every now and then. Even intrinsics such
as System::arrayCopy have, over time, changed to insert some safepoint,
not to stall GC completely when running a long bulk operation.
But if you have evidence and/or benchmark where you think long loops are
generating too many safepoints, and that developers are falling back to
use ints as a result, please let us know. I'm not aware of such issues
but somebody else might.
Maurizio
On 09/10/2024 17:18, xichen liu wrote:
> I would like to raise a question regarding the use
> of `MemorySegment` for pointer traversal in memory. I have noticed
> that when using `long` as a loop condition variable for traversal, the
> JVM inserts safepoint checks, which leads to an overall performance
> decrease. As a result, it seems that developers are advised to
> manually convert the `long` variable to an `int` type to avoid this issue.
>
> While I am not an expert in this area, my own testing in GraalVM shows
> that it is capable of achieving similar performance when
> using `long` in loops with fewer iterations, comparable to
> using `int`, whereas C2 does not seem to handle this as efficiently.
>
> I recall that there has been some previous discussion on this issue,
> and I would like to inquire about the current status of this matter.
> Could you please provide any updates or insights on how this has been
> addressed?
>
> Best regards.
More information about the panama-dev
mailing list