Thread safety check of MemorySegment

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Jul 21 23:18:46 UTC 2020


On 21/07/2020 22:51, NekoCaffeine wrote:
>> https://gist.github.com/mcimadamore/128ee904157bb6c729a10596e69edffd
> This is a great example.
>
>> The *right* solution from an API perspective is to find a way to disable confinement in a way that works
> I very much agree with this point, which is exactly what I want to express.
>
> So from a design rather than implementation perspective, should I expect a new way to disable thread checking or should I use CustomMappedSegment?

So the crux of the issue here is that there's no Runnable that will 
unmap a given mapped address. But such a Runnable can be implemented in 
several ways:

* with plain JNI
* using the ForeignLinker API (although that is not part of JDK 15 - but 
is available in the Panama repo)
* going all in and re-implement mapped segment (similar to what I've 
done with CustomMappedSegment)

I think from an API perspective, if we manage to solve the confinement 
problem, then I expect the memory segment API will have an extra method 
to either turn a confined segment into an unconfined one, or vice-versa. 
So you will be able to just create your mapped segment using mapFromPath 
and then just 'share' it (and make it unconfined).

Hope this helps.

Maurizio

>
> Thanks,
>
> NekoCaffeine


More information about the panama-dev mailing list