RFR: 8327109: Refactor data graph cloning used in create_new_if_for_predicate() into separate class

Christian Hagedorn chagedorn at openjdk.org
Fri Mar 1 13:34:00 UTC 2024


On Fri, 1 Mar 2024 13:27:38 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:

> In the review process of https://github.com/openjdk/jdk/pull/16877, we identified an existing issue in `create_bool_from_template_assertion_predicate()` which is also still present in the refactoring of https://github.com/openjdk/jdk/pull/16877: In rare cases, we could endlessly re-process nodes in the DFS walk since a visited set is missing. This needs to be addressed.
> 
> #### Redo refactoring of `create_bool_from_template_assertion_predicate()`
> On top of that bug, the refactored version of https://github.com/openjdk/jdk/pull/16877 is still quite complicated to understand since it tries to do multiple steps simultaneously. We've decided to redo the refactoring and better separate the steps to simplify the algorithm. By doing so, we also want to fix the existing bug. This work is split into three separate RFEs (JDK-8327109, JDK-8327110, and JDK-8327111).
> 
> #### Share data graph cloning code - start from existing code 
> This first PR starts with the existing code found in `clone_nodes_with_same_ctrl()` which is called by `create_new_if_for_predicate()`. `clone_nodes_with_same_ctrl()` already does the data graph cloning in 3 separate steps which can be used as foundation:
> 
> 1. Collect data nodes to clone by using a node filter
> 2. Clone the collected nodes (their data and control inputs still point to the old nodes)
> 3. Fix the cloned data node inputs pointing to the old nodes to the cloned inputs by using an old->new mapping. In this pass, also fix the control inputs of any pinned data node from the old uncommon projection to the new one.
> 
> #### Shared data graph cloning class
> Some of these steps above are shared with the data graph cloning done in `create_bool_from_template_assertion_predicate()` (refactored in JDK-8327110 and JDK-8327111). We therefore extract them in this patch such that we can reuse it in the refactoring for `create_bool_from_template_assertion_predicate()` later. We create a new `DataNodeGraph` class which does the following (to be shared) cloning of a data graph:
> 
> 1. Take a collection of data nodes (the collection step is different in `clone_nodes_with_same_ctrl()` compared to `create_bool_from_template_assertion_predicate()` and thus cannot be shared) and clone them. [Same as step 2 above]
>  2. Fix the cloned data node inputs pointing to the old nodes to the cloned inputs by using an old->new mapping. [Same as first part of step 3 above but drop the second part of rewiring control inputs which is specific to `clone_nodes_with_same_ctrl()`]
> 
> `...

src/hotspot/share/opto/loopPredicate.cpp line 220:

> 218: void PhaseIdealLoop::set_ctrl_of_nodes_with_same_ctrl(Node* start_node, ProjNode* old_uncommon_proj,
> 219:                                                       Node* new_uncommon_proj) {
> 220:   ResourceMark rm;

Added `ResourceMark`s which I think is now safe after [JDK-8325672](https://bugs.openjdk.org/browse/JDK-8325672).

src/hotspot/share/opto/loopPredicate.cpp line 250:

> 248:   DEBUG_ONLY(uint last_idx = C->unique();)
> 249:   Unique_Node_List nodes_with_same_ctrl = find_nodes_with_same_ctrl(node, old_ctrl);
> 250:   Dict old_new_mapping = clone_nodes(nodes_with_same_ctrl); // Cloned but not rewired, yet

Replaced `Dict` with `ResizeableResourceHashtable` which I think is preferable to use.

src/hotspot/share/opto/loopnode.hpp line 1353:

> 1351:   void fix_cloned_data_node_controls(
> 1352:       const ProjNode* old_uncommon_proj, Node* new_uncommon_proj,
> 1353:       const ResizeableResourceHashtable<Node*, Node*, AnyObj::RESOURCE_AREA, mtCompiler>& orig_to_new);

Mostly some renaming and adding `const`.

src/hotspot/share/opto/loopnode.hpp line 1899:

> 1897:         _data_nodes(data_nodes),
> 1898:         // Use 107 as best guess which is the first resize value in ResizeableResourceHashtable::large_table_sizes.
> 1899:         _orig_to_new(107, MaxNodeLimit)

I'm not sure if this is the right default value - was just a best guess. We usually only have a small number of data nodes to copy.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18080#discussion_r1509020430
PR Review Comment: https://git.openjdk.org/jdk/pull/18080#discussion_r1509011640
PR Review Comment: https://git.openjdk.org/jdk/pull/18080#discussion_r1509016113
PR Review Comment: https://git.openjdk.org/jdk/pull/18080#discussion_r1509014377


More information about the hotspot-compiler-dev mailing list