Memory Mapped Segment with offsets into the underlying file

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Sep 10 20:23:26 UTC 2020


On 10/09/2020 21:20, Uwe Schindler wrote:
> Cool. Will try that out! Would it work the same way with mmapped files?
Yes, works for every segment kind.
>
> Do I need to compile on my own or do you have a prebuilt binary?
You will have to build I'm afraid - we're working on a new EA binary, 
but will take few weeks.
>
> Where's the VM patch, I'm interested to see how it's done.

All the explanation is here:

https://git.openjdk.java.net/panama-foreign/pull/304

Thanks
Maurizio

>
> Uwe
>
> Am September 10, 2020 8:12:12 PM UTC schrieb Maurizio Cimadamore 
> <maurizio.cimadamore at oracle.com>:
>
>     Sorry for resurrecting this old thread.
>
>     We have just pushed a patch which enables safe support for shared memory
>     segments.
>
>     In order to remove ownership from a segment you have to call the
>     `withOwnerThread(null)` method - e.g.
>
>     MemorySegment shared =
>     MemorySegment.allocateNative(100).withOwnerThread(null);
>
>     This segment will be accessible from any thread, and also closeable from
>     any thread. Some VM magic prevents hard crashes - but accessing threads
>     which attempt to access the segment in a racy way while it's being
>     closed might fail with an IllegalStateException.
>
>     It would be nice if you could give this a try, and let us know how it
>     works for your use case.
>
>     Cheers
>     Maurizio
>
>     On 02/07/2020 00:49, Maurizio Cimadamore wrote:
>
>         On 01/07/2020 23:44, Johannes Lichtenberger wrote:
>
>             The only thing, which is missing right now might be
>             sharing a MemorySegment between threads, whereas I'm
>             making sure that only ever one thread reads or writes (but
>             that's something where I have to wait for Java 15 or even
>             later I guess). A basic operation SirixDB is offering is a
>             timer based auto-commit with the ScheduledExecutorService,
>             which commits in another thread than the main parent thread. 
>
>         This is at the top of our list of things to work on see [1]
>         for some background. The trick is to find a way to have shared
>         segment which work at speed, and retain some form of
>         deterministic deallocation. In the meantime though, with the
>         Java 15 API you can workaround the limitation by using the
>         MemorySegment::ofNativeRestricted factory - which allows you
>         to set a "null" owner thread (so it's effectively a shared
>         segment, but an unsafe one, so if you manipulate it
>         incorrectly you can crash the VM). Maurizio [1] -
>         https://mail.openjdk.java.net/pipermail/panama-dev/2020-May/009004.html
>
>


More information about the panama-dev mailing list