[foreign-memaccess+abi] RFR: 8293367: Enable native access for modules not in the boot layer

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Sep 20 13:53:37 UTC 2022


On Tue, 20 Sep 2022 13:40:00 GMT, Athijegannathan Sundararajan <sundar at openjdk.org> wrote:

> Adding a new API ModuleLayer.Controller.enableNativeAccess(Module).
> Reworked thread safety of enable native access flag reading and setting.

src/java.base/share/classes/java/lang/Module.java line 283:

> 281:     // flag for this module.
> 282:     private Module enableNativeAccessHolder() {
> 283:         return isNamed()? this : ALL_UNNAMED_MODULE;

Suggestion:

        return isNamed() ? this : ALL_UNNAMED_MODULE;

src/java.base/share/classes/java/lang/Module.java line 298:

> 296:                 // check again with the safely read flag
> 297:                 if (isNativeAccessEnabled) {
> 298:                    return;

I'd suggest adding a comment like "another thread beat us to it - nothing to do"

src/java.base/share/classes/java/lang/ModuleLayer.java line 317:

> 315:          * @return This controller
> 316:          *
> 317:          * @throws IllegalCallerException If the caller module doesn't have native access.

This is a restricted method, and needs the verbiage javadoc around restricted method. See e.g. `Linker::nativeLinker`. It should also probably specify what happens when called with no module in the call stack (possible if call comes from JNI). See `SymbolLookup::libraryLookup` for some hints. (note - the code already does the correct thing in Reflection.java)

src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java line 276:

> 274: 
> 275:     /**
> 276:      * Ensure that the given module has native access. If not, warn

We have a section on restricted methods in the foreign package javadoc. Perhaps we could link to that?

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

PR: https://git.openjdk.org/panama-foreign/pull/729


More information about the panama-dev mailing list