Skip to content

Conversation

@tschatzl
Copy link
Contributor

@tschatzl tschatzl commented Jan 8, 2026

Hi all,

please review this change that makes concurrent mark not try to iterate over objArray metadata for every slice, to make behavior uniform with other garbage collection types/garbage collectors.

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-8374780: G1: Do not iterate klass metadata when splitting objArrays for every slice (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 29116

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

Using diff file

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

Using Webrev

Link to Webrev Comment

Hi all,

  please review this change that makes concurrent mark not try to iterate over `objArray` metadata for every slice, to make behavior uniform with other garbage collection types/garbage collectors.

Testing: tier1-5

Thanks,
  Thomas
@bridgekeeper
Copy link

bridgekeeper bot commented Jan 8, 2026

👋 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 Jan 8, 2026

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

8374780: G1: Do not iterate klass metadata when splitting objArrays for every slice

Reviewed-by: stefank

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

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 changed the title 8374780 8374780: G1: Do not iterate klass metadata when splitting objArrays for every slice Jan 8, 2026
@openjdk
Copy link

openjdk bot commented Jan 8, 2026

@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 added the rfr Pull request is ready for review label Jan 8, 2026
@mlbridge
Copy link

mlbridge bot commented Jan 8, 2026

Webrevs

Copy link
Member

@stefank stefank left a comment

Choose a reason for hiding this comment

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

I agree that we should do a change like this.

I've given some feedback that I think the code would be easier to read if you operated on array indices instead of MemRegion. We do that in other GCs.

Then I have given some length comments about the oop iterate functions. I find their names misleading and inconsistent. I would like to take a stab at slightly tweaking them, if you don't mind. That can be done in parallel with this change, and doesn't block the PR.

inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);

// Iterate over oop elements within [start, end), and metadata.
// Iterate over oop elements within [start, end) without metadata.
Copy link
Member

Choose a reason for hiding this comment

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

I know that you didn't change this, but this inconsistency in the API between oop_oop_iterate_bounded and oop_oop_iterate_range is unsettling. I think they both should be visiting the klass metadata if the obj falls within mr.

FWIW, the InstanceKlass implementation is also slightly different in that it checks if mr spans the start of obj:

ALWAYSINLINE void InstanceKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) {
  if (Devirtualizer::do_metadata(closure)) {
    if (mr.contains(obj)) {
      Devirtualizer::do_klass(closure, this);
    }
  }

I wonder if we should (maybe later) do an experiment where we check that we don't pass down a metadata-visiting closure when we iterate over a range. Similar to:

ALWAYSINLINE void InstanceKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) {
  assert(!Devirtualizer::do_metadata(closure),
      "Code to handle metadata is not implemented");

And then remove the metadata visiting from oop_oop_iterate_bounded as well.

Comment on lines +190 to +192
int start = checked_cast<int>(pointer_delta(MAX2(mr.start(), obj->base()), obj->base(), heapOopSize));
int end = checked_cast<int>(pointer_delta(mr.end(), obj->base(), heapOopSize));
obj->oop_iterate_range(_cm_oop_closure, start, end);
Copy link
Member

Choose a reason for hiding this comment

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

I think this becomes a bit obscure when the lines perform multiple tasks, and having one line per operation makes it easier to make sure that the code is correct.

If we look at the operations we also see an inconsistency between start and end calculation:

For start it calculates the lower boundary and then it converts to an index.
For end it skips calculating a upper boundary and then it converts to an index.

You need to read the callers to figure out if skipping calculating the upper boundary for end is correct.

I would strongly suggest that this code is rewritten so that scan_objArray takes a start and end as array indices, instead of using a MemRegion. And that the same is done for process_array_slice. I think then some of these casts and pointer_deltas will go away and the code will be easier to read and reason about.


public:
// special iterators for index ranges, returns size of object
// Special iterator for index ranges.
Copy link
Member

Choose a reason for hiding this comment

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

This comment goes together with the one above in the objArrayKlass file. While looking at the various oop_oop_iterate functions in ObjArrayKlass I think it would be better if this was called oop_iterate_elements. Given the inconsistency described above, we might also have to do something about the ObjArrayKlass::oop_oop_iterate_range name. Let me take a closer look at these names separately from your patch.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants