Re: RFR: 8317611: Add a tool like jdeprscan to find usage of restricted methods [v8]

2024-06-21 Thread Jorn Vernee
On Thu, 20 Jun 2024 17:25:33 GMT, Alan Bateman  wrote:

>> Something like that yes
>
> An altermative is to use ResolvedModule::reference to get a ModuleReference, 
> then use its open method to open the contents of the module to get a 
> ModuleReader. That will give you a stream over the names of all resources in 
> the module. It will work for all exploded and packaged modules.

I took a look at this. I had to refactor a bit and introduce an intermediate 
abstraction (`ClassFileSource`) to abstract over classes loaded from a 
`JarFile` (for the class path) and a `ModuleReader` (for module path). At that 
point, it was also easy to add a third option for directories of class files on 
that class path, so I've done that as well.

See: 
https://github.com/openjdk/jdk/pull/19774/commits/a046f6fe9465feda63609dd50014338ca218923f

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19774#discussion_r1649434411


Re: RFR: 8317611: Add a tool like jdeprscan to find usage of restricted methods [v8]

2024-06-21 Thread Jorn Vernee
> 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 three additional 
commits since the last revision:

 - Add support for module directories + class path directories
 - sort output for easier diffs
 - Jan comments

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/19774/files
  - new: https://git.openjdk.org/jdk/pull/19774/files/a4723494..a046f6fe

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=19774=07
 - incr: https://webrevs.openjdk.org/?repo=jdk=19774=06-07

  Stats: 275 lines in 8 files changed: 156 ins; 58 del; 61 mod
  Patch: https://git.openjdk.org/jdk/pull/19774.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19774/head:pull/19774

PR: https://git.openjdk.org/jdk/pull/19774