RFR: 8333886: Explicitly specify that asSlice and reinterpret return a memory segment backed by the same region of memory.

Per Minborg pminborg at openjdk.org
Tue Jun 11 09:21:13 UTC 2024


On Mon, 10 Jun 2024 15:45:07 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> This PR proposes to explicitly state that returned segments form the `asSlice` and `reinterpret` method share memory regions with `this` memory segment.
> 
> Note: The term "subset"  means a true subset or the same set.

> In my opinion, any 'sub' terminology is misleading since, as you pointed out, one can (and often will) `reinterpret` to a _larger_ size. Wouldn't something like, "The returned memory segment is backed by the same region of memory that backs this memory segment", be sufficiently accurate? Could even append, "No memory will be allocated or deallocated", to really hammer the point home.
> 
> Using 'subset' for `asSlice` makes sense. Though possibly unnecessary.

If a segment is reinterpreted to be *larger* than `this` segment, then the extra memory is not a part of `this` segment's backing part. So, in this case the total memory is a subset (but not a _proper subset_ but rather the same) of `this` backing memory _plus_ some additional memory.

If a segment is reinterpreted to be *smaller* than `this` segment, then the reduced memory is a proper subset.

So, strictly the proposed text is correct. The proposition "The returned memory segment is backed by the same region of memory that backs this memory segment" appears to be incorrect if a _smaller_ chunk is carved out?

Maybe something more neutral like "The returned memory segment shares a region of backing memory with this segment"?

Adding text similar to "No memory will be allocated or deallocated" sounds like a good idea.

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

PR Comment: https://git.openjdk.org/jdk/pull/19633#issuecomment-2160213978


More information about the core-libs-dev mailing list