On Tue, 18 Nov 2025 09:38:44 GMT, Igor Rudenko <[email protected]> wrote:

>> Logic for creating IndexOutOfBoundsException in MemorySegment is reworked:
>> - separate logic of checking bounds and constructing exception messages for 
>> both `access` and `slice` cases 
>> - idea presented in 
>> [JDK-8288534](https://bugs.openjdk.org/browse/JDK-8288534) slightly reworked 
>> with preservation of the original approach
>
> Igor Rudenko has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   improvements according to reviewer comments

The fundamental issue here is that `checkIndex` takes a bi-function for the 
exception generation. This forces client to resort to _instance_ methods if 
they want to embed more of their state description into the generated message. 
And this requires allocation -- which fundamentally is against the performance 
goals of the check bound routines in AbstractMemorySegmentImpl.

It would be better if Preconditions had more primitive, non-throwing variants 
which just returned true/false. Then we could easily implement whatever logic 
we wanted on top. Maybe we should look there first, and then come back to 
improve messages in the FFM API?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/28124#issuecomment-3547403406

Reply via email to