-
Notifications
You must be signed in to change notification settings - Fork 6k
8273139: C2: assert(f <= 1 && f >= 0) failed: Incorrect frequency #7113
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
👋 Welcome back eme64! A progress list of the required criteria for merging this PR into |
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.
Nice analysis and summary! Looks good.
@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:
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 40 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 (@TobiHartmann, @chhagedorn, @rwestrel) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
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.
Great analysis! Looks good to me, too.
Would it make sense to use better precision ( |
Thanks for your comment, @dean-long. I do not think that changing from The only use of Changing from @dean-long : what would you recommend? @rwestrel : what do you think? |
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.
I think Dean's suggestion is to only to use double locally that is in PathFrequency::to(). I suppose that would be feasible. What do you think? In any case, this logic is used to help c2 decides whether a transformation is beneficial or not. In case of precision errors, worst case, that decision will be slightly wrong and performance should be minimally affected. As far as logging precision errors we can detect: I don't think it's telling us something that's actionable. It doesn't even suggest that something has gone wrong. So I don't think it's useful. |
That would be feasible. But it will not fix the issue, since bad rounding can already happen outside (computing the probabilities and counts). This is most likely why this bug was reported: inside the method we paid attention to round correctly, but the outside numbers most likely had rounding errors, such that if they were added in some adversarial order, they add up to Assume a |
Based on the extra discussion, it sounds like my suggestions don't really help, which is completely acceptable. Ship it! |
Thanks @dean-long @rwestrel for the comments and help :) |
/integrate |
/sponsor |
Going to push as commit 68b40ec.
Your commit was automatically rebased without conflicts. |
@TobiHartmann @eme64 Pushed as commit 68b40ec. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Relaxed assert which can be triggered falsely upon an unfortunate sequence of float additions, such that the sum of all probabilities exceeds 1 by some very small amount in the order of float precision.
Before: assert(f <= 1 && f >= 0)
Now: assert(f >= 0), truncate f to be <=1
Frequency computation is done with floats, which are calculated through counting occurrences and dividing by totals.
This is done in multiple locations in the code.
We considered three options (in conversation with @rwestrel @chhagedorn @tobiasholenstein ):
fesetround
to correctly round up/down (depends on context) if the results are ever used for frequency/probability calculations (many locations, multiple files). This option requires more code and maintainance. Implementing and testing is difficult. This is fragile if new code is added that impacts frequency computation - would have to remember to round correctly.f <= 1+eps && 1 >= 0
, whereeps
is related to float precision, and is as close to zero as possible. However, since there can be an arbitrary number of additions, this error could grow arbitrarily. It is thus not evident how to determineeps
.f <= 1
condition (our choice). The exact comparison is inadequate for floats, and there is no evident replacement. This requires less code, is easier to maintain. Disadvantage: a developer may break something and not realize because the assert is no longer present. The impact would most likely be limited to performance, and not crash the VM or cause incorrect execution.Checked that tests are not affected.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7113/head:pull/7113
$ git checkout pull/7113
Update a local copy of the PR:
$ git checkout pull/7113
$ git pull https://git.openjdk.java.net/jdk pull/7113/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7113
View PR using the GUI difftool:
$ git pr show -t 7113
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7113.diff