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

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Nov 18 12:20:29 UTC 2025


On Tue, 18 Nov 2025 09:38:44 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:
> 
>   improvements according to reviewer comments

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

> 411:     private void checkBounds(long offset, long length, BoundPolicy policy) {
> 412:         if (length > 0) {
> 413:             Preconditions.checkIndex(offset, this.length - length + 1, new BoundsCheckHandler(this, policy));

This is a very very hot path. Allocating here is gonna have negative effect, especially when this code cannot be inlined (in which case the allocation can't be scalar replaced).

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

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


More information about the core-libs-dev mailing list