RFR: 8346657: Improve out of bounds exception messages for MemorySegments [v6]

Chen Liang liach at openjdk.org
Sat Nov 15 03:26:09 UTC 2025


On Fri, 14 Nov 2025 22:28:24 GMT, Igor Rudenko <duke at openjdk.org> 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:
> 
>   rework

src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java line 402:

> 400:     @ForceInline
> 401:     void checkSliceBounds(long offset, long length) {
> 402:         Preconditions.checkFromIndexSize(offset, length, this.length, this::sliceOutOfBoundException);

Is this performance-wise neutral? This is on a hot path and captures a lambda every time, need to verify compiler can eliminate this, which I doubt.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28124#discussion_r2529500502


More information about the core-libs-dev mailing list