RFR: 8321786: SegmentAllocator:allocateFrom(ValueLayout, MemorySegment,ValueLayout,long,long) spec mismatch in exception scenario

Per Minborg pminborg at openjdk.org
Tue Dec 12 11:48:32 UTC 2023


On Tue, 12 Dec 2023 11:05:44 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This PR proposes to change the specification for some methods that take `long` offsets so that they will throw an `IllegalArgumentException` rather than an `IndexOutOfBoundsException` for negative values.
>> 
>> The PR also proposes to fix a bug where the allocation size would overflow and the specified exception was not thrown.
>
> src/java.base/share/classes/java/lang/foreign/SegmentAllocator.java line 737:
> 
>> 735:     private MemorySegment allocateNoInit(MemoryLayout layout, long size) {
>> 736:         long byteSize;
>> 737:         try {
> 
> I don't think we want this. While it is more correct, that would negatively affect performance. If there's an overflow, let it go negative, it will be caught anyway

True. But we will get the wrong type of exception.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17079#discussion_r1423876941


More information about the core-libs-dev mailing list