RFR: 8360510: C2: Template Assertion Predicates are not cloned to the inner counted loop with -XX:+StressDuplicateBackedge [v2]

Christian Hagedorn chagedorn at openjdk.org
Tue Nov 25 12:37:25 UTC 2025


On Tue, 25 Nov 2025 10:38:21 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

> This makes me a little nervous, applying a fix only to debug. But maybe I don't have to be nervous, let's see ;)

See my answer to another comment below. I updated the comment here and at the use-site to make it more explicit why it's guarded with an `ifdef ASSERT`. Let me know if that's clearer.

> src/hotspot/share/opto/loopopts.cpp line 4496:
> 
>> 4494: 
>> 4495: #ifdef ASSERT
>> 4496:   if (StressDuplicateBackedge && head->is_CountedLoop()) {
> 
> Could we somehow add an assert here?
> 
> Would this work?
> `assert(StressDuplicateBackedge || !head->is_CountedLoop(), "counted loop only expected in stress mode");`
> 
> That would give us some additional confidence that this only happens in debug.
> 
> But then why limit the fix to debug, and not apply it to product too, just in case the assert fails?

We already have such an assert at the entry of this method which is why I did not add an additional assert here:
https://github.com/openjdk/jdk/blob/49176e322bbb9ed1ef2f534b949b937770b54162/src/hotspot/share/opto/loopopts.cpp#L4231-L4235

The fix is limited to debug builds only because we can only have a counted loop here if we run with `StressDuplicateBackedge`. Otherwise, it's a normal `Loop` which does not have Template Assertion Predicates above it. Since `StressDuplicateBackedge` is a develop flag, it will always be false in product.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28389#discussion_r2559790206
PR Review Comment: https://git.openjdk.org/jdk/pull/28389#discussion_r2559756340


More information about the hotspot-compiler-dev mailing list