RFR: 8317611: Add a tool like jdeprscan to find usage of restricted methods [v5]
Jorn Vernee
jvernee at openjdk.org
Thu Jun 20 19:40:43 UTC 2024
On Thu, 20 Jun 2024 12:11:25 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> This PR adds a new JDK tool, called `jnativescan`, that can be used to find code that accesses native functionality. Currently this includes `native` method declarations, and methods marked with `@Restricted`.
>>
>> The tool accepts a list of class path and module path entries through `--class-path` and `--module-path`, and a set of root modules through `--add-modules`, as well as an optional target release with `--release`.
>>
>> The default mode is for the tool to report all uses of `@Restricted` methods, and `native` method declaration in a tree-like structure:
>>
>>
>> app.jar (ALL-UNNAMED):
>> main.Main:
>> main.Main::main(String[])void references restricted methods:
>> java.lang.foreign.MemorySegment::reinterpret(long)MemorySegment
>> main.Main::m()void is a native method declaration
>>
>>
>> The `--print-native-access` option can be used print out all the module names of modules doing native access in a comma separated list. For class path code, this will print out `ALL-UNNAMED`.
>>
>> Testing:
>> - `langtools_jnativescan` tests.
>> - Running the tool over jextract's libclang bindings, which use the FFM API, and thus has a lot of references to `@Restricted` methods.
>> - tier 1-3
>
> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
>
> update man page header to be consisten with the others
I've massaged the parsing code to where the help message now looks like this:
...
Option Description
------ -----------
-?, -h, --help help
--add-modules <String> List of root modules to scan
--class-path <Path> The class path as used at runtime
--module-path <Path> The module path as used at runtime
--print-native-access print a comma separated list of modules that may
perform native access operations. ALL-UNNAMED is used
to indicate unnamed modules.
--release <Version> The runtime version that will run the application
--version Print version information and exit
I'm not sure if joptsimple has a way to display the option arguments like `<Path>[,<Path>]` to indicate multiple options (at least I couldn't find it immediately).
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19774#issuecomment-2181397654
More information about the build-dev
mailing list