Skip to content

8371327: G1: Replace FromCardCache with thread-local per-card cache - #32479

Open
walulyai wants to merge 13 commits into
openjdk:masterfrom
walulyai:FromCardCache_v2
Open

8371327: G1: Replace FromCardCache with thread-local per-card cache#32479
walulyai wants to merge 13 commits into
openjdk:masterfrom
walulyai:FromCardCache_v2

Conversation

@walulyai

@walulyai walulyai commented Aug 21, 2026

Copy link
Copy Markdown
Member

Hi,

Please review this change that replaces the global direct-indexed G1FromCardCache with a per-worker local cache.

After JEP 522, additions to G1CardSets are performed during linear heap scans: Concurrent refinement sweeps and Concurrent remset rebuild. The linear traversal does not need to cache state for previously processed cards. We can maintain only the cache state for the current card, then discard the state when traversal advances.

The new cache maintains the current source card and an array of cardsets already visited for that card. This reduces the memory overhead of the FromCardCache from O(number of regions × number of workers) to O(maximum references per card × number of active workers).

The old cache provided constant-time lookups, while the new cache linearly searches the array of cardsets. These arrays are normally short (the benchmarks show approximately 1.3 comparisons per lookup) and in the worst case bounded by the maximum references per card.

Testing:

  • Tier 1-3
  • No performance regression was observed in the tested workloads.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8371327: G1: Replace FromCardCache with thread-local per-card cache (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 32479

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Aug 21, 2026

Copy link
Copy Markdown

👋 Welcome back iwalulya! 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 commented Aug 21, 2026

Copy link
Copy Markdown

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

@openjdk openjdk Bot added the hotspot-gc hotspot-gc-dev@openjdk.org label Aug 21, 2026
@openjdk

openjdk Bot commented Aug 21, 2026

Copy link
Copy Markdown

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

  • hotspot-gc

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 commented Aug 21, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot-gc. This can be overridden with the /reviewers command.

@walulyai
walulyai marked this pull request as ready for review August 21, 2026 11:29
@openjdk openjdk Bot added the rfr Pull request is ready for review label Aug 21, 2026
@mlbridge

mlbridge Bot commented Aug 21, 2026

Copy link
Copy Markdown

Webrevs

@tschatzl tschatzl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you provide some more statistics on refinement time/number of iterations in that new FCC? Like benchmark/refinement time before/after, avg number of iterations to search

Comment on lines +96 to +98
if (_cm->do_yield_check()) {
_rebuild_closure.reset_from_card_cache();
if (!should_rebuild_or_scrub(hr)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a suggestion, maybe encapsulate the yield check with the reset, i.e. something like:

bool my_yield_check() {
  bool yielded = _cm->do_yield_check();
  if (yielded) {
    _rebuild_closure.reset_from_card_cache();
  }
  return yielded;
}

Maybe not though.

verify_card_pair_refers_to_same_card(source_card, dest_card);

G1RemSet::RefineResult res = _rem_set->refine_card_concurrently(source_card, _worker_id);
G1RemSet::RefineResult res = _rem_set->refine_card_concurrently(source_card, _conc_refine_cl);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you consider putting the _conc_refine_cl construction into refine_card_concurrently()? Its lifecycle is exactly the same as that method after all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, started out with G1ConcurrentRefineOopClosure conc_refine_cl local to the refine_card_concurrently, but maybe hoisting it was "premature" optimization.

Comment on lines -52 to -55
// This card index indicates "no card for that entry" yet. This allows us to use the OS
// lazy backing of memory with zero-filled pages to avoid initial actual memory use.
// This means that the heap must not contain card zero.
static const uintptr_t InvalidCard = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer if that constant were explicitly retained for clarity. Its comment explains why its use is safe...

Comment thread src/hotspot/share/gc/g1/g1FromCardCache.hpp Outdated

assert(_num_cardsets < MaxNumCardsets, "source card has too many destination cardsets");

if (_num_cardsets < MaxNumCardsets) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this check is redundant and/or harmful. First, there is that assert above, and loosing a card just makes the program crash.

I would make sure that MaxCardSizeInBytes is consistent with the flag, and only add the assert.

Comment thread src/hotspot/share/gc/g1/g1FromCardCache.hpp Outdated
Comment thread src/hotspot/share/gc/g1/g1FromCardCache.hpp Outdated
Comment thread src/hotspot/share/gc/g1/g1CollectionSetCandidates.hpp Outdated
Comment thread src/hotspot/share/gc/g1/g1FullGCResetMetadataTask.cpp Outdated
Comment thread test/hotspot/gtest/gc/g1/test_g1FromCardCache.cpp Outdated
albertnetymk added a commit to albertnetymk/jdk that referenced this pull request Aug 25, 2026
Applied from openjdk/jdk PR openjdk#32479 by Ivan Walulya.

After JEP 522, additions to G1CardSets happen during linear heap scans, so
there is no need to cache state for previously processed cards. Replace the
global O(regions x workers) direct-indexed FromCardCache with a per-closure
cache holding the current source card and the cardset ids already visited for
it, keyed on the cset candidate group id.
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

Development

Successfully merging this pull request may close these issues.

2 participants