Skip to content

Conversation

@eme64
Copy link
Contributor

@eme64 eme64 commented Oct 20, 2025

When working on #27889, I was irritated by the lack of documentation and suboptimal naming.

Here, I'm doing the following:

  • Add more documentation, and improve it in other cases.
  • Rename "lazy" methods: "lazy" could indicate that we delay it somehow until later, but it is unclear what is delayed.
    • lazy_replace -> replace_ctrl_node_and_forward_ctrl_and_idom
    • lazy_update -> install_lazy_ctrl_and_idom_forwarding
  • Made some methods private, and added some additional asserts.

I'd be more than happy for even better names, and suggestions how to improve the documentation further :)

Related issues:
#27889
#15720


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-8370220: C2: rename methods and improve documentation around get_ctrl and idom lazy updating/forwarding of ctrl and idom via dead ctrl nodes (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27892

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 20, 2025

👋 Welcome back epeter! 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 20, 2025

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

8370220: C2: rename methods and improve documentation around get_ctrl and idom lazy updating/forwarding of ctrl and idom via dead ctrl nodes

Reviewed-by: chagedorn, thartmann

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

  • 5ed6c20: 8370681: [BACKOUT] Improve memory ordering in new CPU Time Profiler
  • 7bb490c: 8370318: AES-GCM vector intrinsic may read out of bounds (x86_64, AVX-512)
  • 6f8d07a: 8368500: ContextClassLoader cannot be reset on threads in ForkJoinPool.commonPool()

Please see this link for an up-to-date comparison between the source branch of this pull request and 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 JDK-8370220 8370220: C2: improve documentation around get_ctrl and _loop_or_ctrl implementation Oct 20, 2025
@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Oct 20, 2025
@openjdk
Copy link

openjdk bot commented Oct 20, 2025

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

  • hotspot-compiler

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.

@eme64 eme64 changed the title 8370220: C2: improve documentation around get_ctrl and _loop_or_ctrl implementation 8370220: C2: rename methods and improve documentation around get_ctrl and idom lazy updating/forwarding of ctrl and idom via dead ctrl nodes Oct 20, 2025
@eme64 eme64 marked this pull request as ready for review October 20, 2025 12:53
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 20, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 20, 2025

Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

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

Thanks a lot for following up with a documentation and renaming! Some small suggestions, otherwise, looks good!

Note: There are some build failures in GHA.

// reach a live ctrl node. Shorten the path to avoid chasing the
// forwarding in the future.
// - When querying "idom": from some node get its old idom, which
// may be dead but has a ctrl forwarding to the new and live
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add this:

Suggested change
// may be dead but has a ctrl forwarding to the new and live
// may be dead but has an idom forwarding (piggy-backing on '_loop_or_ctrl') to the new and live

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I applied something that is inspired by your suggestion instead :)

// Using "install_lazy_ctrl_and_idom_forwarding" allows us to only edit
// the entry for the old dead node now, and we do not have to update all
// the nodes that had the old_node as their "get_ctrl" or "idom". We
// clean up the forwarding links when we query "get_ctrl" or "idom".
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// clean up the forwarding links when we query "get_ctrl" or "idom".
// clean up the forwarding links when we query "get_ctrl" or "idom" for these nodes the next time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied it but with a line break ;)

// If everything went right, this dead CFG node should have had a idom/ctrl
// forwarding installed, using "install_lazy_ctrl_and_idom_forwarding".
// We now have to jump from the old (dead) ctrl node to the new (live)
// ctrl/idom node, in possibly multiple ctrl/idom forwarding steps.
Copy link
Member

@chhagedorn chhagedorn Oct 20, 2025

Choose a reason for hiding this comment

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

Maybe for clarification since it's somehow surprising at first that we reuse _loop_or_ctrl:

Suggested change
// ctrl/idom node, in possibly multiple ctrl/idom forwarding steps.
// idom node, in possibly multiple idom forwarding steps.
// Note that we piggy back on `_loop_or_ctrl` do the the forwarding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied with even more information.

Node* n = idom_no_update(didx);
// We store the found idom in the side-table again. In most cases,
// this is a no-op, since we just read from _idom. But in cases where
// there was a ctrl forwarding via dead ctrl nodes, this shortens the path.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// there was a ctrl forwarding via dead ctrl nodes, this shortens the path.
// there was an idom forwarding via dead idom nodes, this shortens the path.

Node *idom(uint didx) const {
Node *n = idom_no_update(didx);
_idom[didx] = n; // Lazily remove dead CFG nodes from table.
Node* idom(uint didx) const {
Copy link
Member

Choose a reason for hiding this comment

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

While at it: Maybe also name this node_index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose to replace it with node_idx, since it comes from n->_idx.

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

openjdk bot commented Oct 21, 2025

@eme64 hotspot, shenandoah have been added to this pull request based on files touched in new commit(s).

eme64 and others added 2 commits October 21, 2025 09:26
Co-authored-by: Christian Hagedorn <christian.hagedorn@oracle.com>
// Replace the old ctrl node with a new ctrl node.
// - Update the node inputs of all uses.
// - Lazily update the ctrl and idom info of all uses, via a ctrl/idom forwarding.
void replace_ctrl_node_and_forward_ctrl_and_idom(Node *old_node, Node *new_node) {
Copy link
Member

Choose a reason for hiding this comment

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

Drive-by comment (sorry): I think this is way too heavy. Descriptive names are good but for complex methods, not all the semantics can be put into the name but should rather be in a comment.

Couldn't we just name these replace_and_update_ctrl and update_ctrl? I think this entails updating idom which is dependent on ctrl. And the comments explain the details well enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TobiHartmann

update_ctrl: Sounds too much like set_ctrl, but it is not at all similar conceptually.

What about:

  • install_ctrl_and_idom_forwarding -> forward_ctrl
  • replace_ctrl_node_and_forward_ctrl_and_idom -> replace_node_and_forward_ctrl
    • Because it is really a specialization of _igvn.replace_node, so it should have some name similarity.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's much better, good with me!

@eme64
Copy link
Contributor Author

eme64 commented Oct 21, 2025

@chhagedorn Thanks for all the suggestions / comments, I think I applied them all now :)

@TobiHartmann thanks for the drive-by comment / suggestion.

@rwestrel You are somewhat familiar with this code, would you mind reviewing?

@vnkozlov You may also want to have quick look, just so you are aware of the renamings. But feel free to also review ;)

Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

Nice improvement, looks good to me!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 21, 2025
Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

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

Good naming update! The update looks good to me apart from some last nits.

Co-authored-by: Christian Hagedorn <christian.hagedorn@oracle.com>
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Oct 21, 2025
@eme64
Copy link
Contributor Author

eme64 commented Oct 21, 2025

Seems GHA is giving me some failures I did not see in our internal testing:

compiler.lib.ir_framework.flag.FlagVM compiler.gcbarriers.TestShenandoahBarrierExpansion

#  Internal Error (/home/runner/work/jdk/jdk/src/hotspot/share/opto/loopnode.hpp:1168), pid=5884, tid=5904
#  assert(!has_ctrl(old_node) && old_node->is_CFG() && old_node->in(0) == nullptr) failed: must be dead ctrl (CFG) node

This is part of the assert I added. Will have to investigate.

@openjdk
Copy link

openjdk bot commented Oct 22, 2025

⚠️ @eme64 This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

fix_memory_uses(u, n, n, c);
} else if (_phase->C->get_alias_index(u->adr_type()) == _alias) {
_phase->lazy_replace(u, n);
_phase->igvn().replace_node(u, n);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can see, the lazy_replace only did igvn.replace_node for non-ctrl nodes anyway. Since we are dealing with PhiNodes here, we might as well only use igvn.replace_node.

I discovered this, because it hit my !old_node->is_CFG() check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rwestrel Do you have an opinion on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

That change looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rwestrel Thank, good to know :)

@eme64
Copy link
Contributor Author

eme64 commented Oct 27, 2025

@chhagedorn @TobiHartmann Would either of you be able to re-approve? I've fixed a little issue for shenandoah, and Roland approved that change. I merged with master and am currently running some last testing.

Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

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

Still good!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 27, 2025
@eme64
Copy link
Contributor Author

eme64 commented Oct 28, 2025

@chhagedorn @TobiHartmann Thanks for the review / approval!
@rwestrel Thanks for approving the shanandoah changes!

/integrate

@openjdk
Copy link

openjdk bot commented Oct 28, 2025

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 28, 2025

@eme64 Pushed as commit d5ce666.

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

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

Labels

hotspot hotspot-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated shenandoah shenandoah-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

4 participants