Split MappedMemorySegment out of the hierarchy
Quân Anh Mai
anhmdq at gmail.com
Tue Dec 6 17:03:56 UTC 2022
Hi,
What I mean is that to make MappedMemorySegment(Container) a separate
hierarchy that contains a data segment, other operations will be performed
through this.data apart from makeByteBuffer and asSlice which will be
separate from that of a MemorySegment (i.e. this.data.asSlice will return a
normal segment that acts similar to any other kind of memory, while
this.asSlice will return a MappedMemorySegment(Container). I believe this
situation can be seen as similar to an Arena which can allocate and
deallocate memory, which contains a scope which can be used to keep track
of the memory lifetime.
Thanks,
Quan Anh
On Wed, 7 Dec 2022 at 00:54, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:
> Hi,
> we have considered this approach - but it creates some asymmetries. For
> instance, the Spliterator method has to feature covariant return, etc.
>
> Also, if you have a subclass of memory segment, it means that cast would
> have to be inserted when interacting with downcall method handles.
>
> On balance, you get a marginal API simplification, but not clear to me
> that it's worth it.
>
> Another directon I've been thiking about lately is whether we need
> mapped segments at all - e.g. the semantics of load()/force() etc. is
> completely OS-specific (most of these methods are no-op on windows).
>
> While these methods used to make sense on MappedByteBuffer - are we sure
> they still make sense for memory segments? Wouldn't an advanced client
> using the FFM API prefer to use its own way to "force" mapped segments,
> using system-specific primitives?
>
> Maurizio
>
> On 06/12/2022 16:28, Quân Anh Mai wrote:
> > Hi Panama experts,
> >
> > The MemorySegment interface has several methods dedicated to
> > supporting MappedMemorySegment such as isMapped, load, etc. May I ask
> > if we can make it become a separate class that contains a
> > NativeMemorySegment instead, and make the dedicated methods members of
> > the encompassing class instead? I have taken a look at
> > MappedMemorySegment and it seems that the only other methods that
> > need to be mappedness-specific are asSlice and makeByteBuffer. And in
> > that case, we can make asSlice and makeByteBuffer also methods for the
> > encompassing class, too.
> >
> > This may make the interface clearer by not overloading MemorySegment
> > with methods that it is not really capable of, and also helps the JIT
> > to emit more optimised code for other operations with a more
> > restricted hierarchy.
> >
> > Thanks a lot for your reading and I really appreciate your responses.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20221207/a80f7a03/attachment.htm>
More information about the panama-dev
mailing list