[foreign-memaccess+abi] RFR: 8310659: The jar tool should support allowing access to restricted methods from executable jars [v4]

Jorn Vernee jvernee at openjdk.org
Tue Jun 27 20:00:07 UTC 2023


On Tue, 27 Jun 2023 19:54:14 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> Add `Enable-Native-Access` jar attribute. `Enable-Native-Access: true` is equal to passing `--enable-native-access=ALL-UNNAMED` on the command line when running an executable jar (using `-jar <jar file>`).
>> 
>> Question: right now I've implemented this to check if the attribute value is exactly `true`, otherwise it is ignored. Should we only allow `true` or `false`, and throw an error on other values?
>> 
>> Reviewer note: I've factored some of a test code for analyzing output to `TestEnableNativeAccessBase` for the enable native access tests.
>
> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
> 
>   error when flag is set to false

src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java line 776:

> 774:     private static final boolean HAS_ENABLE_NATIVE_ACCESS_FLAG;
> 775:     private static final Set<String> NATIVE_ACCESS_MODULES;
> 776:     private static boolean ENABLE_NATIVE_ACCESS_SET_IN_MANIFEST = false;

We initialize this class before the manifest is read, so I made this flag mutable.

test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccess.java line 33:

> 31:  * @build TestEnableNativeAccess
> 32:  *        panama_module/*
> 33:  *        org.openjdk.foreigntest.unnamed.PanamaMainUnnamedModule

Had to move these classes to a different package, since when we put the same package on the class and module path, the package in the module hides the one on the class path.

test/jdk/java/foreign/enablenativeaccess/panama_module/org/openjdk/foreigntest/PanamaMain.java line 2:

> 1: /*
> 2:  * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.

I noticed this file was unused, so I've remove it. It is superseded by `PanamaMainDirect`, but I guess we got both files through a merge somehow.

test/jdk/java/foreign/enablenativeaccess/panama_module/org/openjdk/foreigntest/libLinkerInvokerModule.cpp line 60:

> 58:         if (context.exception != nullptr) {
> 59:             env->Throw(context.exception); // transfer exception to this thread
> 60:         }

Since we invoke the target method on a different thread, the exception wasn't being propagated properly, and as a result, the exit code was just 0, even when we had an error occur.

I've added the exception transfer here.

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

PR Review Comment: https://git.openjdk.org/panama-foreign/pull/843#discussion_r1244274419
PR Review Comment: https://git.openjdk.org/panama-foreign/pull/843#discussion_r1244275674
PR Review Comment: https://git.openjdk.org/panama-foreign/pull/843#discussion_r1244277588
PR Review Comment: https://git.openjdk.org/panama-foreign/pull/843#discussion_r1244276583


More information about the panama-dev mailing list