Unsafe vs MemorySegments / Bounds checking...

Mike Hearn mike at plan99.net
Thu Oct 31 09:45:04 UTC 2024


>
> Hence my suggestion to go back a little, and see what we can do to speed
> up access for a segment created with:
>
> MemorySegment.NULL.reinterpret(Long.MAX_VALUE)
>
> (which, as Ron correctly points out, might not mean *exactly as fast as
> Unsafe*)
>
If a sign check is genuinely causing a meaningful slow down you could
potentially re-spec such a NULL->MAX memory segment to not do it. In that
case a negative number would be treated as unsigned. Alternatively, the
sign bit could be masked out of the address which should be faster than a
compare and branch. Given that such a memory segment is already requesting
that safety checks be disabled, maybe the check for negative addresses
isn't that important as there are already so many ways to segfault the VM
with such a segment.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20241031/51363780/attachment.htm>


More information about the panama-dev mailing list