RFR: 8295044: Implementation of Foreign Function and Memory API (Second Preview) [v22]

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Nov 15 15:38:49 UTC 2022


On Tue, 15 Nov 2022 15:22:07 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/foreign/Arena.java line 89:
>> 
>>> 87: 
>>> 88:     /**
>>> 89:      * Returns a native memory segment with the given size (in bytes) and alignment constraint (in bytes).
>> 
>> It is noted that the current documentation does not require a **new** native memory segment to be returned. Would it not be better with:
>> 
>> Creates a new native memory segment ...
>> 
>> The new shared segment might share actual backing memory though.
>
> My feeling is that being overly precise over identity might backfire. It is not important whether the segment is a new instance or not. But there is, perhaps, another invariant that is more semantically relevant: e.g. the returned segments (whether new or not, we don't care) should be backed by "disjoint" regions of memory. That is, if the method returns a segment with address `0` and size `100`, calling the method again cannot return a segment whose address is `50` and size is `100`. In principle, the segment allocator interface allows for this (see `SegmentAllocator::prefixAllocator`) - but for an arena, a behavior such as this would be indesirable, IMHO.

I will add:


Furthermore, for any two segments S1, S2 returned by this method, the following invariant must hold:

 S1.overlappingSlice(S2).isEmpty() == true
 ```

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

PR: https://git.openjdk.org/jdk/pull/10872


More information about the hotspot-dev mailing list