Skip to content

8346774: Use Predicate classes instead of Node classes #23234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

chhagedorn
Copy link
Member

@chhagedorn chhagedorn commented Jan 22, 2025

This small cleanup PR replaces a lot of usages of Node pointers, to pass around either the head (i.e. IfNode) or the tail (i.e. a success projection) of predicates, with actual Predicate classes. This simplifies the usages, readability and the logical flow, and enables more simplifications in the future, especially once we replace Template Assertion Predicates with a dedicated node.

I've also included some minor refactorings like adding const or fixing typos.

There are no semantic changes involved. The return value optimization should take care to avoid a lot of copies when returning new objects from methods.

Thanks,
Christian


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-8346774: Use Predicate classes instead of Node classes (Sub-task - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23234

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 22, 2025

👋 Welcome back chagedorn! 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 22, 2025

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

8346774: Use Predicate classes instead of Node classes

Reviewed-by: epeter, kvn

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 1 new commit pushed to the master branch:

  • 6f4fc82: 8348675: TrayIcon tests fail in Ubuntu 24.10 Wayland

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

openjdk bot commented Jan 22, 2025

@chhagedorn 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.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Jan 22, 2025
Comment on lines +192 to +193
OpaqueLoopInitNode* new_opaque_init = new OpaqueLoopInitNode(phase->C, new_opaque_input);
phase->register_new_node(new_opaque_init, new_control);
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved here from the caller of clone_and_replace_init(). He now provides the input to the opaque node instead of creating the opaque node and passing the created node to this method.

// of the newly created Initialized Assertion Predicate.
IfTrueNode* TemplateAssertionPredicate::initialize(PhaseIdealLoop* phase, Node* new_control) const {
// Create a new Initialized Assertion Predicate from this template at the template success projection.
InitializedAssertionPredicate TemplateAssertionPredicate::initialize(PhaseIdealLoop* phase) const {
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed new_control. All callers created the Initialized Assertion Predicate below the template. Eventually, this will always be the case since we want to keep Template Assertion Predicates around in the future.

Comment on lines +806 to +807
InitializedAssertionPredicate InitializedAssertionPredicateCreator::create_from_template(
IfNode* template_assertion_predicate, Node* new_control, Node* new_init, Node* new_stride) const {
Copy link
Member Author

Choose a reason for hiding this comment

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

Also made const and split long line.

Comment on lines +818 to +819
InitializedAssertionPredicate InitializedAssertionPredicateCreator::create_from_template_and_insert_below(
const TemplateAssertionPredicate& template_assertion_predicate) const {
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above: Removed new_control.
Also made const.

Comment on lines +825 to +827
IfNode* template_assertion_predicate_if = template_assertion_predicate.head();
AssertionPredicateType assertion_predicate_type = template_assertion_predicate_if->assertion_predicate_type();
int if_opcode = template_assertion_predicate_if->Opcode();
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to fetch the information from the Template Assertion Predicate now instead of directly from the If.

OpaqueLoopInitNode* opaque_init = new OpaqueLoopInitNode(_phase->C, _init);
_phase->register_new_node(opaque_init, _old_target_loop_entry);
Copy link
Member Author

Choose a reason for hiding this comment

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

See earlier comment about moving opaque creation from caller -> callee.

Comment on lines +1028 to +1029
assert(predicate.head()->_idx >= _node_index_before_cloning, "must be a newly cloned predicate");
assert(predicate.tail()->_idx >= _node_index_before_cloning, "must be a newly cloned predicate");
Copy link
Member Author

Choose a reason for hiding this comment

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

Can now verify both the head and tail.

@chhagedorn chhagedorn marked this pull request as ready for review January 23, 2025 07:33
@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 23, 2025
@mlbridge
Copy link

mlbridge bot commented Jan 23, 2025

Webrevs

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

You use copy constructors to return *Predicate* objects (I assume because base class is StackObj). How it affects performance of C2? Unless all these methods are inlined.

@chhagedorn
Copy link
Member Author

I assumed that RVO will make sure that we do not create an extra copy regardless of whether a method is inlined or not. Maybe @kimbarrett can comment on that.

Nevertheless, let me run some performance testing.

@chhagedorn
Copy link
Member Author

Performance testing looked good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 28, 2025
@chhagedorn
Copy link
Member Author

Thanks Vladimir for your review!

@kimbarrett
Copy link

I assumed that RVO will make sure that we do not create an extra copy regardless of whether a method is inlined or not. Maybe @kimbarrett can comment on that.

Not a review, just a response to the question about RVO.

The use of NRVO and RVO here looks fine to me.

C++17 makes RVO mandatory. We're not using C++17 yet, but part of the
rationale for making it mandatory is that compilers were already doing it (and
had been for some time), at least with optimizing settings. You just couldn't
rely on it, and had to provide the appropriate ctors even if RVO was always
performed. (For example, a copy-ctor is needed even if always using a factory
function that returns a directly constructed object.)

While NRVO was not made mandatory, that may have been more a matter of concern
over specification difficulty for corner cases. In my experience, obvious
cases like those in this PR have been getting NRVO from optimizing compilers
for a long time.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.html
https://en.cppreference.com/w/cpp/language/copy_elision

Support for guaranteed copy elision
https://en.cppreference.com/w/cpp/compiler_support/17
gcc: 7, clang: 4, msvc: 19.13 (VS 2017 15.6)
These versions are for the C++17 "guaranteed in all circumstances" feature.

@chhagedorn
Copy link
Member Author

Thanks a lot Kim for your detailed answer and the links! That's great to hear and gives us more confidence about these changes.

Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

Looks reasonable, I have a few minor suggestions.

// Clone this Template Assertion Predicate and replace the OpaqueLoopInitNode with the provided 'new_opaque_init' node.
IfTrueNode* TemplateAssertionPredicate::clone_and_replace_init(Node* new_control, OpaqueLoopInitNode* new_opaque_init,
PhaseIdealLoop* phase) const {
// Clone this Template Assertion Predicate and replace the input of the OpaqueLoopInitNode with 'new_opaque_input'.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you now also create a new OpaqueLoopInitNode, so that is slightly inaccurate, right?

Comment on lines 810 to 813
IfTrueNode* success_proj = create_control_nodes(new_control, template_assertion_predicate->Opcode(),
assertion_expression,
template_assertion_predicate->assertion_predicate_type());
return InitializedAssertionPredicate(success_proj);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
IfTrueNode* success_proj = create_control_nodes(new_control, template_assertion_predicate->Opcode(),
assertion_expression,
template_assertion_predicate->assertion_predicate_type());
return InitializedAssertionPredicate(success_proj);
IfTrueNode* success_proj = create_control_nodes(new_control,
template_assertion_predicate->Opcode(),
assertion_expression,
template_assertion_predicate->assertion_predicate_type());
return InitializedAssertionPredicate(success_proj);

Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation, and: If you split the args over lines, I would at least split all of them consistently.

Copy link
Member Author

Choose a reason for hiding this comment

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

I usually just make sure that long lines split but don't enforce a single arg per line. But I don't mind adapting to that here :-)

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Feb 3, 2025
Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

Looks good now!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 3, 2025
@chhagedorn
Copy link
Member Author

Thanks Emanuel for your review! I'm running some testing again with latest master and will then integrate it.

@chhagedorn
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Feb 4, 2025

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

  • 7ea176d: 8349193: compiler/intrinsics/TestContinuationPinningAndEA.java missing @requires vm.continuations
  • 9b49597: 8334320: Replace vmTestbase/metaspace/share/TriggerUnloadingWithWhiteBox.java with ClassUnloadCommon from testlibrary
  • 43979fb: 8347428: Avoid using secret-key in specifications
  • 618c5eb: 8349183: [BACKOUT] Optimization for StringBuilder append boolean & null
  • bb837d2: 8342775: [Graal] java/util/concurrent/locks/Lock/OOMEInAQS.java fails OOME thrown from the UncaughtExceptionHandler
  • a57c9b1: 8349184: [JMH] jdk.incubator.vector.ColumnFilterBenchmark.filterDoubleColumn fails on linux-aarch64
  • d330421: 8337548: Parallel class loading can pass is_superclass true for interfaces
  • 3f1d9b5: 8348575: SpinLockT is typedef'ed but unused
  • 6f4fc82: 8348675: TrayIcon tests fail in Ubuntu 24.10 Wayland

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 4, 2025

@chhagedorn Pushed as commit c545a3e.

💡 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-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants