Skip to content

8382584: [lworld] Mandatory pre-loading still present in systemDictionary.cpp#2409

Open
caspernorrbin wants to merge 5 commits into
openjdk:lworldfrom
caspernorrbin:systemdict-nullrestricted-loading
Open

8382584: [lworld] Mandatory pre-loading still present in systemDictionary.cpp#2409
caspernorrbin wants to merge 5 commits into
openjdk:lworldfrom
caspernorrbin:systemdict-nullrestricted-loading

Conversation

@caspernorrbin
Copy link
Copy Markdown
Member

@caspernorrbin caspernorrbin commented May 7, 2026

Hi everyone,

This change removes the remaining mandatory preloading path for null-restricted instance fields when loading classes from CDS. JDK-8380053 already changed normal class loading so null-restricted field types are no longer loaded just because the field is null-restriced. Instead, the preloading is speculative and driven by the LoadableDescriptor attribute. The CDS path still had the older special case in SystemDictionary::preload_from_null_free_field, which could force loading of null-restricted field types.

This fix removes that CDS-only preload helper and routes non-static field signatures through the existing LoadableDescriptor path instead. This makes loading follow the same model as in ClassFileParser::fetch_field_classes() with speculative loading.

Testing:

  • Tier 1-3


Progress

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

Issue

  • JDK-8382584: [lworld] Mandatory pre-loading still present in systemDictionary.cpp (Bug - P2)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2409

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2409.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented May 7, 2026

👋 Welcome back cnorrbin! A progress list of the required criteria for merging this PR into lworld 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
Copy Markdown

openjdk Bot commented May 7, 2026

@caspernorrbin This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8382584: [lworld] Mandatory pre-loading still present in systemDictionary.cpp

Reviewed-by: coleenp

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 3 new commits pushed to the lworld branch:

  • 884d529: 8385344: [lworld] ProblemList tools/javac/platform/CanHandleClassFilesTest.java with --enable-preview
  • d7bb464: 8385301: [lworld] Remove serviceability/sa/TestJhsdbJstackMixedWithXComp.java from problem list
  • 71f4b08: 8385331: [lworld] adjust ValueComparisonTest.java again to work around JDK-8370769

Please see this link for an up-to-date comparison between the source branch of this pull request and the lworld branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@coleenp) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk Bot changed the title 8382584 8382584: [lworld] Mandatory pre-loading still present in systemDictionary.cpp May 7, 2026
@openjdk openjdk Bot added the rfr Pull request is ready for review label May 7, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented May 7, 2026

Webrevs

// A false return means that the class didn't load for other reasons than an exception.
bool check = preload_from_null_free_field(ik, class_loader, sig, field_index, CHECK_NULL);
if (!check) {
ik->set_shared_loading_failed();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we safely drop this failure marking?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's used for regular shared class loading so I don't think we can drop this shared_loading_failed marker.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Didn't realise that one was needed. I've re-added it, along with an edit to try_preload_from_loadable_descriptors so we can see if we failed or not. It now also has a new parameter that decides if failing means we call shared_loading_failed .

Copy link
Copy Markdown
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.

Looks good!

// A false return means that the class didn't load for other reasons than an exception.
bool check = preload_from_null_free_field(ik, class_loader, sig, field_index, CHECK_NULL);
if (!check) {
ik->set_shared_loading_failed();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's used for regular shared class loading so I don't think we can drop this shared_loading_failed marker.

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label May 8, 2026
@caspernorrbin
Copy link
Copy Markdown
Member Author

Following our offline discussions, I have now pushed a more robust version that:

  • Validates archived flat/null-restricted field metadata by resolving the field class at runtime and ensuring it matches the archived dependency.
  • Renames check_shared_class_super_type to check_shared_class_dependency, since the helper is now used for more than super classes/interfaces.
  • Adds a regression test that strips LoadableDescriptors and verifies the archived class is still rejected when its field dependency is substituted.

// Pre-load class referred to in non-static fields with archived inline field metadata. These fields
// must be checked against the resolved runtime class before the shared class can be used.
bool SystemDictionary::preload_from_required_inline_field(InstanceKlass* ik, Handle class_loader, Symbol* sig, int field_index, TRAPS) {
TempNewSymbol name = Signature::strip_envelope(sig);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This symbol is only used in logging, could it be possible to create it only when a message is logged?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have now wrapped the creation(s) inside if (is_log_enabled(...)).

} else if (Signature::has_envelope(sig)) {
// Pending exceptions are cleared so we can fail silently
} else {
// Pending exceptions are cleared so we can fail silently.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need this branch to attempt to preload? As long as we have the classes for the flattened fields, we should be OK. I would expect the other classes to be optional at this point

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This branch handles the speculative preloading from the LoadableDescriptors attribute for non-flat nullable fields, so it is not part of the required flat/null-restricted validation. I kept it to preserve the existing behavior where LoadableDescriptors can opportunistically load field classes. These loads are optional, failures are ignored and should not cause the shared loading to fail.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm fine with leaving this for now but we should think further about this after the merge to mainline. With CDS, these field classes for non-flat fields will be loaded during ik->link_class() so this may be additional complexity we can simplify


if (ik->has_inlined_fields()) {
for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
if (fs.access_flags().is_static()) continue;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@fparain As per our discussion about nullresticted fields, this will need to be updated as well to not skip static fields

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, does this mean NR static fields may have non-reference layout?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, this is related to ensuring that NR fields at dump time and NR fields at restore time are consistent

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To @DanHeidinga , yes, null-restricted static fields should not be skipped, but this PR would need JDK-8384756 to be fixed before being able to implement this change.

Copy link
Copy Markdown
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.

I guess I should un-review this since it's changed since my review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

5 participants