RFR: 8346657: Improve out of bounds exception messages for MemorySegments [v9]
Igor Rudenko
duke at openjdk.org
Tue Nov 18 15:10:12 UTC 2025
On Tue, 18 Nov 2025 12:26:41 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> 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?
@mcimadamore
I measured some benchmarks
**master**:
Benchmark (asTypeCompiled) (polluteProfile) Mode Cnt Score Error Units
LoopOverNonConstant.BB_get N/A N/A avgt 30 0.893 ± 0.004 ns/op
LoopOverNonConstant.BB_loop N/A N/A avgt 30 0.243 ± 0.002 ms/op
LoopOverNonConstant.segment_get N/A N/A avgt 30 0.997 ± 0.006 ns/op
LoopOverNonConstant.segment_loop N/A N/A avgt 30 0.236 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_instance N/A N/A avgt 30 0.237 ± 0.007 ms/op
LoopOverNonConstant.segment_loop_instance_index N/A N/A avgt 30 0.233 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_instance_unaligned N/A N/A avgt 30 0.231 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_nested N/A N/A avgt 30 0.232 ± 0.002 ms/op
LoopOverNonConstant.segment_loop_nested_unaligned N/A N/A avgt 30 0.231 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_readonly N/A N/A avgt 30 0.229 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_slice N/A N/A avgt 30 0.230 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_unaligned N/A N/A avgt 30 0.229 ± 0.001 ms/op
LoopOverNonConstant.unsafe_get N/A N/A avgt 30 0.452 ± 0.007 ns/op
LoopOverNonConstant.unsafe_loop N/A N/A avgt 30 0.230 ± 0.002 ms/op
**1095cf6**:
Benchmark (asTypeCompiled) (polluteProfile) Mode Cnt Score Error Units
LoopOverNonConstant.BB_get N/A N/A avgt 30 0.802 ± 0.007 ns/op
LoopOverNonConstant.BB_loop N/A N/A avgt 30 0.223 ± 0.001 ms/op
LoopOverNonConstant.segment_get N/A N/A avgt 30 0.932 ± 0.007 ns/op
LoopOverNonConstant.segment_loop N/A N/A avgt 30 0.226 ± 0.002 ms/op
LoopOverNonConstant.segment_loop_instance N/A N/A avgt 30 0.226 ± 0.002 ms/op
LoopOverNonConstant.segment_loop_instance_index N/A N/A avgt 30 0.228 ± 0.004 ms/op
LoopOverNonConstant.segment_loop_instance_unaligned N/A N/A avgt 30 0.226 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_nested N/A N/A avgt 30 0.224 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_nested_unaligned N/A N/A avgt 30 0.223 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_readonly N/A N/A avgt 30 0.225 ± 0.001 ms/op
LoopOverNonConstant.segment_loop_slice N/A N/A avgt 30 0.226 ± 0.002 ms/op
LoopOverNonConstant.segment_loop_unaligned N/A N/A avgt 30 0.224 ± 0.001 ms/op
LoopOverNonConstant.unsafe_get N/A N/A avgt 30 0.434 ± 0.007 ns/op
LoopOverNonConstant.unsafe_loop N/A N/A avgt 30 0.223 ± 0.001 ms/op
<img width="1670" height="1322" alt="Screenshot 2025-11-18 at 17 03 32" src="https://github.com/user-attachments/assets/9f117a08-0e1d-4858-960e-36b19142ae92" />
-------------
PR Comment: https://git.openjdk.org/jdk/pull/28124#issuecomment-3548049574
More information about the core-libs-dev
mailing list