Skip to content

Conversation

@eme64
Copy link
Contributor

@eme64 eme64 commented Oct 30, 2025

It seems we keep finding issues in CompressBitsNode::Value, using the TemplateFramework #26885.

This is a JDK26 regression of the bugfix #23947, which was itself reported by my prototype of the TemplateFramework.

The bug is simple: On windows 1UL is only a 32-bit value, and not a 64-bit value. We should use 1ULL instead. Impacted lines:

hi = (1UL << bitcount) - 1;

hi = MIN2((jlong)((1UL << result_bit_width) - 1L), hi);

This means that simple cases like these wrongly constant fold to zero:

  • Long.compress(-2683206580L, Integer.toUnsignedLong(x))
  • Long.compress(x, 0xffff_ffffL)

This sort of bug (1UL vs 1ULL) is of course very subtle, and easy to miss in a code review. So that is why testing is paramount.

Why was this not caught in the testing of #23947? After all there were quite a few tests there, right? There were simply not enough tests, or not the right ones ;)

I did at the time ask for a "range-based" test (#23947 (comment)). I then doubled down and even proposed a conctete test (#23947 (comment)) that would create "range-based" inputs:

public static test(int mask, int src) {
  mask = Math.max(CON1, Math.min(CON2, mask));
  src = Math.max(CON2, Math.min(CON4, src));
  result = Integer.compress(src, mask);
  int sum = 0;
  if (sum > LIMIT_1) { sum += 1; }
  if (sum > LIMIT_2) { sum += 2; }
  if (sum > LIMIT_3) { sum += 4; }
  if (sum > LIMIT_4) { sum += 8; }
  if (sum > LIMIT_5) { sum += 16; }
  if (sum > LIMIT_6) { sum += 32; }
  if (sum > LIMIT_7) { sum += 64; }
  if (sum > LIMIT_8) { sum += 128; }
  return new int[] {sum, result};
}

What is implortant here: both the src and mask must have random ranges. But the test that ended up being integrated only made the src "range-based" using the min/max. Without the mask being tested "range-based", the bug here could not have been caught by that test.

I was asked again for my review (#23947 (comment)), but I had to go on vacation, and was not able to catch the issue (#23947).


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-8370459: C2: CompressBitsNode::Value produces wrong result on Windows (1UL vs 1ULL), found by ExpressionFuzzer (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28062

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@eme64 eme64 changed the title Jdk 8370459 expression fuzz failure JDK-8370459 Oct 30, 2025
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 30, 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 30, 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:

8370459: C2: CompressBitsNode::Value produces wrong result on Windows (1UL vs 1ULL), found by ExpressionFuzzer

Reviewed-by: dlong, jbhateja, 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 46 new commits pushed to 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-8370459 8370459: Test compiler/igvn/ExpressionFuzzer.java failed: Value mismatch: false vs true Oct 30, 2025
@openjdk
Copy link

openjdk bot commented Oct 30, 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 8370459: Test compiler/igvn/ExpressionFuzzer.java failed: Value mismatch: false vs true 8370459: C2: CompressBitsNode::Value produces wrong result on Windows (1UL vs 1ULL), found by ExpressionFuzzer Oct 31, 2025
@eme64 eme64 marked this pull request as ready for review October 31, 2025 05:45
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 31, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 31, 2025

Webrevs

Copy link
Member

@jatin-bhateja jatin-bhateja left a comment

Choose a reason for hiding this comment

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

Hi @eme64,
Your fix looks good to me!
Thanks for addressing this.

Best Regards

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 31, 2025
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.

Looks good to me. Thank you for your persistence on improving our testing! Good that we caught this in-time for JDK 26.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Oct 31, 2025
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 31, 2025
// We can further constrain the upper bound of bit compression if the number of bits
// which can be set(one) is less than the maximum number of bits of integral type.
hi = MIN2((jlong)((1UL << result_bit_width) - 1L), hi);
hi = MIN2((jlong)((1ULL << result_bit_width) - 1L), hi);
Copy link
Member

Choose a reason for hiding this comment

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

It seems weird having - 1L mixed with ULL now. It might be better to use right_n_bits_typed() here and at line 276.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea, I did not know about right_n_bits_typed :)

@openjdk
Copy link

openjdk bot commented Oct 31, 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).

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

eme64 commented Oct 31, 2025

@dean-long Does it look better now?

@dean-long
Copy link
Member

@dean-long Does it look better now?

Yes, much better, thanks!

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

eme64 commented Nov 3, 2025

@dean-long @TobiHartmann @jatin-bhateja thanks for the quick reviews!

/integrate

@openjdk
Copy link

openjdk bot commented Nov 3, 2025

Going to push as commit 0ca0852.
Since your change was applied there have been 56 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 Nov 3, 2025
@openjdk openjdk bot closed this Nov 3, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 3, 2025
@openjdk
Copy link

openjdk bot commented Nov 3, 2025

@eme64 Pushed as commit 0ca0852.

💡 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 [email protected] integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants