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

Jorn Vernee jvernee at openjdk.org
Wed Sep 21 14:30:59 UTC 2022


On Wed, 21 Sep 2022 14:16:32 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> That's a thought that occurred to me as well. E.g. declare the variable w/o `volatile`, but then use either Unsafe, or VarHandle to access the variable in `volatile` mode when required. That said, note that this will not get rid of all the synchronization needs: we would still need to synchronize on a module in the native access check to make sure that we issue at most one warning. But perhaps we can have a private lock just for that.
>
> I think it would be possible to emit only one warning by using a compare and exchange.
> 
> 
> boolean shouldEnable = !ModuleBootstrap.hasEnableNativeAccessFlag();
> isNativeAccessEnabled = Unsafe.compareAndExchangeBoolean(target, OFFSET, false, shouldEnable);
> // check again with the safely read flag
> if (isNativeAccessEnabled) {
>     // another thread beat us to it - nothing to do
>     return;
> } else if (!shouldEnable) {
>     throw new IllegalCallerException("Illegal native access from: " + this);
> } else {
>     // If we get here, compare and exchange above has set enableNativeAccess to true.
>     // emit watning
> }

To be clear. The current implementation looks correct to me as well. So I'm fine with going ahead as is.

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

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


More information about the panama-dev mailing list