Enable native access for modules not in the boot layer

Johannes Kuhn info at j-kuhn.de
Mon Jun 6 11:53:10 UTC 2022


In a short discussion with Jorn Vernee I asked how to enable native 
access for modules not present in the boot layer, and got this answer:

 > I don't think we have an API for doing that at the moment. But, I 
didn't really work on this part. If you have a small reproducer, please 
send it into panama-dev at openjdk.java.net

Reproducer: https://github.com/DasBrain/PanamaRuntimeModule

I sincerely believe that this is not an unreasonable requirement.
But we can argue over that :)

----

After looking a bit deeper into how native access is implemented, I also 
came up with a prototype:

https://github.com/openjdk/jdk/pull/9040/files

It adds a `Module.enableNativeAccess()` method. That method is itself 
restricted - and can be used to "delegate" a module's own native access 
to an other module, similar to how `Module.addOpens` works.

I also added `boolean Module.isNativeAccessEnabled()` - which was 
previously only visible through the shared secrets - but when exposing 
the enable part, then exposing the check part also makes sense IMHO.

----

I would be happy to hear your opinions and suggestions on that topic.
Things doesn't have to be implemented that way. It's just a suggestion 
(where I am sure that it does at least work _technically_).

- Johannes


More information about the panama-dev mailing list