Skip to content

8319955: Improve dependencies removal during class unloading #16639

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

Conversation

tschatzl
Copy link
Contributor

@tschatzl tschatzl commented Nov 13, 2023

Hi all,

please review this performance improvement to dependency removal during class unloading: instead of moving the dependencies item by item via a cmpxchg, batch this operation.

This makes that part of class unloading ~7x faster in my measurements (class unloading stress test, loading/unloading 6k classes).

Testing: tier1-7

Thanks,
Thomas


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-8319955: Improve dependencies removal during class unloading (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16639

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

Using diff file

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

Webrev

Link to Webrev Comment

@tschatzl
Copy link
Contributor Author

/label add hotspot-runtime

@tschatzl
Copy link
Contributor Author

/label add hotspot-gc

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 13, 2023

👋 Welcome back tschatzl! 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 changed the title 8319955 8319955: Improve dependencies removal during class unloading Nov 13, 2023
@openjdk openjdk bot added rfr Pull request is ready for review hotspot-runtime hotspot-runtime-dev@openjdk.org labels Nov 13, 2023
@openjdk
Copy link

openjdk bot commented Nov 13, 2023

@tschatzl
The hotspot-runtime label was successfully added.

@openjdk openjdk bot added the hotspot-gc hotspot-gc-dev@openjdk.org label Nov 13, 2023
@openjdk
Copy link

openjdk bot commented Nov 13, 2023

@tschatzl
The hotspot-gc label was successfully added.

@tschatzl tschatzl marked this pull request as draft November 13, 2023 18:56
@openjdk openjdk bot removed the rfr Pull request is ready for review label Nov 13, 2023
@tschatzl tschatzl marked this pull request as ready for review November 14, 2023 07:41
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 14, 2023
@mlbridge
Copy link

mlbridge bot commented Nov 14, 2023

Webrevs

@dholmes-ora
Copy link
Member

So this batches the operation by moving the batch to the purge list, but it doesn't actually release anything. Who/what will process the purge list and when? The implications of this change in terms of concurrent activities is far from clear.

@tschatzl
Copy link
Contributor Author

So this batches the operation by moving the batch to the purge list, but it doesn't actually release anything. Who/what will process the purge list and when? The implications of this change in terms of concurrent activities is far from clear.

There is no observable difference (apart from being faster) here - the move of the dependencies from the (single) Klass to the purge list is and has been under the ClassLoaderData_lock anyway, locking out "everything" already.

The current basic structure is like:

(indentation means call level)
lock ClassLoaderDataGraph_lock
CLGD::do_unloading()
  CLD::unload
  foreach (Klass in CLD) {
    remove_all_dependents()
  }
unlock ClassLoaderDataGraph_lock

The only thing that change is the performance of remove_all_dependents, from

void DependencyContext::remove_all_dependents() {
  for (all dependents x) {
    loadload barrier
    cmpxchg x into purge list
  }
}

to

void DependencyContext::remove_all_dependents() {
  find last pointer of dependents list of the dead(!) Klass, i.e. verified unreachable by the mutator
  cmpxchg first/last into purge list
}

Literally no change in locking or the scope of the ClassLoaderDataGraph_lock. Everything else is already locked out (for a really long time in that stress test).

The only change is the amount of atomic operations.

Actually, the time to hold the CLDG_lock is much shorter now as indicated by the numbers in the CR.

The purge list is processed as before at some point afterwards. No change here.

Unfortunately the code still needs to traverse the linked list (and there are really many linked lists here and in nmethod management :( ) which are not very amenable to performance improvements (e.g. parallelization).

It is a non-goal for this CR to change data structures.

@tschatzl
Copy link
Contributor Author

tschatzl commented Nov 14, 2023

Sorry forgot to answer this:

Who/what will process the purge list and when?

There is a call to ClassLoaderDataGraph::purge which does that, executed later at the garbage collector's convenience. This change does not change the amount of elements (apart from the order of the elements) too, so no difference here.

(During class unloading DependencyContext::delete_on_release() is and has always been false, and the existing code always moves entries to the purge list - there is an appropriate assert in the new code).

@tschatzl
Copy link
Contributor Author

tschatzl commented Nov 14, 2023

Concurrent additions to the purge list (during (concurrent) class unloading) should be fine due to the cmpxchg used, i.e. callers of DependencyContext::release() while the first part of class unloading (i.e. CLD unlinking) is in progress (i.e. !delete_on_release()).

This is as before afaict.

@dholmes-ora
Copy link
Member

(During class unloading DependencyContext::delete_on_release() is and has always been false, and the existing code always moves entries to the purge list - there is an appropriate assert in the new code).

Thanks I can see that now. So all this does is move a chunk of elements to the purge-list instead of doing it one at a time. Makes me wonder why this wasn't noticed sooner. :)

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Changes look good. Thanks

@openjdk
Copy link

openjdk bot commented Nov 14, 2023

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

8319955: Improve dependencies removal during class unloading

Reviewed-by: dholmes, eosterlund

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

  • 12fce4b: 8287843: File::getCanonicalFile doesn't work for \?\C:\ style paths DOS device paths
  • 346dbd6: 8319196: ExecutableElement.getReceiverType doesn't return receiver types for methods loaded from bytecode
  • 0ea5804: 8318759: Add four DigiCert root certificates
  • 6a75c24: 8319958: test/jdk/java/io/File/libGetXSpace.c does not compile on Windows 32-bit
  • 58af9ae: 8316392: compiler/interpreter/TestVerifyStackAfterDeopt.java failed with SIGBUS in PcDescContainer::find_pc_desc_internal
  • a75b6e5: 8191460: crash in Annotate with duplicate declaration and annotation processing enabled
  • 7bb1999: 8316342: CLHSDB "dumpclass" command produces invalid classes
  • 97ea5bf: 8319961: JvmtiEnvBase doesn't zero _ext_event_callbacks
  • 25f9af9: 8319883: Zero: Use atomic built-ins for 64-bit accesses
  • 9c98270: 8254693: Add Panama feature to pass heap segments to native code
  • ... and 28 more: https://git.openjdk.org/jdk/compare/6b21ff61dad6f633c744c1c33c29ea86183b509d...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 Nov 14, 2023
Copy link
Contributor

@fisk fisk 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.

@tschatzl
Copy link
Contributor Author

Thanks @dholmes-ora @fisk for your reviews
/integrate

@openjdk
Copy link

openjdk bot commented Nov 15, 2023

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

  • 4c1540b: 8287284: C2: loop optimization performs split_thru_phi infinitely many times
  • 70f0c01: 8320054: Remove unused _count from NMT walker classes
  • e7486e8: 8315986: [macos14] javax/swing/JMenuItem/4654927/bug4654927.java: component must be showing on the screen to determine its location
  • a6343c0: 8319999: Refactor MetaspaceShared::use_full_module_graph()
  • d9a89c5: 8319572: Test jdk/incubator/vector/LoadJsvmlTest.java ignores VM flags
  • 1e76ba0: 8319439: Move BufferNode from PtrQueue files to new files
  • d5abe49: 8319628: DateFormat does not mention IllegalArgumentException for invalid style args
  • d725b73: 8301310: The SendRawSysexMessage test may cause a JVM crash
  • 12fce4b: 8287843: File::getCanonicalFile doesn't work for \?\C:\ style paths DOS device paths
  • 346dbd6: 8319196: ExecutableElement.getReceiverType doesn't return receiver types for methods loaded from bytecode
  • ... and 36 more: https://git.openjdk.org/jdk/compare/6b21ff61dad6f633c744c1c33c29ea86183b509d...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 15, 2023

@tschatzl Pushed as commit fbe1937.

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

@tschatzl tschatzl deleted the submit/8319955-improve-dependency-removal branch January 16, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-gc hotspot-gc-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants