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

8306929: Avoid CleanClassLoaderDataMetaspaces safepoints when previous versions are shared #13716

Closed

Conversation

kstefanj
Copy link
Contributor

@kstefanj kstefanj commented Apr 28, 2023

Hi all,

Please review this change to avoid CleanClassLoaderDataMetaspaces safepoint when there is nothing that can be cleaned up.

Summary
When transforming/redefining classes a previous version list is linked together in the InstanceKlass. The original class is added to this list if it is still used or shared. The difference between shared and used is not currently noted. This leads to a problem when doing concurrent class unloading, because during that we postpone some potential work to a safepoint (since we are not in one). This is the CleanClassLoaderDataMetaspaces and it is triggered by the ServiceThread if there is work to be done, for example if InstanceKlass::_has_previous_versions is true.

Since we currently does not differentiate between shared and "in use" we always set _has_previous_versions if anything is on this list. This together with the fact that shared previous versions should never be cleaned out leads to this safepoint being triggered after every concurrent class unloading even though there is nothing that can be cleaned out.

This can be avoided by making sure the _previous_versions list is only cleaned when there are non-shared classes on it. This change renames _has_previous_versions to _clean_previous_versions and only updates it if we have non-shared classes on the list.

Testing

  • A lot of manual testing verifying that we do get the safepoint when we should.
  • Added new test to verify expected behavior by parsing the logs. The test uses JFR to trigger redefinition of some shared classes (when -Xshare:on).
  • Mach5 run of new test and tier 1-3

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-8306929: Avoid CleanClassLoaderDataMetaspaces safepoints when previous versions are shared

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13716

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 28, 2023

👋 Welcome back sjohanss! 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 rfr Pull request is ready for review label Apr 28, 2023
@openjdk
Copy link

openjdk bot commented Apr 28, 2023

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

  • hotspot
  • serviceability

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.

@openjdk openjdk bot added serviceability serviceability-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels Apr 28, 2023
@mlbridge
Copy link

mlbridge bot commented Apr 28, 2023

Webrevs

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. Thanks for all the testing and adding the new test.

@openjdk
Copy link

openjdk bot commented Apr 28, 2023

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

8306929: Avoid CleanClassLoaderDataMetaspaces safepoints when previous versions are shared

Reviewed-by: coleenp, sspitsyn

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

  • 3930709: 8068925: Add @OverRide in javax.tools classes
  • fc76687: 8306836: Remove pinned tag for G1 heap regions
  • ccf91f8: 8306933: C2: "assert(false) failed: infinite loop" failure
  • e9807a4: 8306042: C2: failed: Missed optimization opportunity in PhaseCCP (adding LShift->Cast->Add notification)
  • fcb280a: 8305092: Improve Thread.sleep(millis, nanos) for sub-millisecond granularity
  • 891530f: 8307005: Make CardTableBarrierSet::initialize non-virtual
  • e0774be: 8306997: C2: "malformed control flow" assert due to missing safepoint on backedge with a switch
  • 462b1df: 8307106: Allow concurrent GCs to walk CLDG without ClassLoaderDataGraph_lock
  • c8f3756: 8306729: Add nominal descriptors of modules and packages to Constants API
  • 0b5b642: 8307150: RISC-V: Remove remaining StoreLoad barrier with UseCondCardMark for Serial/Parallel GC
  • ... and 57 more: https://git.openjdk.org/jdk/compare/fee02f066879e77e55e217660daa46607778b6e8...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 Apr 28, 2023
@@ -715,16 +715,16 @@ class InstanceKlass: public Klass {
}

private:
static bool _has_previous_versions;
static bool _clean_previous_versions;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I'd suggest to name it as _should_clean_previous_versions.
Then the corresponding function needs to be named as should_clean_previous_versions().

Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

Thank you for taking care about it.
I've posted a couple of comments but it it looks good anyway.
Thanks,
Serguei

// classes to be in use.
.shouldNotContain("scratch class added; one of its methods is on_stack.")
.shouldHaveExitValue(0);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

The fragments 61-74 and 79-93 have a big common part which can be a good base for a refactoring.
But it can be not worth it. So, I leave it up to you.

@kstefanj
Copy link
Contributor Author

kstefanj commented May 3, 2023

Thanks for the reviews @coleenp and @sspitsyn.

Pushed two changes according to Sergueis suggestions.

Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

Thank you for the update.
Looks good.
Thanks,
Serguei

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed ready Pull request is ready to be integrated labels May 3, 2023
@kstefanj
Copy link
Contributor Author

kstefanj commented May 4, 2023

Thanks again @coleenp and @sspitsyn for the reviews.

/integrate

@openjdk
Copy link

openjdk bot commented May 4, 2023

Going to push as commit 408cec5.
Since your change was applied there have been 81 commits pushed to the master branch:

  • cecf817: 8307181: MemoryLayout.structLayout uses undocumented strict alignment constraints
  • 3f1927a: 8307346: Add missing gc+phases logging for ObjectCount(AfterGC) JFR event collection code
  • e206d57: 8307362: Remove test com/sun/jdi/JdbLastErrorTest.java
  • 82a8e91: 8306489: Open source AWT List related tests
  • 465bdd9: 8307091: A few client tests intermittently throw ConcurrentModificationException
  • caee1be: 8307305: Update debugger tests to support JTREG_TEST_THREAD_FACTORY mode
  • 3599448: 8307147: [x86] Dangling pointer warning for Assembler::_attributes
  • 64ac9a0: 8306946: jdk/test/lib/process/ProcessToolsStartProcessTest.java fails with "wrong number of lines in OutputAnalyzer output"
  • 03030d4: 8307134: Add GTS root CAs
  • 63cd0a3: 4200096: OffScreenImageSource.removeConsumer NullPointerException
  • ... and 71 more: https://git.openjdk.org/jdk/compare/fee02f066879e77e55e217660daa46607778b6e8...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented May 4, 2023

@kstefanj Pushed as commit 408cec5.

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

@olivergillespie
Copy link
Contributor

/backport jdk17u-dev

@openjdk
Copy link

openjdk bot commented Aug 2, 2024

@olivergillespie Could not automatically backport 408cec51 to openjdk/jdk17u-dev due to conflicts in the following files:

  • src/hotspot/share/oops/instanceKlass.cpp

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-olivergillespie-408cec51-master

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 408cec516bb5fd82fb6dcddeee934ac0c5ecffaf

# Backport the commit
$ git cherry-pick --no-commit 408cec516bb5fd82fb6dcddeee934ac0c5ecffaf
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 408cec516bb5fd82fb6dcddeee934ac0c5ecffaf'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport 408cec516bb5fd82fb6dcddeee934ac0c5ecffaf.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 408cec51 from the openjdk/jdk repository.

The commit being backported was authored by Stefan Johansson on 4 May 2023 and was reviewed by Coleen Phillimore and Serguei Spitsyn.

Thanks!

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

Successfully merging this pull request may close these issues.

4 participants