Skip to content
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

8265605: Cannot call BootLoader::loadClassOrNull before initPhase2 #3992

Conversation

@iklam
Copy link
Member

@iklam iklam commented May 12, 2021

This bug was discovered during the development of JDK-6824466: when CDS is enabled, if BootLoader::loadClassOrNull is called before initPhase2, it would trigger the initialization of the archived module graph in the wrong order. Because of unanticipated nesting of <clinit> methods, BootLoader::SERVICES_CATALOG becomes empty, causing future ServiceLoader operations to fail.

The fix has 2 parts:

  • BootLoader::loadClassOrNull no longer calls ClassLoaders::bootLoader(). This avoids triggering the archived module graph initialization. Instead, it makes a direct call to Classloader::findBootstrapClassOrNull(). We don't actually need a ClassLoader instance for this call, so I changed Classloader::findBootstrapClassOrNull() to be a static method.
  • The object returned by BootLoader::getServicesCatalog() is now maintained inside jdk.internal.loader.ClassLoaders. Although not strictly required for the fix, this simplifies the initialization of the archived module graph. It also makes the logic consistent for the 3 built-in loaders (boot/platform/app).

Testing: tiers1-4 in progress. I also verified that the bug reported by Mandy is no longer reproducible after I applied this patch on her branch.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8265605: Cannot call BootLoader::loadClassOrNull before initPhase2

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3992/head:pull/3992
$ git checkout pull/3992

Update a local copy of the PR:
$ git checkout pull/3992
$ git pull https://git.openjdk.java.net/jdk pull/3992/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3992

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3992.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented May 12, 2021

👋 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.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented May 12, 2021

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

  • core-libs
  • hotspot-runtime
  • security

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.

Loading

@iklam
Copy link
Member Author

@iklam iklam commented May 12, 2021

/label remove hotspot-runtime
/label remove security

Loading

@openjdk openjdk bot removed the hotspot-runtime label May 12, 2021
@openjdk
Copy link

@openjdk openjdk bot commented May 12, 2021

@iklam
The hotspot-runtime label was successfully removed.

Loading

@openjdk openjdk bot removed the security label May 12, 2021
@openjdk
Copy link

@openjdk openjdk bot commented May 12, 2021

@iklam
The security label was successfully removed.

Loading

@iklam iklam marked this pull request as ready for review May 12, 2021
@openjdk openjdk bot added the rfr label May 12, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented May 12, 2021

Loading

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Changes for CDS usually make the code harder to maintain but I think this patch is okay and improves a few areas. Just a few cleanups to keep the code consistent.

Loading

@@ -55,15 +55,20 @@ private ClassLoaders() { }
private static final PlatformClassLoader PLATFORM_LOADER;
private static final AppClassLoader APP_LOADER;

private static void setArchivedServicesCatalog(ArchivedClassLoaders archivedClassLoaders, ClassLoader loader) {
Copy link
Contributor

@AlanBateman AlanBateman May 12, 2021

Choose a reason for hiding this comment

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

I'd prefer if we could keep the code consistent if possible. In this case, the method declaration can be split over two lines to avoid one really one line in the file. Also can you add a one line // comment to be consistent with the other private methods.

Loading

@@ -83,6 +72,8 @@ private BootLoader() { }
private static final NativeLibraries NATIVE_LIBS
= NativeLibraries.jniNativeLibraries(null);

private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
Copy link
Contributor

@AlanBateman AlanBateman May 12, 2021

Choose a reason for hiding this comment

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

It be nicer if you could move this to the top to be consistent with the other files.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented May 12, 2021

@iklam 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:

8265605: Cannot call BootLoader::loadClassOrNull before initPhase2

Reviewed-by: alanb, mchung

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

Loading

@openjdk openjdk bot added the ready label May 12, 2021
Copy link
Member

@mlchung mlchung left a comment

Thanks for fixing this. This is also an improvement in how service catalogs are loaded from the CDS archive.

Loading

@iklam
Copy link
Member Author

@iklam iklam commented May 12, 2021

Thanks alan and mandy for you review. I've made the changes suggested by Alan.

Loading

@@ -55,15 +55,23 @@ private ClassLoaders() { }
private static final PlatformClassLoader PLATFORM_LOADER;
private static final AppClassLoader APP_LOADER;

// Sets the ServicesCatalog for the specified loader using archived objects.
private static void setArchivedServicesCatalog(
ArchivedClassLoaders archivedClassLoaders, ClassLoader loader)
Copy link
Contributor

@AlanBateman AlanBateman May 12, 2021

Choose a reason for hiding this comment

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

Thanks for the update. The formatting on L60 is messed now, can't the ArchivedClassLoaders go on the previous line? I don't have any other comments, it's worked out well.

Loading

Copy link
Member Author

@iklam iklam May 12, 2021

Choose a reason for hiding this comment

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

How about the latest version (4cd981c)? I removed the archivedClassLoaders argument; this also makes the callers simpler.

Loading

Copy link
Member

@mlchung mlchung May 12, 2021

Choose a reason for hiding this comment

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

Looks good to me.

Loading

Copy link
Contributor

@AlanBateman AlanBateman May 13, 2021

Choose a reason for hiding this comment

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

This makes it simpler and much nicer - thank you!

Loading

@iklam
Copy link
Member Author

@iklam iklam commented May 14, 2021

Thanks @AlanBateman and @mlchung for the review.
/integrate

Loading

@openjdk openjdk bot closed this May 14, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels May 14, 2021
@openjdk
Copy link

@openjdk openjdk bot commented May 14, 2021

@iklam Pushed as commit 1e0ecd6.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Loading

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