RFR: 8319343: Improve CDS module graph support for --add-modules option

John R Rose jrose at openjdk.org
Wed Oct 16 23:21:11 UTC 2024


On Wed, 16 Oct 2024 22:46:40 GMT, Calvin Cheung <ccheung at openjdk.org> wrote:

> Summary of changes:
> 
> Before dumping info the archive, all the module names from `--add-modules` will be sorted and then concatenated into one string with comma as the separator between module names.
> 
> During runtime, same function will be used to obtain the string in the same format with sorted module names. The string will be compared with the one from the archive to determine if the same module names were specified during dump time.
> 
> ModuleBootstrap.java
>         The `addModulesFromRuntimeImage` method is added to check if the modules in `addModules` are from the runtime image. If any of the modules isn't in the runtime image, archiving will be disabled.
> 
> ArchivedModuleGraph.java
>        The constructor has an addition argument `Set addModules`
>        The `get` method also has an addition argument `Set addModules`. It returns the `archivedModuleGraph` only if both the `mainModule` and the `addModules` are the same as the input arguments.
> 
> Passed tiers 1 - 4 testing.

src/hotspot/share/classfile/modules.cpp line 697:

> 695:       st.print("%s%s", prefix, m);
> 696:       last_string = m;
> 697:       prefix = ",";

You use comma as the separator.  Folks will have various opinions, but I think you should use a character which is positively forbidden by the JVMS 4.2.3.  That says, basically, that any character is fine (in the classfile format) EXCEPT control characters.  The most visible control character is probably `'\n'` so I suggest using that instead of comma.  Your key-strings will look like groups of sorted lines, one module name per line.  That's plenty readable.

If you keep comma, nothing will break, unless some smart guy figures out how to cook up a classfile that has a module name in it with a comma inside, that looks like two other legitimate modules names separated by that comma.  Something odd could happen next.  Better to avoid it from the start by using a truly illegal module name character.

(If these were class names I'd be suggesting `';'` or `'.'` not `'\n'` because the rules for class names are different, in the JVMS.  Again, none of these issues come up with inputs which are compiled from normal Java sources, but they can appear with craftily crafted classfiles.)

https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.html#jvms-4.2.3

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21553#discussion_r1803902019


More information about the core-libs-dev mailing list