Skip to content

Conversation

@pengxiaolong
Copy link

@pengxiaolong pengxiaolong commented Oct 29, 2025

To allocate an object in Collector/OldCollector partition, current implementation may traverse the regions in the partition twice:

  1. fast path: traverse regions between left most and right most in the partition, and try to allocate in an affiliated region in the partition;
  2. if fails in fast path, traverse regions between left most empty and right most empty in the partition, and try try to allocate in a FREE region.

2 can be saved if we also remember the first FREE region seem in 1.

The PR makes the code much cleaner, and more efficient(although the performance impact may not be measurable, I have run some dacapo benchmarks and didn't see meaningful difference)

Test:

  • hotspot_gc_shenandoah

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-8370850: Shenandoah: Simplify collector allocation to save unnecessary region iteration (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28036

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 29, 2025

👋 Welcome back xpeng! 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 Oct 29, 2025

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

@openjdk openjdk bot added hotspot-gc hotspot-gc-dev@openjdk.org shenandoah shenandoah-dev@openjdk.org labels Oct 29, 2025
@openjdk
Copy link

openjdk bot commented Oct 29, 2025

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

  • hotspot-gc
  • shenandoah

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.

@pengxiaolong pengxiaolong marked this pull request as ready for review October 29, 2025 23:23
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 29, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 29, 2025

Webrevs

result = allocate_with_affiliation(iterator, req.affiliation(), req, in_new_region);
}

bool allow_new_region = can_allocate_in_new_region(req);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we losing the check here? Before this change, the region had to be FREE and the generation affiliated with the request had to have free_unaffiliated_regions.

Copy link
Author

Choose a reason for hiding this comment

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

I was confused about this part, if we can find a FREE region in the partition, why we still need to test if the generation must have free_unaffiliated_regions, I can add can_allocate_in_new_region back to retain the original behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

The young and old collector reserves both have FREE regions, but we need to make sure we don't exceed the reserves for one or the other.

Copy link
Author

Choose a reason for hiding this comment

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

I have added the can_allocate_in_new_region check back, it should have same behavior now.

Copy link
Author

Choose a reason for hiding this comment

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

I have removed can_allocate_in_new_region again after merging @kdnilsen's change unifying accountings, since we don't have consistency in accountings anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

We still need to enforce that requests for a young evacuation don't take memory that was reserved for old evacuations. can_allocate_in_new_region isn't about consistency between freeset and generation accounting, it's used to maintain old/young collector reserves.

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 rfr Pull request is ready for review shenandoah shenandoah-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

2 participants