-
Notifications
You must be signed in to change notification settings - Fork 6.3k
8350485: C2: factor out common code in Node::grow() and Node::out_grow() #23928
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
Conversation
Hi @sarannat, welcome to this OpenJDK project and thanks for contributing! We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user sarannat" as summary for the issue. If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing |
@sarannat 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:
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 184 new commits pushed to the
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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@eme64, @TobiHartmann, @robcasloz) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/covered |
Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarannat I'm mostly leaving code style comments. I promise I won't be so pedantic in the future ;)
It may be good for you to read through this, at least to have an overview:
https://github.com/openjdk/jdk/blob/master/doc/hotspot-style.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations on your first PR, Saranya! 🥳
I also left a code style comment but looks good to me otherwise.
src/hotspot/share/opto/node.cpp
Outdated
_in = (Node**)arena->Arealloc(_in, _max*sizeof(Node*), new_max*sizeof(Node*)); | ||
Copy::zero_to_bytes(&_in[_max], (new_max-_max)*sizeof(Node*)); // null all new space | ||
_max = new_max; // Record new max length | ||
if(!is_in){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(!is_in){ | |
if (!is_in) { |
Same below.
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning up this code, Saranya! I have a few more style/naming suggestions, the refactored logic looks otherwise good to me.
src/hotspot/share/opto/node.hpp
Outdated
// Resize input or output array to grow it the next larger power-of-2 bigger | ||
// than len. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Resize input or output array to grow it the next larger power-of-2 bigger | |
// than len. | |
// Resize input or output array to grow it to the next larger power-of-2 | |
// bigger than len. |
src/hotspot/share/opto/node.cpp
Outdated
//------------------------------grow------------------------------------------- | ||
// Grow the input array, making space for more edges | ||
void Node::grow(uint len) { | ||
// Resize input or output array to grow it the next larger power-of-2 bigger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Resize input or output array to grow it the next larger power-of-2 bigger | |
// Resize input or output array to grow it to the next larger power-of-2 bigger |
src/hotspot/share/opto/node.cpp
Outdated
// This assertion makes sure that Node::_max is wide enough to | ||
// represent the numerical value of new_max. | ||
assert(_max == new_max && _max > len, "int width of _max is too small"); | ||
assert(max_size == new_max && max_size > len, "int width of _max is too small"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pre-existing, but I think it is worth simplifying anyway:
assert(max_size == new_max && max_size > len, "int width of _max is too small"); | |
assert(max_size > len, "int width of _max is too small"); |
src/hotspot/share/opto/node.cpp
Outdated
new_max = next_power_of_2(len); | ||
// Trimming to limit allows a uint8 to handle up to 255 edges. | ||
// Previously I was using only powers-of-2 which peaked at 128 edges. | ||
//if( new_max >= limit ) new_max = limit-1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to remove this line that was already commented out before this changeset.
src/hotspot/share/opto/node.cpp
Outdated
if (!is_input_array) { | ||
assert(array != nullptr && array != NO_OUT_ARRAY, "out must have sensible value"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is somewhat subjective, but I prefer to inline the !is_input_array
pre-condition into the assertion itself, for compactness.
if (!is_input_array) { | |
assert(array != nullptr && array != NO_OUT_ARRAY, "out must have sensible value"); | |
} | |
assert(is_input_array || (array != nullptr && array != NO_OUT_ARRAY), "out must have sensible value"); |
src/hotspot/share/opto/node.cpp
Outdated
|
||
//-----------------------------out_grow---------------------------------------- | ||
// Grow the input array, making space for more edges | ||
void Node::out_grow( uint len ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For style consistency with Node::grow
:
void Node::out_grow( uint len ) { | |
void Node::out_grow(uint len) { |
src/hotspot/share/opto/node.cpp
Outdated
void Node::grow(uint len) { | ||
// Resize input or output array to grow it the next larger power-of-2 bigger | ||
// than len. | ||
void Node::resize_array(Node**& array, node_idx_t& max_size, uint len, bool is_input_array) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is subjective, but I would find it clearer if the name of bool is_input_array
reflected what does resize_array
needs to do with array
rather than what is the source/origin of array
. My suggestion would be something like bool needs_clearing
, bool initialize_to_null
, or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me too.
/integrate |
/sponsor |
Going to push as commit 8f64ccc.
Your commit was automatically rebased without conflicts. |
@robcasloz @sarannat Pushed as commit 8f64ccc. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Node:grow() and Node::out_grow() are copy-pasted from each other and their core logic could be factored out into a third function or at least cleaned up. Hence,the fix includes a function Node::array_resize() that implements the core logic of Node::grow() and Node::out_grow().
Link to Github action which had no failures : https://github.com/sarannat/jdk/actions/runs/13677508359
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23928/head:pull/23928
$ git checkout pull/23928
Update a local copy of the PR:
$ git checkout pull/23928
$ git pull https://git.openjdk.org/jdk.git pull/23928/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 23928
View PR using the GUI difftool:
$ git pr show -t 23928
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23928.diff
Using Webrev
Link to Webrev Comment