[foreign-memaccess+abi] RFR: 8296417: Make memory session a pure lifetime abstraction [v3]
Jorn Vernee
jvernee at openjdk.org
Fri Nov 4 22:34:55 UTC 2022
On Fri, 4 Nov 2022 22:25:05 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> test/jdk/java/foreign/TestSegmentAllocators.java line 90:
>>
>>> 88: } catch (IndexOutOfBoundsException | IllegalStateException ex) {
>>> 89: //failure is expected if bound
>>> 90: assertTrue(isBound);
>>
>> Not sure I get this `catch`. AFAICS only a slicing allocator is bound, which should result in `NULL` being returned, not an exception, right?
>
> You are correct in the sense that slicing allocator returns NULL when it cannot allocate. However, if we allocate using e.g. `SegmentAllocator.allocate(ValueLayout.OfInt, int)` there will be issues because the returned segment has zero size and we will be trying to set a value on it. I think returning NULL here is perhaps too clever, we should just throw IOOBE on the allocate method - agree?
Ah, I see. But, returning `NULL` seems nice for composing with other allocators. I guess you'd need to override all the methods of SegmentAllocator in SlicingAllocator to forward the `NULL` returned by the base `allocate`.
If you go for throwing an exception, I suggest sticking with OOME though.
-------------
PR: https://git.openjdk.org/panama-foreign/pull/750
More information about the panama-dev
mailing list