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

8291840: Avoid JavaCalls for setting up _java_system_loader and _java_platform_loader #9734

Conversation

calvinccheung
Copy link
Member

@calvinccheung calvinccheung commented Aug 3, 2022

Please review this small optimization for setting up the _java_system_loader and _java_platform_loader.

I saw startup perf improvements with HelloWorld on linux-x64 like the following:

instr delta =      -102248    -0.1226%
time  delta =       -0.125 ms -0.3507%

Passed tiers 1,2,3 testing.


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

Issue

  • JDK-8291840: Avoid JavaCalls for setting up _java_system_loader and _java_platform_loader

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9734

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

Using diff file

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

@calvinccheung
Copy link
Member Author

/label add hotspot-runtime

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 3, 2022

👋 Welcome back ccheung! 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 openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Aug 3, 2022
@openjdk
Copy link

openjdk bot commented Aug 3, 2022

@calvinccheung
The hotspot-runtime label was successfully added.

@calvinccheung calvinccheung marked this pull request as ready for review August 3, 2022 19:20
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 3, 2022
@mlbridge
Copy link

mlbridge bot commented Aug 3, 2022

Webrevs

ClassLoaderDataShared::restore_java_platform_loader_from_archive(platform_loader_data);

ClassLoaderData* system_loader_data = SystemDictionary::register_loader(h_system_loader);
SystemDictionary::set_system_loader(system_loader_data);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should add an assert here:

// system_loader_data here is always an instance of jdk.internal.loader.ClassLoader$AppClassLoader.
// However, if -Djava.system.class.loader=xxx is specified, java_platform_loader() would
// be an instance of a user-defined class, so make sure this never happens.
assert(Arguments::get_property("java.system.class.loader") == NULL,
         "archived full module should have been disabled");

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

vmSymbols::void_classloader_signature(),
CHECK);
_java_system_loader = OopHandle(Universe::vm_global(), result.get_oop());
}
Copy link
Member

Choose a reason for hiding this comment

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

To check that the we correctly restored _java_system_loader from CDS, I think we should move the Java upcall to a worker function and add some asserts:

if (_java_system_loader.is_empty()) {
    _java_system_loader = get_system_classloader_impl();
} else {
   // It must have been restored from the archived module graph
   assert(UseSharedSpaces, "must be");
   assert(MetaspaceShared::use_full_module_graph(). "must be");
   assert(_java_system_loader.resolve() == get_system_classloader_impl(), "must be");
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

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.

This looks good. So the platform and java_system loader are already restored in the ClassLoaderData, and you can get them from there instead of upcall to Java?

@openjdk
Copy link

openjdk bot commented Aug 4, 2022

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

8291840: Avoid JavaCalls for setting up _java_system_loader and _java_platform_loader

Reviewed-by: coleenp, iklam

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 45 new commits pushed to the master branch:

  • 6e6c64c: 8291941: ProblemList java/lang/ProcessBuilder/PipelineLeaksFD.java on linux-all
  • 617a196: 8290812: Add a test for ResourceHashtable
  • 1edc245: 8291899: Zero VM is broken on MacOS after JDK-8290840 due to os::setup_fpu() is missing
  • 6ad6b1c: 8272998: ImageIO.read() throws incorrect exception type
  • 90257f9: 8169187: [macosx] Aqua: java/awt/image/multiresolution/MultiresolutionIconTest.java
  • c48cd88: 8291926: ProblemList multiple tests in -Xcomp mode due to JDK-8291649
  • 3c32564: 8288377: [REDO] DST not applying properly with zone id offset set with TZ env variable
  • fd9ac62: 8291457: Clean up lifecycle of CDS dump-time data structures
  • 3ba3171: 8285935: Spurious lint warning for static method accessed through instance qualifier
  • 92d2982: 8283232: x86: Improve vector broadcast operations
  • ... and 35 more: https://git.openjdk.org/jdk/compare/57bf603b7332db86c39680d16b78f94a904daf46...master

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.

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

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 4, 2022
@calvinccheung
Copy link
Member Author

Coleen,
Thanks for your review.
When the Modules::define_archived_modules() is called from java, we can cache the platform and system class loaders so that we don't need to do another java upcall again to set them up later in SystemDictionary::compute_java_loaders().

Copy link
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

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

LGTM.

@calvinccheung
Copy link
Member Author

Thanks @iklam, @coleenp for the review.

/integrate

@openjdk
Copy link

openjdk bot commented Aug 4, 2022

Going to push as commit 27c8826.
Since your change was applied there have been 45 commits pushed to the master branch:

  • 6e6c64c: 8291941: ProblemList java/lang/ProcessBuilder/PipelineLeaksFD.java on linux-all
  • 617a196: 8290812: Add a test for ResourceHashtable
  • 1edc245: 8291899: Zero VM is broken on MacOS after JDK-8290840 due to os::setup_fpu() is missing
  • 6ad6b1c: 8272998: ImageIO.read() throws incorrect exception type
  • 90257f9: 8169187: [macosx] Aqua: java/awt/image/multiresolution/MultiresolutionIconTest.java
  • c48cd88: 8291926: ProblemList multiple tests in -Xcomp mode due to JDK-8291649
  • 3c32564: 8288377: [REDO] DST not applying properly with zone id offset set with TZ env variable
  • fd9ac62: 8291457: Clean up lifecycle of CDS dump-time data structures
  • 3ba3171: 8285935: Spurious lint warning for static method accessed through instance qualifier
  • 92d2982: 8283232: x86: Improve vector broadcast operations
  • ... and 35 more: https://git.openjdk.org/jdk/compare/57bf603b7332db86c39680d16b78f94a904daf46...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Aug 4, 2022
@openjdk openjdk bot closed this Aug 4, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 4, 2022
@openjdk
Copy link

openjdk bot commented Aug 4, 2022

@calvinccheung Pushed as commit 27c8826.

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

@calvinccheung calvinccheung deleted the 8291840-avoid-javacalls-system-platform-loaders branch August 5, 2022 00:01
Comment on lines +182 to +185
void SystemDictionary::set_system_loader(ClassLoaderData *cld) {
if (_java_system_loader.is_empty()) {
_java_system_loader = cld->class_loader_handle();
}
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be an error to call this when the loader has already been set?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi David,

Are you thinking about adding an else case to the function and call the vm_exit_during_initialization() ?

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking:

void SystemDictionary::set_system_loader(ClassLoaderData *cld) {
  assert(_java_system_loader.is_empty(), "already set!");
  _java_system_loader = cld->class_loader_handle();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, I just realized, how does this not get into trouble with GC? If we copy this OopHandle, then GC will follow it from two locations. This doesn't seem 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.

Hi Coleen,

Let me know what needs to be done to get this right. I can file another bug to fix it together with David's suggestion above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry Calvin, this is fine. We can copy OopHandle because they're walked by their OopStorage location not where they're copied to anymore. We do this in lots of places.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Coleen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
4 participants