Skip to content

8360555: Archive all unnamed modules in CDS full module graph #26082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iklam
Copy link
Member

@iklam iklam commented Jul 2, 2025

The CDS full module graph is supposed to contain a snapshot of the boot layer, which has 3 unnamed modules for the boot, platform and system class loaders. Each unnamed module is represented by a java.lang.Module Java object and a ModuleEntry C++ object.

Currently, we archive only the java.lang.Module for the platform and system loaders. The other 4 objects are dynamically created in the production run while executing Java bytecodes during VM bootstrap.

With this PR, we archive all of the above 6 objects when CDSConfig::is_dumping_full_module_graph() is true.

This is required for JDK-8350550, as we need the java.lang.Module object for archived classes in the unnamed module of the boot loader prior to executing any Java code.

We also archive the ModuleEntry objects for the 3 unnamed modules for uniformity, as these objects are already archived for named modules.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Warnings

 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/javax/swing/beaninfo/images/JAppletColor16.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/javax/swing/beaninfo/images/JAppletColor32.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/javax/swing/beaninfo/images/JAppletMono16.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/javax/swing/beaninfo/images/JAppletMono32.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/javax/swing/doc-files/JRootPane-1.gif)

Issue

  • JDK-8360555: Archive all unnamed modules in CDS full module graph (Sub-task - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26082/head:pull/26082
$ git checkout pull/26082

Update a local copy of the PR:
$ git checkout pull/26082
$ git pull https://git.openjdk.org/jdk.git pull/26082/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26082

View PR using the GUI difftool:
$ git pr show -t 26082

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26082.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 2, 2025

👋 Welcome back iklam! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jul 2, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 2, 2025
@openjdk
Copy link

openjdk bot commented Jul 2, 2025

@iklam The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

mlbridge bot commented Jul 2, 2025

Webrevs

#if INCLUDE_CDS_JAVA_HEAP
if (CDSConfig::is_using_full_module_graph()) {
precond(unnamed_module == ClassLoaderDataShared::archived_boot_unnamed_module());
unnamed_module->restore_archived_oops(boot_loader_data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're restoring the module oop from the archive, what is the module oop passed into this that the rest of the code is using?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're storing the unnamed module oop in the archive should this method not be called? If it is, what are you saving by archiving the unnamed module?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callstack is:

jdk.internal.loader.BootLoader.setBootLoaderUnnamedModule0(java.base@26-internal/Native Method)
jdk.internal.loader.BootLoader.<clinit>(java.base@26-internal/BootLoader.java:71)
jdk.internal.module.ModuleBootstrap.boot(java.base@26-internal/ModuleBootstrap.java:162)
java.lang.System.initPhase2(java.base@26-internal/System.java:1932)

Both the Java code and the native code have a handle to this unnamed module oop. The precond checks that they indeed are pointing the same oop.

Also, even though the oop is archived, we still need to set up some native states inside the unnamed_module->restore_archived_oops(boot_loader_data) call. E.g., set up the OopHandle that binds the oop to the ModuleEntry.


what are you saving by archiving the unnamed module?

It's for JDK-8350550) -- I want to be able to reference the unnamed module before executing any Java code, so that archived classes can be loaded at the very beginning of vmClasses::resolve_all(). See my draft PR: #26375


Currently, we still execute a lot of Java code when setting up the archived module graph (inside ModuleBootstrap.boot(). I am working on a way to enable the archived module graph without executing any Java code (which will be a few REFs after JDK-8350550), so this call will eventually be gone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. At this point, you're just checking that what you've referred to before loading the unnamed module matches what you've previously saved in the shared archive. Did I get that right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's checking that the Java and C++ code both found the same archived unnamed module.

UNNAMED_MODULE = archivedClassLoaders.unnamedModuleForBootLoader();
} else {
UNNAMED_MODULE = jla.defineUnnamedModule(null);
}
jla.addEnableNativeAccess(UNNAMED_MODULE);
setBootLoaderUnnamedModule0(UNNAMED_MODULE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's being called. Should this be called?

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good.

#if INCLUDE_CDS_JAVA_HEAP
if (CDSConfig::is_using_full_module_graph()) {
precond(unnamed_module == ClassLoaderDataShared::archived_boot_unnamed_module());
unnamed_module->restore_archived_oops(boot_loader_data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. At this point, you're just checking that what you've referred to before loading the unnamed module matches what you've previously saved in the shared archive. Did I get that right?

@openjdk
Copy link

openjdk bot commented Jul 21, 2025

@iklam this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout 8360555-archive-all-unnamed-modules
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Jul 21, 2025
Copy link
Contributor

@iwanowww iwanowww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs [email protected] hotspot-runtime [email protected] merge-conflict Pull request has merge conflict with target branch rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants