Skip to content

Conversation

tschatzl
Copy link
Contributor

@tschatzl tschatzl commented Sep 16, 2025

Hi all,

please review this change to parallel klass cleaning to improve performance.

The current implementation only parallelizes cleaning of weak class links, while the main work, cleaning the object tree is single-threaded. Hence in practice, the current mechanism does not scale beyond 2-3 threads.

Cleaning an object graph in an application that loads some jars and instantiates central classes within them, with around 180k classes the current G1 Complete Cleaning task (which executes this code) can take 80ms (with 25 threads).

The suggested change is to walk the object graph by (live) ClassLoaderData klass by klass, fixing only the links of that particular klass.

E.g.

CLD1 has klasses A, B, C, CLD2 has klasses a, b, c and CLD3 has klasses 0, 1, 2, 4;
vertical links are subklass references, while horizontal links are sibling references.

j.l.O
  |
  A - B - c - 3
  |
  0 - 2 - C - 1

CLD 3 is dead. Thread 1 claims CLD 1, Thread 2 claims CLD 2 (and nobody claims CLD3 because it's dead).

So thread 1, when reaching A fixes its subklass link to C, and otherwise does nothing with A. When looking at C, it will remove the link to 1.
Thread 2 will only remove the link to 3 of c.

The result is

j.l.O
  |
  A - B - c
  |
  C

There should be no unnecessary object graph walking.

There is a slight change in printing during unlinking: previously the code, when cleaning subklasses it printed unlinking class (subclass)for every class that has been removed on the way to the next live one. In above case, it would print

unlinking class (subclass): 0
unlinking class (subclass): 2

With the change, to avoid following the subklasses of the graph twice, it prints

unlinking class (subclass): 0
unlinking class (sibling): 0

because the string in brackets is the actual link that is followed. I can revert that change.

With the change "Complete Cleaning" time for 200k classes takes 7.6ms (The test is a bit random on when it does the class unloading).

Testing: tier1-5

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-8363932: G1: Better distribute KlassCleaningTask (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27316

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 16, 2025

👋 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
Copy link

openjdk bot commented Sep 16, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title 8363932 8363932: G1: Better distribute KlassCleaningTask Sep 16, 2025
@openjdk
Copy link

openjdk bot commented Sep 16, 2025

@tschatzl this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout submit/8363932-klasstaskcleaning-distribution
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Sep 16, 2025
@openjdk
Copy link

openjdk bot commented Sep 16, 2025

@tschatzl The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Sep 17, 2025
@tschatzl
Copy link
Contributor Author

/label add hotspot-gc
/label add hotspot-runtime
/label remove hotspot

@tschatzl tschatzl marked this pull request as ready for review September 17, 2025 13:55
@openjdk openjdk bot added rfr Pull request is ready for review hotspot-gc [email protected] labels Sep 17, 2025
@openjdk
Copy link

openjdk bot commented Sep 17, 2025

@tschatzl
The hotspot-gc label was successfully added.

@openjdk
Copy link

openjdk bot commented Sep 17, 2025

@tschatzl
The hotspot-runtime label was successfully added.

@openjdk
Copy link

openjdk bot commented Sep 17, 2025

@tschatzl
The hotspot label was successfully removed.

@mlbridge
Copy link

mlbridge bot commented Sep 17, 2025

Webrevs

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

Successfully merging this pull request may close these issues.

1 participant